|
|
|
@ -1,23 +1,33 @@
|
|
|
|
|
package com.chanko.yunxi.mes.module.biz.manager;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.chanjet.openapi.sdk.java.exception.ChanjetApiException;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.chanjet.ChanjetSpi;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.chanjet.vo.CreateDepartmentVO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.chanjet.vo.QueryPartnerVO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.chanjet.vo.SimpleChanjetResponse;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.controller.admin.workshop.vo.WorkshopSaveReqVO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.dal.dataobject.customer.CustomerDO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.dal.dataobject.workshop.WorkshopDO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.dal.mysql.customer.CustomerMapper;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.enums.ValidStatusEnum;
|
|
|
|
|
import com.chanko.yunxi.mes.module.biz.service.workshop.WorkshopService;
|
|
|
|
|
import com.chanko.yunxi.mes.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.system.dal.dataobject.dept.DeptDO;
|
|
|
|
|
import com.chanko.yunxi.mes.module.system.service.dept.DeptService;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.chanko.yunxi.mes.module.biz.chanjet.ChanjetInterfaceEnum.CREATE_DEPARTMENT;
|
|
|
|
|
import static com.chanko.yunxi.mes.module.biz.chanjet.ChanjetInterfaceEnum.QUERY_CUSTOMER;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 畅捷通 管理类
|
|
|
|
@ -34,6 +44,8 @@ public class ChanjetManager {
|
|
|
|
|
private DeptService deptService;
|
|
|
|
|
@Resource
|
|
|
|
|
private WorkshopService workshopService;
|
|
|
|
|
@Resource
|
|
|
|
|
private CustomerMapper customerMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建部门
|
|
|
|
@ -77,4 +89,72 @@ public class ChanjetManager {
|
|
|
|
|
}
|
|
|
|
|
return workshopId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取客户数据
|
|
|
|
|
* @throws ChanjetApiException
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void queryCustomer() throws ChanjetApiException {
|
|
|
|
|
|
|
|
|
|
Long maxTs = null;
|
|
|
|
|
do {
|
|
|
|
|
QueryPartnerVO.QueryPartnerParamVO paramVO = new QueryPartnerVO.QueryPartnerParamVO(new HashMap<String, String>() {{
|
|
|
|
|
put("Name", "客户");
|
|
|
|
|
}}, maxTs);
|
|
|
|
|
SimpleChanjetResponse response = (SimpleChanjetResponse) chanjetSpi.execute(QUERY_CUSTOMER, new QueryPartnerVO(paramVO));
|
|
|
|
|
if(!response.isSuccess()){
|
|
|
|
|
throw new RuntimeException(response.getMessage());
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(response.getResult())){
|
|
|
|
|
List<Map> dataList = JSON.parseObject(JSON.toJSONString(response.getResult()), new TypeReference<List<Map>>() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 取最大 ts
|
|
|
|
|
Map tsMaxData = dataList.stream().sorted((Comparator.comparing(m -> 0 - Long.parseLong(String.valueOf(m.get("ts")))))).findFirst().get();
|
|
|
|
|
maxTs = Long.parseLong(String.valueOf(tsMaxData.get("ts")));
|
|
|
|
|
|
|
|
|
|
// 存在即更新不存在则插入
|
|
|
|
|
ArrayList<CustomerDO> customerList = new ArrayList<>(16);
|
|
|
|
|
ArrayList<CustomerDO> insertCustomerList = new ArrayList<>(16);
|
|
|
|
|
ArrayList<CustomerDO> updateCustomerList = new ArrayList<>(16);
|
|
|
|
|
dataList.forEach(dataMap -> {
|
|
|
|
|
// TODO 缺少其他字段
|
|
|
|
|
String code = String.valueOf(dataMap.get("code"));
|
|
|
|
|
String name = String.valueOf(dataMap.get("name"));
|
|
|
|
|
String shorthand = String.valueOf(dataMap.get("shorthand"));
|
|
|
|
|
|
|
|
|
|
CustomerDO customerSaveReqVO = new CustomerDO();
|
|
|
|
|
customerSaveReqVO.setCode(code).setName(name).setBrief(shorthand).setStatus(ValidStatusEnum.VALID.getCode());
|
|
|
|
|
customerList.add(customerSaveReqVO);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<String> codeList = customerList.stream().map(CustomerDO::getCode).collect(Collectors.toList());
|
|
|
|
|
List<CustomerDO> customerDOList = customerMapper.selectList(new LambdaQueryWrapper<CustomerDO>() {{
|
|
|
|
|
in(CustomerDO::getCode, codeList);
|
|
|
|
|
}});
|
|
|
|
|
Map<String, List<CustomerDO>> existsCustomers = customerDOList.stream().collect(Collectors.groupingBy(CustomerDO::getCode));
|
|
|
|
|
customerList.forEach(customerSaveReqVO -> {
|
|
|
|
|
List<CustomerDO> historyCustomerDOs = existsCustomers.get(customerSaveReqVO.getCode());
|
|
|
|
|
if(historyCustomerDOs != null){
|
|
|
|
|
// 对比字段 如有变化则更新
|
|
|
|
|
CustomerDO customerDO = historyCustomerDOs.get(0);
|
|
|
|
|
if(!customerDO.getName().equals(customerSaveReqVO.getName()) || !customerDO.getBrief().equals(customerSaveReqVO.getBrief())){
|
|
|
|
|
customerDO.setName(customerSaveReqVO.getName()).setBrief(customerSaveReqVO.getBrief());
|
|
|
|
|
updateCustomerList.add(customerDO);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
insertCustomerList.add(customerSaveReqVO);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 入库
|
|
|
|
|
if(!insertCustomerList.isEmpty()) customerMapper.insertBatch(insertCustomerList);
|
|
|
|
|
if(!updateCustomerList.isEmpty()) customerMapper.updateBatch(updateCustomerList);
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
maxTs = null;
|
|
|
|
|
}
|
|
|
|
|
}while (maxTs != null);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|