Ver código fonte

入库功能调整

lizhenhao 2 anos atrás
pai
commit
9f0948b66c
12 arquivos alterados com 603 adições e 131 exclusões
  1. 53 2
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/controller/WareHouseController.java
  2. 10 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WareHouseBasic.java
  3. 13 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WareHouseDetailed.java
  4. 62 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WarehouseUpHi.java
  5. 9 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WareHouseBasicMapper.java
  6. 12 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WareHouseDetailedMapper.java
  7. 27 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WarehouseUpHiMapper.java
  8. 9 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WareHouseBasicMapper.xml
  9. 24 1
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WareHouseDetailedMapper.xml
  10. 67 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WarehouseUpHiMapper.xml
  11. 302 127
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/service/WareHouseBasicService.java
  12. 15 0
      jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/service/dto/WareHouseDto.java

+ 53 - 2
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/controller/WareHouseController.java

@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.jeeplus.aop.logging.annotation.ApiLog;
 import com.jeeplus.common.utils.ResponseUtil;
+import com.jeeplus.sys.utils.StringUtils;
 import com.jeeplus.test.materialManagement.purchase.service.MaterialService;
 import com.jeeplus.test.materialManagement.purchase.service.dto.MaterialInfoDto;
+import com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi;
 import com.jeeplus.test.materialManagement.wareHouse.service.WareHouseBasicService;
 import com.jeeplus.test.materialManagement.wareHouse.service.dto.WareHouseDto;
 import io.swagger.annotations.Api;
@@ -14,6 +16,8 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author: 王强
@@ -151,6 +155,14 @@ public class WareHouseController {
         return ResponseUtil.newInstance().add("businessTable", "material_management_warehouse_basics").add("businessId", id).ok ("操作成功");
     }
 
+
+    @ApiOperation(value = "流程终止、取消修改")
+    @GetMapping("/backSourceData")
+    public ResponseEntity<Map<String, String>> backSourceData(String id){
+        Map<String, String> map = basicService.backSourceData(id);
+        return ResponseEntity.ok(map);
+    }
+
     /**
      * 查询
      * @param id
@@ -158,8 +170,11 @@ public class WareHouseController {
      */
     @ApiOperation(value = "查询")
     @GetMapping("/findById")
-    public ResponseEntity<WareHouseDto> findById(@RequestParam String id) throws Exception{
-        WareHouseDto dto = basicService.findById(id);
+    public ResponseEntity<WareHouseDto> findById(@RequestParam String id, @RequestParam(required = false) String status) throws Exception{
+        if (StringUtils.isBlank(status)) {
+            status = "false";
+        }
+        WareHouseDto dto = basicService.findById(id,status);
         return ResponseEntity.ok(dto);
     }
 
@@ -174,4 +189,40 @@ public class WareHouseController {
         String id = basicService.findRequestId(purchaseNo);
         return ResponseEntity.ok(id);
     }
+
+    /**
+     * 根据入库表id查询其全部历史修改数据
+     * @return
+     */
+    @ApiOperation(value = "查询历史修改表数据")
+    @GetMapping("/findHiById")
+    public ResponseEntity findHiById(@RequestParam String id) {
+        List<WarehouseUpHi> list = basicService.findHiById(id);
+        return ResponseEntity.ok(list);
+    }
+
+    /**
+     * 根据历史表id查询历史表数据
+     * @param id
+     * @return
+     */
+    @ApiOperation(value = "根据id查询历史修改表数据")
+    @GetMapping("/findHiByHiId")
+    public ResponseEntity findHiByHiId(@RequestParam String id) {
+        WareHouseDto hi = basicService.findHiByHiId(id);
+        return ResponseEntity.ok(hi);
+    }
+
+    /**
+     * 根据入库表id查询最近的一个修改历史
+     * @param id
+     * @return
+     */
+    @ApiOperation(value = "根据入库表id查询最近的一个修改历史")
+    @GetMapping("/findLastHiByid")
+    public ResponseEntity findLastHiByid(@RequestParam String id) {
+        WareHouseDto hi = basicService.findLastHiByid(id);
+        return ResponseEntity.ok(hi);
+    }
+
 }

+ 10 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WareHouseBasic.java

@@ -73,4 +73,14 @@ public class WareHouseBasic extends BaseEntity {
      * 经办人部门
      */
     private String handledByOffice;
+
+    /**
+     * 修改人
+     */
+    private String updateUser;
+
+    /**
+     * 修改原因
+     */
+    private String updateCause;
 }

+ 13 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WareHouseDetailed.java

@@ -88,4 +88,17 @@ public class WareHouseDetailed extends BaseEntity {
      * 备注
      */
     private String remarks;
+
+    /**
+     * 修改标记  0未修改  1已修改  2已删除
+     */
+    private String upFlag;
+
+    /**
+     * 入库详情数据id
+     */
+    private String sourceId;
+
+    @TableField(exist = false)
+    private List<WareHouseDetailed> wareHouseDetailed;
 }

+ 62 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/domain/WarehouseUpHi.java

