Răsfoiți Sursa

修改库存,pda库存查询

huang 1 lună în urmă
părinte
comite
2e3a4db5c2

+ 15 - 0
docs/new_sql.sql

@@ -87,3 +87,18 @@ CREATE TABLE `task_stocktaking_item` (
     `status` int DEFAULT '1' COMMENT '盘点状态(1.未盘,2.盘盈,3.盘亏 4.无差异)',
     PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='盘点任务关联商品表';
+
+-- 库存修改日志表
+DROP TABLE IF EXISTS `jsh_inventory_log`;
+CREATE TABLE `jsh_inventory_log` (
+  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
+  `type` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT '商品修改' COMMENT '操作类型',
+  `item_id` bigint DEFAULT NULL COMMENT '单据、盘点子表id',
+  `material_id` bigint DEFAULT NULL COMMENT '商品id',
+  `material_extend_id` bigint DEFAULT NULL COMMENT '商品子表id',
+  `original_stock` int DEFAULT NULL COMMENT '原始库存',
+  `current_stock` int DEFAULT NULL COMMENT '当前库存',
+  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
+  `update_user` bigint DEFAULT NULL COMMENT '更新用户',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='库存修改日志表';

+ 18 - 4
src/main/java/com/jsh/erp/controller/pda/PdaController.java

@@ -13,6 +13,7 @@ import com.jsh.erp.datasource.entities.MaterialVo4Unit;
 import com.jsh.erp.datasource.entities.Supplier;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
+import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingDTO;
 import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
@@ -267,12 +268,25 @@ public class PdaController extends BaseController {
         return AjaxResult.success();
     }
 
-    @ApiOperation("商品存货查询")
-    @GetMapping("/inventoryInquiry/{type}/{keyword}")
-    public TableDataInfo inventoryInquiry(@PathVariable("type") String type,@PathVariable("keyword") String keyword){
+    @PostMapping("/inventoryInquiry")
+    @ApiOperation("存货查询-商品存货查询")
+    public TableDataInfo inventoryInquiry(@RequestBody PDAInventoryDTO pdaInventoryDTO){
         startPage();
-        List<PDADepotItemVO> list = materialService.inventoryInquiry(type , keyword);
+        List<PDADepotItemVO> list = materialService.inventoryInquiry(pdaInventoryDTO);
         return getDataTable(list);
     }
 
+    @ApiOperation("存货查询-库位树查询")
+    @GetMapping("/inventoryPositionTree")
+    public AjaxResult inventoryPositionTree() throws Exception {
+        return AjaxResult.success(materialService.selectPosition());
+    }
+
+    @ApiOperation("存货查询-类型树查询")
+    @GetMapping("/inventoryTypeTree")
+    public AjaxResult inventoryTypeTree() throws Exception {
+        return AjaxResult.success(materialCategoryService.getMaterialCategoryTree(null));
+    }
+
+
 }

+ 14 - 1
src/main/java/com/jsh/erp/controller/stocktaking/StocktakingController.java

@@ -9,11 +9,14 @@ import com.jsh.erp.datasource.dto.TaskStocktakingDTO;
 import com.jsh.erp.datasource.dto.TaskStocktakingItemDTO;
 import com.jsh.erp.datasource.dto.TaskStocktakingItemQueryDTO;
 import com.jsh.erp.datasource.dto.TaskStocktakingQueryDTO;
+import com.jsh.erp.datasource.entities.MaterialExtend;
 import com.jsh.erp.datasource.entities.TaskStocktaking;
 import com.jsh.erp.datasource.entities.TaskStocktakingItem;
 import com.jsh.erp.datasource.entities.User;
 import com.jsh.erp.datasource.vo.SpinnerVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingVO;
+import com.jsh.erp.query.LambdaQueryWrapperX;
+import com.jsh.erp.service.MaterialExtendService;
 import com.jsh.erp.service.TaskStocktakingItemService;
 import com.jsh.erp.service.TaskStocktakingService;
 import com.jsh.erp.service.UserService;
@@ -41,6 +44,9 @@ public class StocktakingController extends BaseController {
     @Resource
     private TaskStocktakingItemService taskStocktakingItemService;
 
+    @Resource
+    private MaterialExtendService materialExtendService;
+
     @ApiOperation("盘点任务列表")
     @PostMapping("/list")
     public TableDataInfo list(@RequestBody TaskStocktakingQueryDTO taskStocktakingQueryDTO){
@@ -170,9 +176,16 @@ public class StocktakingController extends BaseController {
 
     @ApiOperation("任务更新库存")
     @GetMapping("/taskUpdateStock/{ids}")
-    public AjaxResult updateStock(@PathVariable("ids") Long[] ids) {
+    public AjaxResult updateStock(@PathVariable("ids") Long[] ids) throws Exception {
         for (Long id : ids) {
             taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 5).eq("id", id));
+            List<TaskStocktakingItem> list = taskStocktakingItemService.list(new LambdaQueryWrapperX<TaskStocktakingItem>().eq(TaskStocktakingItem::getTaskStocktakingId,id));
+            for (TaskStocktakingItem taskStocktakingItem : list) {
+                MaterialExtend materialExtend = materialExtendService.getMaterialExtend(taskStocktakingItem.getMaterialItemId());
+                materialExtend.setInventory(taskStocktakingItem.getNewInventory());
+                materialExtend.setPosition(taskStocktakingItem.getNewPosition());
+                materialExtendService.updateInventory("盘点",taskStocktakingItem.getId(),materialExtend);
+            }
         }
         return AjaxResult.success();
     }

+ 4 - 4
src/main/java/com/jsh/erp/datasource/entities/InventoryLog.java

@@ -16,11 +16,11 @@ public class InventoryLog {
     @ApiModelProperty("主键id")
     private Long id;
 
-    @ApiModelProperty("单据主表id")
-    private Long depotHeadId;
+    @ApiModelProperty("操作类型")
+    private String type;
 
-    @ApiModelProperty("单据子表id")
-    private Long depotItemId;
+    @ApiModelProperty("单据、盘点子表id")
+    private Long itemId;
 
     @ApiModelProperty("商品id")
     private Long materialId;

+ 2 - 0
src/main/java/com/jsh/erp/datasource/entities/MaterialExtend.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.experimental.Accessors;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -13,6 +14,7 @@ import java.util.Date;
  */
 @Data
 @TableName("jsh_material_extend")
+@Accessors
 public class MaterialExtend {
 
     @ApiModelProperty("主键id")

+ 5 - 5
src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java

@@ -102,19 +102,19 @@ public class MaterialVo4Unit extends Material{
     private String depotName;
 
     @ApiModelProperty("实际出入库数量")
-    private BigDecimal actualQuantityInStorage;
+    private String actualQuantityInStorage = "";
 
     @ApiModelProperty("出入库差异")
-    private BigDecimal warehousingVariance;
+    private String warehousingVariance = "";
 
     @ApiModelProperty("出入库差异原因")
-    private String reasonOfDifference;
+    private String reasonOfDifference = "";
 
     @ApiModelProperty("出入库用户")
-    private Long warehousingUser;
+    private String warehousingUser = "";
 
     @ApiModelProperty("出入库时间")
-    private Date warehousingTime;
+    private String warehousingTime = "";
 
     @ApiModelProperty("多单位集合")
     private List<UnitListVo> unitList;

+ 2 - 0
src/main/java/com/jsh/erp/datasource/mappers/MaterialExtendMapper.java

@@ -52,4 +52,6 @@ public interface MaterialExtendMapper extends BaseMapperX<MaterialExtend>{
     BigDecimal getInventorySumByDepotAndMid(@Param("depotList") List<Long> depotList,
                                             @Param("mid") long mid);
 
+    List<String> selectPosition();
+
 }

+ 2 - 1
src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java

@@ -1,6 +1,7 @@
 package com.jsh.erp.datasource.mappers;
 
 import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
 import org.apache.ibatis.annotations.Param;
@@ -164,7 +165,7 @@ public interface MaterialMapperEx {
 
     List<MaterialVo4Unit> getMaterialBySystemSku(@Param("systemSkuArray") String [] systemSkuArray);
 
-    List<PDADepotItemVO> inventoryInquiry();
+    List<PDADepotItemVO> inventoryInquiry(PDAInventoryDTO pdaInventoryDTO);
 
 
 }

+ 25 - 0
src/main/java/com/jsh/erp/datasource/pda/dto/PDAInventoryDTO.java

@@ -0,0 +1,25 @@
+package com.jsh.erp.datasource.pda.dto;
+
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * 存货查询接口
+ */
+@Data
+public class PDAInventoryDTO {
+
+    @ApiModelProperty("查询类型")
+    private String type;
+
+    @ApiModelProperty("商品种类ID")
+    private Long categoryId;
+
+    @ApiModelProperty("库位")
+    private String position;
+
+    @ApiModelProperty("关键字")
+    private String keyword;
+
+}

+ 30 - 0
src/main/java/com/jsh/erp/datasource/pda/vo/PDATypeTree.java

@@ -0,0 +1,30 @@
+package com.jsh.erp.datasource.pda.vo;
+
+import com.jsh.erp.datasource.vo.TreeNode;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * PDA库位类型树
+ */
+@Data
+public class PDATypeTree {
+
+    private Long id;
+
+    private Long key;
+
+    private String value;
+
+    /**
+     * title显示的文本
+     * */
+    private String label;
+
+    /**
+     * children 子节点
+     * */
+    private List<PDATypeTree> children;
+
+}

+ 1 - 1
src/main/java/com/jsh/erp/service/MaterialExtendService.java

@@ -58,5 +58,5 @@ public interface MaterialExtendService extends IService<MaterialExtend> {
     /**
      * 修改子商品库存
      */
-    void updateInventory(Long depotHeadId, Long depotItemId,MaterialExtend materialExtend) throws Exception;
+    void updateInventory(String type, Long id,MaterialExtend materialExtend) throws Exception;
 }

+ 9 - 3
src/main/java/com/jsh/erp/service/MaterialService.java

@@ -5,7 +5,9 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.pda.vo.PDATypeTree;
 import com.jsh.erp.datasource.vo.MaterialWarnListVo;
 import com.jsh.erp.utils.BaseResponseInfo;
 import org.springframework.transaction.annotation.Transactional;
@@ -185,9 +187,13 @@ public interface MaterialService extends IService<Material> {
 
     /**
      * PDA库存查询
-     * @param type 库存类别 有/无/全部
-     * @param keyword 关键字
+     * pdaInventoryDTO
      * @return
      */
-    List<PDADepotItemVO> inventoryInquiry(String type,String keyword);
+    List<PDADepotItemVO> inventoryInquiry(PDAInventoryDTO pdaInventoryDTO);
+
+    /**
+     * 查询库位树
+     */
+    List<PDATypeTree> selectPosition();
 }

+ 3 - 2
src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java

@@ -767,11 +767,11 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
                 if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType())){
                     //表单入库,修改商品库存
                     materialExtend.setInventory(materialExtend.getInventory().add(depotItem.getBasicNumber()));
-                    materialExtendService.updateInventory(depotHead.getId(),depotItem.getId(),materialExtend);
+                    materialExtendService.updateInventory("单据",depotItem.getId(),materialExtend);
                 }else if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
                     //表单入库,修改商品库存
                     materialExtend.setInventory(materialExtend.getInventory().subtract(depotItem.getBasicNumber()));
-                    materialExtendService.updateInventory(depotHead.getId(),depotItem.getId(),materialExtend);
+                    materialExtendService.updateInventory("单据",depotItem.getId(),materialExtend);
                 }
                 this.insertDepotItemWithObj(depotItem);
                 //更新当前库存
@@ -1643,4 +1643,5 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
         }
         return materialOther;
     }
+
 }

+ 5 - 5
src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java

@@ -306,7 +306,7 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         int res =0;
         try{
             //修改库存
-            updateInventory(null,null,materialExtend);
+            updateInventory("商品修改",null,materialExtend);
             res= materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
         }catch(Exception e){
             JshException.writeFail(logger, e);
@@ -495,7 +495,7 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
      * 修改子商品库存
      */
     @Override
-    public synchronized void updateInventory(Long depotHeadId, Long depotItemId, MaterialExtend materialExtend) throws Exception {
+    public synchronized void updateInventory(String type, Long id, MaterialExtend materialExtend) throws Exception {
         if (materialExtend.getInventory() != null){
             User user = userService.getCurrentUser();
             InventoryLog log = new InventoryLog();
@@ -506,10 +506,10 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
             log.setOriginalStock(materialExtendMapper.selectByPrimaryKey(materialExtend.getId()).getInventory().intValue());
             Integer i = materialExtend.getInventory().intValue();
             log.setCurrentStock(i);
-            log.setDepotHeadId(depotHeadId);
-            log.setDepotItemId(depotItemId);
+            log.setItemId(id);
+            log.setType(type);
             inventoryLogService.save(log);
-            update(new UpdateWrapper<MaterialExtend>().set("inventory",materialExtend.getInventory()).eq("id",materialExtend.getId()));;
+            update(new UpdateWrapper<MaterialExtend>().set("inventory",materialExtend.getInventory()).set("position",materialExtend.getPosition()).eq("id",materialExtend.getId()));;
         }
     }
     /**

+ 41 - 2
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -9,12 +9,16 @@ import com.jsh.erp.constants.BusinessConstants;
 import com.jsh.erp.constants.ExceptionConstants;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
+import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.pda.vo.PDATypeTree;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
 import com.jsh.erp.datasource.vo.MaterialWarnListVo;
+import com.jsh.erp.datasource.vo.TreeNode;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.query.LambdaQueryWrapperX;
+import com.jsh.erp.query.QueryWrapperX;
 import com.jsh.erp.service.*;
 import com.jsh.erp.utils.*;
 import jxl.Sheet;
@@ -1991,8 +1995,43 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     }
 
     @Override
-    public List<PDADepotItemVO> inventoryInquiry(String type, String keyword) {
-        return materialMapperEx.inventoryInquiry();
+    public List<PDADepotItemVO> inventoryInquiry(PDAInventoryDTO pdaInventoryDTO) {
+        return materialMapperEx.inventoryInquiry(pdaInventoryDTO);
+    }
+
+    /**
+     * 查询库位树
+     */
+    @Override
+    public List<PDATypeTree> selectPosition() {
+        List<String> positions = materialExtendMapper.selectPosition();
+        Map<String,List<String>> map = new HashMap<>();
+        for (String s : positions) {
+            String [] str = s.split("-");
+            if (map.get(str[0]) == null){
+                List<String> list = new ArrayList<>();
+                list.add(str[1]);
+                map.put(str[0],list);
+            }else {
+                map.get(str[0]).add(str[1]);
+            }
+        }
+        List<PDATypeTree> typeTrees = new ArrayList<>();
+        map.forEach((key,value) -> {
+            PDATypeTree typeTree = new PDATypeTree();
+            typeTree.setLabel(key);
+            typeTree.setValue(key);
+            List<PDATypeTree> children = new ArrayList<>();
+            for (String s : value) {
+                PDATypeTree childrenTree = new PDATypeTree();
+                childrenTree.setLabel(key + "-" + s);
+                childrenTree.setValue(key + "-" + s);
+                children.add(childrenTree);
+            }
+            typeTree.setChildren(children);
+            typeTrees.add(typeTree);
+        });
+        return typeTrees;
     }
 
     /**

+ 3 - 3
src/main/resources/mapper_xml/DepotHeadMapper.xml

@@ -275,7 +275,7 @@
         receiver_phone,
       </if>
       <if test="receiverAddress != null">
-        receiver_address,
+        receiver_address
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -388,10 +388,10 @@
         #{linkTesco,jdbcType=VARCHAR},
       </if>
       <if test="receiverName != null">
-        #{receiverName,jdbcType=VARCHAR}
+        #{receiverName,jdbcType=VARCHAR},
       </if>
       <if test="receiverPhone != null">
-        #{receiverPhone,jdbcType=VARCHAR}
+        #{receiverPhone,jdbcType=VARCHAR},
       </if>
       <if test="receiverAddress != null">
         #{receiverAddress,jdbcType=VARCHAR}

+ 4 - 0
src/main/resources/mapper_xml/MaterialExtendMapper.xml

@@ -481,4 +481,8 @@
     AND ifnull(me.delete_Flag,'0') !='1'
   </select>
 
+  <select id="selectPosition"  resultType="String">
+    SELECT DISTINCT position FROM jsh_material_extend WHERE position IS NOT NULL AND ifnull(delete_Flag,'0') !='1'
+  </select>
+
 </mapper>

+ 19 - 1
src/main/resources/mapper_xml/MaterialMapperEx.xml

@@ -858,7 +858,25 @@
         left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
         left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
         left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
-        where m.enabled=1 and me.id is not null
+        where m.enabled = 1
+        and me.id is not null
+        <if test="keyword != null and keyword !=''">
+            <bind name="bindKey" value="'%'+materialParam+'%'"/>
+            and me.batch_number like #{bindKey} or m.name like #{bindKey}
+        </if>
+        <if test="position != null and position !=''">
+            <bind name="bindPosition" value="'%'+position+'%'"/>
+            and me.position like #{bindPosition}
+        </if>
+        <if test="categoryId != null">
+            and m.category_id = #{category_id}
+        </if>
+        <if test="type == 'have'">
+            and me.inventory > 0
+        </if>
+        <if test="type == 'none'">
+            and me.inventory &lt;= 0
+        </if>
         and ifnull(me.delete_flag,'0') !='1'
     </select>