From 2de35f3091aa97bb2d5d080860c0fd55f7ce9b27 Mon Sep 17 00:00:00 2001 From: chenhc <2369838784@qq.com> Date: Wed, 28 Feb 2024 18:05:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E9=A1=B9=E7=9B=AE=E7=BB=84?= =?UTF-8?q?=E5=A5=97=E5=92=8C=E4=B8=89=E6=96=B9=E5=87=BA=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=98=8E=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/glxp/api/constant/Constant.java | 5 + .../com/glxp/api/constant/ConstantStatus.java | 4 +- .../com/glxp/api/constant/ConstantType.java | 4 +- .../glxp/api/controller/TestController.java | 9 + .../api/dao/basic/BasicDestinyRelMapper.java | 2 + .../dao/thrsys/ThrInvOrderDetailMapper.java | 24 ++ .../api/dao/thrsys/ThrInvOrderMapper.java | 19 + .../basic/BasicSkProjectDetailEntity.java | 1 + .../glxp/api/entity/thrsys/ThrInvOrder.java | 103 +++++ .../api/entity/thrsys/ThrInvOrderDetail.java | 156 ++++++++ .../java/com/glxp/api/http/ErpInvClient.java | 30 +- .../api/res/inv/ThrInvResultResponse.java | 130 ++++++- .../basic/impl/BasicDestinyRelService.java | 4 + .../inv/impl/StockCompareServiceImpl.java | 2 +- .../service/thrsys/ThrInvOrderService.java | 11 + .../thrsys/impl/ThrInvOrderServiceImpl.java | 139 +++++++ .../com/glxp/api/task/ThrInvOrderTask.java | 88 +++++ .../mapper/basic/BasicDestinyRelMapper.xml | 8 + .../mapper/thrsys/ThrInvOrderDetailMapper.xml | 356 ++++++++++++++++++ .../mapper/thrsys/ThrInvOrderMapper.xml | 226 +++++++++++ 20 files changed, 1301 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java create mode 100644 src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java create mode 100644 src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java create mode 100644 src/main/java/com/glxp/api/entity/thrsys/ThrInvOrderDetail.java create mode 100644 src/main/java/com/glxp/api/service/thrsys/ThrInvOrderService.java create mode 100644 src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderServiceImpl.java create mode 100644 src/main/java/com/glxp/api/task/ThrInvOrderTask.java create mode 100644 src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml create mode 100644 src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml diff --git a/src/main/java/com/glxp/api/constant/Constant.java b/src/main/java/com/glxp/api/constant/Constant.java index 6ff098e29..2705e0957 100644 --- a/src/main/java/com/glxp/api/constant/Constant.java +++ b/src/main/java/com/glxp/api/constant/Constant.java @@ -78,6 +78,11 @@ public class Constant { */ public static final String INV_PLACE_ORDER = "PO"; + /** + * 三方出入库单据前缀 + */ + public static final String TRIPARTITE_INV_ORDER = "SFIO"; + public static final String dlThrProducts = "THR_DOWNLOAD_PRODUCTS"; public static final String dlThrInvProducts = "THR_DOWNLOAD_INV_PRODUCTS"; diff --git a/src/main/java/com/glxp/api/constant/ConstantStatus.java b/src/main/java/com/glxp/api/constant/ConstantStatus.java index 305c0b26c..98dfd6aee 100644 --- a/src/main/java/com/glxp/api/constant/ConstantStatus.java +++ b/src/main/java/com/glxp/api/constant/ConstantStatus.java @@ -327,5 +327,7 @@ public class ConstantStatus { public static final int SPACE_OUT_SET = 1; //按指定货位出库 public static final int SPACE_OUT_CODE = 2; //按条码默认货位出库 - + //三方出入库单据 + public static final int SFIO_DRAFT = 0; //草稿 + public static final int SFIO_CFMD = 1; //已确认 } diff --git a/src/main/java/com/glxp/api/constant/ConstantType.java b/src/main/java/com/glxp/api/constant/ConstantType.java index 77235d6ae..2387fa948 100644 --- a/src/main/java/com/glxp/api/constant/ConstantType.java +++ b/src/main/java/com/glxp/api/constant/ConstantType.java @@ -3,6 +3,6 @@ package com.glxp.api.constant; public interface ConstantType { String TYPE_STOCK_CHECK = "StockCheck"; //盘点 - String TYPE_PUT = "WareHouseIn"; //出库 - String TYPE_OUT = "WareHouseOut"; //入库 + String TYPE_PUT = "WareHouseIn"; //入库 + String TYPE_OUT = "WareHouseOut"; //出库 } diff --git a/src/main/java/com/glxp/api/controller/TestController.java b/src/main/java/com/glxp/api/controller/TestController.java index 3a9cacd71..ff5f2d7c0 100644 --- a/src/main/java/com/glxp/api/controller/TestController.java +++ b/src/main/java/com/glxp/api/controller/TestController.java @@ -6,7 +6,9 @@ import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.Constant; import com.glxp.api.req.sync.BasicExportStatusRequest; +import com.glxp.api.task.SyncThirdSysTask; import com.glxp.api.task.TestStatOrderService; +import com.glxp.api.task.ThrInvOrderTask; import com.glxp.api.util.MsDateUtil; import com.glxp.api.util.RedisUtil; import lombok.extern.slf4j.Slf4j; @@ -22,6 +24,8 @@ import java.util.Date; public class TestController { @Resource TestStatOrderService statOrderService; + @Resource + ThrInvOrderTask thrInvOrderTask; @GetMapping("/test/stat/order") @@ -68,4 +72,9 @@ public class TestController { return ResultVOUtils.success("hello"); } + @GetMapping("/test/thrInvOrderTask") + public BaseResponse thrInvOrderTask() { + thrInvOrderTask.process(); + return ResultVOUtils.success(); + } } diff --git a/src/main/java/com/glxp/api/dao/basic/BasicDestinyRelMapper.java b/src/main/java/com/glxp/api/dao/basic/BasicDestinyRelMapper.java index 509cd686b..b19169e7a 100644 --- a/src/main/java/com/glxp/api/dao/basic/BasicDestinyRelMapper.java +++ b/src/main/java/com/glxp/api/dao/basic/BasicDestinyRelMapper.java @@ -5,6 +5,7 @@ import com.glxp.api.entity.basic.BasicSkProjectDetailEntity; import com.glxp.api.req.basic.FilterUdiRelRequest; import com.glxp.api.res.basic.UdiRelevanceResponse; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -16,4 +17,5 @@ public interface BasicDestinyRelMapper extends BaseMapperPlus filterDestinyProducts(FilterUdiRelRequest filterUdiRelRequest); + List filterDestinyRelListByPId(@Param("thrCode") String thrCode); } diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java new file mode 100644 index 000000000..5c0d32c5f --- /dev/null +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java @@ -0,0 +1,24 @@ +package com.glxp.api.dao.thrsys; + +import com.glxp.api.dao.BaseMapperPlus; +import com.glxp.api.dao.inout.IoOrderDetailBizDao; +import com.glxp.api.entity.inout.IoOrderDetailBizEntity; +import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface ThrInvOrderDetailMapper extends BaseMapperPlus { + int deleteByPrimaryKey(Integer id); + + int insert(ThrInvOrderDetail record); + + int insertSelective(ThrInvOrderDetail record); + + ThrInvOrderDetail selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(ThrInvOrderDetail record); + + int updateByPrimaryKey(ThrInvOrderDetail record); +} diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java new file mode 100644 index 000000000..5e8c5b632 --- /dev/null +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java @@ -0,0 +1,19 @@ +package com.glxp.api.dao.thrsys; + +import com.glxp.api.entity.thrsys.ThrInvOrder; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ThrInvOrderMapper { + int deleteByPrimaryKey(Integer id); + + int insert(ThrInvOrder record); + + int insertSelective(ThrInvOrder record); + + ThrInvOrder selectByPrimaryKey(Integer id); + + int updateByPrimaryKeySelective(ThrInvOrder record); + + int updateByPrimaryKey(ThrInvOrder record); +} \ No newline at end of file diff --git a/src/main/java/com/glxp/api/entity/basic/BasicSkProjectDetailEntity.java b/src/main/java/com/glxp/api/entity/basic/BasicSkProjectDetailEntity.java index 5b9c08915..dc7615544 100644 --- a/src/main/java/com/glxp/api/entity/basic/BasicSkProjectDetailEntity.java +++ b/src/main/java/com/glxp/api/entity/basic/BasicSkProjectDetailEntity.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** diff --git a/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java new file mode 100644 index 000000000..26494cde1 --- /dev/null +++ b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java @@ -0,0 +1,103 @@ +package com.glxp.api.entity.thrsys; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +/** + * 库存出入库明细 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "thr_inv_order") +public class ThrInvOrder implements Serializable { + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 单据号 + */ + private String billNo; + + /** + * 单据时间 + */ + private Date billDate; + + /** + * 库存开始时间 + */ + private Date startDate; + + /** + * 库存结束时间 + */ + private Date endDate; + + /** + * 出入库类型 + */ + private String mainAction; + + /** + * 第三方单据类型 + */ + private String billType; + + /** + * 部门编码 + */ + private String deptCode; + + /** + * 仓库编码 + */ + private String invCode; + + /** + * 货位编码 + */ + private String spaceCode; + + /** + * 单据状态 + */ + private Integer status; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 创建人 + */ + private String createUser; + + /** + * 更新时间 + */ + private Date updateTime; + + /** + * 更新人 + */ + private String updateUser; + + /** + * 备注 + */ + private String remark; + + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrderDetail.java b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrderDetail.java new file mode 100644 index 000000000..b853e88bc --- /dev/null +++ b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrderDetail.java @@ -0,0 +1,156 @@ +package com.glxp.api.entity.thrsys; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@TableName(value = "thr_inv_order_detail") +public class ThrInvOrderDetail implements Serializable { + @TableId(value = "id", type = IdType.AUTO) + private Long id; + /** + * 单据号 + */ + private String orderIdFk; + + /** + * 产品通用名称 + */ + private String cpmctymc; + + /** + * 物资字典主键 + */ + private Long relId; + + /** + * 第三方项目编码/耗材字典 + */ + private String thrCode; + + /** + * DI + */ + private String nameCode; + + /** + * 规格型号 + */ + private String ggxh; + + /** + * 批次号 + */ + private Long batchNo; + + /** + * 计量单位 + */ + private String measname; + + /** + * 价格 + */ + private BigDecimal price; + + /** + * 生产日期 + */ + private Date productionDate; + + /** + * 失效日期 + */ + private Date expireDate; + + /** + * 医疗器械注册备案人 + */ + private String ylqxzcrbarmc; + + /** + * 注册/备案号 + */ + private String zczbhhzbapzbh; + + /** + * 入库数量 + */ + private String inCount; + + /** + * 出库数量 + */ + private String outCount; + + /** + * 供应商 + */ + private String supName; + + /** + * 部门 + */ + private String deptName; + + /** + * 部门编码 + */ + private String deptCode; + + /** + * 仓库 + */ + private String invName; + + /** + * 仓库编码 + */ + private String invCode; + + /** + * 货位 + */ + private String spaceCode; + + /** + * 货位编码 + */ + private String spaceName; + + /** + * 实际数量 + */ + private String reCount; + + /** + * 出入库类型 + */ + private String mainAction; + + /** + * 生产企业 + */ + private String manufacturer; + + /** + * 备注 + */ + private String remark; + + private static final long serialVersionUID = 1L; + + +} diff --git a/src/main/java/com/glxp/api/http/ErpInvClient.java b/src/main/java/com/glxp/api/http/ErpInvClient.java index 7dce05235..85b252cae 100644 --- a/src/main/java/com/glxp/api/http/ErpInvClient.java +++ b/src/main/java/com/glxp/api/http/ErpInvClient.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; +import com.glxp.api.constant.ConstantType; import com.glxp.api.entity.thrsys.ThrSystemEntity; import com.glxp.api.req.inv.FilterInvProductRequest; import com.glxp.api.req.thrsys.ThrOnhandRequest; @@ -18,6 +19,7 @@ import okhttp3.OkHttpClient; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -77,15 +79,27 @@ public class ErpInvClient { } public BaseResponse> getInvResult(FilterInvProductRequest invProductRequest) { - ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(invProductRequest.getThirdSys()); - String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/inv/getInvResult"; +// ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(invProductRequest.getThirdSys()); +// String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/inv/getInvResult"; try { - String response = httpOkClient.uCloudPost(url, invProductRequest); - BaseResponse> listBaseResponse = - JSONObject.parseObject(response, new TypeReference>>() { - }); - - return listBaseResponse; +// String response = httpOkClient.uCloudPost(url, invProductRequest); + ThrInvResultResponse thrInvResultResponse = new ThrInvResultResponse(); + thrInvResultResponse.setThrCode("11"); + thrInvResultResponse.setOutCount("2"); + thrInvResultResponse.setBillType(ConstantType.TYPE_OUT); + ArrayList objects = new ArrayList<>(); + objects.add(thrInvResultResponse); + PageSimpleResponse thrInvResultResponsePageSimpleResponse = new PageSimpleResponse<>(); + thrInvResultResponsePageSimpleResponse.setList(objects); + BaseResponse> pageSimpleResponseBaseResponse = new BaseResponse<>(); + pageSimpleResponseBaseResponse.setCode(20000); + pageSimpleResponseBaseResponse.setData(thrInvResultResponsePageSimpleResponse); + return pageSimpleResponseBaseResponse; +// BaseResponse> listBaseResponse = +// JSONObject.parseObject(response, new TypeReference>>() { +// }); +// +// return listBaseResponse; } catch (Exception e) { log.error("获取第三方库存明细异常", e); return ResultVOUtils.error(500, "连接第三方系统接口服务出错"); diff --git a/src/main/java/com/glxp/api/res/inv/ThrInvResultResponse.java b/src/main/java/com/glxp/api/res/inv/ThrInvResultResponse.java index dd84bdc62..639488e66 100644 --- a/src/main/java/com/glxp/api/res/inv/ThrInvResultResponse.java +++ b/src/main/java/com/glxp/api/res/inv/ThrInvResultResponse.java @@ -2,31 +2,145 @@ package com.glxp.api.res.inv; import lombok.Data; +import java.math.BigDecimal; +import java.util.Date; + @Data public class ThrInvResultResponse { - private Integer id; +// private Long id; +// /** +// * 单据号 +// */ +// private String orderIdFk; + + /** + * 产品通用名称 + */ private String cpmctymc; + +// /** +// * 物资字典主键 +// */ +// private Long relId; + + /** + * 第三方项目编码/耗材字典 + */ private String thrCode; + + /** + * DI + */ private String nameCode; + + /** + * 规格型号 + */ private String ggxh; - private String batchNo; + + /** + * 批次号 + */ + private Integer batchNo; + + /** + * 计量单位 + */ private String measname; - private String price; - private String productionDate; - private String expireDate; + + /** + * 价格 + */ + private BigDecimal price; + + /** + * 生产日期 + */ + private Date productionDate; + + /** + * 失效日期 + */ + private Date expireDate; + + /** + * 医疗器械注册备案人 + */ private String ylqxzcrbarmc; + + /** + * 注册/备案号 + */ private String zczbhhzbapzbh; - private Integer inCount; - private Integer outCount; + + /** + * 入库数量 + */ + private String inCount; + + /** + * 出库数量 + */ + private String outCount; + + /** + * 供应商 + */ private String supName; + + /** + * 部门 + */ private String deptName; + + /** + * 部门编码 + */ private String deptCode; + + /** + * 仓库 + */ private String invName; + + /** + * 仓库编码 + */ private String invCode; + + /** + * 货位 + */ private String spaceCode; + + /** + * 货位编码 + */ private String spaceName; - private Integer reCount; + +// /** +// * 实际数量 +// */ +// private String reCount; + + /** + * 出入库类型 + */ private String mainAction; + + /** + * 生产企业 + */ + private String manufacturer; + + /** + * 备注 + */ private String remark; + + /** + * 第三方单据类型 + */ + private String billType; } diff --git a/src/main/java/com/glxp/api/service/basic/impl/BasicDestinyRelService.java b/src/main/java/com/glxp/api/service/basic/impl/BasicDestinyRelService.java index 9000764ea..d1e67551a 100644 --- a/src/main/java/com/glxp/api/service/basic/impl/BasicDestinyRelService.java +++ b/src/main/java/com/glxp/api/service/basic/impl/BasicDestinyRelService.java @@ -150,4 +150,8 @@ public class BasicDestinyRelService extends ServiceImpl filterDestinyRelListByPId(String thrCode) { + return basicDestinyRelMapper.filterDestinyRelListByPId(thrCode); + } } diff --git a/src/main/java/com/glxp/api/service/inv/impl/StockCompareServiceImpl.java b/src/main/java/com/glxp/api/service/inv/impl/StockCompareServiceImpl.java index f0feb3dbb..207c50849 100644 --- a/src/main/java/com/glxp/api/service/inv/impl/StockCompareServiceImpl.java +++ b/src/main/java/com/glxp/api/service/inv/impl/StockCompareServiceImpl.java @@ -148,7 +148,7 @@ public class StockCompareServiceImpl extends CustomServiceImpl> baseResponse = erpInvClient.getInvResult(filterInvProductRequest); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + if (CollectionUtil.isNotEmpty(list)){ + String billNo = generateBillNo(filterInvProductRequest);//单据号 + //处理 返回实体 转换成 单据 和 单据明细 + List thrInvOrderDetails = new ArrayList<>(); + handleExternalConvertThrInvOrderDetail(list,thrInvOrderDetails,billNo); + + if (CollectionUtil.isNotEmpty(thrInvOrderDetails)){ + ThrInvOrder thrInvOrder = new ThrInvOrder(); + handleExternalConvertThrInvOrder(billNo,filterInvProductRequest,thrInvOrder,list.get(0)); + + //保存数据 + thrInvOrderMapper.insert(thrInvOrder); + thrInvOrderDetailMapper.insertBatch(thrInvOrderDetails); + } + } + } + } + + /** + * 生成单号 SFIO + 6位起始日期 + 6位结束日期 + 6位随机 + * @param filterInvProductRequest + * @return + */ + private String generateBillNo(FilterInvProductRequest filterInvProductRequest) { + String startDate = sdf.format(filterInvProductRequest.getStartDate()).substring(2); + String endDate = sdf.format(filterInvProductRequest.getEndDate()).substring(2); + Integer random = new Random().nextInt(900000) + 100000; + return Constant.TRIPARTITE_INV_ORDER + startDate+endDate + random; + } + + /** + * 将三方的出入库明细列表 转换为 系统的出入库单据 + * @param filterInvProductRequest + * @param thrInvOrder + * @param thrInvResultResponse + */ + private void handleExternalConvertThrInvOrder(String billNo,FilterInvProductRequest filterInvProductRequest,ThrInvOrder thrInvOrder,ThrInvResultResponse thrInvResultResponse) { + + Date newDate = new Date(); + thrInvOrder.setBillNo(billNo);//单据号 + thrInvOrder.setBillDate(newDate);//单据时间 + thrInvOrder.setStartDate(filterInvProductRequest.getStartDate());//库存开始时间 + thrInvOrder.setEndDate(filterInvProductRequest.getEndDate());//库存结束时间 + thrInvOrder.setMainAction(thrInvResultResponse.getMainAction());//出入库类型 + thrInvOrder.setBillType(thrInvResultResponse.getMainAction());//第三方单据类型 + thrInvOrder.setDeptCode(thrInvResultResponse.getDeptCode());//部门编号 + thrInvOrder.setInvCode(thrInvResultResponse.getInvCode());//仓库代码 + thrInvOrder.setSpaceCode(thrInvResultResponse.getSpaceCode());//货位编码 + thrInvOrder.setStatus(ConstantStatus.SFIO_DRAFT);//单据状态 草稿 + thrInvOrder.setCreateTime(newDate); + thrInvOrder.setCreateUser("系统自动"); + + } + + /** + * 将三方的出入库明细列表 转换为 系统的出入库单据明细 + * @param list + * @param thrInvOrderDetails + * @param billNo + */ + private void handleExternalConvertThrInvOrderDetail(List list, List thrInvOrderDetails,String billNo) { + list.forEach( item -> { + String thrCode = item.getThrCode(); + String mainAction = item.getMainAction(); + Integer count = 0; + if (ConstantType.TYPE_PUT.equals(mainAction)) { + count = Integer.valueOf(item.getInCount()); + }else { + count = Integer.valueOf(item.getOutCount()); + } + //通过thrCode获取到项目组套 + List skProjectDetailEntityList= basicDestinyRelService.filterDestinyRelListByPId(thrCode); + if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0 ){ + Integer finalCount = count; + skProjectDetailEntityList.forEach(sk -> { + ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail(); + BeanUtils.copyProperties(item,thrInvOrderDetail); + thrInvOrderDetail.setOrderIdFk(billNo); + thrInvOrderDetail.setRelId(sk.getRelId()); + Integer skCount = sk.getCount(); + if (skCount != null && skCount > 0){ + thrInvOrderDetail.setReCount(String.valueOf(skCount * finalCount)); + thrInvOrderDetails.add(thrInvOrderDetail); + } + }); + } + }); + } +} diff --git a/src/main/java/com/glxp/api/task/ThrInvOrderTask.java b/src/main/java/com/glxp/api/task/ThrInvOrderTask.java new file mode 100644 index 000000000..891672731 --- /dev/null +++ b/src/main/java/com/glxp/api/task/ThrInvOrderTask.java @@ -0,0 +1,88 @@ +package com.glxp.api.task; + +import cn.hutool.core.date.DateRange; +import com.glxp.api.dao.schedule.ScheduledDao; +import com.glxp.api.entity.system.ScheduledEntity; +import com.glxp.api.req.inv.FilterInvProductRequest; +import com.glxp.api.req.system.ScheduledRequest; +import com.glxp.api.service.thrsys.ThrInvOrderService; +import lombok.extern.slf4j.Slf4j; +import org.apache.regexp.RE; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +/** + * 自动抓取第三方出入库明细生成单据 + */ +@Slf4j +@Component +public class ThrInvOrderTask implements SchedulingConfigurer { + + @Resource + ScheduledDao scheduledDao; + @Resource + ThrInvOrderService thrInvOrderService; + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + scheduledTaskRegistrar.addTriggerTask(this::process, triggerContext -> { + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("thrInvOrderTask"); + ScheduledEntity scheduled = scheduledDao.findScheduled(scheduledRequest); + if (null == scheduled) { + log.error("自动抓取第三方出入库明细生成单据定时任务未配置,请注意!"); + return null; + } + String cron = scheduled.getCron(); + return new CronTrigger(cron).nextExecutionTime(triggerContext); + }); + } + + public void process() { + log.info("自动抓取第三方出入库明细生成单据定时任务开始"); + FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest(); + String days = getBeginAndEndDateByDays(1); + + filterInvProductRequest.setStartDate(stringToDate(days +" 00:00:00")); + filterInvProductRequest.setEndDate(stringToDate(days +" 23:59:59")); + thrInvOrderService.handleExternalThrInvOrder(filterInvProductRequest); + log.info("自动抓取第三方出入库明细生成单据定时任务结束"); + } + + /** + * 获取距离当前时间日期(n天)的开始时间和结束时间 + * @param n + * @return + */ + public static String getBeginAndEndDateByDays(int n) { + Date date=new Date();//取时间 + Calendar calendar = new GregorianCalendar(); + calendar.setTime(date); + calendar.add(calendar.DATE,-1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数 + date=calendar.getTime(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + return formatter.format(date); + } + + public static Date stringToDate(String time) { + SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = null; + try { + date = dateformat.parse(time); + } catch (ParseException e) { + e.printStackTrace(); + } + return date; + } + +} diff --git a/src/main/resources/mybatis/mapper/basic/BasicDestinyRelMapper.xml b/src/main/resources/mybatis/mapper/basic/BasicDestinyRelMapper.xml index b74fdad65..0a49b862b 100644 --- a/src/main/resources/mybatis/mapper/basic/BasicDestinyRelMapper.xml +++ b/src/main/resources/mybatis/mapper/basic/BasicDestinyRelMapper.xml @@ -284,4 +284,12 @@ group by basic_products.uuid + + + diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml new file mode 100644 index 000000000..9efe866e9 --- /dev/null +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml @@ -0,0 +1,356 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, orderIdFk, cpmctymc, relId, thrCode, nameCode, ggxh, batchNo, measname, price, + productionDate, expireDate, ylqxzcrbarmc, zczbhhzbapzbh, inCount, outCount, supName, + deptName, deptCode, invName, invCode, spaceCode, spaceName, reCount, mainAction, + manufacturer, remark + + + + + delete from thr_inv_order_detail + where id = #{id,jdbcType=INTEGER} + + + + insert into thr_inv_order_detail (orderIdFk, cpmctymc, relId, + thrCode, nameCode, ggxh, + batchNo, measname, price, + productionDate, expireDate, ylqxzcrbarmc, + zczbhhzbapzbh, inCount, outCount, + supName, deptName, deptCode, + invName, invCode, spaceCode, + spaceName, reCount, mainAction, + manufacturer, remark) + values (#{orderIdFk,jdbcType=VARCHAR}, #{cpmctymc,jdbcType=VARCHAR}, #{relId,jdbcType=INTEGER}, + #{thrCode,jdbcType=VARCHAR}, #{nameCode,jdbcType=VARCHAR}, #{ggxh,jdbcType=VARCHAR}, + #{batchNo,jdbcType=INTEGER}, #{measname,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, + #{productionDate,jdbcType=TIMESTAMP}, #{expireDate,jdbcType=TIMESTAMP}, #{ylqxzcrbarmc,jdbcType=VARCHAR}, + #{zczbhhzbapzbh,jdbcType=VARCHAR}, #{inCount,jdbcType=VARCHAR}, #{outCount,jdbcType=VARCHAR}, + #{supName,jdbcType=VARCHAR}, #{deptName,jdbcType=VARCHAR}, #{deptCode,jdbcType=VARCHAR}, + #{invName,jdbcType=VARCHAR}, #{invCode,jdbcType=VARCHAR}, #{spaceCode,jdbcType=VARCHAR}, + #{spaceName,jdbcType=VARCHAR}, #{reCount,jdbcType=VARCHAR}, #{mainAction,jdbcType=VARCHAR}, + #{manufacturer,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}) + + + + insert into thr_inv_order_detail + + + orderIdFk, + + + cpmctymc, + + + relId, + + + thrCode, + + + nameCode, + + + ggxh, + + + batchNo, + + + measname, + + + price, + + + productionDate, + + + expireDate, + + + ylqxzcrbarmc, + + + zczbhhzbapzbh, + + + inCount, + + + outCount, + + + supName, + + + deptName, + + + deptCode, + + + invName, + + + invCode, + + + spaceCode, + + + spaceName, + + + reCount, + + + mainAction, + + + manufacturer, + + + remark, + + + + + #{orderIdFk,jdbcType=VARCHAR}, + + + #{cpmctymc,jdbcType=VARCHAR}, + + + #{relId,jdbcType=INTEGER}, + + + #{thrCode,jdbcType=VARCHAR}, + + + #{nameCode,jdbcType=VARCHAR}, + + + #{ggxh,jdbcType=VARCHAR}, + + + #{batchNo,jdbcType=INTEGER}, + + + #{measname,jdbcType=VARCHAR}, + + + #{price,jdbcType=DECIMAL}, + + + #{productionDate,jdbcType=TIMESTAMP}, + + + #{expireDate,jdbcType=TIMESTAMP}, + + + #{ylqxzcrbarmc,jdbcType=VARCHAR}, + + + #{zczbhhzbapzbh,jdbcType=VARCHAR}, + + + #{inCount,jdbcType=VARCHAR}, + + + #{outCount,jdbcType=VARCHAR}, + + + #{supName,jdbcType=VARCHAR}, + + + #{deptName,jdbcType=VARCHAR}, + + + #{deptCode,jdbcType=VARCHAR}, + + + #{invName,jdbcType=VARCHAR}, + + + #{invCode,jdbcType=VARCHAR}, + + + #{spaceCode,jdbcType=VARCHAR}, + + + #{spaceName,jdbcType=VARCHAR}, + + + #{reCount,jdbcType=VARCHAR}, + + + #{mainAction,jdbcType=VARCHAR}, + + + #{manufacturer,jdbcType=VARCHAR}, + + + #{remark,jdbcType=VARCHAR}, + + + + + + update thr_inv_order_detail + + + orderIdFk = #{orderIdFk,jdbcType=VARCHAR}, + + + cpmctymc = #{cpmctymc,jdbcType=VARCHAR}, + + + relId = #{relId,jdbcType=INTEGER}, + + + thrCode = #{thrCode,jdbcType=VARCHAR}, + + + nameCode = #{nameCode,jdbcType=VARCHAR}, + + + ggxh = #{ggxh,jdbcType=VARCHAR}, + + + batchNo = #{batchNo,jdbcType=INTEGER}, + + + measname = #{measname,jdbcType=VARCHAR}, + + + price = #{price,jdbcType=DECIMAL}, + + + productionDate = #{productionDate,jdbcType=TIMESTAMP}, + + + expireDate = #{expireDate,jdbcType=TIMESTAMP}, + + + ylqxzcrbarmc = #{ylqxzcrbarmc,jdbcType=VARCHAR}, + + + zczbhhzbapzbh = #{zczbhhzbapzbh,jdbcType=VARCHAR}, + + + inCount = #{inCount,jdbcType=VARCHAR}, + + + outCount = #{outCount,jdbcType=VARCHAR}, + + + supName = #{supName,jdbcType=VARCHAR}, + + + deptName = #{deptName,jdbcType=VARCHAR}, + + + deptCode = #{deptCode,jdbcType=VARCHAR}, + + + invName = #{invName,jdbcType=VARCHAR}, + + + invCode = #{invCode,jdbcType=VARCHAR}, + + + spaceCode = #{spaceCode,jdbcType=VARCHAR}, + + + spaceName = #{spaceName,jdbcType=VARCHAR}, + + + reCount = #{reCount,jdbcType=VARCHAR}, + + + mainAction = #{mainAction,jdbcType=VARCHAR}, + + + manufacturer = #{manufacturer,jdbcType=VARCHAR}, + + + remark = #{remark,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + + update thr_inv_order_detail + set orderIdFk = #{orderIdFk,jdbcType=VARCHAR}, + cpmctymc = #{cpmctymc,jdbcType=VARCHAR}, + relId = #{relId,jdbcType=INTEGER}, + thrCode = #{thrCode,jdbcType=VARCHAR}, + nameCode = #{nameCode,jdbcType=VARCHAR}, + ggxh = #{ggxh,jdbcType=VARCHAR}, + batchNo = #{batchNo,jdbcType=INTEGER}, + measname = #{measname,jdbcType=VARCHAR}, + price = #{price,jdbcType=DECIMAL}, + productionDate = #{productionDate,jdbcType=TIMESTAMP}, + expireDate = #{expireDate,jdbcType=TIMESTAMP}, + ylqxzcrbarmc = #{ylqxzcrbarmc,jdbcType=VARCHAR}, + zczbhhzbapzbh = #{zczbhhzbapzbh,jdbcType=VARCHAR}, + inCount = #{inCount,jdbcType=VARCHAR}, + outCount = #{outCount,jdbcType=VARCHAR}, + supName = #{supName,jdbcType=VARCHAR}, + deptName = #{deptName,jdbcType=VARCHAR}, + deptCode = #{deptCode,jdbcType=VARCHAR}, + invName = #{invName,jdbcType=VARCHAR}, + invCode = #{invCode,jdbcType=VARCHAR}, + spaceCode = #{spaceCode,jdbcType=VARCHAR}, + spaceName = #{spaceName,jdbcType=VARCHAR}, + reCount = #{reCount,jdbcType=VARCHAR}, + mainAction = #{mainAction,jdbcType=VARCHAR}, + manufacturer = #{manufacturer,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + + diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml new file mode 100644 index 000000000..85aa52871 --- /dev/null +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml @@ -0,0 +1,226 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + id, billNo, billDate, startDate, endDate, mainAction, billType, deptCode, invCode, + spaceCode, `status`, createTime, `createUser`, updateTime, updateUser, remark + + + + + delete from thr_inv_order + where id = #{id,jdbcType=INTEGER} + + + + insert into thr_inv_order (billNo, billDate, startDate, + endDate, mainAction, billType, + deptCode, invCode, spaceCode, + `status`, createTime, `createUser`, + updateTime, updateUser, remark + ) + values (#{billNo,jdbcType=VARCHAR}, #{billDate,jdbcType=TIMESTAMP}, #{startDate,jdbcType=TIMESTAMP}, + #{endDate,jdbcType=TIMESTAMP}, #{mainAction,jdbcType=VARCHAR}, #{billType,jdbcType=VARCHAR}, + #{deptCode,jdbcType=VARCHAR}, #{invCode,jdbcType=VARCHAR}, #{spaceCode,jdbcType=VARCHAR}, + #{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{createUser,jdbcType=VARCHAR}, + #{updateTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR} + ) + + + + insert into thr_inv_order + + + billNo, + + + billDate, + + + startDate, + + + endDate, + + + mainAction, + + + billType, + + + deptCode, + + + invCode, + + + spaceCode, + + + `status`, + + + createTime, + + + `createUser`, + + + updateTime, + + + updateUser, + + + remark, + + + + + #{billNo,jdbcType=VARCHAR}, + + + #{billDate,jdbcType=TIMESTAMP}, + + + #{startDate,jdbcType=TIMESTAMP}, + + + #{endDate,jdbcType=TIMESTAMP}, + + + #{mainAction,jdbcType=VARCHAR}, + + + #{billType,jdbcType=VARCHAR}, + + + #{deptCode,jdbcType=VARCHAR}, + + + #{invCode,jdbcType=VARCHAR}, + + + #{spaceCode,jdbcType=VARCHAR}, + + + #{status,jdbcType=TINYINT}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{createUser,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{updateUser,jdbcType=VARCHAR}, + + + #{remark,jdbcType=VARCHAR}, + + + + + + update thr_inv_order + + + billNo = #{billNo,jdbcType=VARCHAR}, + + + billDate = #{billDate,jdbcType=TIMESTAMP}, + + + startDate = #{startDate,jdbcType=TIMESTAMP}, + + + endDate = #{endDate,jdbcType=TIMESTAMP}, + + + mainAction = #{mainAction,jdbcType=VARCHAR}, + + + billType = #{billType,jdbcType=VARCHAR}, + + + deptCode = #{deptCode,jdbcType=VARCHAR}, + + + invCode = #{invCode,jdbcType=VARCHAR}, + + + spaceCode = #{spaceCode,jdbcType=VARCHAR}, + + + `status` = #{status,jdbcType=TINYINT}, + + + createTime = #{createTime,jdbcType=TIMESTAMP}, + + + `createUser` = #{createUser,jdbcType=VARCHAR}, + + + updateTime = #{updateTime,jdbcType=TIMESTAMP}, + + + updateUser = #{updateUser,jdbcType=VARCHAR}, + + + remark = #{remark,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + + update thr_inv_order + set billNo = #{billNo,jdbcType=VARCHAR}, + billDate = #{billDate,jdbcType=TIMESTAMP}, + startDate = #{startDate,jdbcType=TIMESTAMP}, + endDate = #{endDate,jdbcType=TIMESTAMP}, + mainAction = #{mainAction,jdbcType=VARCHAR}, + billType = #{billType,jdbcType=VARCHAR}, + deptCode = #{deptCode,jdbcType=VARCHAR}, + invCode = #{invCode,jdbcType=VARCHAR}, + spaceCode = #{spaceCode,jdbcType=VARCHAR}, + `status` = #{status,jdbcType=TINYINT}, + createTime = #{createTime,jdbcType=TIMESTAMP}, + `createUser` = #{createUser,jdbcType=VARCHAR}, + updateTime = #{updateTime,jdbcType=TIMESTAMP}, + updateUser = #{updateUser,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file From 85c9db2ae521b30216692b785d487055fdc45d7b Mon Sep 17 00:00:00 2001 From: chenhc <2369838784@qq.com> Date: Thu, 29 Feb 2024 18:12:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E9=A1=B9=E7=9B=AE=E7=BB=84?= =?UTF-8?q?=E5=A5=97=E5=92=8C=E4=B8=89=E6=96=B9=E5=87=BA=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E6=98=8E=E7=BB=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../glxp/api/constant/ThirdSysConstant.java | 5 + .../glxp/api/controller/TestController.java | 10 - .../thrsys/ThrInvOrderController.java | 111 +++++++++ .../dao/thrsys/ThrInvOrderDetailMapper.java | 3 + .../api/dao/thrsys/ThrInvOrderMapper.java | 11 +- .../glxp/api/entity/thrsys/ThrInvOrder.java | 5 + .../java/com/glxp/api/http/ErpInvClient.java | 39 +-- .../api/req/inv/FilterInvProductRequest.java | 1 + .../FilterThrInvOrderDetailRequest.java | 13 + .../req/thrsys/FilterThrInvOrderRequest.java | 32 +++ .../api/req/thrsys/GenerateOrderRequest.java | 28 +++ .../thrsys/ThrInvOrderDetailService.java | 14 ++ .../service/thrsys/ThrInvOrderService.java | 24 ++ .../impl/ThrInvOrderDetailServiceImpl.java | 47 ++++ .../thrsys/impl/ThrInvOrderServiceImpl.java | 234 +++++++++++++++--- .../com/glxp/api/task/SyncThirdSysTask.java | 30 +++ .../com/glxp/api/task/ThrInvOrderTask.java | 88 ------- .../mapper/thrsys/ThrInvOrderDetailMapper.xml | 11 + .../mapper/thrsys/ThrInvOrderMapper.xml | 61 ++++- 19 files changed, 604 insertions(+), 163 deletions(-) create mode 100644 src/main/java/com/glxp/api/controller/thrsys/ThrInvOrderController.java create mode 100644 src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderDetailRequest.java create mode 100644 src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderRequest.java create mode 100644 src/main/java/com/glxp/api/req/thrsys/GenerateOrderRequest.java create mode 100644 src/main/java/com/glxp/api/service/thrsys/ThrInvOrderDetailService.java create mode 100644 src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderDetailServiceImpl.java delete mode 100644 src/main/java/com/glxp/api/task/ThrInvOrderTask.java diff --git a/src/main/java/com/glxp/api/constant/ThirdSysConstant.java b/src/main/java/com/glxp/api/constant/ThirdSysConstant.java index e3ae025d7..f5db60e1c 100644 --- a/src/main/java/com/glxp/api/constant/ThirdSysConstant.java +++ b/src/main/java/com/glxp/api/constant/ThirdSysConstant.java @@ -50,5 +50,10 @@ public interface ThirdSysConstant { */ String SICKER_QUERY_URL = "sickerQueryUrl"; + /** + * 出入库明细下载 + */ + String INV_ORDER_QUERY_URL = "invOrderUrl"; + } diff --git a/src/main/java/com/glxp/api/controller/TestController.java b/src/main/java/com/glxp/api/controller/TestController.java index ff5f2d7c0..57a40fb84 100644 --- a/src/main/java/com/glxp/api/controller/TestController.java +++ b/src/main/java/com/glxp/api/controller/TestController.java @@ -6,9 +6,7 @@ import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.Constant; import com.glxp.api.req.sync.BasicExportStatusRequest; -import com.glxp.api.task.SyncThirdSysTask; import com.glxp.api.task.TestStatOrderService; -import com.glxp.api.task.ThrInvOrderTask; import com.glxp.api.util.MsDateUtil; import com.glxp.api.util.RedisUtil; import lombok.extern.slf4j.Slf4j; @@ -17,15 +15,12 @@ import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.text.ParseException; -import java.util.Date; @Slf4j @RestController public class TestController { @Resource TestStatOrderService statOrderService; - @Resource - ThrInvOrderTask thrInvOrderTask; @GetMapping("/test/stat/order") @@ -72,9 +67,4 @@ public class TestController { return ResultVOUtils.success("hello"); } - @GetMapping("/test/thrInvOrderTask") - public BaseResponse thrInvOrderTask() { - thrInvOrderTask.process(); - return ResultVOUtils.success(); - } } diff --git a/src/main/java/com/glxp/api/controller/thrsys/ThrInvOrderController.java b/src/main/java/com/glxp/api/controller/thrsys/ThrInvOrderController.java new file mode 100644 index 000000000..e85dbeaea --- /dev/null +++ b/src/main/java/com/glxp/api/controller/thrsys/ThrInvOrderController.java @@ -0,0 +1,111 @@ +package com.glxp.api.controller.thrsys; + +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.thrsys.ThrInvOrder; +import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.entity.thrsys.ThrOrderDetailEntity; +import com.glxp.api.entity.thrsys.ThrOrderEntity; +import com.glxp.api.req.system.DeleteRequest; +import com.glxp.api.req.thrsys.*; +import com.glxp.api.res.PageSimpleResponse; +import com.glxp.api.service.thrsys.ThrInvOrderDetailService; +import com.glxp.api.service.thrsys.ThrInvOrderService; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +@RestController +public class ThrInvOrderController { + + @Resource + ThrInvOrderService thrInvOrderService; + + @Resource + ThrInvOrderDetailService thrInvOrderDetailService; + + @AuthRuleAnnotation("") + @GetMapping("/udiwms/thrsys/getThrInvOrders") + public BaseResponse getOrders(FilterThrInvOrderRequest filterThrInvOrderRequest, + BindingResult bindingResult) { + + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + List thrInvOrders + = thrInvOrderService.filterThrInvOrder(filterThrInvOrderRequest); + PageInfo pageInfo; + pageInfo = new PageInfo<>(thrInvOrders); + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setTotal(pageInfo.getTotal()); + pageSimpleResponse.setList(thrInvOrders); + return ResultVOUtils.success(pageSimpleResponse); + } + + @AuthRuleAnnotation("") + @GetMapping("/udiwms/thrsys/getThrInvOrderDetails") + public BaseResponse getThrInvOrderDetails(FilterThrInvOrderDetailRequest filterThrInvOrderDetailRequest, + BindingResult bindingResult) { + + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + List thrInvOrderDetails + = thrInvOrderDetailService.filterThrInvOrderDetails(filterThrInvOrderDetailRequest); + PageInfo pageInfo; + pageInfo = new PageInfo<>(thrInvOrderDetails); + PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); + pageSimpleResponse.setTotal(pageInfo.getTotal()); + pageSimpleResponse.setList(thrInvOrderDetails); + return ResultVOUtils.success(pageSimpleResponse); + } + + @AuthRuleAnnotation("") + @PostMapping("/udiwms/thrsys/delThrInvOrderDetail") + public BaseResponse delThrInvOrderDetail(@RequestBody DeleteRequest deleteRequest, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + String id = deleteRequest.getId(); + int b = thrInvOrderDetailService.delThrInvOrderDetail(Integer.parseInt(id)); + if (b > 0) return ResultVOUtils.success("删除成功"); + else return ResultVOUtils.error(500, "无法删除!"); + } + + @AuthRuleAnnotation("") + @PostMapping("/udiwms/thrsys/delThrInvOrder") + public BaseResponse delThrInvOrder(@RequestBody DeleteRequest deleteRequest, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + String billNo = deleteRequest.getBillNo(); + int b = thrInvOrderService.delThrInvOrderByBillNo(billNo); + if (b > 0) { + thrInvOrderDetailService.delThrInvOrderDetailByBillNo(billNo); + return ResultVOUtils.success("删除成功"); + } + else return ResultVOUtils.error(500, "无法删除!"); + } + + @AuthRuleAnnotation("") + @PostMapping("/udiwms/thrsys/generateOrder") + public BaseResponse generateOrder(@RequestBody @Valid GenerateOrderRequest generateOrderRequest, BindingResult bindingResult) { + if (bindingResult.hasErrors()) { + return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); + } + if (thrInvOrderService.generateOrder(generateOrderRequest)){ + return ResultVOUtils.success("生成成功"); + } + return ResultVOUtils.error(500, "生成失败!"); + } + +} diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java index 5c0d32c5f..f7c7564b9 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderDetailMapper.java @@ -4,6 +4,7 @@ import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.dao.inout.IoOrderDetailBizDao; import com.glxp.api.entity.inout.IoOrderDetailBizEntity; import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.req.thrsys.FilterThrInvOrderDetailRequest; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -21,4 +22,6 @@ public interface ThrInvOrderDetailMapper extends BaseMapperPlus filterThrOrderDetailDetail(FilterThrInvOrderDetailRequest filterThrInvOrderDetailRequest); } diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java index 5e8c5b632..8036a0ac1 100644 --- a/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java +++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvOrderMapper.java @@ -1,10 +1,15 @@ package com.glxp.api.dao.thrsys; +import com.glxp.api.dao.BaseMapperPlus; import com.glxp.api.entity.thrsys.ThrInvOrder; +import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.req.thrsys.FilterThrInvOrderRequest; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + @Mapper -public interface ThrInvOrderMapper { +public interface ThrInvOrderMapper extends BaseMapperPlus { int deleteByPrimaryKey(Integer id); int insert(ThrInvOrder record); @@ -16,4 +21,6 @@ public interface ThrInvOrderMapper { int updateByPrimaryKeySelective(ThrInvOrder record); int updateByPrimaryKey(ThrInvOrder record); -} \ No newline at end of file + + List filterThrInvOrder(FilterThrInvOrderRequest filterThrInvOrderRequest); +} diff --git a/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java index 26494cde1..8d31854fc 100644 --- a/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java +++ b/src/main/java/com/glxp/api/entity/thrsys/ThrInvOrder.java @@ -53,6 +53,11 @@ public class ThrInvOrder implements Serializable { */ private String billType; + /** + * 外部系统 + */ + private String thirdSysFk; + /** * 部门编码 */ diff --git a/src/main/java/com/glxp/api/http/ErpInvClient.java b/src/main/java/com/glxp/api/http/ErpInvClient.java index 85b252cae..f4cbb2508 100644 --- a/src/main/java/com/glxp/api/http/ErpInvClient.java +++ b/src/main/java/com/glxp/api/http/ErpInvClient.java @@ -79,27 +79,28 @@ public class ErpInvClient { } public BaseResponse> getInvResult(FilterInvProductRequest invProductRequest) { -// ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(invProductRequest.getThirdSys()); + ThrSystemEntity basicThirdSysEntity = basicThirdSysService.selectByThirdId(invProductRequest.getThirdSys()); // String url = basicThirdSysEntity.getThridUrl() + "/udiwms/erp/inv/getInvResult"; + String url = basicThirdSysEntity.getThridUrl() + invProductRequest.getThirdSysUrlValue(); try { -// String response = httpOkClient.uCloudPost(url, invProductRequest); - ThrInvResultResponse thrInvResultResponse = new ThrInvResultResponse(); - thrInvResultResponse.setThrCode("11"); - thrInvResultResponse.setOutCount("2"); - thrInvResultResponse.setBillType(ConstantType.TYPE_OUT); - ArrayList objects = new ArrayList<>(); - objects.add(thrInvResultResponse); - PageSimpleResponse thrInvResultResponsePageSimpleResponse = new PageSimpleResponse<>(); - thrInvResultResponsePageSimpleResponse.setList(objects); - BaseResponse> pageSimpleResponseBaseResponse = new BaseResponse<>(); - pageSimpleResponseBaseResponse.setCode(20000); - pageSimpleResponseBaseResponse.setData(thrInvResultResponsePageSimpleResponse); - return pageSimpleResponseBaseResponse; -// BaseResponse> listBaseResponse = -// JSONObject.parseObject(response, new TypeReference>>() { -// }); -// -// return listBaseResponse; + String response = httpOkClient.uCloudPost(url, invProductRequest); +// ThrInvResultResponse thrInvResultResponse = new ThrInvResultResponse(); +// thrInvResultResponse.setThrCode("11"); +// thrInvResultResponse.setOutCount("2"); +// thrInvResultResponse.setBillType(ConstantType.TYPE_OUT); +// ArrayList objects = new ArrayList<>(); +// objects.add(thrInvResultResponse); +// PageSimpleResponse thrInvResultResponsePageSimpleResponse = new PageSimpleResponse<>(); +// thrInvResultResponsePageSimpleResponse.setList(objects); +// BaseResponse> pageSimpleResponseBaseResponse = new BaseResponse<>(); +// pageSimpleResponseBaseResponse.setCode(20000); +// pageSimpleResponseBaseResponse.setData(thrInvResultResponsePageSimpleResponse); +// return pageSimpleResponseBaseResponse; + BaseResponse> listBaseResponse = + JSONObject.parseObject(response, new TypeReference>>() { + }); + + return listBaseResponse; } catch (Exception e) { log.error("获取第三方库存明细异常", e); return ResultVOUtils.error(500, "连接第三方系统接口服务出错"); diff --git a/src/main/java/com/glxp/api/req/inv/FilterInvProductRequest.java b/src/main/java/com/glxp/api/req/inv/FilterInvProductRequest.java index 16c8d679c..16a4708e8 100644 --- a/src/main/java/com/glxp/api/req/inv/FilterInvProductRequest.java +++ b/src/main/java/com/glxp/api/req/inv/FilterInvProductRequest.java @@ -124,6 +124,7 @@ public class FilterInvProductRequest extends ListPageRequest { private Date startDate; private Date endDate; private String thirdSys; + private String thirdSysUrlValue; private Long compareId; diff --git a/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderDetailRequest.java b/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderDetailRequest.java new file mode 100644 index 000000000..c1b5cbdf9 --- /dev/null +++ b/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderDetailRequest.java @@ -0,0 +1,13 @@ +package com.glxp.api.req.thrsys; + + +import com.glxp.api.util.page.ListPageRequest; +import lombok.Data; + + +@Data +public class FilterThrInvOrderDetailRequest extends ListPageRequest { + + private String orderIdFk; + +} diff --git a/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderRequest.java b/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderRequest.java new file mode 100644 index 000000000..b88be0e69 --- /dev/null +++ b/src/main/java/com/glxp/api/req/thrsys/FilterThrInvOrderRequest.java @@ -0,0 +1,32 @@ +package com.glxp.api.req.thrsys; + +import com.glxp.api.res.thrsys.ThrOrderResponse; +import com.glxp.api.util.page.ListPageRequest; +import lombok.Data; + +import java.util.List; + +@Data +public class FilterThrInvOrderRequest extends ListPageRequest { + + /** + * 单据号 + */ + private String billNo; + /** + * 外部系统 + */ + private String thirdSysFk; + /** + * 开始日期 + */ + private String startDate; //起始日期 + /** + * 结束日期 + */ + private String endDate; //结束日期 + /** + * 单据类型 + */ + private String billType; +} diff --git a/src/main/java/com/glxp/api/req/thrsys/GenerateOrderRequest.java b/src/main/java/com/glxp/api/req/thrsys/GenerateOrderRequest.java new file mode 100644 index 000000000..40d24ffa9 --- /dev/null +++ b/src/main/java/com/glxp/api/req/thrsys/GenerateOrderRequest.java @@ -0,0 +1,28 @@ +package com.glxp.api.req.thrsys; + +import lombok.Data; + +import javax.validation.constraints.NotEmpty; + +@Data +public class GenerateOrderRequest { + + /** + * 来源单据号 + */ + @NotEmpty(message = "来源单据号不能为空!") + private String billNo; + + /** + * 业务类型 + */ + @NotEmpty(message = "业务类型不能为空!") + private String action; + + /** + * 往来单位 + */ + @NotEmpty(message = "往来单位不能为空!") + private String fromCorp; + +} diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderDetailService.java b/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderDetailService.java new file mode 100644 index 000000000..c6cde2ca4 --- /dev/null +++ b/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderDetailService.java @@ -0,0 +1,14 @@ +package com.glxp.api.service.thrsys; + +import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.req.thrsys.FilterThrInvOrderDetailRequest; + +import java.util.List; + +public interface ThrInvOrderDetailService { + public List filterThrInvOrderDetails(FilterThrInvOrderDetailRequest filterThrInvOrderDetailRequest); + + int delThrInvOrderDetail(Integer id); + + int delThrInvOrderDetailByBillNo(String billNo); +} diff --git a/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderService.java b/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderService.java index 1f270352e..684aec5b2 100644 --- a/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderService.java +++ b/src/main/java/com/glxp/api/service/thrsys/ThrInvOrderService.java @@ -1,6 +1,12 @@ package com.glxp.api.service.thrsys; +import com.glxp.api.entity.thrsys.ThrInvOrder; +import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.inv.FilterInvProductRequest; +import com.glxp.api.req.thrsys.FilterThrInvOrderRequest; +import com.glxp.api.req.thrsys.GenerateOrderRequest; + +import java.util.List; public interface ThrInvOrderService { @@ -8,4 +14,22 @@ public interface ThrInvOrderService { * 查询三方系统的出入库明细、进行处理 */ public void handleExternalThrInvOrder(FilterInvProductRequest filterInvProductRequest); + + void downloadInvOrder(ThrSystemDetailEntity thrSystemDetailEntity); + + /** + * 分忧条件查询 + * @param filterThrInvOrderRequest + * @return + */ + List filterThrInvOrder(FilterThrInvOrderRequest filterThrInvOrderRequest); + + int delThrInvOrderByBillNo(String billNo); + + /** + * 转生成单据 + * @param generateOrderRequest + * @return + */ + boolean generateOrder(GenerateOrderRequest generateOrderRequest); } diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderDetailServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderDetailServiceImpl.java new file mode 100644 index 000000000..d0bb45156 --- /dev/null +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderDetailServiceImpl.java @@ -0,0 +1,47 @@ +package com.glxp.api.service.thrsys.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.github.pagehelper.PageHelper; +import com.glxp.api.dao.thrsys.ThrInvOrderDetailMapper; +import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.entity.thrsys.ThrOrderDetailEntity; +import com.glxp.api.req.thrsys.FilterThrInvOrderDetailRequest; +import com.glxp.api.service.thrsys.ThrInvOrderDetailService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +@Service +public class ThrInvOrderDetailServiceImpl implements ThrInvOrderDetailService { + + @Resource + ThrInvOrderDetailMapper thrInvOrderDetailMapper; + + @Override + public List filterThrInvOrderDetails(FilterThrInvOrderDetailRequest filterThrInvOrderDetailRequest) { + if (filterThrInvOrderDetailRequest == null) { + return Collections.emptyList(); + } + if (filterThrInvOrderDetailRequest.getPage() != null) { + int offset = (filterThrInvOrderDetailRequest.getPage() - 1) * filterThrInvOrderDetailRequest.getLimit(); + PageHelper.offsetPage(offset, filterThrInvOrderDetailRequest.getLimit()); + } + List data = thrInvOrderDetailMapper.filterThrOrderDetailDetail(filterThrInvOrderDetailRequest); + return data; + } + + @Override + public int delThrInvOrderDetail(Integer id) { + return thrInvOrderDetailMapper.deleteByPrimaryKey(id); + } + + @Override + public int delThrInvOrderDetailByBillNo(String billNo) { + UpdateWrapper uw = new UpdateWrapper<>(); + uw.eq("orderIdFk",billNo); + return thrInvOrderDetailMapper.delete(uw); + } +} diff --git a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderServiceImpl.java b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderServiceImpl.java index df58014f1..700526337 100644 --- a/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderServiceImpl.java +++ b/src/main/java/com/glxp/api/service/thrsys/impl/ThrInvOrderServiceImpl.java @@ -1,7 +1,11 @@ package com.glxp.api.service.thrsys.impl; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.IdUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.github.pagehelper.PageHelper; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; @@ -9,20 +13,34 @@ import com.glxp.api.constant.ConstantType; import com.glxp.api.dao.thrsys.ThrInvOrderDetailMapper; import com.glxp.api.dao.thrsys.ThrInvOrderMapper; import com.glxp.api.entity.basic.BasicSkProjectDetailEntity; +import com.glxp.api.entity.inout.IoOrderDetailBizEntity; +import com.glxp.api.entity.inout.IoOrderEntity; +import com.glxp.api.entity.system.SystemParamConfigEntity; import com.glxp.api.entity.thrsys.ThrInvOrder; import com.glxp.api.entity.thrsys.ThrInvOrderDetail; +import com.glxp.api.entity.thrsys.ThrOrderEntity; +import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.http.ErpInvClient; import com.glxp.api.req.inv.FilterInvProductRequest; +import com.glxp.api.req.thrsys.FilterThrInvOrderRequest; +import com.glxp.api.req.thrsys.GenerateOrderRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.inv.ThrInvResultResponse; +import com.glxp.api.service.auth.CustomerService; import com.glxp.api.service.basic.impl.BasicDestinyRelService; +import com.glxp.api.service.inout.IoOrderDetailBizService; +import com.glxp.api.service.inout.IoOrderService; +import com.glxp.api.service.system.SystemParamConfigService; import com.glxp.api.service.thrsys.ThrInvOrderService; +import com.glxp.api.util.GennerOrderUtils; +import com.glxp.api.util.OrderNoTypeBean; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -40,6 +58,17 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { ThrInvOrderMapper thrInvOrderMapper; @Resource ThrInvOrderDetailMapper thrInvOrderDetailMapper; + @Resource + SystemParamConfigService systemParamConfigService; + @Resource + GennerOrderUtils gennerOrderUtils; + @Resource + CustomerService customerService; + @Resource + IoOrderService ioOrderService; + @Resource + IoOrderDetailBizService ioOrderDetailBizService; + // 设置要输出的日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); @@ -48,15 +77,15 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { BaseResponse> baseResponse = erpInvClient.getInvResult(filterInvProductRequest); if (baseResponse.getCode() == 20000) { List list = baseResponse.getData().getList(); - if (CollectionUtil.isNotEmpty(list)){ + if (CollectionUtil.isNotEmpty(list)) { String billNo = generateBillNo(filterInvProductRequest);//单据号 //处理 返回实体 转换成 单据 和 单据明细 List thrInvOrderDetails = new ArrayList<>(); - handleExternalConvertThrInvOrderDetail(list,thrInvOrderDetails,billNo); + handleExternalConvertThrInvOrderDetail(list, thrInvOrderDetails, billNo); - if (CollectionUtil.isNotEmpty(thrInvOrderDetails)){ + if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) { ThrInvOrder thrInvOrder = new ThrInvOrder(); - handleExternalConvertThrInvOrder(billNo,filterInvProductRequest,thrInvOrder,list.get(0)); + handleExternalConvertThrInvOrder(billNo, filterInvProductRequest, thrInvOrder, list.get(0)); //保存数据 thrInvOrderMapper.insert(thrInvOrder); @@ -66,8 +95,98 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { } } + @Override + public void downloadInvOrder(ThrSystemDetailEntity thrSystemDetailEntity) { + log.info("自动抓取第三方出入库明细生成单据定时任务开始"); + FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest(); + filterInvProductRequest.setThirdSys(thrSystemDetailEntity.getThirdSysFk()); + filterInvProductRequest.setThirdSysUrlValue(thrSystemDetailEntity.getValue()); + String days = getBeginAndEndDateByDays(1); + + filterInvProductRequest.setStartDate(stringToDate(days + " 00:00:00")); + filterInvProductRequest.setEndDate(stringToDate(days + " 23:59:59")); + handleExternalThrInvOrder(filterInvProductRequest); + log.info("自动抓取第三方出入库明细生成单据定时任务结束"); + + } + + @Override + public List filterThrInvOrder(FilterThrInvOrderRequest filterThrInvOrderRequest) { + if (filterThrInvOrderRequest == null) { + return Collections.emptyList(); + } + if (filterThrInvOrderRequest.getPage() != null) { + int offset = (filterThrInvOrderRequest.getPage() - 1) * filterThrInvOrderRequest.getLimit(); + PageHelper.offsetPage(offset, filterThrInvOrderRequest.getLimit()); + } + List data = thrInvOrderMapper.filterThrInvOrder(filterThrInvOrderRequest); + return data; + } + + @Override + public int delThrInvOrderByBillNo(String billNo) { + UpdateWrapper uw = new UpdateWrapper<>(); + uw.eq("billNo", billNo); + return thrInvOrderMapper.delete(uw); + } + + @Override + public boolean generateOrder(GenerateOrderRequest generateOrderRequest) { + String billNo = generateOrderRequest.getBillNo(); + //通过单号获取单据信息 + QueryWrapper qw = new QueryWrapper<>(); + qw.eq("billNo",billNo); + ThrInvOrder thrInvOrder = thrInvOrderMapper.selectOne(qw); + if (Objects.isNull(thrInvOrder)) return false; + + //通过单号获取单据明细信息 + QueryWrapper qwd = new QueryWrapper<>(); + qwd.eq("orderIdFk",billNo); + List thrInvOrderDetails = thrInvOrderDetailMapper.selectList(qwd); + if (CollectionUtil.isNotEmpty(thrInvOrderDetails)) return false; + + //新单号 + String newBillNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER, "yyyyMMdd")); + + IoOrderEntity ioOrderEntity = new IoOrderEntity(); + ioOrderEntity.setBillNo(newBillNo); + ioOrderEntity.setMainAction(thrInvOrder.getMainAction()); + ioOrderEntity.setFromCorp(generateOrderRequest.getFromCorp()); + ioOrderEntity.setInvCode(thrInvOrder.getInvCode()); + ioOrderEntity.setDeptCode(thrInvOrder.getDeptCode()); + + ioOrderEntity.setFromType(ConstantStatus.FROM_THRORDER);//网页新增 + ioOrderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE);//草稿 + ioOrderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT);//草稿 + ioOrderEntity.setCorpOrderId(billNo);//单据号 + ioOrderEntity.setUpdateTime(new Date()); + ioOrderEntity.setCreateTime(new Date()); + Long userId = customerService.getUserId(); + ioOrderEntity.setCreateUser(userId + ""); + ioOrderEntity.setUpdateUser(userId + ""); + ioOrderEntity.setOrderType(ConstantStatus.ORDER_TYPE_NORMAL);//正常单据处理 + + List newOrderDetailBiz = new ArrayList<>(thrInvOrderDetails.size()); + if (!copyOrderDetailBiz(thrInvOrderDetails,newOrderDetailBiz)){ + return false; + } + + ioOrderService.insertOrder(ioOrderEntity); + return ioOrderDetailBizService.batchInsertBizs(newOrderDetailBiz); + } + + private boolean copyOrderDetailBiz(List thrInvOrderDetails, List newOrderDetailBiz) { + /** + * 1、获取产品的集合列表信息 + * 2、遍历封装 + */ + + return true; + } + /** * 生成单号 SFIO + 6位起始日期 + 6位结束日期 + 6位随机 + * * @param filterInvProductRequest * @return */ @@ -75,16 +194,17 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { String startDate = sdf.format(filterInvProductRequest.getStartDate()).substring(2); String endDate = sdf.format(filterInvProductRequest.getEndDate()).substring(2); Integer random = new Random().nextInt(900000) + 100000; - return Constant.TRIPARTITE_INV_ORDER + startDate+endDate + random; + return Constant.TRIPARTITE_INV_ORDER + startDate + endDate + random; } /** * 将三方的出入库明细列表 转换为 系统的出入库单据 + * * @param filterInvProductRequest * @param thrInvOrder * @param thrInvResultResponse */ - private void handleExternalConvertThrInvOrder(String billNo,FilterInvProductRequest filterInvProductRequest,ThrInvOrder thrInvOrder,ThrInvResultResponse thrInvResultResponse) { + private void handleExternalConvertThrInvOrder(String billNo, FilterInvProductRequest filterInvProductRequest, ThrInvOrder thrInvOrder, ThrInvResultResponse thrInvResultResponse) { Date newDate = new Date(); thrInvOrder.setBillNo(billNo);//单据号 @@ -93,6 +213,7 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { thrInvOrder.setEndDate(filterInvProductRequest.getEndDate());//库存结束时间 thrInvOrder.setMainAction(thrInvResultResponse.getMainAction());//出入库类型 thrInvOrder.setBillType(thrInvResultResponse.getMainAction());//第三方单据类型 + thrInvOrder.setThirdSysFk(filterInvProductRequest.getThirdSys());//外部系统 thrInvOrder.setDeptCode(thrInvResultResponse.getDeptCode());//部门编号 thrInvOrder.setInvCode(thrInvResultResponse.getInvCode());//仓库代码 thrInvOrder.setSpaceCode(thrInvResultResponse.getSpaceCode());//货位编码 @@ -104,36 +225,83 @@ public class ThrInvOrderServiceImpl implements ThrInvOrderService { /** * 将三方的出入库明细列表 转换为 系统的出入库单据明细 + * * @param list * @param thrInvOrderDetails * @param billNo */ - private void handleExternalConvertThrInvOrderDetail(List list, List thrInvOrderDetails,String billNo) { - list.forEach( item -> { - String thrCode = item.getThrCode(); - String mainAction = item.getMainAction(); - Integer count = 0; - if (ConstantType.TYPE_PUT.equals(mainAction)) { - count = Integer.valueOf(item.getInCount()); - }else { - count = Integer.valueOf(item.getOutCount()); - } - //通过thrCode获取到项目组套 - List skProjectDetailEntityList= basicDestinyRelService.filterDestinyRelListByPId(thrCode); - if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0 ){ - Integer finalCount = count; - skProjectDetailEntityList.forEach(sk -> { - ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail(); - BeanUtils.copyProperties(item,thrInvOrderDetail); - thrInvOrderDetail.setOrderIdFk(billNo); - thrInvOrderDetail.setRelId(sk.getRelId()); - Integer skCount = sk.getCount(); - if (skCount != null && skCount > 0){ - thrInvOrderDetail.setReCount(String.valueOf(skCount * finalCount)); - thrInvOrderDetails.add(thrInvOrderDetail); - } - }); - } - }); + private void handleExternalConvertThrInvOrderDetail(List list, List thrInvOrderDetails, String billNo) { + Integer inv_set_enable = Integer.valueOf(systemParamConfigService.selectValueByParamKey("inv_set_enable")); + if (inv_set_enable == null || inv_set_enable == 0) { + list.forEach(item -> { + String mainAction = item.getMainAction(); + Integer count = 0; + if (ConstantType.TYPE_PUT.equals(mainAction)) { + count = Integer.valueOf(item.getInCount()); + } else { + count = Integer.valueOf(item.getOutCount()); + } + ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail(); + BeanUtils.copyProperties(item, thrInvOrderDetail); + thrInvOrderDetail.setOrderIdFk(billNo); + thrInvOrderDetail.setRelId(Long.parseLong(item.getThrCode())); + thrInvOrderDetail.setReCount(String.valueOf(count)); + thrInvOrderDetails.add(thrInvOrderDetail); + }); + } else { + list.forEach(item -> { + String thrCode = item.getThrCode(); + String mainAction = item.getMainAction(); + Integer count = 0; + if (ConstantType.TYPE_PUT.equals(mainAction)) { + count = Integer.valueOf(item.getInCount()); + } else { + count = Integer.valueOf(item.getOutCount()); + } + //通过thrCode获取到项目组套 + List skProjectDetailEntityList = basicDestinyRelService.filterDestinyRelListByPId(thrCode); + if (CollectionUtil.isNotEmpty(skProjectDetailEntityList) && count > 0) { + Integer finalCount = count; + skProjectDetailEntityList.forEach(sk -> { + ThrInvOrderDetail thrInvOrderDetail = new ThrInvOrderDetail(); + BeanUtils.copyProperties(item, thrInvOrderDetail); + thrInvOrderDetail.setOrderIdFk(billNo); + thrInvOrderDetail.setRelId(sk.getRelId()); + Integer skCount = sk.getCount(); + if (skCount != null && skCount > 0) { + thrInvOrderDetail.setReCount(String.valueOf(skCount * finalCount)); + thrInvOrderDetails.add(thrInvOrderDetail); + } + }); + } + }); + } + } + + /** + * 获取距离当前时间日期(n天)的开始时间和结束时间 + * + * @param n + * @return + */ + public static String getBeginAndEndDateByDays(int n) { + Date date = new Date();//取时间 + Calendar calendar = new GregorianCalendar(); + calendar.setTime(date); + calendar.add(calendar.DATE, -1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数 + date = calendar.getTime(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + return formatter.format(date); + } + + public static Date stringToDate(String time) { + SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date date = null; + try { + date = dateformat.parse(time); + } catch (ParseException e) { + e.printStackTrace(); + } + return date; } } diff --git a/src/main/java/com/glxp/api/task/SyncThirdSysTask.java b/src/main/java/com/glxp/api/task/SyncThirdSysTask.java index 6d138e7f0..8785f2528 100644 --- a/src/main/java/com/glxp/api/task/SyncThirdSysTask.java +++ b/src/main/java/com/glxp/api/task/SyncThirdSysTask.java @@ -9,6 +9,7 @@ import com.glxp.api.constant.ThirdSysConstant; import com.glxp.api.dao.schedule.ScheduledDao; import com.glxp.api.dao.system.SyncDataSetDao; import com.glxp.api.dao.thrsys.ThrSystemDetailDao; +import com.glxp.api.entity.inv.InvPlaceOrderEntity; import com.glxp.api.entity.system.ScheduledEntity; import com.glxp.api.entity.thrsys.ThrSystemDetailEntity; import com.glxp.api.req.basic.GetSickRequest; @@ -63,6 +64,8 @@ public class SyncThirdSysTask implements SchedulingConfigurer { private IoOrderService orderService; @Resource ThrOrderService thrOrderService; + @Resource + ThrInvOrderService thrInvOrderService; final Logger logger = LoggerFactory.getLogger(SyncHeartTask.class); @Resource @@ -138,6 +141,10 @@ public class SyncThirdSysTask implements SchedulingConfigurer { //下载患者信息 downloadSicker(thrSystemDetailEntity); break; + case ThirdSysConstant.INV_ORDER_QUERY_URL: + //下载出入库明细 + downloadInvOrder(thrSystemDetailEntity); + break; default: //其他接口暂不处理 break; @@ -171,6 +178,29 @@ public class SyncThirdSysTask implements SchedulingConfigurer { } } + /** + * 下载三方出入库明细 + * + * @param thrSystemDetailEntity + */ + private void downloadInvOrder(ThrSystemDetailEntity thrSystemDetailEntity) { + //校验任务并更新redis数据执行标识 + if (verifyTask(thrSystemDetailEntity)) { + getExecutor().submit(() -> { + log.info("开始下载三方出入库明细"); + try { + thrInvOrderService.downloadInvOrder(thrSystemDetailEntity); + } catch (Exception e) { + log.error("下载三方出入库明细异常", ExceptionUtils.getStackTrace(e)); + } finally { + updateTask(getTaskKey(thrSystemDetailEntity)); + } + log.info("下载三方出入库明细完成"); + }); + } + } + + /** * 下载第三方单据类型 * diff --git a/src/main/java/com/glxp/api/task/ThrInvOrderTask.java b/src/main/java/com/glxp/api/task/ThrInvOrderTask.java deleted file mode 100644 index 891672731..000000000 --- a/src/main/java/com/glxp/api/task/ThrInvOrderTask.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.glxp.api.task; - -import cn.hutool.core.date.DateRange; -import com.glxp.api.dao.schedule.ScheduledDao; -import com.glxp.api.entity.system.ScheduledEntity; -import com.glxp.api.req.inv.FilterInvProductRequest; -import com.glxp.api.req.system.ScheduledRequest; -import com.glxp.api.service.thrsys.ThrInvOrderService; -import lombok.extern.slf4j.Slf4j; -import org.apache.regexp.RE; -import org.springframework.scheduling.annotation.SchedulingConfigurer; -import org.springframework.scheduling.config.ScheduledTaskRegistrar; -import org.springframework.scheduling.support.CronTrigger; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -/** - * 自动抓取第三方出入库明细生成单据 - */ -@Slf4j -@Component -public class ThrInvOrderTask implements SchedulingConfigurer { - - @Resource - ScheduledDao scheduledDao; - @Resource - ThrInvOrderService thrInvOrderService; - - @Override - public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { - scheduledTaskRegistrar.addTriggerTask(this::process, triggerContext -> { - ScheduledRequest scheduledRequest = new ScheduledRequest(); - scheduledRequest.setCronName("thrInvOrderTask"); - ScheduledEntity scheduled = scheduledDao.findScheduled(scheduledRequest); - if (null == scheduled) { - log.error("自动抓取第三方出入库明细生成单据定时任务未配置,请注意!"); - return null; - } - String cron = scheduled.getCron(); - return new CronTrigger(cron).nextExecutionTime(triggerContext); - }); - } - - public void process() { - log.info("自动抓取第三方出入库明细生成单据定时任务开始"); - FilterInvProductRequest filterInvProductRequest = new FilterInvProductRequest(); - String days = getBeginAndEndDateByDays(1); - - filterInvProductRequest.setStartDate(stringToDate(days +" 00:00:00")); - filterInvProductRequest.setEndDate(stringToDate(days +" 23:59:59")); - thrInvOrderService.handleExternalThrInvOrder(filterInvProductRequest); - log.info("自动抓取第三方出入库明细生成单据定时任务结束"); - } - - /** - * 获取距离当前时间日期(n天)的开始时间和结束时间 - * @param n - * @return - */ - public static String getBeginAndEndDateByDays(int n) { - Date date=new Date();//取时间 - Calendar calendar = new GregorianCalendar(); - calendar.setTime(date); - calendar.add(calendar.DATE,-1);//把日期往前减少一天,若想把日期向后推一天则将负数改为正数 - date=calendar.getTime(); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - return formatter.format(date); - } - - public static Date stringToDate(String time) { - SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date date = null; - try { - date = dateformat.parse(time); - } catch (ParseException e) { - e.printStackTrace(); - } - return date; - } - -} diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml index 9efe866e9..3947dd139 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderDetailMapper.xml @@ -353,4 +353,15 @@ where id = #{id,jdbcType=INTEGER} + + diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml index 85aa52871..b8e373c2e 100644 --- a/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml +++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvOrderMapper.xml @@ -11,6 +11,7 @@ + @@ -23,12 +24,12 @@ - id, billNo, billDate, startDate, endDate, mainAction, billType, deptCode, invCode, + id, billNo, billDate, startDate, endDate, mainAction, billType,thirdSysFk, deptCode, invCode, spaceCode, `status`, createTime, `createUser`, updateTime, updateUser, remark + SELECT thr_inv_order.* + FROM thr_inv_order + + + AND billNo like concat('%', #{billNo}, '%') + + + AND billType = #{billType} + + + AND thirdSysFk = #{thirdSysFk} + + + = DATE_FORMAT(#{startDate}, '%Y-%m-%d') + ]]> + + + + + + ORDER BY thr_inv_order.billNo DESC + +