diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java index 21a16df37..fedc2db8e 100644 --- a/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrProductsController.java @@ -1,20 +1,20 @@ package com.glxp.api.controller.thrsys; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; -import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.thrsys.ThrProductsEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.system.DeleteRequest; import com.glxp.api.req.thrsys.FilterThrProductsRequest; -import com.glxp.api.req.thrsys.ThrProductsRequest; +import com.glxp.api.req.thrsys.PostThrProductsRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.service.auth.CustomerService; @@ -23,6 +23,7 @@ import com.glxp.api.service.thrsys.ThrSystemDetailService; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.Date; @@ -166,15 +167,14 @@ public class ThrProductsController { */ @AuthRuleAnnotation("") @PostMapping("/udiwms/udiinfo/erp/products/saveProduct") - public BaseResponse saveProduct(@RequestBody ThrProductsEntity thrProductsEntity,FilterThrProductsRequest filterThrProductsRequest) { - + public BaseResponse saveProduct(@RequestBody ThrProductsEntity thrProductsEntity, FilterThrProductsRequest filterThrProductsRequest) { if (null == thrProductsEntity) return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL); - BeanUtils.copyProperties(thrProductsEntity,filterThrProductsRequest); + BeanUtils.copyProperties(thrProductsEntity, filterThrProductsRequest); List thrProductsEntities = thrProductsService.filterThrProducts1(filterThrProductsRequest); - if(thrProductsEntities.size()==0){ + if (thrProductsEntities.size() == 0) { thrProductsEntity.setUpdateUser(String.valueOf(customerService.getUserId())); thrProductsEntity.setCreateUser(String.valueOf(customerService.getUserId())); thrProductsEntity.setUpdateTime(new Date()); @@ -182,7 +182,7 @@ public class ThrProductsController { thrProductsService.insertThrProducts(thrProductsEntity); return ResultVOUtils.success(); } - return ResultVOUtils.error(999,"数据已存在!"); + return ResultVOUtils.error(999, "数据已存在!"); // //新增主系统产品信息直接加到耗材字典里 @@ -194,4 +194,45 @@ public class ThrProductsController { } + /** + * 第三方产品信息导入 + * + * @param files + * @param thirdSys + * @return + */ + @PostMapping("/udiwms/erp/pi/upload") + public BaseResponse uploadPi(@RequestParam("file") List files, @RequestParam("thirdSys") String thirdSys) { + if (StrUtil.isBlank(thirdSys)) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "未选择指定系统"); + } + if (CollUtil.isEmpty(files)) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "请选择导入文件"); + } + if (files.size() > 1) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, "每次只能上传一个文件!"); + } + ThreadUtil.execAsync(() -> { + thrProductsService.uploadPi(files, thirdSys); + }); + return ResultVOUtils.success("正在导入中,稍后请刷新页面查看"); + } + + /** + * 第三方接口服务解析excel数据回调接口,接收解析数据并插入到数据库中 + * + * @param postThrProductsRequest + * @return + */ + @PostMapping("/udiwms/thrsys/postThrProducts") + public BaseResponse postThrProducts(@RequestBody PostThrProductsRequest postThrProductsRequest) { + if (null == postThrProductsRequest) { + return ResultVOUtils.error(500, "参数不能为空"); + } + ThreadUtil.execAsync(() -> { + thrProductsService.importUploadPi(postThrProductsRequest); + }); + return ResultVOUtils.success(); + } + } \ No newline at end of file diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpDao.java index 4e435cd66..250ea6cf1 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpDao.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpDao.java @@ -39,4 +39,12 @@ public interface ThrCorpDao { List selectByLastTime(@Param("lastUpdateTime") Date lastUpdateTime); + /** + * 下载第三方往来单位数据,查询关键字段 + * + * @param unitId + * @param thirdId + * @return + */ + ThrCorpEntity selectByUnitIdAndThirdId(@Param("unitId") String unitId, @Param("thirdId") String thirdId); } diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvWarehouseDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvWarehouseDao.java index 0b77c9319..69c1ef3e9 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrInvWarehouseDao.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvWarehouseDao.java @@ -35,4 +35,13 @@ public interface ThrInvWarehouseDao { List filterThrInvWarehouseResponse(FilterThrSubInvWarehouseRequest filterThrSubInvWarehouseRequest); List selectByLastTime(@Param("lastUpdateTime") Date lastUpdateTime); + + /** + * 下载仓库信息查询变更字段方法 + * + * @param code + * @param thirdId + * @return + */ + ThrInvWarehouseEntity selectByCodeAndThirdId(@Param("code") String code, @Param("thirdId") String thirdId); } diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java index e228b9aa7..069211918 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsDao.java @@ -30,6 +30,7 @@ public interface ThrProductsDao { boolean insertThrProducts(ThrProductsEntity thrProductsEntity); + boolean insertThrProductsList(List list); List selectByLastTime(@Param("lastUpdateTime") Date lastUpdateTime); } diff --git a/src/main/java/com/glxp/api/http/ErpBasicClient.java b/src/main/java/com/glxp/api/http/ErpBasicClient.java index 122cbbd8a..899397936 100644 --- a/src/main/java/com/glxp/api/http/ErpBasicClient.java +++ b/src/main/java/com/glxp/api/http/ErpBasicClient.java @@ -9,20 +9,20 @@ import com.glxp.api.entity.thrsys.ThrSystemBusApiEntity; import com.glxp.api.entity.thrsys.ThrSystemEntity; import com.glxp.api.http.req.UdiwmsBusTypeRequest; import com.glxp.api.http.req.UdiwmsUnitRequest; -import com.glxp.api.req.thrsys.FilterBasicThirdSysDetailRequest; -import com.glxp.api.req.thrsys.FilterThrProductsRequest; -import com.glxp.api.req.thrsys.ThrUnitMaintainFilterRequest; -import com.glxp.api.req.thrsys.UdiwmsWarehouseRequest; +import com.glxp.api.req.thrsys.*; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrCorpsResponse; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.res.thrsys.UdiwmsWarehouseDetail; import com.glxp.api.service.thrsys.ThrSystemService; import lombok.extern.slf4j.Slf4j; +import okhttp3.*; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.util.List; /** * 第三方服务HttpClient @@ -30,6 +30,9 @@ import javax.annotation.Resource; @Slf4j @Service public class ErpBasicClient { + + @Resource + private OkHttpClient okHttpClient; @Resource HttpOkClient httpOkClient; @Resource @@ -79,28 +82,7 @@ public class ErpBasicClient { } } - // //获取单据类型 -// public BaseResponse> getBusTypes(FilterBasicThirdSysDetailRequest filterBasicThirdSysDetailRequest) { -// BasicThirdSysEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(filterBasicThirdSysDetailRequest.getThirdSysFk()); -// String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/getOrderType"; -// UdiwmsBusTypeRequest udiwmsBusTypeRequest = new UdiwmsBusTypeRequest(); -// udiwmsBusTypeRequest.setThirdSys(filterBasicThirdSysDetailRequest.getThirdSysFk()); -// udiwmsBusTypeRequest.setPage(filterBasicThirdSysDetailRequest.getPage()); -// udiwmsBusTypeRequest.setLimit(filterBasicThirdSysDetailRequest.getLimit()); -// try { -// String response = httpOkClient.uCloudPost(url, udiwmsBusTypeRequest, basicThirdSysEntity); -// log.info(response); -// BaseResponse> udiDlDeviceResponse = -// JSONObject.parseObject(response, new TypeReference>>() { -// }); -// return udiDlDeviceResponse; -// } catch (Exception e) { -// log.error("获取单据类型异常", e); -// return ResultVOUtils.error(500, "连接第三方系统接口服务出错!"); -// } -// } -// -//查询仓库货位号 + //查询仓库货位号 public BaseResponse> getWarehouse(UdiwmsWarehouseRequest udiwmsWarehouseRequest) { ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(udiwmsWarehouseRequest.getThirdSys()); String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/getWarehouse"; @@ -158,9 +140,9 @@ public class ErpBasicClient { BaseResponse> udiDlDeviceResponse = JSONObject.parseObject(response, new TypeReference>>() { }); - if(udiDlDeviceResponse!=null){ + if (udiDlDeviceResponse != null) { return udiDlDeviceResponse; - }else{ + } else { return ResultVOUtils.error(500, "查询第三方数据失败!"); } @@ -169,4 +151,47 @@ public class ErpBasicClient { return ResultVOUtils.error(500, "连接第三方系统接口服务出错!"); } } + + /** + * 上传文件到第三方接口服务,解析第三方系统产品信息并获取回调结果 + * + * @param files + * @param thirdSys + * @return + */ + public BaseResponse uploadPi(List files, String thirdSys) { + ThrSystemEntity thrSystemEntity = basicThirdSysService.selectByThirdId(thirdSys); + String url = thrSystemEntity.getThridUrl() + "/udiwms/erp/pi/upload"; + + try { + MultipartBody.Builder builder = new MultipartBody.Builder() + .setType(MultipartBody.FORM); + for (MultipartFile file : files) { + builder.addFormDataPart("file", file.getOriginalFilename(), RequestBody.create(MediaType.parse("application/vnd.ms-excel"), file.getBytes())); + } + builder.addFormDataPart("thirdSys", thirdSys); + MultipartBody multipartBody = builder.build(); + + Request request = new Request.Builder().url(url).post(multipartBody).build(); + + try { + Response response = okHttpClient.newCall(request).execute(); + response.close(); + + if (response.code() == 200) { + return ResultVOUtils.success("解析成功"); + } else { + log.info("解析接口响应信息失败,返回信息:{}", response); + return ResultVOUtils.error(500, "解析第三方产品信息失败"); + } + } catch (Exception e) { + log.error("解析第三方产品信息失败", e); + return ResultVOUtils.error(500, "解析第三方产品信息失败"); + } + } catch (Exception e) { + log.error("解析第三方系统产品信息失败", e); + return ResultVOUtils.error(500, "解析第三方系统产品信息失败"); + } + + } } diff --git a/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java b/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java index 5df74fb9e..ff222a5e1 100644 --- a/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java +++ b/src/main/java/com/glxp/api/service/thrsys/IThrBusTypeOriginService.java @@ -1,6 +1,6 @@ package com.glxp.api.service.thrsys; -import com.glxp.api.entity.basic.BasicBusTypeChangeEntity; +import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.thrsys.FilterThrBusTypeOriginRequest; @@ -106,4 +106,5 @@ public interface IThrBusTypeOriginService { List findByLastTime(Date lastUpdateTime); + BaseResponse downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity); } diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java b/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java index bf14238dc..e262c470e 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrCorpService.java @@ -1,6 +1,7 @@ package com.glxp.api.service.thrsys; +import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.thrsys.ThrCorpEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.thrsys.FilterThrCorpRequest; @@ -31,4 +32,13 @@ public interface ThrCorpService { ThrSystemDetailEntity selectByKey(String key, String thirdSys); List findByLastTime(Date lastUpdateTime); + + /** + * 下载第三方往来单位信息 + * + * @param thrSystemDetailEntity + * @return + */ + BaseResponse downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity); + } diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrInvWarehouseService.java b/src/main/java/com/glxp/api/service/thrsys/ThrInvWarehouseService.java index 5572240dd..562990fa3 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrInvWarehouseService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrInvWarehouseService.java @@ -1,6 +1,7 @@ package com.glxp.api.service.thrsys; +import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.thrsys.ThrInvWarehouseEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.thrsys.FilterThrSubInvWarehouseRequest; @@ -44,5 +45,5 @@ public interface ThrInvWarehouseService { * * @param thrSystemDetailEntity */ - void downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity); + BaseResponse downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity); } diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java index e6ae6cb15..8989a265e 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrProductsService.java @@ -1,9 +1,12 @@ package com.glxp.api.service.thrsys; +import com.glxp.api.common.res.BaseResponse; import com.glxp.api.entity.thrsys.ThrProductsEntity; import com.glxp.api.req.thrsys.FilterThrProductsRequest; +import com.glxp.api.req.thrsys.PostThrProductsRequest; import com.glxp.api.res.thrsys.ThrProductsResponse; +import org.springframework.web.multipart.MultipartFile; import java.util.Date; import java.util.List; @@ -35,4 +38,21 @@ public interface ThrProductsService { List findByLastTime(Date lastUpdateTime); + + /** + * 导入第三方产品信息 + * + * @param files + * @param thirdSys + * @return + */ + BaseResponse uploadPi(List files, String thirdSys); + + /** + * 将上传的第三方系统的数据插入到数据库 + * + * @param postThrProductsRequest + * @return + */ + BaseResponse importUploadPi(PostThrProductsRequest postThrProductsRequest); } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java index 9e92a7a35..e75486a8d 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrBusTypeOriginServiceImpl.java @@ -4,10 +4,12 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.thrsys.ThrBusTypeOriginDao; -import com.glxp.api.entity.basic.BasicBusTypeChangeEntity; import com.glxp.api.entity.thrsys.ThrBusTypeOriginEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrBusTypeOriginRequest; import com.glxp.api.res.thrsys.ThrBusTypeOriginResponse; import com.glxp.api.service.auth.CustomerService; @@ -35,6 +37,8 @@ public class ThrBusTypeOriginServiceImpl implements IThrBusTypeOriginService { @Lazy @Resource private ThrSystemDetailService thrSystemDetailService; + @Resource + private ErpBasicClient erpBasicClient; @Override public List filterEnableList(FilterThrBusTypeOriginRequest filterThrBusTypeOriginRequest) { @@ -154,4 +158,19 @@ public class ThrBusTypeOriginServiceImpl implements IThrBusTypeOriginService { public List findByLastTime(Date lastUpdateTime) { return thrBusTypeOriginDao.selectList(new QueryWrapper().gt("updateTime", lastUpdateTime)); } + + @Override + public BaseResponse downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity) { + int page = 1; + int limit = 100; + /*while (true) { + FilterBasicThirdSysDetailRequest request = new FilterBasicThirdSysDetailRequest(); + request.setPage(page); + request.setLimit(limit); + request.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk()); + + erpBasicClient.getBusTypes(request); + }*/ + return ResultVOUtils.success("下载完成"); + } } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java index 117f1c53e..2dccfab6b 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrCorpServiceImpl.java @@ -1,11 +1,17 @@ package com.glxp.api.service.thrsys.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.thrsys.ThrCorpDao; import com.glxp.api.entity.thrsys.ThrCorpEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrCorpRequest; import com.glxp.api.req.thrsys.ThrUnitMaintainFilterRequest; +import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrCorpsResponse; import com.glxp.api.res.thrsys.ThrUnitMaintainResponse; import com.glxp.api.service.thrsys.ThrCorpService; @@ -23,6 +29,8 @@ public class ThrCorpServiceImpl implements ThrCorpService { @Resource private ThrCorpDao thrCorpDao; + @Resource + private ErpBasicClient erpBasicClient; @Override public List filterThrCorps(FilterThrCorpRequest filterThrCorpRequest) { @@ -66,6 +74,7 @@ public class ThrCorpServiceImpl implements ThrCorpService { public boolean deleteAll() { return thrCorpDao.deleteAll(); } + @Override public ThrUnitMaintainResponse selectByThirdId(String thirdId, String thirdSys) { @@ -87,7 +96,7 @@ public class ThrCorpServiceImpl implements ThrCorpService { @Override public ThrSystemDetailEntity selectByKey(String key, String thirdSys) { - return thrCorpDao.selectByKey(key,thirdSys); + return thrCorpDao.selectByKey(key, thirdSys); } @Override @@ -95,4 +104,81 @@ public class ThrCorpServiceImpl implements ThrCorpService { return thrCorpDao.selectByLastTime(lastUpdateTime); } + @Override + public BaseResponse downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity) { + int page = 1; + int limit = 100; + + while (true) { + ThrUnitMaintainFilterRequest request = new ThrUnitMaintainFilterRequest(); + request.setPage(page); + request.setLimit(limit); + request.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk()); + BaseResponse> baseResponse = erpBasicClient.getErpCrop(request); + + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.parallelStream().forEach(thrCorpsResponse -> { + ThrCorpEntity thrCorpEntity = thrCorpDao.selectByUnitIdAndThirdId(thrCorpsResponse.getUnitId(), thrSystemDetailEntity.getThirdSysFk()); + if (null == thrCorpEntity) { + thrCorpEntity = new ThrCorpEntity(); + BeanUtil.copyProperties(thrCorpsResponse, thrCorpEntity); + thrCorpEntity.setCreateTime(new Date()); + thrCorpEntity.setUpdateTime(new Date()); + thrCorpEntity.setId(null); + thrCorpDao.insertThrCorps(thrCorpEntity); + } else { + boolean isChange = verifyDataChange(thrCorpEntity, thrCorpsResponse); + if (isChange) { + thrCorpEntity.setUpdateTime(new Date()); + thrCorpDao.updateThrCorps(thrCorpEntity); + } + } + }); + + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return baseResponse; + } + } + + return ResultVOUtils.success("下载完成"); + } + + /** + * 校验拉取的第三方数据是否有更新 + * + * @param thrCorpEntity + * @param thrCorpsResponse + * @return + */ + private boolean verifyDataChange(ThrCorpEntity thrCorpEntity, ThrCorpsResponse thrCorpsResponse) { + if (!StrUtil.equals(thrCorpEntity.getSpell(), thrCorpsResponse.getSpell())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getAddr(), thrCorpsResponse.getAddr())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getCreditNo(), thrCorpsResponse.getCreditNo())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getContact(), thrCorpsResponse.getContact())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getMobile(), thrCorpsResponse.getMobile())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getName(), thrCorpsResponse.getName())) { + return true; + } + if (!StrUtil.equals(thrCorpEntity.getRemark(), thrCorpsResponse.getRemark())) { + return true; + } + return false; + } + } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java index 1debd0960..a01cb5ecd 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvWarehouseServiceImpl.java @@ -3,12 +3,19 @@ package com.glxp.api.service.thrsys.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.thrsys.ThrInvWarehouseDao; import com.glxp.api.entity.thrsys.ThrInvWarehouseEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrSubInvWarehouseRequest; +import com.glxp.api.req.thrsys.UdiwmsWarehouseRequest; +import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.thrsys.ThrInvWarehouseResponse; +import com.glxp.api.res.thrsys.UdiwmsWarehouseDetail; import com.glxp.api.service.thrsys.ThrInvWarehouseService; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,12 +24,15 @@ import java.util.Collections; import java.util.Date; import java.util.List; +@Slf4j @Service @Transactional(rollbackFor = Exception.class) public class ThrInvWarehouseServiceImpl implements ThrInvWarehouseService { @Resource - ThrInvWarehouseDao thrInvWarehouseDao; + private ThrInvWarehouseDao thrInvWarehouseDao; + @Resource + private ErpBasicClient erpBasicClient; @Override @@ -120,8 +130,67 @@ public class ThrInvWarehouseServiceImpl implements ThrInvWarehouseService { } @Override - public void downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity) { + public BaseResponse downloadThrInv(ThrSystemDetailEntity thrSystemDetailEntity) { + int page = 1; + int limit = 100; + while (true) { + UdiwmsWarehouseRequest udiwmsWarehouseRequest = new UdiwmsWarehouseRequest(); + udiwmsWarehouseRequest.setThirdSys(thrSystemDetailEntity.getThirdSysFk()); + udiwmsWarehouseRequest.setPage(page); + udiwmsWarehouseRequest.setLimit(limit); + + BaseResponse> baseResponse = erpBasicClient.getWarehouse(udiwmsWarehouseRequest); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.parallelStream().forEach(udiwmsWarehouseDetail -> { + //查询此编码对应的仓库是否存在,若不存在,则直接插入,存在则判断数据是否有更新,有更新则更新此数据 + ThrInvWarehouseEntity thrInvWarehouseEntity = thrInvWarehouseDao.selectByCodeAndThirdId(udiwmsWarehouseDetail.getCode(), thrSystemDetailEntity.getThirdSysFk()); + if (null == thrInvWarehouseEntity) { + thrInvWarehouseEntity = new ThrInvWarehouseEntity(); + thrInvWarehouseEntity.setParentId("0"); + thrInvWarehouseEntity.setName(udiwmsWarehouseDetail.getName()); + thrInvWarehouseEntity.setCode(udiwmsWarehouseDetail.getCode()); + thrInvWarehouseEntity.setThirdSysFk(thrSystemDetailEntity.getThirdSysFk()); + thrInvWarehouseEntity.setUpdateTime(new Date()); + thrInvWarehouseDao.insertThrInvWarehouse(thrInvWarehouseEntity); + } else { + //数据存在,判断此数据是否存在不同,存在则说明数据有更新,更新数据库中的数据到最新的数据 + boolean isChange = verifyDataChange(thrInvWarehouseEntity, udiwmsWarehouseDetail); + if (isChange) { + thrInvWarehouseEntity.setUpdateTime(new Date()); + thrInvWarehouseDao.updateThrInvWarehouse(thrInvWarehouseEntity); + } + } + }); + + //请求下一页数据 + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return baseResponse; + } + } + return ResultVOUtils.success("下载结束!"); + } + /** + * 校验拉取的第三方数据是否有更新 + * + * @param thrInvWarehouseEntity + * @param udiwmsWarehouseDetail + * @return + */ + private boolean verifyDataChange(ThrInvWarehouseEntity thrInvWarehouseEntity, UdiwmsWarehouseDetail udiwmsWarehouseDetail) { + if (!StrUtil.equals(thrInvWarehouseEntity.getName(), udiwmsWarehouseDetail.getName())) { + return true; + } + if (!StrUtil.equals(thrInvWarehouseEntity.getRemark(), udiwmsWarehouseDetail.getRemark())) { + return true; + } + return false; } } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java index 9f84eeace..ea69e1e93 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrProductsServiceImpl.java @@ -1,15 +1,27 @@ package com.glxp.api.service.thrsys.impl; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageHelper; +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.dao.thrsys.ThrProductsDao; import com.glxp.api.entity.thrsys.ThrProductsEntity; +import com.glxp.api.http.ErpBasicClient; import com.glxp.api.req.thrsys.FilterThrProductsRequest; +import com.glxp.api.req.thrsys.PostThrProductsRequest; import com.glxp.api.res.thrsys.ThrProductsResponse; import com.glxp.api.service.thrsys.ThrProductsService; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.ibatis.session.TransactionIsolationLevel; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.Collections; @@ -18,18 +30,23 @@ import java.util.List; /** *

- * 服务实现类 + * 服务实现类 *

* * @author ${author} * @since 2023-01-10 */ +@Slf4j @Service @Transactional(rollbackFor = Exception.class) public class ThrProductsServiceImpl implements ThrProductsService { @Resource - ThrProductsDao thrProductsDao; + private ThrProductsDao thrProductsDao; + @Resource + private ErpBasicClient erpBasicClient; + @Resource + private SqlSessionFactory sqlSessionFactory; @Override public ThrProductsEntity selectByCode(String code) { @@ -102,4 +119,41 @@ public class ThrProductsServiceImpl implements ThrProductsService { return thrProductsDao.selectByLastTime(lastUpdateTime); } + @Override + public BaseResponse uploadPi(List files, String thirdSys) { + BaseResponse baseResponse = erpBasicClient.uploadPi(files, thirdSys); + if (baseResponse.getCode() == 20000) { + return ResultVOUtils.success("导入成功"); + } else { + return ResultVOUtils.error(500, "导入失败"); + } + } + + @Override + public BaseResponse importUploadPi(PostThrProductsRequest postThrProductsRequest) { + List list = postThrProductsRequest.getDatas(); + + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED); + ThrProductsDao mapper = sqlSession.getMapper(ThrProductsDao.class); + + list.forEach(item -> { + ThrProductsEntity thrProductsEntity = new ThrProductsEntity(); + BeanUtil.copyProperties(item, thrProductsEntity); + thrProductsEntity.setThirdSysFk(postThrProductsRequest.getThirdSys()); + thrProductsEntity.setCreateTime(DateUtil.date(new Date())); + thrProductsEntity.setUpdateTime(DateUtil.date(new Date())); + + try { + mapper.insertThrProducts(thrProductsEntity); + } catch (Exception e) { + log.error("", e); + } + }); + + sqlSession.commit(); + sqlSession.close(); + + return ResultVOUtils.success("第三方系统产品数据已插入到数据库"); + } + } diff --git a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java index f78c5f595..a98b33a3e 100644 --- a/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java +++ b/src/main/java/com/glxp/api/task/ThirdSysInterfaceTask.java @@ -123,7 +123,15 @@ public class ThirdSysInterfaceTask { * @param thrSystemDetailEntity */ private void downloadThrBusType(ThrSystemDetailEntity thrSystemDetailEntity) { - + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方单据类型"); + thrBusTypeOriginService.downloadThrBusType(thrSystemDetailEntity); + updateTask(getTaskKey(thrSystemDetailEntity)); + log.info("第三方单据类型下载完成"); + }); + } } /** @@ -141,7 +149,15 @@ public class ThirdSysInterfaceTask { * @param thrSystemDetailEntity */ private void downloadThrCorp(ThrSystemDetailEntity thrSystemDetailEntity) { - + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载第三方往来单位信息"); + thrCorpService.downloadThrCorp(thrSystemDetailEntity); + updateTask(getTaskKey(thrSystemDetailEntity)); + log.info("第三方往来单位信息下载完成"); + }); + } } /** diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cc8bc4c7a..cec12a306 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,6 +7,8 @@ spring: multipart: max-file-size: 200MB max-request-size: 200MB + location: D:/tmp + mybatis-plus: mapper-locations: classpath:mybatis/mapper/*/*.xml configuration: diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml index a297e26f5..d767b3ff2 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrCorpDao.xml @@ -2,22 +2,24 @@ - - select * FROM basic_corp + select * + FROM basic_corp AND thirdId = #{thirdId} @@ -172,6 +190,28 @@ + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml index 4bf8afc4f..517773099 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvWarehouseDao.xml @@ -127,4 +127,17 @@ + + \ No newline at end of file diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml index bac14b4ef..c3b2d59bd 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrProductsDao.xml @@ -195,4 +195,47 @@ + + + replace + INTO thr_products + (code, `name`, measname, spec, registerNo, manufactory, + cplb, flbm, qxlb, ybbm, sptm, tyshxydm, zczbhhzbapzbh, ylqxzcrbarmc, ylqxzcrbarywmc, cpms, + thirdSysFk, updateTime, supName, model, standard, qtbm, zczyxqz, remark, remark1, remark2, remark3, price, + createUser, createTime, updateUser) + values + + #{item.code}, + #{item.name}, + #{item.measname}, + #{item.spec}, + #{item.registerNo}, + #{item.manufactory}, + #{item.cplb}, + #{item.flbm}, + #{item.qxlb}, + #{item.ybbm}, + #{item.sptm}, + #{item.tyshxydm}, + #{item.zczbhhzbapzbh}, + #{item.ylqxzcrbarmc}, + #{item.ylqxzcrbarywmc}, + #{item.cpms}, + #{item.thirdSysFk}, + #{item.updateTime}, + #{item.supName}, + #{item.model}, + #{item.standard}, + #{item.qtbm}, + #{item.zczyxqz}, + #{item.remark}, + #{item.remark1}, + #{item.remark2}, + #{item.remark3}, + #{item.price}, + #{item.createUser}, + #{item.createTime}, + #{item.updateUser} + + diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrSystemDetailDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrSystemDetailDao.xml index ce9872754..0ad8788ba 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrSystemDetailDao.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrSystemDetailDao.xml @@ -50,9 +50,11 @@ SELECT tsd.*, ts.thridUrl FROM thr_system_detail tsd - inner join thr_system ts ON tsd.thirdSysFk = ts.thirdId + INNER JOIN thr_system ts ON tsd.thirdSysFk = ts.thirdId WHERE ts.enabled = 1 - and tsd.fromType = 3 - AND tsd.time > 0; + AND tsd.fromType = 3 + AND tsd.enabled = 1 + AND (tsd.`value` is not null and tsd.`value` != '') + AND tsd.time > 0 \ No newline at end of file