【需求】获取客户数据接口

dev
zengchenxi 6 months ago
parent d960bd8118
commit ed0e59df40

@ -70,4 +70,12 @@ public class ChanjetController {
public CommonResult<Long> createWorkshop(@Valid @RequestBody WorkshopSaveReqVO createReqVO) throws ChanjetApiException {
return success(chanjetManager.createWorkshop(createReqVO));
}
@PostMapping("/customer/query")
@Operation(summary = "获取客户数据")
@PreAuthorize("@ss.hasPermission('biz:customer:query')")
public CommonResult<Void> queryCustomer() throws ChanjetApiException {
chanjetManager.queryCustomer();
return success(null);
}
}

@ -5,6 +5,7 @@ import com.chanjet.openapi.sdk.java.ChanjetContent;
import com.chanjet.openapi.sdk.java.ChanjetResponse;
import com.chanjet.openapi.sdk.java.enums.HttpMethod;
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 lombok.Getter;
@ -17,6 +18,7 @@ import lombok.Getter;
public enum ChanjetInterfaceEnum {
CREATE_DEPARTMENT("/tplus/api/v2/department/Create", "创建部门", CreateDepartmentVO.class, SimpleChanjetResponse.class),
CREATE_WORKSHOP("/tplus/api/v2/department/Create", "创建车间", CreateDepartmentVO.class, SimpleChanjetResponse.class),
QUERY_CUSTOMER("/tplus/api/v2/partner/Query", "查询客户", QueryPartnerVO.class, SimpleChanjetResponse.class), // TODO reponse
;
private String uri;

@ -1,5 +1,6 @@
package com.chanko.yunxi.mes.module.biz.chanjet.vo;
import com.chanjet.openapi.sdk.java.AbstractChanjetContent;
import lombok.AllArgsConstructor;
import lombok.Data;
@ -20,12 +21,11 @@ import java.util.Map;
*/
@Data
@AllArgsConstructor
public class QueryPartnerVO {
public class QueryPartnerVO extends AbstractChanjetContent {
private Object param;
private QueryPartnerParamVO param;
@Data
@AllArgsConstructor
public static class QueryPartnerParamVO {
/*
@ -35,9 +35,20 @@ public class QueryPartnerVO {
* */
private Map<String,String> PartnerType;
private Integer pageSize;
private Integer pageSize = 100;
private String SelectFields = "ID,Code,Name,Disabled,Ts,";
private String SelectFields = "ID,Code,Name,Disabled,TS,Shorthand";
private Long TS;
public QueryPartnerParamVO(Map<String, String> partnerType) {
PartnerType = partnerType;
}
public QueryPartnerParamVO(Map<String, String> partnerType, Long TS) {
PartnerType = partnerType;
this.TS = TS;
}
}

@ -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);
}
}

@ -225,4 +225,3 @@ chanjet:
appSecret: B071433DABBE48DB2241AE12280C8CBC #需要填写在开放平台申请的appSecret
secret: 1234567890123456 #秘钥,用于解密,需要去开放平台自主填写,然后配置在此处
redirectUri: http://192.168.0.158:9021/admin-api/mes/chanjet/receiveCode #Oauth重定向地址需要去开放平台自主填写然后配置在此处
code: c-6ff9b5e5e1014a788abb31f9d87bb42d

Loading…
Cancel
Save