From ed0e59df40e6a6dad89f2607687e84e221316876 Mon Sep 17 00:00:00 2001 From: zengchenxi Date: Fri, 19 Apr 2024 15:54:21 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=9C=80=E6=B1=82=E3=80=91=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=AE=A2=E6=88=B7=E6=95=B0=E6=8D=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/biz/chanjet/ChanjetController.java | 8 ++ .../biz/chanjet/ChanjetInterfaceEnum.java | 2 + .../module/biz/chanjet/vo/QueryPartnerVO.java | 21 +++-- .../module/biz/manager/ChanjetManager.java | 82 ++++++++++++++++++- .../src/main/resources/application-local.yaml | 1 - 5 files changed, 107 insertions(+), 7 deletions(-) diff --git a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetController.java b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetController.java index 3eee1d05..c1b8838e 100644 --- a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetController.java +++ b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetController.java @@ -70,4 +70,12 @@ public class ChanjetController { public CommonResult 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 queryCustomer() throws ChanjetApiException { + chanjetManager.queryCustomer(); + return success(null); + } } diff --git a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetInterfaceEnum.java b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetInterfaceEnum.java index f917226c..4d6ef465 100644 --- a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetInterfaceEnum.java +++ b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/ChanjetInterfaceEnum.java @@ -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; diff --git a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/vo/QueryPartnerVO.java b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/vo/QueryPartnerVO.java index e9524a05..d21b274d 100644 --- a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/vo/QueryPartnerVO.java +++ b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/chanjet/vo/QueryPartnerVO.java @@ -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 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 partnerType) { + PartnerType = partnerType; + } + + public QueryPartnerParamVO(Map partnerType, Long TS) { + PartnerType = partnerType; + this.TS = TS; + } } diff --git a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/manager/ChanjetManager.java b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/manager/ChanjetManager.java index 007791bc..84eda0d6 100644 --- a/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/manager/ChanjetManager.java +++ b/mes-module-majoys/mes-module-majoys-biz/src/main/java/com/chanko/yunxi/mes/module/biz/manager/ChanjetManager.java @@ -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() {{ + 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 dataList = JSON.parseObject(JSON.toJSONString(response.getResult()), new TypeReference>() { + }); + + // 取最大 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 customerList = new ArrayList<>(16); + ArrayList insertCustomerList = new ArrayList<>(16); + ArrayList 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 codeList = customerList.stream().map(CustomerDO::getCode).collect(Collectors.toList()); + List customerDOList = customerMapper.selectList(new LambdaQueryWrapper() {{ + in(CustomerDO::getCode, codeList); + }}); + Map> existsCustomers = customerDOList.stream().collect(Collectors.groupingBy(CustomerDO::getCode)); + customerList.forEach(customerSaveReqVO -> { + List 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); + + } } diff --git a/mes-server/src/main/resources/application-local.yaml b/mes-server/src/main/resources/application-local.yaml index d817b677..248a7906 100644 --- a/mes-server/src/main/resources/application-local.yaml +++ b/mes-server/src/main/resources/application-local.yaml @@ -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