|
|
@@ -26,8 +26,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.github.kevinsawicki.http.HttpRequest;
|
|
|
import com.jdy.v7sdk.models.AccountGroupRequest;
|
|
|
import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springblade.check.dto.AuditProecessDTO;
|
|
|
import org.springblade.check.entity.AuditPathsActs;
|
|
|
import org.springblade.check.entity.AuditPathsLevels;
|
|
|
@@ -70,9 +72,15 @@ import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.io.Serializable;
|
|
|
+import javax.net.ssl.*;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.security.SecureRandom;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -83,6 +91,7 @@ import java.util.stream.Collectors;
|
|
|
* @author BladeX
|
|
|
* @since 2021-11-03
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlement> implements ISettlementService {
|
|
|
@@ -613,13 +622,16 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Settlement apply(List<Items> itemsList, String billType, String url) throws Exception {
|
|
|
+ public Settlement apply(List<Items> itemsList, String billType, String url,String pageStatus,String pageLabel,String checkType) throws Exception {
|
|
|
BigDecimal total = itemsList.stream().filter(e -> e.getAmount() != null && e.getCurrency().equals("CNY")).map(Items::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
BigDecimal foreignTotal = itemsList.stream().filter(e -> e.getAmount() != null && !e.getCurrency().equals("CNY")).map(Items::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
Settlement settlement = new Settlement();
|
|
|
settlement.setBillType(billType);
|
|
|
settlement.setCorpId(itemsList.get(0).getCorpId());
|
|
|
settlement.setUrl(url);
|
|
|
+ settlement.setPageStatus(pageStatus);
|
|
|
+ settlement.setPageLabel(pageLabel);
|
|
|
+ settlement.setCheckType(checkType);
|
|
|
settlement.setSrcOrderno(itemsList.get(0).getSrcOrderno());
|
|
|
//todo 系统编号暂时按时间戳, 后续按正式
|
|
|
settlement.setSysNo(String.valueOf(System.currentTimeMillis()));
|
|
|
@@ -636,6 +648,8 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
}
|
|
|
settlement.setSrcBillId(itemsList.get(0).getSrcParentId());
|
|
|
settlement.setCheckStatus("录入");
|
|
|
+ settlement.setDc("c");
|
|
|
+ settlement.setSettlementType(1);
|
|
|
baseMapper.insert(settlement);
|
|
|
|
|
|
itemsList.forEach(e -> {
|
|
|
@@ -683,6 +697,8 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
});
|
|
|
List<CorpsBank> corpsBanks = corpsDescClient.listBankByCorpId(settlement.getCorpId());
|
|
|
settlement.setBankList(corpsBanks);
|
|
|
+ //付费申请-直接开启审批
|
|
|
+ this.check(settlement);
|
|
|
return settlement;
|
|
|
|
|
|
|
|
|
@@ -690,7 +706,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void applyList(List<Items> itemsList, String billType, String url) {
|
|
|
+ public void applyList(List<Items> itemsList, String billType, String url,String pageStatus,String pageLabel,String checkType) {
|
|
|
Settlement settlement = new Settlement();
|
|
|
settlement.setBillType(billType);
|
|
|
settlement.setCorpId(itemsList.get(0).getCorpId());
|
|
|
@@ -701,7 +717,13 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
settlement.setTenantId(AuthUtil.getTenantId());
|
|
|
settlement.setCreateUser(AuthUtil.getUserId());
|
|
|
settlement.setStatus(0);
|
|
|
+ settlement.setDc("c");
|
|
|
+ settlement.setSettlementType(1);
|
|
|
settlement.setCheckStatus("未请核");
|
|
|
+ settlement.setUrl(url);
|
|
|
+ settlement.setPageStatus(pageStatus);
|
|
|
+ settlement.setPageLabel(pageLabel);
|
|
|
+ settlement.setCheckType(checkType);
|
|
|
baseMapper.insert(settlement);
|
|
|
|
|
|
|
|
|
@@ -709,7 +731,6 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
itemsList.forEach(e -> {
|
|
|
|
|
|
|
|
|
-
|
|
|
e.setPid(settlement.getId());
|
|
|
e.setCreateTime(new Date());
|
|
|
e.setTenantId(AuthUtil.getTenantId());
|
|
|
@@ -725,6 +746,8 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
settlement.setForeignAmount(e.getAmount());
|
|
|
}*/
|
|
|
});
|
|
|
+ //直接开启审批
|
|
|
+ this.check(settlement);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -802,6 +825,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
Acc acc = new Acc();
|
|
|
BeanUtils.copyProperties(e, acc);
|
|
|
acc.setId(null);
|
|
|
+ acc.setDc("d");
|
|
|
acc.setItemType(e.getItemType());
|
|
|
acc.setAccSysNo(e.getSrcOrderno());
|
|
|
acc.setSrcParentId(e.getSrcParentId());
|
|
|
@@ -918,6 +942,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
acc.setBillType(settlement.getBillType());
|
|
|
acc.setCreateTime(new Date());
|
|
|
acc.setStatus(0);
|
|
|
+ acc.setDc(settlement.getDc());
|
|
|
acc.setRemarks(e.getRemarks());
|
|
|
acc.setItemType(e.getItemType());
|
|
|
acc.setCreateUser(AuthUtil.getUserId());
|
|
|
@@ -1006,7 +1031,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
cLambdaQueryWrapper
|
|
|
.eq(JdModule::getAccountId,accountId)
|
|
|
.eq(JdModule::getModule,"销售订单")
|
|
|
- .eq(JdModule::getDc,"1")
|
|
|
+ .eq(JdModule::getDc,"-1")
|
|
|
.eq(JdModule::getTenantId,AuthUtil.getTenantId());
|
|
|
JdModule cModule = moduleMapper.selectOne(cLambdaQueryWrapper);
|
|
|
if(cModule==null)
|
|
|
@@ -1021,8 +1046,8 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
item.setEntries(entriesList);
|
|
|
jdYitems.add(item);
|
|
|
try {
|
|
|
- AccountGroupRequest accountGroupRequest = this.getAccountGroupRequest();
|
|
|
- String saveUrl="http://api.kingdee.com/jdy/gl/voucher_save?access_token="+accountGroupRequest.getAccessToken();
|
|
|
+ String token = this.getAccountGroupRequest();
|
|
|
+ String saveUrl="http://api.kingdee.com/jdy/gl/voucher_save?access_token="+token;
|
|
|
JdyTool.testSaveVoucher(saveUrl,accountId,groupName,jdYitems);
|
|
|
} catch (Exception exception) {
|
|
|
throw new SecurityException("操作失败,保存金蝶错误:"+exception.getMessage());
|
|
|
@@ -1082,7 +1107,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
}
|
|
|
|
|
|
//测试获取AccountGroupRequest
|
|
|
- public AccountGroupRequest getAccountGroupRequest() throws Exception
|
|
|
+ public String getAccountGroupRequest() throws Exception
|
|
|
{
|
|
|
//校验当前租户配置,如果存在配置,返回token
|
|
|
LambdaQueryWrapper<JdTenant> jdTenantLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
@@ -1094,16 +1119,18 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
{
|
|
|
throw new SecurityException("当前租户未配置凭证信息");
|
|
|
}
|
|
|
- TokenRequestQuery tokenRequestQuery = TokenRequestQuery.build(TeaConverter.buildMap(
|
|
|
- new TeaPair("clientId", jdTenant.getClientId()),
|
|
|
- new TeaPair("clientSecret", jdTenant.getClientSecret()),
|
|
|
- new TeaPair("username", jdTenant.getUsername()),
|
|
|
- new TeaPair("password", jdTenant.getPassword())
|
|
|
- ));
|
|
|
- //获取token
|
|
|
- com.jdy.v7sdk.auth auth = new com.jdy.v7sdk.auth();
|
|
|
- AccountGroupRequest accessTokenObject = auth.getToken(tokenRequestQuery);
|
|
|
- return accessTokenObject;
|
|
|
+ //获取token的url
|
|
|
+ //String getTokenUrl="https://api.kingdee.com/auth/user/access_token";
|
|
|
+ String getTokenUrl="https://api.kingdee.com/auth/user/access_token?client_id=205022&client_secret=1b16d77089b1e60b3f7c907aa3cc612e&username=17220202021&password=Jdy202101";
|
|
|
+ Map<String, String> urlParams=new HashMap<>();
|
|
|
+ /*urlParams.put("clientId",jdTenant.getClientId());
|
|
|
+ urlParams.put("client_secret",jdTenant.getClientSecret());
|
|
|
+ urlParams.put("username",jdTenant.getUsername());
|
|
|
+ urlParams.put("password",jdTenant.getPassword());*/
|
|
|
+ String result = this.doGet(getTokenUrl, urlParams);
|
|
|
+ tokenDTO tokenDTO = JSONObject.parseObject(result, tokenDTO.class);
|
|
|
+ String accessToken = tokenDTO.getData().getAccess_token();
|
|
|
+ return accessToken;
|
|
|
}
|
|
|
|
|
|
/* //测试获取套账
|
|
|
@@ -1129,7 +1156,178 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
}*/
|
|
|
|
|
|
|
|
|
+ public String doGet(String url, Map<String, String> urlParams)
|
|
|
+ throws IOException {
|
|
|
+ if (isEmpty(url)) {
|
|
|
+ throw new IllegalArgumentException("The parameter 'url' can not be null or blank.");
|
|
|
+ }
|
|
|
+ url += buildQuery(urlParams, "UTF-8");
|
|
|
+ HttpURLConnection conn = getConnection(new URL(url), "GET");
|
|
|
+ String s = getResponseAsString(conn);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断字符串为空
|
|
|
+ *
|
|
|
+ * @param str 字符串信息
|
|
|
+ * @return true or false
|
|
|
+ */
|
|
|
+ private boolean isEmpty(String str) {
|
|
|
+ return str == null || str.trim().length() == 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param params 请求参数
|
|
|
+ * @return 构建query
|
|
|
+ */
|
|
|
+ public String buildQuery(Map<String, String> params, String charset) throws UnsupportedEncodingException {
|
|
|
+ if (params == null || params.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ boolean first = true;
|
|
|
+ for (Map.Entry<String, String> entry : params.entrySet()) {
|
|
|
+ if (first) {
|
|
|
+ sb.append("?");
|
|
|
+ first = false;
|
|
|
+ } else {
|
|
|
+ sb.append("&");
|
|
|
+ }
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ if (areNotEmpty(key, value)) {
|
|
|
+ sb.append(key).append("=").append(URLEncoder.encode(value, charset));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断字符数组,不为空
|
|
|
+ *
|
|
|
+ * @param values 字符数组
|
|
|
+ * @return true or false
|
|
|
+ */
|
|
|
+ public boolean areNotEmpty(String... values) {
|
|
|
+ if (values == null || values.length == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String value : values) {
|
|
|
+ if (isEmpty(value)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private HttpURLConnection getConnection(URL url, String method)
|
|
|
+ throws IOException {
|
|
|
+
|
|
|
+ HttpURLConnection conn;
|
|
|
+ if ("https".equals(url.getProtocol())) {
|
|
|
+ SSLContext ctx;
|
|
|
+ try {
|
|
|
+ ctx = SSLContext.getInstance("TLS");
|
|
|
+ ctx.init(new KeyManager[0], new TrustManager[] { new DefaultTrustManager() },
|
|
|
+ new SecureRandom());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IOException(e);
|
|
|
+ }
|
|
|
+ HttpsURLConnection connHttps = (HttpsURLConnection) url.openConnection();
|
|
|
+ connHttps.setSSLSocketFactory(ctx.getSocketFactory());
|
|
|
+ connHttps.setHostnameVerifier(new HostnameVerifier() {
|
|
|
+
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;// 默认都认证通过
|
|
|
+ }
|
|
|
+ });
|
|
|
+ conn = connHttps;
|
|
|
+ } else {
|
|
|
+ conn = (HttpURLConnection) url.openConnection();
|
|
|
+ }
|
|
|
+ conn.setRequestMethod(method);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ conn.setRequestProperty("Connection", "Keep-Alive");
|
|
|
+ return conn;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ private static class DefaultTrustManager implements X509TrustManager {
|
|
|
+
|
|
|
+ public X509Certificate[] getAcceptedIssuers() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkClientTrusted(X509Certificate[] cert, String oauthType)
|
|
|
+ throws java.security.cert.CertificateException {
|
|
|
+ }
|
|
|
|
|
|
+ public void checkServerTrusted(X509Certificate[] cert, String oauthType)
|
|
|
+ throws java.security.cert.CertificateException {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String getResponseAsString(HttpURLConnection conn) throws IOException {
|
|
|
+ InputStream es = conn.getErrorStream();
|
|
|
+ if (es == null) {
|
|
|
+ return getStreamAsString(conn.getInputStream(), "UTF-8");
|
|
|
+ } else {
|
|
|
+ String msg = getStreamAsString(es, "UTF-8");
|
|
|
+ if (isEmpty(msg)) {
|
|
|
+ throw new IOException(conn.getResponseCode() + " : " + conn.getResponseMessage());
|
|
|
+ } else {
|
|
|
+ throw new IOException(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStreamAsString(InputStream input, String charset) throws IOException {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ BufferedReader bf = null;
|
|
|
+ try {
|
|
|
+ bf = new BufferedReader(new InputStreamReader(input, charset));
|
|
|
+ String str;
|
|
|
+ while ((str = bf.readLine()) != null) {
|
|
|
+ sb.append(str);
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ } finally {
|
|
|
+ if (bf != null) {
|
|
|
+ bf.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ @Data
|
|
|
+ public class tokenDTO
|
|
|
+ {
|
|
|
+ private Long errcode;
|
|
|
+
|
|
|
+ private String description;
|
|
|
+
|
|
|
+ private tokenData data;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public class tokenData
|
|
|
+ {
|
|
|
+ private String access_token;
|
|
|
+ private String avatar;
|
|
|
+ private String expires;
|
|
|
+ private String expires_in;
|
|
|
+ private String gender;
|
|
|
+ private String nickname;
|
|
|
+ private String uid;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|