@@ -0,0 +1,62 @@
+package com.jeeplus.test.materialManagement.wareHouse.domain;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.jeeplus.core.domain.BaseEntity;
+import lombok.Data;
+
+/**
+ * 入库数据修改历史表
+ * @TableName material_management_warehouse_up_hi
+ */
+@TableName(value ="material_management_warehouse_up_hi")
+@Data
+public class WarehouseUpHi extends BaseEntity {
+
+    /**
+     * 备注
+     */
+    private String remarks;
+
+    /**
+     * 入库id
+     */
+    private String warehouseId;
+
+    /**
+     * json数据
+     */
+    private String jsonData;
+
+    /**
+     * 标记  0为原数据 1为已完成数据
+     */
+    private String endflag;
+
+    /**
+     * 修改申请人
+     */
+    private String updateUser;
+
+    /**
+     * 修改数据的商品名称
+     */
+    private String updateTradeName;
+
+    /**
+     * 修改数据的商品类型
+     */
+    private String updateTradeType;
+
+    /**
+     * 创建人姓名
+     */
+    @TableField(exist = false)
+    private String createName;
+
+    @TableField(exist = false)
+    private static final long serialVersionUID = 1L;
+}

+ 9 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WareHouseBasicMapper.java

@@ -38,4 +38,13 @@ public interface WareHouseBasicMapper extends BaseMapper<WareHouseBasic> {
      */
     WareHouseDto getByTypeAndGoodsName(@Param("goodsName")String goodsName,
                                @Param("collectTypeId")String collectTypeId);
+
+    // 保存当前修改申请人
+    void saveUpdateUser(String basicId, String userId);
+
+    // 根据入库数据id获取修改申请人
+    String getUpdateUser(String basicId);
+
+    // 根据入库数据id删除修改申请人
+    void deleteUpdateUser(String basicId);
 }

+ 12 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WareHouseDetailedMapper.java

