|
|
@@ -24,9 +24,11 @@ import com.aliyun.tea.TeaConverter;
|
|
|
import com.aliyun.tea.TeaPair;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
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;
|
|
|
@@ -44,6 +46,7 @@ import org.springblade.deliver.goods.feign.IDeliveryClient;
|
|
|
import org.springblade.finance.TokenRequestQuery;
|
|
|
import org.springblade.finance.dto.SettlementDTO;
|
|
|
import org.springblade.finance.entity.InvoiceItem;
|
|
|
+import org.springblade.finance.entity.JdCorps;
|
|
|
import org.springblade.finance.entity.JdModule;
|
|
|
import org.springblade.finance.entity.JdTenant;
|
|
|
import org.springblade.finance.enums.SettlementEnum;
|
|
|
@@ -120,8 +123,14 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
|
|
|
private JdModuleMapper moduleMapper;
|
|
|
|
|
|
+ private JdCorpsMapper corpsMapper;
|
|
|
+
|
|
|
private InvoiceItemMapper invoiceItemMapper;
|
|
|
|
|
|
+ private static final String DEFAULT_CHARSET = "UTF-8";
|
|
|
+
|
|
|
+ private static final String METHOD_POST = "POST";
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public IPage<SettlementVO> selectSettlementPage(IPage<SettlementVO> page, SettlementVO settlement) {
|
|
|
@@ -202,9 +211,71 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
@Override
|
|
|
@Transactional
|
|
|
@GlobalTransactional
|
|
|
- public Settlement modify(SettlementDTO settlementDTO) {
|
|
|
+ public Settlement modify(SettlementDTO settlementDTO)
|
|
|
+ {
|
|
|
Long id = settlementDTO.getId();
|
|
|
Settlement settlement = baseMapper.selectById(id);
|
|
|
+ String corpsName=null;
|
|
|
+ R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(settlement.getCorpId());
|
|
|
+ if(corpMessage.isSuccess()&&corpMessage.getData()!=null)
|
|
|
+ {
|
|
|
+ corpsName=corpMessage.getData().getCname();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //测试账套-保存凭证
|
|
|
+ if (settlement.getTenantId().equals("681169"))
|
|
|
+ {
|
|
|
+ //查询原始订单的类型,销售 还是 采购
|
|
|
+ if(StringUtils.isNotBlank(settlement.getSrcOrderno()))
|
|
|
+ {
|
|
|
+ Order mode=new Order();
|
|
|
+ mode.setOrderNo(settlement.getSrcOrderno());
|
|
|
+ Order order = orderDescClient.getByOrder(mode);
|
|
|
+ if(order==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("原始单据不存在 或者 已被删除");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //销售
|
|
|
+ if(order.getBillType().equals("XS"))
|
|
|
+ {
|
|
|
+ //销售收款-保存凭证
|
|
|
+ if(settlement.getSettlementType()==1 && settlement.getBillType().equals("收费"))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ String accountName="金蝶开发者测试账套";
|
|
|
+ //测试账套-销售保存凭证
|
|
|
+ this.testSaleCollectionSaveVoucher(accountName,corpsName,settlement.getAmount().toString());
|
|
|
+ }
|
|
|
+ catch (Exception exception)
|
|
|
+ {
|
|
|
+ throw new SecurityException(exception.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //采购
|
|
|
+ else if(order.getBillType().equals("CG"))
|
|
|
+ {
|
|
|
+ //采购付款-保存凭证
|
|
|
+ if(settlement.getSettlementType()==1 && settlement.getBillType().equals("付费"))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
if (settlement == null) {
|
|
|
throw new SecurityException("未查到结算单,禁止操作");
|
|
|
}
|
|
|
@@ -808,12 +879,13 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- String accountName="开发者测试账套";
|
|
|
- this.testSaveVoucher(accountName,e);
|
|
|
+ String accountName="金蝶开发者测试账套";
|
|
|
+ //测试账套-销售保存凭证
|
|
|
+ this.testSaleSaveVoucher(accountName,e);
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
- throw new SecurityException("产生凭证失败:"+exception.getMessage());
|
|
|
+ throw new SecurityException(exception.getMessage());
|
|
|
}
|
|
|
}
|
|
|
if (e.getSrcType() == 2) {
|
|
|
@@ -1173,9 +1245,97 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
invoiceItemMapper.updateById(invoiceItem);
|
|
|
}
|
|
|
|
|
|
+ //金蝶保存凭证测试-销售收款生成凭证
|
|
|
+ public void toSaleCollectionJinDie(String Account,String corpName,String accountId,String groupName,JdTenant jdTenant)
|
|
|
+ {
|
|
|
+ JDYitems item = new JDYitems();
|
|
|
+ item.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
|
|
|
+ List<JDYentries> entriesList = new ArrayList<>();
|
|
|
+ List<JDYitems> jdYitems = new ArrayList<>();
|
|
|
+
|
|
|
+ //财务借方
|
|
|
+ JDYentries d = new JDYentries();
|
|
|
+ d.setDc("1");
|
|
|
+ LambdaQueryWrapper<JdModule> dLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ dLambdaQueryWrapper
|
|
|
+ .eq(JdModule::getAccountId,accountId)
|
|
|
+ .eq(JdModule::getModule,"销售收款")
|
|
|
+ .eq(JdModule::getDc,"1")
|
|
|
+ .eq(JdModule::getTenantId,AuthUtil.getTenantId());
|
|
|
+ JdModule dModule = moduleMapper.selectOne(dLambdaQueryWrapper);
|
|
|
+ if(dModule==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("获取销售订单科目号失败");
|
|
|
+ }
|
|
|
+ d.setExplanation("收款-"+ corpName);
|
|
|
+ d.setAccount_number(dModule.getProjectCode());
|
|
|
+ d.setDebitamount(Account);
|
|
|
+ entriesList.add(d);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //财务贷方
|
|
|
+ JDYentries c = new JDYentries();
|
|
|
+ c.setDc("-1");
|
|
|
+
|
|
|
+ LambdaQueryWrapper<JdModule> cLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ cLambdaQueryWrapper
|
|
|
+ .eq(JdModule::getAccountId,accountId)
|
|
|
+ .eq(JdModule::getModule,"销售收款")
|
|
|
+ .eq(JdModule::getDc,"-1")
|
|
|
+ .eq(JdModule::getTenantId,AuthUtil.getTenantId());
|
|
|
+ JdModule cModule = moduleMapper.selectOne(cLambdaQueryWrapper);
|
|
|
+ if(cModule==null)
|
|
|
+ {
|
|
|
+ throw new SecurityException("获取销售订单科目号失败");
|
|
|
+ }
|
|
|
+ c.setExplanation("收款-"+ corpName);
|
|
|
+ c.setAccount_number(cModule.getProjectCode());
|
|
|
+ c.setCreditamount(Account);
|
|
|
+
|
|
|
+
|
|
|
+ //===========辅助核算=================
|
|
|
+ List<JDYassist> cList=new ArrayList<>();
|
|
|
+
|
|
|
+ //查询客户
|
|
|
+ String jdCorpName="测试客户";//具体到时候用哪个客户,需要关联查询传参,今天先用测试的
|
|
|
+ LambdaQueryWrapper<JdCorps> corpsQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ corpsQueryWrapper
|
|
|
+ .eq(JdCorps::getAccountId,accountId)
|
|
|
+ .eq(JdCorps::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .eq(JdCorps::getCorpsName,jdCorpName);
|
|
|
+ JdCorps jdCorps = corpsMapper.selectOne(corpsQueryWrapper);
|
|
|
+
|
|
|
+ JDYassist jdYassist=new JDYassist();
|
|
|
+ jdYassist.setType("bd_customer");
|
|
|
+ if(jdCorps!=null)
|
|
|
+ {
|
|
|
+ jdYassist.setNumber(jdCorps.getCorpsCode());
|
|
|
+ }
|
|
|
+ cList.add(jdYassist);
|
|
|
+ c.setAssist(cList);
|
|
|
+ //===========辅助核算=================
|
|
|
+
|
|
|
+
|
|
|
+ entriesList.add(c);
|
|
|
+
|
|
|
+
|
|
|
+ //组装数据
|
|
|
+ item.setEntries(entriesList);
|
|
|
+ jdYitems.add(item);
|
|
|
+ try {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- //金蝶保存凭证测试
|
|
|
- public void toJinDie(Items items,String accountId,String groupName,JdTenant jdTenant) {
|
|
|
+ //金蝶保存凭证测试-销售生成凭证
|
|
|
+ public void toSaleJinDie(Items items,String accountId,String groupName,JdTenant jdTenant) {
|
|
|
//不是某一家 直接返回
|
|
|
/*if (!AuthUtil.getTenantId().equals("681169")) {
|
|
|
return;
|
|
|
@@ -1220,7 +1380,17 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
{
|
|
|
throw new SecurityException("获取销售订单科目号失败");
|
|
|
}
|
|
|
- c.setExplanation("客户资料:" + items.getCorpName());
|
|
|
+ Long corpId = items.getCorpId();
|
|
|
+ String corpName=null;
|
|
|
+ if(corpId!=null)
|
|
|
+ {
|
|
|
+ R<CorpsDesc> corpMessage = corpsDescClient.getCorpMessage(corpId);
|
|
|
+ if(corpMessage.isSuccess()&& corpMessage.getData()!=null)
|
|
|
+ {
|
|
|
+ corpName=corpMessage.getData().getCname();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ c.setExplanation("客户资料:" + corpName);
|
|
|
c.setAccount_number(cModule.getProjectCode());
|
|
|
c.setCreditamount(items.getAmount().toString());
|
|
|
entriesList.add(c);
|
|
|
@@ -1262,14 +1432,92 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
return businessOverpaymentClient.updateOverpayment(overpayment);
|
|
|
}
|
|
|
|
|
|
+ //销售收款生成账单
|
|
|
+ public void testSaleCollectionSaveVoucher(String accountName,String corpName,String account)throws Exception
|
|
|
+ {
|
|
|
+ //非达沃特用户直接返回
|
|
|
+ if(!AuthUtil.getTenantId().equals("681169"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //获取token
|
|
|
+ String token = this.getAccountGroupRequest();
|
|
|
+ //获取套账url
|
|
|
+ String getAccountUrl="https://api.kingdee.com/jdy/sys/accountGroup?access_token="+token;
|
|
|
+ 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.doPost(getAccountUrl, urlParams);
|
|
|
+ JdyTool.getAccountGroup getAccountGroup = JSONObject.parseObject(result, JdyTool.getAccountGroup.class);
|
|
|
|
|
|
- public void testSaveVoucher(String accountName,Items items) throws Exception {
|
|
|
+ List<JdyTool.AccountGroup> list=new ArrayList<>();
|
|
|
+ if(!CollectionUtils.isNotEmpty(getAccountGroup.getData()))
|
|
|
+ {
|
|
|
+ throw new SecurityException("操作失败,暂无账套信息");
|
|
|
+ }
|
|
|
+ //获取此账号下,全部账套
|
|
|
+ getAccountGroup.getData().forEach(e->{
|
|
|
+ list.addAll(e.getAccountGroups());
|
|
|
+ });
|
|
|
+ //匹配账套
|
|
|
+ List<JdyTool.AccountGroup> groupList = list.stream().filter(e -> e.getAccountName().equals(accountName)).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isNotEmpty(groupList))
|
|
|
+ {
|
|
|
+ throw new SecurityException("未找到: "+accountName+" 的套账信息");
|
|
|
+ }
|
|
|
+ JdyTool.AccountGroup group = groupList.get(0);
|
|
|
+ //1.获取租户信息
|
|
|
+ LambdaQueryWrapper<JdTenant> jdTenantLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
+ jdTenantLambdaQueryWrapper
|
|
|
+ .eq(JdTenant::getIsEnable,1)
|
|
|
+ .eq(JdTenant::getTenantId,AuthUtil.getTenantId())
|
|
|
+ .eq(JdTenant::getAccountName,accountName);
|
|
|
+ JdTenant jdTenant = jdTenantMapper.selectOne(jdTenantLambdaQueryWrapper);
|
|
|
+ if(jdTenant==null)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //2.销售收款-保存凭证
|
|
|
+ toSaleCollectionJinDie(account,corpName,jdTenant.getAccountId(),group.getGroupName(),jdTenant);
|
|
|
+ }
|
|
|
+
|
|
|
+ //销售生成账单
|
|
|
+ public void testSaleSaveVoucher(String accountName,Items items) throws Exception
|
|
|
+ {
|
|
|
|
|
|
//非达沃特用户直接返回
|
|
|
if(!AuthUtil.getTenantId().equals("681169"))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
+ //获取token
|
|
|
+ String token = this.getAccountGroupRequest();
|
|
|
+ //获取套账url
|
|
|
+ String getAccountUrl="https://api.kingdee.com/jdy/sys/accountGroup?access_token="+token;
|
|
|
+ Map<String, String> urlParams=new HashMap<>();
|
|
|
+ String result = this.doPost(getAccountUrl, urlParams);
|
|
|
+ JdyTool.getAccountGroup getAccountGroup = JSONObject.parseObject(result, JdyTool.getAccountGroup.class);
|
|
|
+
|
|
|
+ List<JdyTool.AccountGroup> list=new ArrayList<>();
|
|
|
+ if(!CollectionUtils.isNotEmpty(getAccountGroup.getData()))
|
|
|
+ {
|
|
|
+ throw new SecurityException("操作失败,暂无账套信息");
|
|
|
+ }
|
|
|
+ //获取此账号下,全部账套
|
|
|
+ getAccountGroup.getData().forEach(e->{
|
|
|
+ list.addAll(e.getAccountGroups());
|
|
|
+ });
|
|
|
+ //匹配账套
|
|
|
+ List<JdyTool.AccountGroup> groupList = list.stream().filter(e -> e.getAccountName().equals(accountName)).collect(Collectors.toList());
|
|
|
+ if(!CollectionUtils.isNotEmpty(groupList))
|
|
|
+ {
|
|
|
+ throw new SecurityException("未找到: "+accountName+" 的套账信息");
|
|
|
+ }
|
|
|
+ JdyTool.AccountGroup group = groupList.get(0);
|
|
|
+
|
|
|
+
|
|
|
//1.获取套账信息
|
|
|
LambdaQueryWrapper<JdTenant> jdTenantLambdaQueryWrapper=new LambdaQueryWrapper<>();
|
|
|
jdTenantLambdaQueryWrapper
|
|
|
@@ -1282,10 +1530,8 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
- //2.保存套账
|
|
|
- toJinDie(items,jdTenant.getAccountId(),jdTenant.getGroupName(),jdTenant);
|
|
|
-
|
|
|
-
|
|
|
+ //2.销售保存凭证
|
|
|
+ toSaleJinDie(items,jdTenant.getAccountId(),group.getGroupName(),jdTenant);
|
|
|
}
|
|
|
|
|
|
//测试获取AccountGroupRequest
|
|
|
@@ -1301,9 +1547,12 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
{
|
|
|
throw new SecurityException("当前租户未配置凭证信息");
|
|
|
}
|
|
|
- //获取token的url
|
|
|
+ //获取测试账套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";
|
|
|
+ String getTokenUrl="https://api.kingdee.com/auth/user/access_token?client_id=" +jdTenant.getClientId()+
|
|
|
+ "&client_secret=" +jdTenant.getClientSecret()+
|
|
|
+ "&username=" +jdTenant.getUsername()+
|
|
|
+ "&password="+jdTenant.getPassword();
|
|
|
Map<String, String> urlParams=new HashMap<>();
|
|
|
/*urlParams.put("clientId",jdTenant.getClientId());
|
|
|
urlParams.put("client_secret",jdTenant.getClientSecret());
|
|
|
@@ -1311,6 +1560,10 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
urlParams.put("password",jdTenant.getPassword());*/
|
|
|
String result = this.doGet(getTokenUrl, urlParams);
|
|
|
tokenDTO tokenDTO = JSONObject.parseObject(result, tokenDTO.class);
|
|
|
+ if(tokenDTO.errcode==1006)
|
|
|
+ {
|
|
|
+ throw new SecurityException("当前密码错误次数超过限定值");
|
|
|
+ }
|
|
|
String accessToken = tokenDTO.getData().getAccess_token();
|
|
|
return accessToken;
|
|
|
}
|
|
|
@@ -1349,6 +1602,19 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
return s;
|
|
|
}
|
|
|
|
|
|
+ public String doPost(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, DEFAULT_CHARSET);
|
|
|
+ HttpURLConnection conn = getConnection(new URL(url), METHOD_POST);
|
|
|
+/* conn.setConnectTimeout(connectTimeOut);
|
|
|
+ conn.setReadTimeout(readTimeOut);
|
|
|
+ conn.getOutputStream().write(requestJson.getBytes(DEFAULT_CHARSET));*/
|
|
|
+ String s = getResponseAsString(conn);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断字符串为空
|
|
|
*
|
|
|
@@ -1489,7 +1755,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
|
|
|
}
|
|
|
@Data
|
|
|
- public class tokenDTO
|
|
|
+ public static class tokenDTO
|
|
|
{
|
|
|
private Long errcode;
|
|
|
|
|
|
@@ -1499,7 +1765,7 @@ public class SettlementServiceImpl extends ServiceImpl<SettlementMapper, Settlem
|
|
|
}
|
|
|
|
|
|
@Data
|
|
|
- public class tokenData
|
|
|
+ public static class tokenData
|
|
|
{
|
|
|
private String access_token;
|
|
|
private String avatar;
|