【需求】获取供应商数据接口

dev
zengchenxi 6 months ago
parent a06e20de65
commit 4065e91cf6

@ -78,4 +78,12 @@ public class ChanjetController {
chanjetManager.queryCustomer();
return success(null);
}
@PostMapping("/supplier/query")
@Operation(summary = "获取供应商数据")
@PreAuthorize("@ss.hasPermission('biz:supplier:query')")
public CommonResult<Void> querySupplier() throws ChanjetApiException {
chanjetManager.querySupplier();
return success(null);
}
}

@ -19,6 +19,7 @@ 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
QUERY_SUPPLIER("/tplus/api/v2/partner/Query", "查询供应商", QueryPartnerVO.class, SimpleChanjetResponse.class), // TODO reponse
;
private String uri;

@ -10,8 +10,10 @@ 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.supplier.SupplierDO;
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.dal.mysql.supplier.SupplierMapper;
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;
@ -26,8 +28,7 @@ import javax.validation.Valid;
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;
import static com.chanko.yunxi.mes.module.biz.chanjet.ChanjetInterfaceEnum.*;
/**
*
@ -46,6 +47,8 @@ public class ChanjetManager {
private WorkshopService workshopService;
@Resource
private CustomerMapper customerMapper;
@Resource
private SupplierMapper supplierMapper;
/**
*
@ -157,4 +160,70 @@ public class ChanjetManager {
}while (maxTs != null);
}
/**
*
* @throws ChanjetApiException
*/
public void querySupplier() 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_SUPPLIER, 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<SupplierDO> doList = new ArrayList<>(16);
ArrayList<SupplierDO> insertList = new ArrayList<>(16);
ArrayList<SupplierDO> updateList = 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"));
SupplierDO aDo = new SupplierDO();
aDo.setCode(code).setName(name).setBrief(shorthand).setStatus(ValidStatusEnum.VALID.getCode());
doList.add(aDo);
});
List<String> codeList = doList.stream().map(SupplierDO::getCode).collect(Collectors.toList());
List<SupplierDO> existsDOList = supplierMapper.selectList(new LambdaQueryWrapper<SupplierDO>() {{
in(SupplierDO::getCode, codeList);
}});
Map<String, List<SupplierDO>> existsDOs = existsDOList.stream().collect(Collectors.groupingBy(SupplierDO::getCode));
doList.forEach(sDO -> {
List<SupplierDO> historyDOs = existsDOs.get(sDO.getCode());
if(historyDOs != null){
// 对比字段 如有变化则更新
SupplierDO hDO = historyDOs.get(0);
if(!hDO.getName().equals(sDO.getName()) || !hDO.getBrief().equals(sDO.getBrief())){
hDO.setName(sDO.getName()).setBrief(sDO.getBrief());
updateList.add(hDO);
}
}else{
insertList.add(sDO);
}
});
// 入库
if(!insertList.isEmpty()) supplierMapper.insertBatch(insertList);
if(!updateList.isEmpty()) supplierMapper.updateBatch(updateList);
}else{
maxTs = null;
}
}while (maxTs != null);
}
}

@ -64,3 +64,8 @@ export const deleteCustomer = async (id: number) => {
export const exportCustomer = async (params) => {
return await request.download({ url: `/biz/customer/export-excel`, params })
}
// 查询客户数据
export const queryCustomerChanjet = async () => {
return await request.get({ url: `/biz/chanjet/customer/query` })
}

@ -70,3 +70,8 @@ export const deleteSupplier = async (id: number) => {
export const exportSupplier = async (params) => {
return await request.download({ url: `/biz/supplier/export-excel`, params })
}
// 查询客户数据
export const querySupplierChanjet = async () => {
return await request.get({ url: `/biz/chanjet/supplier/query` })
}

Loading…
Cancel
Save