@@ -13,11 +13,13 @@ import java.util.List;
  **/
 public interface WareHouseDetailedMapper extends BaseMapper<WareHouseDetailed> {
     /**
-     * 根据入库基础表的id查入库明细相关数据
+     * 根据入库基础表的id查入库明细相关数据(upFlag = '0')
      * @param id
      * @return
      */
     List<WareHouseDetailed> getByBasicId(String id);
+    // 根据入库基础表的id查入库明细相关数据(upFlag 全部)
+    List<WareHouseDetailed> getByBasicIdAll(String id);
 
     //查出附件信息
     List<WorkAttachmentDto> getByAttachmentId(String id);
@@ -30,4 +32,13 @@ public interface WareHouseDetailedMapper extends BaseMapper<WareHouseDetailed> {
      * @return
      */
     List<UserDTO> getUsersInfo();
+
+    // 根据id置空sourceId
+    void upSourceIdEmpty(String id);
+
+    // 根据入库id删除详情  物理删除
+    void deleteByBasicId(String basicId);
+
+    // 根据入库id删除关联附件  物理删除
+    void deleteFilesByIdList(List<String> attachmentIdList);
 }

+ 27 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/WarehouseUpHiMapper.java

@@ -0,0 +1,27 @@
+package com.jeeplus.test.materialManagement.wareHouse.mapper;
+
+import com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface WarehouseUpHiMapper extends BaseMapper<WarehouseUpHi> {
+
+    // 根据入库表id获取原数据 endFlag = '0'
+    String getSourceData(String warehouseId);
+
+    // 根据入库表id查询其全部历史修改数据
+    List<WarehouseUpHi> findHiById(String warehouseId);
+
+    // 根据历史表id查询历史表数据
+    WarehouseUpHi findHiByHiId(String hiId);
+
+    // 根据入库表id查询最近的一个修改历史
+    WarehouseUpHi findLastHiByid(String warehouseId);
+}
+
+
+
+

+ 9 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WareHouseBasicMapper.xml

@@ -177,4 +177,13 @@
 			HAVING sum( trade_number ) - IFNULL(collect_number,0) > 0
 			ORDER BY a.update_date DESC
 	</select>
+	<update id="saveUpdateUser">
+		update material_management_warehouse_basics set update_user = #{userId} where id = #{basicId}
+	</update>
+	<select id="getUpdateUser" resultType="string">
+		select update_user from material_management_warehouse_basics where id = #{basicId}
+	</select>
+	<update id="deleteUpdateUser">
+		update material_management_warehouse_basics set update_user = null where id = #{basicId}
+	</update>
 </mapper>

+ 24 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WareHouseDetailedMapper.xml

@@ -9,7 +9,18 @@
         left join sys_user b on a.ware_house_man = b.id and b.del_flag = '0'
         left join sys_office c on b.office_id = c.id
         left join material_management_type d on a.ware_house_type = d.id
-        where a.basic_id = #{id} and a.del_flag = '0'
+        where a.basic_id = #{id} and a.del_flag = '0' and a.up_flag = '0'
+        ORDER BY a.create_date desc
+    </select>
+    <select id="getByBasicIdAll"
+            resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseDetailed">
+        select a.*,b.name as wareHouseMan,b.id as wareHouseManId,c.name as wareHouseManOffice,
+        d.id as wareHouseTypeId, d.name as wareHouseType
+        from material_management_warehouse_detailed a
+        left join sys_user b on a.ware_house_man = b.id and b.del_flag = '0'
+        left join sys_office c on b.office_id = c.id
+        left join material_management_type d on a.ware_house_type = d.id
+        where a.basic_id = #{id} and a.del_flag = '0' and (a.up_flag = '1' or a.up_flag = '2')
         ORDER BY a.create_date desc
     </select>
     <select id="getByAttachmentId" resultType="com.jeeplus.test.workContract.service.dto.WorkAttachmentDto">
@@ -31,4 +42,16 @@
     <select id="getUsersInfo" resultType="com.jeeplus.sys.service.dto.UserDTO">
         select a.user_id as id,a.user_name as loginName  from material_user a
     </select>
+    <update id="upSourceIdEmpty">
+        update material_management_warehouse_detailed set source_id = null where id = #{id}
+    </update>
+    <delete id="deleteByBasicId">
+        delete from material_management_warehouse_detailed where basic_id = #{basicId}
+    </delete>
+    <delete id="deleteFilesByIdList">
+        delete from work_attachment where attachment_id in
+        <foreach collection="attachmentIdList" item="attachmentId" open="(" separator="," close=")">
+            #{attachmentId}
+        </foreach>
+    </delete>
 </mapper>

+ 67 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/mapper/xml/WarehouseUpHiMapper.xml

@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.jeeplus.test.materialManagement.wareHouse.mapper.WarehouseUpHiMapper">
+
+    <resultMap id="BaseResultMap" type="com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi">
+            <id property="id" column="id" jdbcType="VARCHAR"/>
+            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
+            <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
+            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
+            <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
+            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
+            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
+            <result property="warehouseId" column="warehouse_id" jdbcType="VARCHAR"/>
+            <result property="jsonData" column="json_data" jdbcType="VARCHAR"/>
+            <result property="endflag" column="endFlag" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <sql id="HI_Column_List">
+        hi.id,
+        hi.create_by,
+        hi.create_date,
+        hi.update_by,
+        hi.update_date,
+        hi.del_flag,
+        hi.remarks,
+        hi.warehouse_id,
+        hi.json_data,
+        hi.endFlag,
+        hi.update_user,
+        hi.update_trade_name,
+        hi.update_trade_type
+    </sql>
+
+    <select id="getSourceData" resultType="java.lang.String">
+        select
+            hi.json_data
+        from material_management_warehouse_up_hi hi
+        where hi.del_flag = '0' and hi.warehouse_id = #{warehouseId} and hi.endFlag = '0'
+    </select>
+
+    <select id="findHiById" resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi">
+        select
+        <include refid="HI_Column_List"></include>,
+        su.name as updateUser
+        from material_management_warehouse_up_hi hi
+        left join sys_user su on su.id = hi.update_user
+        where hi.del_flag = '0' and hi.warehouse_id = #{id} and (hi.endFlag = '1' or hi.endFlag = '2')
+        order by hi.create_date desc
+    </select>
+    <select id="findHiByHiId" resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi">
+        select
+        <include refid="HI_Column_List"></include>
+        from material_management_warehouse_up_hi hi
+        where hi.del_flag = '0' and hi.id = #{hiId}
+    </select>
+
+    <select id="findLastHiByid" resultType="com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi">
+        select
+        <include refid="HI_Column_List"></include>
+        from material_management_warehouse_up_hi hi
+        where hi.del_flag = '0' and hi.warehouse_id = #{warehouseId}
+        order by hi.create_date desc
+        limit 1
+    </select>
+</mapper>

+ 302 - 127
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/service/WareHouseBasicService.java

@@ -1,5 +1,10 @@
 package com.jeeplus.test.materialManagement.wareHouse.service;
 
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.TypeReference;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -11,6 +16,7 @@ import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.utils.StringUtils;
 import com.jeeplus.sys.utils.UserUtils;
 import com.jeeplus.test.cw.contractRegistration.service.ContractInfoService;
+import com.jeeplus.test.cw.workClientInfo.service.dto.CwWorkClientBaseDTO;
 import com.jeeplus.test.materialManagement.purchase.domain.MaterialBasic;
 import com.jeeplus.test.materialManagement.purchase.domain.MaterialDetailed;
 import com.jeeplus.test.materialManagement.purchase.mapper.MaterialBasicMapper;
@@ -18,9 +24,11 @@ import com.jeeplus.test.materialManagement.purchase.mapper.MaterialDetailedMappe
 import com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseBasic;
 import com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseDetailed;
 import com.jeeplus.test.materialManagement.wareHouse.domain.WareHouseSummary;
+import com.jeeplus.test.materialManagement.wareHouse.domain.WarehouseUpHi;
 import com.jeeplus.test.materialManagement.wareHouse.mapper.WareHouseBasicMapper;
 import com.jeeplus.test.materialManagement.wareHouse.mapper.WareHouseDetailedMapper;
 import com.jeeplus.test.materialManagement.wareHouse.mapper.WareHouseSummaryMapper;
+import com.jeeplus.test.materialManagement.wareHouse.mapper.WarehouseUpHiMapper;
 import com.jeeplus.test.materialManagement.wareHouse.service.dto.WareHouseDto;
 import com.jeeplus.test.mould.service.SerialnumTplService;
 import com.jeeplus.test.oss.domain.WorkAttachment;
@@ -31,10 +39,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
+import java.util.stream.Collectors;
+
 import org.springframework.beans.BeanUtils;
 
 /**
@@ -72,6 +79,9 @@ public class WareHouseBasicService {
     @Resource
     private FlowTaskService flowTaskService;
 
+    @Resource
+    private WarehouseUpHiMapper warehouseUpHiMapper;
+
 
     /**
      * 列表查询
@@ -155,13 +165,38 @@ public class WareHouseBasicService {
         return "操作成功";
     }
 
-    public WareHouseDto findById(String id) {
+    public WareHouseDto findById(String id, String status) {
         WareHouseDto dto = new WareHouseDto();
         // 查询基础信息表
         WareHouseBasic info = basicMapper.selectById(id);
         BeanUtils.copyProperties(info, dto);
         //将入库详情数据查出
         List<WareHouseDetailed> wareHouseList = detailedMapper.getByBasicId(id);
+        if ("audit".equals(status) || "taskFormDetail".equals(status)) {
+            List<WareHouseDetailed> wareList = new ArrayList<>();
+            List<WareHouseDetailed> finalWareHouseList = detailedMapper.getByBasicIdAll(id);
+            List<WareHouseDetailed> detailedList = wareHouseList; // 这里不copy一下会报错
+            detailedList.stream().forEach(item2 -> {
+                if (StringUtils.isBlank(item2.getSourceId())) {
+                    wareList.add(item2);
+                }
+            });
+            finalWareHouseList.stream().forEach(item -> {
+                if("2".equals(item.getUpFlag())) {
+                    wareList.add(item);
+                } else if ("1".equals(item.getUpFlag())) {
+                    wareList.add(item);
+                    detailedList.stream().forEach(item2 -> {
+                        if (StringUtils.isNotBlank(item2.getSourceId())) {
+                            if (item2.getSourceId().equals(item.getId())) {
+                                wareList.add(item2);
+                            }
+                        }
+                    });
+                }
+            });
+            wareHouseList = new ArrayList<>(wareList);
+        }
         if (CollectionUtils.isNotEmpty(wareHouseList)){
             wareHouseList.forEach(detailed->{
                 //附件信息
@@ -223,138 +258,185 @@ public class WareHouseBasicService {
     }
 
     public String update(WareHouseDto dto, UserDTO userDTO) {
+        if (StringUtils.isNotBlank(dto.getFunctionFlag())) {
+            if ("start".equals(dto.getFunctionFlag())) { // 送审时执行
+                // 添加当前修改申请人
+                basicMapper.saveUpdateUser(dto.getId(),UserUtils.getCurrentUserDTO().getId());
+                // 判断是否为第一次送审(排除撤回后送审或者驳回后送审)
+                List<WarehouseUpHi> warehouseUpHis = warehouseUpHiMapper.selectList(new LambdaQueryWrapper<WarehouseUpHi>()
+                        .eq(WarehouseUpHi::getWarehouseId, dto.getId()).eq(WarehouseUpHi::getEndflag, "0"));
+                if (CollectionUtil.isEmpty(warehouseUpHis)) { // 当前送审操作为第一次送审
+                    // 将未修改的数据添加到历史数据表中
+                    WareHouseDto byId = this.findById(dto.getId(),"false");
+                    String jsonString = JSON.toJSONString(byId);
+                    WarehouseUpHi warehouseUpHi = new WarehouseUpHi();
+                    warehouseUpHi.setEndflag("0");
+                    warehouseUpHi.setJsonData(jsonString);
+                    warehouseUpHi.setWarehouseId(dto.getId());
+                    warehouseUpHiMapper.insert(warehouseUpHi);
+                }
+            }
+            if ("agree".equals(dto.getFunctionFlag())) { // 审核通过时执行
+                // 将历史数据表中的原始数据删除(end_flag = 0并且warehouse_id = 当前数据id)
+                warehouseUpHiMapper.delete(new LambdaQueryWrapper<WarehouseUpHi>().eq(WarehouseUpHi::getEndflag,"0").eq(WarehouseUpHi::getWarehouseId,dto.getId()));
+                WarehouseUpHi warehouseUpHi = new WarehouseUpHi();
+                WareHouseDto byId = this.findById(dto.getId(),"audit");
+                if (ObjectUtil.isNotEmpty(byId)) {
+                    // 获取修改数据的商品名称、商品类型
+                    if (CollectionUtil.isNotEmpty(byId.getWareHouse())){
+                        List<WareHouseDetailed> updateData = byId.getWareHouse().stream().filter(i -> {
+                            if ("1".equals(i.getUpFlag()) || "2".equals(i.getUpFlag())) {
+                                return true;
+                            }
+                            return false;
+                        }).collect(Collectors.toList());
+                        List<String> updateTradeNameList = updateData.stream().map(WareHouseDetailed::getTradeName).collect(Collectors.toList());
+                        if (CollectionUtil.isNotEmpty(updateTradeNameList)) {
+                            warehouseUpHi.setUpdateTradeName(String.join(",",updateTradeNameList)); //获取修改数据的商品名称
+                        }
+                        List<String> updateTradeTypeList = updateData.stream().map(WareHouseDetailed::getWareHouseType).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+                        if (CollectionUtil.isNotEmpty(updateTradeTypeList)) {
+                            warehouseUpHi.setUpdateTradeType(String.join(",",updateTradeTypeList)); //获取修改数据的商品类型
+                        }
+                    }
+                    // 将审核页面的数据存储到历史数据表中
+                    String jsonString = JSON.toJSONString(byId);
+                    warehouseUpHi.setJsonData(jsonString);
+                }
+                // 获取数据修改申请人
+                String updateUser = basicMapper.getUpdateUser(dto.getId());
+                if (StringUtils.isNotBlank(updateUser)) {
+                    warehouseUpHi.setUpdateUser(updateUser);
+                    basicMapper.deleteUpdateUser(dto.getId()); // 删除数据修改申请人
+                }
+                warehouseUpHi.setEndflag("1");
+                warehouseUpHi.setWarehouseId(dto.getId());
+                warehouseUpHiMapper.insert(warehouseUpHi);
+                // 修改基础信息
+                WareHouseBasic info = new WareHouseBasic();
+                BeanUtils.copyProperties(dto, info);
+                info.setHandledBy(dto.getHandledById());
+                basicMapper.updateById(info);
+                // 入库详情修改
+                List<WareHouseDetailed> wareHouseDetaileds = detailedMapper.selectList(new LambdaQueryWrapper<WareHouseDetailed>()
+                        .eq(WareHouseDetailed::getBasicId,info.getId()));
+                wareHouseDetaileds.stream().forEach(item -> {
+                    if ("1".equals(item.getUpFlag()) || "2".equals(item.getUpFlag())) { // 将修改前的数据以及删除标记的数据删除
+                        detailedMapper.deleteById(item.getId());
+                    } else if ("0".equals(item.getUpFlag())) {
+                        if (StringUtils.isNotBlank(item.getSourceId())) { // 将修改后数据的sourceId置空
+                            detailedMapper.upSourceIdEmpty(item.getId()); // 根据入库详情id置空sourceId
+                        }
+                    }
+                });
+                return dto.getId();
+            }
+            if ("back".equals(dto.getFunctionFlag())) {
+                // 修改基础信息
+                WareHouseBasic info = new WareHouseBasic();
+                BeanUtils.copyProperties(dto, info);
+                info.setHandledBy(dto.getHandledById());
+                basicMapper.updateById(info);
+                basicMapper.deleteUpdateUser(dto.getId()); // 删除数据修改申请人
+                // 修改附件信息列表
+                if (CollectionUtils.isNotEmpty(dto.getFiles())) {
+                    infoService.updateFiles(dto.getFiles(), userDTO, dto.getId());
+                }
+                // 入库详情修改
+                // 物理删除此入库的全部入库关联的附件表数据,然后再新增附件。因为如果不物理删除,新增时会有主键冲突
+                List<WareHouseDetailed> wareHouseDetaileds = detailedMapper.selectList(new QueryWrapper<WareHouseDetailed>().lambda().eq(WareHouseDetailed::getBasicId, dto.getId()));
+                List<String> detailedIdList = wareHouseDetaileds.stream().map(WareHouseDetailed::getId).collect(Collectors.toList());
+                detailedMapper.deleteFilesByIdList(detailedIdList);
+                // 物理删除此入库的全部入库详情,然后再新增。因为如果不物理删除,新增时会有主键冲突
+                detailedMapper.deleteByBasicId(dto.getId());
+                if (CollectionUtils.isNotEmpty(dto.getWareHouse())) {
+                    dto.getWareHouse().stream().forEach(item -> {
+                        item.setWareHouseMan(item.getWareHouseManId());
+                        item.setWareHouseType(item.getWareHouseTypeId());
+                        detailedMapper.insert(item);
+                        // 保存附件信息列表
+                        if (CollectionUtils.isNotEmpty(item.getFileInfoLost())) {
+                            infoService.updateFiles(item.getFileInfoLost(), userDTO, item.getId());
+                        }
+                    });
+                }
+                // 删除送审时在历史修改表添加的数据
+                warehouseUpHiMapper.delete(new QueryWrapper<WarehouseUpHi>().lambda()
+                        .eq(WarehouseUpHi::getWarehouseId,dto.getId()).eq(WarehouseUpHi::getEndflag,"0"));
+            }
+        }
+
         // 修改基础信息
         WareHouseBasic info = new WareHouseBasic();
         BeanUtils.copyProperties(dto, info);
-        info.setUpdateBy(userDTO.getId());
-        info.setUpdateDate(new Date());
         info.setHandledBy(dto.getHandledById());
         basicMapper.updateById(info);
-        // 修改报销详情列表信息
-        // 删除原有数据
-//        LambdaQueryWrapper<WareHouseDetailed> detailWrapper = new LambdaQueryWrapper<>();
-//        detailWrapper.eq(WareHouseDetailed::getBasicId, dto.getId());
-//        detailedMapper.delete(detailWrapper);
-        if (CollectionUtils.isNotEmpty(dto.getWareHouse())) {
 
-            List<String> idList = detailedMapper.getIdByBasicId(info.getId());
-            for (WareHouseDetailed detailInfo : dto.getWareHouse()) {
-                //删除多余的领用详情
-                //根据基础表id获取所有的详情表id
-                if (null != idList) {
-                    if (idList.contains(detailInfo.getId())){
-                        idList.remove(detailInfo.getId());
-                    }
+        // 入库详情修改
+        if (CollectionUtils.isNotEmpty(dto.getWareHouse())) {
+            // 获取前端删除的入库详情
+            List<String> liveIds = dto.getWareHouse().stream().map(WareHouseDetailed::getId).collect(Collectors.toList());
+            List<WareHouseDetailed> wareHouseDetaileds = detailedMapper.selectList(new LambdaQueryWrapper<WareHouseDetailed>()
+                    .eq(WareHouseDetailed::getBasicId,info.getId()).notIn(WareHouseDetailed::getId, liveIds));
+            wareHouseDetaileds.stream().forEach(d -> {
+                if ("0".equals(d.getUpFlag())) {
+                    d.setUpFlag("2"); // 已删除标记
+                    dto.getWareHouse().add(d);
                 }
-            }
-            if (null != idList & idList.size()>0) {
-                idList.forEach(id->{
-                    detailedMapper.deleteById(id);
-                    //汇总表中的数据也删除掉
-//                    summaryMapper.deleteByDetailedId(id);
-                });
-            }
-
-            for (WareHouseDetailed detailInfo : dto.getWareHouse()) {
-                // 生成id
-                WareHouseDetailed wareHouseDetailed = detailedMapper.selectById(detailInfo.getId());
-                if (null == wareHouseDetailed) {
-                    String detailId = UUID.randomUUID().toString().replace("-", "");
-                    detailInfo.setId(detailId);
-                    detailInfo.setWareHouseMan(detailInfo.getWareHouseManId());
-                    detailInfo.setCreateBy(userDTO.getId());
-                    detailInfo.setCreateDate(new Date());
-                    detailInfo.setWareHouseMan(detailInfo.getWareHouseManId());
-                    detailInfo.setUpdateBy(userDTO.getId());
-                    detailInfo.setUpdateDate(new Date());
-                    detailInfo.setWareHouseType(detailInfo.getWareHouseTypeId());
-                    detailInfo.setDelFlag(0);
-                    // 保存基础表信息主键值
-                    detailInfo.setBasicId(dto.getId());
-                    detailInfo.setTradeTotalPrice(dto.getWareHouseTotalPrice());
-                    detailedMapper.insert(detailInfo);
-                    //保存详情列表附件信息
-                    if (CollectionUtils.isNotEmpty(detailInfo.getFileInfoLost())){
-                        infoService.saveFiles(detailInfo.getFileInfoLost(), userDTO, detailId);
+            });
+            dto.getWareHouse().stream().forEach(detailInfo -> {
+                detailInfo.setWareHouseMan(detailInfo.getWareHouseManId());
+                detailInfo.setWareHouseType(detailInfo.getWareHouseTypeId());
+                detailInfo.setBasicId(dto.getId()); // 保存基础表信息主键值
+                detailInfo.setTradeTotalPrice(dto.getWareHouseTotalPrice());
+                if ("1".equals(detailInfo.getUpFlag())) { // 已修改标记数据
+                    if(StringUtils.isBlank(detailInfo.getSourceId())) {
+                        WareHouseDetailed ware = detailedMapper.selectById(detailInfo.getId());
+                        boolean is = false;
+                        if (judgmentEquals(detailInfo.getWareHouseMan(),ware.getWareHouseMan())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getWareHouseType(),ware.getWareHouseType())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getTradeName(),ware.getTradeName())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getTradeNumber(),ware.getTradeNumber())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getCompany(),ware.getCompany())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getTradePrice(),ware.getTradePrice())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getActualPrice(),ware.getActualPrice())) {
+                            is = true;
+                        } else if (judgmentEquals(detailInfo.getRemarks(),ware.getRemarks())) {
+                            is = true;
+                        }
+                        if (is) {
+                            ware.setUpFlag("1");
+                            detailedMapper.updateById(ware);
+                            detailInfo.setSourceId(ware.getId());
+                            detailInfo.setId(new String());
+                            detailInfo.setUpFlag("0");
+                            detailedMapper.insert(detailInfo);
+                        }
+                    }else{
+                        detailInfo.setUpFlag("0");
+                        detailedMapper.updateById(detailInfo);
                     }
-                    //将入库详情商品信息汇总处理
-                    //根据商品名称及入库类型查是否有相关数据
-//                    WareHouseSummary summary = summaryMapper.getInfoByTradeName(detailInfo.getTradeName(),detailInfo.getWareHouseType());;
-//                    if (null != summary) {
-//                        if (summary.getTradeName().equals(detailInfo.getTradeName()) &&
-//                                summary.getWareHouseType().equals(detailInfo.getWareHouseType())) {
-//                            String num = Double.valueOf(detailInfo.getTradeNumber())
-//                                    + Double.valueOf(summary.getTradeNumber()) + "";
-//                            summary.setTradeNumber(num);
-//                            summary.setWareHouseType(detailInfo.getWareHouseType());
-//                            summary.setUpdateBy(userDTO.getId());
-//                            summary.setUpdateDate(new Date());
-//                            summary.setDetailedId(detailInfo.getId());
-//                            summaryMapper.updateById(summary);
-//                        }
-//                    } else {
-//                        summary = new WareHouseSummary();
-//                        // 生成id
-//                        String summaryId = UUID.randomUUID().toString().replace("-", "");
-//                        summary.setDetailedId(detailInfo.getId());
-//                        summary.setId(summaryId);
-//                        summary.setCreateBy(userDTO.getId());
-//                        summary.setCreateDate(new Date());
-//                        summary.setUpdateBy(userDTO.getId());
-//                        summary.setUpdateDate(new Date());
-//                        summary.setDelFlag(0);
-//                        summary.setWareHouseType(detailInfo.getWareHouseType());
-//                        summary.setTradeName(detailInfo.getTradeName());
-//                        summary.setTradeNumber(detailInfo.getTradeNumber());
-//                        summaryMapper.insert(summary);
-//                    }
-                } else {
-                    detailInfo.setWareHouseMan(detailInfo.getWareHouseManId());
-                    detailInfo.setUpdateBy(userDTO.getId());
-                    detailInfo.setUpdateDate(new Date());
-                    detailInfo.setDelFlag(0);
-                    detailInfo.setWareHouseType(detailInfo.getWareHouseTypeId());
-                    // 保存基础表信息主键值
-                    detailInfo.setBasicId(dto.getId());
-                    detailInfo.setTradeTotalPrice(dto.getWareHouseTotalPrice());
-                    detailedMapper.updateById(detailInfo);
-                    // 修改附件信息列表
-                    if (CollectionUtils.isNotEmpty(detailInfo.getFileInfoLost())) {
-                        infoService.updateFiles(detailInfo.getFileInfoLost(), userDTO, detailInfo.getId());
+                } else if ("2".equals(detailInfo.getUpFlag())) { // 已删除标记数据
+                    if(StringUtils.isBlank(detailInfo.getSourceId())) {
+                        detailedMapper.updateById(detailInfo);
+                    }else{
+                        WareHouseDetailed wareHouseDetailed = detailedMapper.selectById(detailInfo.getSourceId());
+                        wareHouseDetailed.setUpFlag("2");
+                        detailedMapper.updateById(wareHouseDetailed);
+                        detailedMapper.deleteById(detailInfo.getId());
                     }
-                    //将入库详情商品信息汇总处理
-                    //根据商品名称及入库类型查是否有相关数据
-//                    WareHouseSummary summary = summaryMapper.getInfoByTradeName(detailInfo.getTradeName(),detailInfo.getWareHouseType());;
-//                    if (null != summary) {
-//                        if (wareHouseDetailed.getTradeNumber().equals(detailInfo.getTradeNumber()) &&
-//                                !wareHouseDetailed.getTradeName().equals(detailInfo.getTradeName())) {
-//                            String num = Double.valueOf(detailInfo.getTradeNumber())
-//                                    + Double.valueOf(summary.getTradeNumber()) + "";
-//                            summary.setTradeNumber(num);
-//                            summary.setUpdateBy(userDTO.getId());
-//                            summary.setWareHouseType(detailInfo.getWareHouseType());
-//                            summary.setUpdateDate(new Date());
-//                            summary.setDetailedId(detailInfo.getId());
-//                            summaryMapper.updateById(summary);
-//                        }
-//                    } else {
-//                        summary = new WareHouseSummary();
-//                        // 生成id
-//                        String summaryId = UUID.randomUUID().toString().replace("-", "");
-//                        summary.setDetailedId(detailInfo.getId());
-//                        summary.setId(summaryId);
-//                        summary.setCreateBy(userDTO.getId());
-//                        summary.setCreateDate(new Date());
-//                        summary.setUpdateBy(userDTO.getId());
-//                        summary.setUpdateDate(new Date());
-//                        summary.setDelFlag(0);
-//                        summary.setWareHouseType(detailInfo.getWareHouseType());
-//                        summary.setTradeName(detailInfo.getTradeName());
-//                        summary.setTradeNumber(detailInfo.getTradeNumber());
-//                        summaryMapper.insert(summary);
-//                    }
                 }
-            }
+                // 修改附件信息列表
+                if (CollectionUtils.isNotEmpty(detailInfo.getFileInfoLost())) {
+                    infoService.updateFiles(detailInfo.getFileInfoLost(), userDTO, detailInfo.getId());
+                }
+            });
         }
         // 修改附件信息列表
         if (CollectionUtils.isNotEmpty(dto.getFiles())) {
@@ -363,6 +445,36 @@ public class WareHouseBasicService {
         return dto.getId();
     }
 
+    // 判断两个字符串是否不相等  true不相等 false相等
+    public boolean judgmentEquals(String a,String b) {
+        if (StringUtils.isNotBlank(a) && StringUtils.isBlank(b)) { // a非空  b空
+            return true;
+        }
+        if (StringUtils.isBlank(a) && StringUtils.isNotBlank(b)) { // a空  b非空
+            return true;
+        }
+        if (StringUtils.isNotBlank(a) && StringUtils.isNotBlank(b) && !a.equals(b)) { // a非空  b非空  a、b相等
+            return true;
+        }
+        return false;
+    }
+
+    // 流程结束将全部修改的数据撤回到未修改
+    public Map<String,String> backSourceData(String id){
+        Map<String,String> map = new HashMap<>();
+        map.put("result","error");
+        String sourceData = warehouseUpHiMapper.getSourceData(id);
+        if (StringUtils.isNotBlank(sourceData)) {
+            WareHouseDto wareHouseDto = JSON.parseObject(sourceData, WareHouseDto.class);
+            if (ObjectUtil.isNotEmpty(wareHouseDto)){
+                wareHouseDto.setFunctionFlag("back");
+                this.update(wareHouseDto,UserUtils.getCurrentUserDTO());
+                map.replace("result","success");
+            }
+        }
+        return map;
+    }
+
     public String add(WareHouseDto dto, UserDTO userDTO) throws Exception{
         // 生成id
         String id = UUID.randomUUID().toString().replace("-", "");
@@ -398,6 +510,7 @@ public class WareHouseBasicService {
                 // 保存基础表信息主键值
                 detailed.setBasicId(id);
                 detailed.setTradeTotalPrice(dto.getWareHouseTotalPrice());
+                detailed.setUpFlag("0");
                 detailedMapper.insert(detailed);
                 //保存详情列表附件信息
                 if (CollectionUtils.isNotEmpty(detailed.getFileInfoLost())){
@@ -433,6 +546,17 @@ public class WareHouseBasicService {
         if (CollectionUtils.isNotEmpty(dto.getFiles())) {
             infoService.saveFiles(dto.getFiles(), userDTO, id);
         }
+
+        // 将新增的数据保存到历史数据表中
+        WareHouseDto byId = this.findById(info.getId(),"false");
+        String jsonString = JSON.toJSONString(byId);
+        WarehouseUpHi warehouseUpHi = new WarehouseUpHi();
+        warehouseUpHi.setUpdateUser(byId.getCreateBy());
+        warehouseUpHi.setWarehouseId(byId.getId());
+        warehouseUpHi.setEndflag("2");
+        warehouseUpHi.setJsonData(jsonString);
+        warehouseUpHiMapper.insert(warehouseUpHi);
+
         return id;
     }
 
@@ -569,4 +693,55 @@ public class WareHouseBasicService {
         return "操作成功";
     }
 
+    // 根据入库表id查询其全部历史修改数据
+    public List<WarehouseUpHi> findHiById(String warehouseId) {
+        return warehouseUpHiMapper.findHiById(warehouseId);
+    }
+
+    // 根据历史表id查询历史表数据
+    public WareHouseDto findHiByHiId(String hiId) {
+        WareHouseDto wareHouseDto = new WareHouseDto();
+        WarehouseUpHi hiByHiId = warehouseUpHiMapper.findHiByHiId(hiId); // 根据历史表id查询历史表数据
+        if (ObjectUtil.isNotEmpty(hiByHiId) && StringUtils.isNotBlank(hiByHiId.getJsonData())) {
+            wareHouseDto = JSON.parseObject(hiByHiId.getJsonData(), WareHouseDto.class); // json字符串解析为java对象
+            // 入库详情中的附件数据获取。
+            // 在这里要重新获取一下入库详情附件的原因是,json字符串中的附件createBy值存储不正确,所以重新获取一下
+            if(ObjectUtil.isNotEmpty(wareHouseDto) && CollectionUtil.isNotEmpty(wareHouseDto.getWareHouse())) {
+                wareHouseDto.getWareHouse().forEach(detailed->{
+                    List<WorkAttachmentDto> acList = detailedMapper.getByAttachmentId(detailed.getId());
+                    if (CollectionUtils.isNotEmpty(acList)) {
+                        for (WorkAttachmentDto i : acList) {
+                            i.setCreateBy(UserUtils.get(i.getBy()));
+                        }
+                    }
+                    detailed.setFileInfoLost(acList);
+                });
+            }
+        }
+        return wareHouseDto;
+    }
+
+    // 根据入库表id查询最近的一个修改历史
+    public WareHouseDto findLastHiByid(String warehouseId) {
+        WareHouseDto wareHouseDto = new WareHouseDto();
+        WarehouseUpHi hiByHiId = warehouseUpHiMapper.findLastHiByid(warehouseId); // 根据入库表id查询最近的一个修改历史
+        if (ObjectUtil.isNotEmpty(hiByHiId) && StringUtils.isNotBlank(hiByHiId.getJsonData())) {
+            wareHouseDto = JSON.parseObject(hiByHiId.getJsonData(), WareHouseDto.class); // json字符串解析为java对象
+            // 入库详情中的附件数据获取。
+            // 在这里要重新获取一下入库详情附件的原因是,json字符串中的附件createBy值存储不正确,所以重新获取一下
+            if(ObjectUtil.isNotEmpty(wareHouseDto) && CollectionUtil.isNotEmpty(wareHouseDto.getWareHouse())) {
+                wareHouseDto.getWareHouse().forEach(detailed->{
+                    List<WorkAttachmentDto> acList = detailedMapper.getByAttachmentId(detailed.getId());
+                    if (CollectionUtils.isNotEmpty(acList)) {
+                        for (WorkAttachmentDto i : acList) {
+                            i.setCreateBy(UserUtils.get(i.getBy()));
+                        }
+                    }
+                    detailed.setFileInfoLost(acList);
+                });
+            }
+        }
+        return wareHouseDto;
+    }
+
 }

+ 15 - 0
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/wareHouse/service/dto/WareHouseDto.java

@@ -271,4 +271,19 @@ public class WareHouseDto {
      * 数据审核人  入库 修改申请
      */
     private List<String> auditUserIds;
+
+    /**
+     * 当前所处节点执行的方法(送审、审核等..)
+     */
+    private String functionFlag;
+
+    /**
+     * 修改人
+     */
+    private String updateUser;
+
+    /**
+     * 修改原因
+     */
+    private String updateCause;
 }