Browse Source

盘点接口

廖泽勇 1 month ago
parent
commit
d40030de13

+ 5 - 1
docs/new_sql.sql

@@ -57,10 +57,13 @@ CREATE TABLE `task_stocktaking` (
     `task_type` varchar(255) DEFAULT NULL COMMENT '任务类型',
     `depot_id` bigint DEFAULT NULL COMMENT '仓库ID',
     `number` varchar(255) DEFAULT NULL COMMENT '任务单号',
+    `category_count` int DEFAULT NULL COMMENT '种类数',
     `material_count` int DEFAULT NULL COMMENT '商品数',
     `task_status` int DEFAULT NULL COMMENT '任务状态',
     `position_range` varchar(255) DEFAULT NULL COMMENT '库位范围',
     `delete_flag` tinyint DEFAULT NULL COMMENT '删除标志(0:否,1是)',
+    `oper_time` datetime DEFAULT NULL COMMENT '盘点时间',
+    `oper_by` bigint DEFAULT NULL COMMENT '盘点人',
     PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='盘点任务表';
 
@@ -78,8 +81,9 @@ CREATE TABLE `task_stocktaking_item` (
     `new_position` varchar(255) DEFAULT NULL COMMENT '新仓位货架',
     `new_inventory` decimal(24,6) DEFAULT NULL COMMENT '新库存数',
     `difference_count` int DEFAULT NULL COMMENT '差异数量',
-    `difference_reasion` varchar(255) DEFAULT NULL COMMENT '差异原因',
+    `difference_reason` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL COMMENT '差异原因',
     `delete_flag` varchar(1) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT '0' COMMENT '删除标记,0未删除,1删除',
     `oper_time` datetime DEFAULT NULL COMMENT '操作时间',
+    `status` int DEFAULT '1' COMMENT '盘点状态(1.未盘,2.盘盈,3.盘亏 4.无差异)',
     PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COMMENT='盘点任务关联商品表';

+ 73 - 7
src/main/java/com/jsh/erp/controller/pda/PdaController.java

@@ -1,21 +1,24 @@
 package com.jsh.erp.controller.pda;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
-import com.jsh.erp.datasource.entities.DepotHead;
-import com.jsh.erp.datasource.entities.Supplier;
-import com.jsh.erp.datasource.entities.TaskStocktakingItem;
-import com.jsh.erp.datasource.entities.User;
+import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
 import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingDTO;
+import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO;
+import com.jsh.erp.datasource.vo.SpinnerVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingVO;
+import com.jsh.erp.datasource.vo.TreeNode;
 import com.jsh.erp.query.LambdaQueryWrapperX;
 import com.jsh.erp.service.*;
 import io.swagger.annotations.Api;
@@ -24,6 +27,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
 
@@ -50,6 +54,12 @@ public class PdaController extends BaseController {
     @Resource
     private UserService userService;
 
+    @Resource
+    private MaterialCategoryService materialCategoryService;
+
+    @Resource
+    private MaterialExtendService materialExtendService;
+
     /**
      * 采购入库
      * @return
@@ -123,10 +133,10 @@ public class PdaController extends BaseController {
     }
 
     @ApiOperation(value = "盘点任务详情-商品列表")
-    @GetMapping("/taskStocktakingItemList/{taskId}")
-    public TableDataInfo taskStocktakingItemList(@PathVariable("taskId") Long taskId){
+    @PostMapping("/taskStocktakingItemList")
+    public TableDataInfo taskStocktakingItemList(@RequestBody PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO){
         startPage();
-        List<PDATaskStocktakingItemVO> list = taskStocktakingService.pdaItemList(taskId);
+        List<PDATaskStocktakingItemVO> list = taskStocktakingService.pdaItemList(pdaTaskStocktakingItemDTO);
         return getDataTable(list);
     }
 
@@ -137,16 +147,64 @@ public class PdaController extends BaseController {
         return AjaxResult.success(taskStocktakingVO);
     }
 
+    /**
+     * 获取商品类别树数据
+     * @Param:
+     * @return com.alibaba.fastjson.JSONArray
+     */
+    @ApiOperation(value = "获取商品类别树数据")
+    @GetMapping(value = "/getMaterialCategoryTree")
+    public JSONArray getMaterialCategoryTree(@RequestParam("id") Long id) throws Exception{
+        JSONArray arr=new JSONArray();
+        List<TreeNode> materialCategoryTree = materialCategoryService.getMaterialCategoryTree(id);
+        if(materialCategoryTree!=null&&materialCategoryTree.size()>0){
+            for(TreeNode node:materialCategoryTree){
+                String str= JSON.toJSONString(node);
+                JSONObject obj=JSON.parseObject(str);
+                arr.add(obj) ;
+            }
+        }
+        return arr;
+    }
+
+    @ApiOperation("开始任务")
+    @GetMapping("/startTask/{id}")
+    public AjaxResult startTask(@PathVariable("id") Long id) {
+        taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 2).eq("id", id));
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("任务完成")
+    @GetMapping("/taskComplete/{id}")
+    public AjaxResult taskComplete(@PathVariable("id") Long id) {
+        taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 3).eq("id", id));
+        return AjaxResult.success();
+    }
+
     @ApiOperation("盘点")
     @PostMapping("/stocktaking")
     public AjaxResult stocktaking(@RequestBody TaskStocktakingItem taskStocktakingItem) throws Exception{
         User currentUser = userService.getCurrentUser();
+        MaterialExtend materialExtend = materialExtendService.getMaterialExtend(taskStocktakingItem.getMaterialItemId());
+        if (materialExtend == null) {
+            return AjaxResult.error("商品信息不存在");
+        }
         UpdateWrapper<TaskStocktakingItem> updateWrapper = new UpdateWrapper<>();
         updateWrapper.eq("id", taskStocktakingItem.getId())
                 .set("creator", currentUser.getId())
                 .set("oper_time", new Date());
         if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewInventory())) {
             updateWrapper.set("new_inventory", taskStocktakingItem.getNewInventory());
+            BigDecimal subtract = taskStocktakingItem.getNewInventory().subtract(materialExtend.getInventory());
+            updateWrapper.set("difference_count", subtract);
+            //差异数量,设置盘点状态为1.未盘,2.盘盈,3.盘亏 4.无差异
+            if (subtract.compareTo(BigDecimal.ZERO) > 0) {
+                updateWrapper.set("status", 2);
+            } else if (subtract.compareTo(BigDecimal.ZERO) < 0) {
+                updateWrapper.set("status", 3);
+            } else {
+                updateWrapper.set("status", 4);
+            }
         }
         if (ObjectUtil.isNotEmpty(taskStocktakingItem.getNewPosition())) {
             updateWrapper.set("new_position", taskStocktakingItem.getNewPosition());
@@ -161,6 +219,14 @@ public class PdaController extends BaseController {
         return AjaxResult.success();
     }
 
+
+    @ApiOperation("负责人下拉列表")
+    @GetMapping("/creatorSpinnerList/{taskId}")
+    public AjaxResult creatorSpinnerList(@PathVariable("taskId") Long taskId) {
+        List<SpinnerVO> spinnerVOList = taskStocktakingItemService.creatorSpinnerList(taskId);
+        return AjaxResult.success(spinnerVOList);
+    }
+
     @ApiOperation("订单-用于返回字段说明")
     @GetMapping("test")
     public AjaxResult test(PDADepotItemVO pdaDepotItemVO) {

+ 45 - 9
src/main/java/com/jsh/erp/controller/stocktaking/StocktakingController.java

@@ -1,11 +1,14 @@
 package com.jsh.erp.controller.stocktaking;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
 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.TaskStocktaking;
 import com.jsh.erp.datasource.entities.TaskStocktakingItem;
 import com.jsh.erp.datasource.entities.User;
@@ -16,7 +19,6 @@ import com.jsh.erp.service.TaskStocktakingService;
 import com.jsh.erp.service.UserService;
 import com.jsh.erp.utils.DateUtils;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.web.bind.annotation.*;
 
@@ -40,9 +42,9 @@ public class StocktakingController extends BaseController {
 
     @ApiOperation("盘点任务列表")
     @PostMapping("/list")
-    public TableDataInfo list(){
+    public TableDataInfo list(@RequestBody TaskStocktakingQueryDTO taskStocktakingQueryDTO){
         startPage();
-        List<TaskStocktakingVO> list = taskStocktakingService.listBy();
+        List<TaskStocktakingVO> list = taskStocktakingService.listBy(taskStocktakingQueryDTO);
         return getDataTable(list);
     }
 
@@ -76,13 +78,16 @@ public class StocktakingController extends BaseController {
 
     /**
      * 任务详情-商品列表
-     * @param taskStocktakingId 任务ID
+     * @param taskStocktakingItemQueryDTO 筛选数据
      * @return
      */
     @ApiOperation("任务详情-商品列表")
-    @GetMapping("/detailByItemList/{taskStocktakingId}")
-    public AjaxResult detailByItemList(@PathVariable("taskStocktakingId") Long taskStocktakingId) {
-        return AjaxResult.success(taskStocktakingService.listByTaskStocktakingId(taskStocktakingId));
+    @PostMapping("/detailByItemList")
+    public AjaxResult detailByItemList(@RequestBody TaskStocktakingItemQueryDTO taskStocktakingItemQueryDTO) {
+        if (ObjectUtil.isEmpty(taskStocktakingItemQueryDTO.getTaskStocktakingId())) {
+            return AjaxResult.error("请选择盘点任务");
+        }
+        return AjaxResult.success(taskStocktakingService.listByTaskStocktakingId(taskStocktakingItemQueryDTO));
     }
 
     @ApiOperation("任务详情-修改")
@@ -99,7 +104,7 @@ public class StocktakingController extends BaseController {
      * 任务详情-商品列表-编辑
      * @return
      */
-    @ApiModelProperty("任务详情-商品-编辑")
+    @ApiOperation("任务详情-商品-编辑")
     @PostMapping("/itemUpdate")
     public AjaxResult itemUpdate(@RequestBody TaskStocktakingItemDTO taskStocktakingItemDTO) throws Exception {
         User currentUser = userService.getCurrentUser();
@@ -119,7 +124,7 @@ public class StocktakingController extends BaseController {
      * @param id 商品ID
      * @return
      */
-    @ApiModelProperty("任务详情-商品-删除")
+    @ApiOperation("任务详情-商品-删除")
     @GetMapping("/itemDelete/{id}")
     public AjaxResult itemDelete(@PathVariable("id") Long id) {
         taskStocktakingItemService.update(new UpdateWrapper<TaskStocktakingItem>().set("delete_flag", true).eq("id", id));
@@ -135,4 +140,35 @@ public class StocktakingController extends BaseController {
         return AjaxResult.success();
     }
 
+    @ApiOperation("删除任务")
+    @GetMapping("/taskDelete/{ids}")
+    public AjaxResult taskDelete(@PathVariable("ids") Long[] ids) {
+        Arrays.asList(ids).forEach(id -> {
+            taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().eq("id", id).set("delete_flag", true));
+        });
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("开始任务")
+    @GetMapping("/startTask/{id}")
+    public AjaxResult startTask(@PathVariable("id") Long id) {
+        taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 2).eq("id", id));
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("完成任务")
+    @GetMapping("/taskComplete/{id}")
+    public AjaxResult taskComplete(@PathVariable("id") Long id) {
+        taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 3).eq("id", id));
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("任务更新库存")
+    @GetMapping("/taskUpdateStock/{id}")
+    public AjaxResult updateStock(@PathVariable("id") Long id) {
+        taskStocktakingService.update(new UpdateWrapper<TaskStocktaking>().set("task_status", 5).eq("id", id));
+        return AjaxResult.success();
+    }
+
+
 }

+ 30 - 0
src/main/java/com/jsh/erp/datasource/dto/TaskStocktakingItemQueryDTO.java

@@ -0,0 +1,30 @@
+package com.jsh.erp.datasource.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+@Data
+@Accessors(chain = true)
+public class TaskStocktakingItemQueryDTO {
+
+    @ApiModelProperty("盘点任务ID")
+    private Long taskStocktakingId;
+
+    @ApiModelProperty("商品类别ID")
+    private Long categoryId;
+
+    @ApiModelProperty("商品名称")
+    private Integer materialName;
+
+    @ApiModelProperty("批次号")
+    private String batchNumber;
+
+    @ApiModelProperty("仓库货架")
+    private Long position;
+
+    @ApiModelProperty("是否存在差异 1:是,2:否,其他是全部")
+    private String isDifference;
+
+
+}

+ 20 - 0
src/main/java/com/jsh/erp/datasource/dto/TaskStocktakingQueryDTO.java

@@ -0,0 +1,20 @@
+package com.jsh.erp.datasource.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+public class TaskStocktakingQueryDTO {
+
+    @ApiModelProperty("任务状态 1.未开始,2.进行中,3.已完成,4.已取消")
+    private Integer taskStatus;
+
+    @ApiModelProperty("任务单号")
+    private String number;
+
+    @ApiModelProperty("盘点仓库ID")
+    private Long depotId;
+
+    @ApiModelProperty("创建人")
+    private String createName;
+
+
+}

+ 1 - 1
src/main/java/com/jsh/erp/datasource/entities/TaskStocktaking.java

@@ -45,7 +45,7 @@ public class TaskStocktaking {
     @ApiModelProperty("商品数")
     private int materialCount;
 
-    @ApiModelProperty("任务状态 1.未开始,2.进行中,3.已完成,4.已取消")
+    @ApiModelProperty("任务状态 1.未开始,2.进行中,3.已完成,4.已取消,5.已更新")
     private Integer taskStatus;
 
     @ApiModelProperty("盘点范围")

+ 3 - 0
src/main/java/com/jsh/erp/datasource/entities/TaskStocktakingItem.java

@@ -41,6 +41,9 @@ public class TaskStocktakingItem {
     @ApiModelProperty("差异原因")
     private String differenceReason;
 
+    @ApiModelProperty("盘点状态:1.未盘,2.盘盈,3.盘亏 4.无差异 其余为全部")
+    private Integer status;
+
     @ApiModelProperty("删除标记,0.未删除,1.已删除")
     private boolean deleteFlag;
 

+ 7 - 2
src/main/java/com/jsh/erp/datasource/mappers/TaskStocktakingItemMapper.java

@@ -1,7 +1,10 @@
 package com.jsh.erp.datasource.mappers;
 
+import com.jsh.erp.datasource.dto.TaskStocktakingItemQueryDTO;
 import com.jsh.erp.datasource.entities.TaskStocktakingItem;
+import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO;
+import com.jsh.erp.datasource.vo.SpinnerVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -9,8 +12,10 @@ import java.util.List;
 
 public interface TaskStocktakingItemMapper extends BaseMapperX<TaskStocktakingItem> {
 
-    List<TaskStocktakingItemVO> listByTaskStocktakingId(@Param("taskStocktakingId") Long taskStocktakingId);
+    List<TaskStocktakingItemVO> listByTaskStocktakingId(TaskStocktakingItemQueryDTO taskStocktakingItemQueryDTO);
 
-    List<PDATaskStocktakingItemVO> pdaList(@Param("taskId") Long taskId);
+    List<PDATaskStocktakingItemVO> pdaList(PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO);
+
+    List<SpinnerVO> creatorSpinnerList(@Param("taskId") Long taskId);
 
 }

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

@@ -1,5 +1,6 @@
 package com.jsh.erp.datasource.mappers;
 
+import com.jsh.erp.datasource.dto.TaskStocktakingQueryDTO;
 import com.jsh.erp.datasource.entities.TaskStocktaking;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingVO;
@@ -9,7 +10,7 @@ import java.util.List;
 
 public interface TaskStocktakingMapper extends BaseMapperX<TaskStocktaking> {
 
-    List<TaskStocktakingVO> listBy();
+    List<TaskStocktakingVO> listBy(TaskStocktakingQueryDTO taskStocktakingQueryDTO);
 
     List<PDATaskStocktakingVO> pdaList(@Param("number") String number , @Param("taskStatus") Integer taskStatus);
 }

+ 9 - 0
src/main/java/com/jsh/erp/datasource/pda/dto/PDATaskStocktakingDTO.java

@@ -12,4 +12,13 @@ public class PDATaskStocktakingDTO {
     @ApiModelProperty("任务单号")
     private String number;
 
+    @ApiModelProperty("用户id")
+    private Long userId;
+
+    @ApiModelProperty("商品种类ID")
+    private Long categoryId;
+
+    @ApiModelProperty("库位")
+    private String position;
+
 }

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

@@ -0,0 +1,25 @@
+package com.jsh.erp.datasource.pda.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class PDATaskStocktakingItemDTO {
+
+    @ApiModelProperty("任务ID")
+    private String taskId;
+
+    @ApiModelProperty("库位")
+    private List<String> positionList;
+
+    @ApiModelProperty("盘点人ID")
+    private List<Long> userIdList;
+
+    @ApiModelProperty("商品种类ID")
+    private List<Long> categoryIdList;
+
+    @ApiModelProperty("商品盘点类型:1.未盘,2.盘盈,3.盘亏 4.无差异 其余为全部")
+    private List<String> statusList;
+}

+ 9 - 0
src/main/java/com/jsh/erp/datasource/pda/vo/PDATaskStocktakingItemVO.java

@@ -22,6 +22,9 @@ public class PDATaskStocktakingItemVO {
     @ApiModelProperty("商品总类")
     private String categoryName;
 
+    @ApiModelProperty("商品ID")
+    private Long materialItemId;
+
     @ApiModelProperty("商品名称")
     private String materialName;
 
@@ -37,7 +40,13 @@ public class PDATaskStocktakingItemVO {
     @ApiModelProperty("库存数")
     private Integer inventory;
 
+    @ApiModelProperty("商品单位")
+    private String commodityUnit;
+
     @ApiModelProperty("盘点库存数")
     private Integer newInventory;
 
+    @ApiModelProperty("盘点状态:1.未盘,2.盘盈,3.盘亏 4.无差异 其余为全部")
+    private Integer status;
+
 }

+ 5 - 0
src/main/java/com/jsh/erp/service/TaskStocktakingItemService.java

@@ -2,6 +2,11 @@ package com.jsh.erp.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.TaskStocktakingItem;
+import com.jsh.erp.datasource.vo.SpinnerVO;
+
+import java.util.List;
 
 public interface TaskStocktakingItemService extends IService<TaskStocktakingItem> {
+
+    List<SpinnerVO> creatorSpinnerList(Long taskId);
 }

+ 7 - 4
src/main/java/com/jsh/erp/service/TaskStocktakingService.java

@@ -2,7 +2,10 @@ package com.jsh.erp.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.dto.TaskStocktakingDTO;
+import com.jsh.erp.datasource.dto.TaskStocktakingItemQueryDTO;
+import com.jsh.erp.datasource.dto.TaskStocktakingQueryDTO;
 import com.jsh.erp.datasource.entities.TaskStocktaking;
+import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
@@ -16,7 +19,7 @@ public interface TaskStocktakingService extends IService<TaskStocktaking> {
      *
      * @return
      */
-    List<TaskStocktakingVO> listBy();
+    List<TaskStocktakingVO> listBy(TaskStocktakingQueryDTO taskStocktakingQueryDTO);
 
     /**
      * 新增任务
@@ -40,10 +43,10 @@ public interface TaskStocktakingService extends IService<TaskStocktaking> {
 
     /**
      * 任务详情-商品明细
-     * @param taskStocktakingId 盘点任务ID
+     * @param taskStocktakingItemQueryDTO 筛选参数
      * @return
      */
-    List<TaskStocktakingItemVO> listByTaskStocktakingId(Long taskStocktakingId);
+    List<TaskStocktakingItemVO> listByTaskStocktakingId(TaskStocktakingItemQueryDTO taskStocktakingItemQueryDTO);
 
     /**
      * PDA-盘点任务列表
@@ -61,7 +64,7 @@ public interface TaskStocktakingService extends IService<TaskStocktaking> {
      */
     TaskStocktakingVO pdaDetail(Long id) throws Exception;
 
-    List<PDATaskStocktakingItemVO> pdaItemList(Long taskId);
+    List<PDATaskStocktakingItemVO> pdaItemList(PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO);
 
 
 }

+ 14 - 0
src/main/java/com/jsh/erp/service/impl/TaskStocktakingItemServiceImpl.java

@@ -3,9 +3,23 @@ package com.jsh.erp.service.impl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.datasource.entities.TaskStocktakingItem;
 import com.jsh.erp.datasource.mappers.TaskStocktakingItemMapper;
+import com.jsh.erp.datasource.vo.SpinnerVO;
 import com.jsh.erp.service.TaskStocktakingItemService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 @Service
+@RequiredArgsConstructor
+@Slf4j
 public class TaskStocktakingItemServiceImpl extends ServiceImpl<TaskStocktakingItemMapper, TaskStocktakingItem> implements TaskStocktakingItemService {
+
+    private final TaskStocktakingItemMapper taskStocktakingItemMapper;
+
+    @Override
+    public List<SpinnerVO> creatorSpinnerList(Long taskId) {
+        return taskStocktakingItemMapper.creatorSpinnerList(taskId);
+    }
 }

+ 25 - 16
src/main/java/com/jsh/erp/service/impl/TaskStocktakingServiceImpl.java

@@ -6,17 +6,20 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.datasource.dto.TaskStocktakingDTO;
+import com.jsh.erp.datasource.dto.TaskStocktakingItemQueryDTO;
+import com.jsh.erp.datasource.dto.TaskStocktakingQueryDTO;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
+import com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO;
 import com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
 import com.jsh.erp.datasource.vo.TaskStocktakingVO;
 import com.jsh.erp.query.LambdaQueryWrapperX;
 import com.jsh.erp.service.DepotService;
+import com.jsh.erp.service.SequenceService;
 import com.jsh.erp.service.TaskStocktakingService;
 import com.jsh.erp.service.UserService;
-import com.jsh.erp.utils.DateUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -51,9 +54,11 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
 
     private final UserService userService;
 
+    private final SequenceService sequenceService;
+
     @Override
-    public List<TaskStocktakingVO> listBy() {
-        return taskStocktakingMapper.listBy();
+    public List<TaskStocktakingVO> listBy(TaskStocktakingQueryDTO taskStocktakingQueryDTO) {
+        return taskStocktakingMapper.listBy(taskStocktakingQueryDTO);
     }
 
     /**
@@ -95,6 +100,8 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
             taskStocktakingDTO.setCreateBy(currentUser.getId());
             taskStocktakingDTO.setCreateTime(new Date());
             taskStocktakingDTO.setTaskStatus(1);
+            //生成单据编号
+            taskStocktakingDTO.setNumber("PDRW"+sequenceService.buildOnlyNumber());
             //生成任务
             this.save(taskStocktakingDTO);
             //生成任务明细
@@ -180,7 +187,7 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
             taskStocktakingDTO.setCreateTime(new Date());
             taskStocktakingDTO.setTaskStatus(1);
             //生成任务
-            this.save(taskStocktakingDTO);
+            this.updateById(taskStocktakingDTO);
             List<Long> taskStocktakingItemIdList = taskStocktakingItemMapper.selectList(new LambdaQueryWrapperX<TaskStocktakingItem>().eq(TaskStocktakingItem::getTaskStocktakingId, taskStocktakingDTO.getId())).stream().map(TaskStocktakingItem::getId).collect(Collectors.toList());
             //生成任务明细
             List<TaskStocktakingItem> addTaskStocktakingItemList = new ArrayList<>();
@@ -195,15 +202,17 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
             List<Long> materialExtendIdList = materialExtendList.stream().map(MaterialExtend::getId).collect(Collectors.toList());
             taskStocktakingItemIdList.forEach(item -> {
                 if (!materialExtendIdList.contains(item)) {
-
-//                    taskStocktakingItemMapper.updateById();
+                    TaskStocktakingItem taskStocktakingItem = new TaskStocktakingItem();
+                    taskStocktakingItem.setId(item);
+                    taskStocktakingItem.setDeleteFlag(true);
+                    taskStocktakingItemMapper.updateById(taskStocktakingItem);
                 }
             });
             if (addTaskStocktakingItemList.size() > 0) {
                 taskStocktakingItemMapper.insertBatch(addTaskStocktakingItemList);
             }
         } catch (Exception e) {
-            log.error("创建盘点任务失败", e);
+            log.error("修改盘点任务失败", e);
             return false;
         }
         return true;
@@ -211,12 +220,12 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
 
     /**
      * 任务详情-商品明细
-     * @param taskStocktakingId 盘点任务ID
+     * @param taskStocktakingItemQueryDTO 筛选参数
      * @return
      */
     @Override
-    public List<TaskStocktakingItemVO> listByTaskStocktakingId(Long taskStocktakingId) {
-        return taskStocktakingItemMapper.listByTaskStocktakingId(taskStocktakingId);
+    public List<TaskStocktakingItemVO> listByTaskStocktakingId(TaskStocktakingItemQueryDTO taskStocktakingItemQueryDTO) {
+        return taskStocktakingItemMapper.listByTaskStocktakingId(taskStocktakingItemQueryDTO);
     }
 
     /**
@@ -256,10 +265,10 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
             differenceRate = BigDecimal.valueOf(itemCount)
                     .divide(BigDecimal.valueOf(itemDifferenceCount), 4, RoundingMode.HALF_UP)
                     .doubleValue();
-            accuracyRate = BigDecimal.valueOf(itemCount)
-                    .divide(BigDecimal.valueOf(finishCount)
-                            .subtract(BigDecimal.valueOf(itemDifferenceCount)), 4, RoundingMode.HALF_UP)
-                    .doubleValue();
+            BigDecimal subtract = BigDecimal.valueOf(finishCount).subtract(BigDecimal.valueOf(itemDifferenceCount));
+            if (!subtract.equals(BigDecimal.ZERO)) {
+                accuracyRate = subtract.divide(BigDecimal.valueOf(itemCount), 4, RoundingMode.HALF_UP).doubleValue();
+            }
         }
         detail.setDifferenceRate(differenceRate);
         detail.setAccuracyRate(accuracyRate);
@@ -268,8 +277,8 @@ public class TaskStocktakingServiceImpl extends ServiceImpl<TaskStocktakingMappe
     }
 
     @Override
-    public List<PDATaskStocktakingItemVO> pdaItemList(Long taskId) {
-        return taskStocktakingItemMapper.pdaList(taskId);
+    public List<PDATaskStocktakingItemVO> pdaItemList(PDATaskStocktakingItemDTO pdaTaskStocktakingItemDTO) {
+        return taskStocktakingItemMapper.pdaList(pdaTaskStocktakingItemDTO);
     }
 
     /**

+ 82 - 19
src/main/resources/mapper_xml/TaskStocktakingItemMapper.xml

@@ -2,7 +2,61 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.jsh.erp.datasource.mappers.TaskStocktakingItemMapper">
 
-    <select id="listByTaskStocktakingId" resultType="com.jsh.erp.datasource.vo.TaskStocktakingItemVO">
+    <select id="pdaList" parameterType="com.jsh.erp.datasource.pda.dto.PDATaskStocktakingItemDTO" resultType="com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO">
+        SELECT
+        tsi.id AS id,
+        tsi.material_item_id AS material_item_id,
+        me.position AS position,
+        mc.`name` AS category_name,
+        m.`name` AS material_name,
+        m.standard AS standard,
+        u.username AS create_name,
+        tsi.oper_time AS oper_time,
+        me.inventory AS inventory,
+        me.commodity_unit AS commodity_unit,
+        tsi.new_inventory AS new_inventory,
+        tsi.new_position AS new_position,
+        tsi.status AS status
+        FROM
+        task_stocktaking_item tsi
+        LEFT JOIN jsh_material_extend me ON tsi.material_item_id = me.id
+        LEFT JOIN jsh_material m ON me.material_id = m.id
+        LEFT JOIN jsh_material_category mc ON m.category_id = mc.id
+        LEFT JOIN jsh_user u ON u.id = tsi.creator
+        <where>
+            tsi.delete_flag = 0
+            AND tsi.task_stocktaking_id = #{taskId}
+            <if test="userIdList != null and userIdList.size > 0">
+                AND tsi.creator IN
+                <foreach collection="userIdList" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="categoryIdList != null and categoryIdList.size > 0">
+                AND m.category_id IN
+                <foreach collection="categoryIdList" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            <if test="positionList != null and positionList.size > 0">
+                AND
+                <foreach collection="positionList" item="item" open="(" separator="OR" close=")">
+                     me.position LIKE CONCAT('%',#{item},'%')
+                </foreach>
+            </if>
+            <if test="statusList != null and statusList.size > 0">
+                AND tsi.status IN
+                <foreach collection="statusList" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        ORDER BY
+        tsi.oper_time DESC,
+        tsi.id DESC
+    </select>
+
+    <select id="listByTaskStocktakingId" parameterType="com.jsh.erp.datasource.dto.TaskStocktakingItemQueryDTO" resultType="com.jsh.erp.datasource.vo.TaskStocktakingItemVO">
         SELECT
             tsi.id AS id,
             mc.`name` AS category_name,
@@ -25,36 +79,45 @@
                 LEFT JOIN jsh_material_category mc ON mc.id = m.category_id
                 LEFT JOIN jsh_supplier s ON me.supplier_id = s.id
                 LEFT JOIN jsh_depot d ON me.depot_id = d.id
-        WHERE
+        <where>
             tsi.delete_flag = 0
             AND tsi.task_stocktaking_id = #{taskStocktakingId}
+            <if test="categoryId != null and categoryId != ''">
+                AND m.category_id = #{categoryId}
+            </if>
+            <if test="materialName != null and materialName != ''">
+                AND m.`name` LIKE CONCAT('%',#{materialName},'%')
+            </if>
+            <if test="batchNumber != null and batchNumber != ''">
+                AND me.batch_number = #{batchNumber}
+            </if>
+            <if test="position != null and position != ''">
+                AND me.position = #{position}
+            </if>
+            <if test="isDifference != null and isDifference == '1'">
+                AND tsi.new_inventory = me.inventory
+            </if>
+            <if test="isDifference != null and isDifference == '2'">
+                AND tsi.new_inventory != 0
+                AND tsi.new_inventory != me.inventory
+            </if>
+        </where>
         ORDER BY
             tsi.oper_time DESC,
             tsi.id DESC
     </select>
 
-    <select id="pdaList" resultType="com.jsh.erp.datasource.pda.vo.PDATaskStocktakingItemVO">
+    <select id="creatorSpinnerList" resultType="com.jsh.erp.datasource.vo.SpinnerVO">
         SELECT
-            me.position AS position,
-            mc.`name` AS category_name,
-            m.`name` AS material_name,
-            m.standard AS standard,
-            u.username AS creator_name,
-            tsi.oper_time AS oper_time,
-            me.inventory AS inventory,
-            tsi.new_inventory AS new_inventory
+            tsi.creator AS value,
+            u.username AS label
         FROM
             task_stocktaking_item tsi
-                LEFT JOIN jsh_material_extend me ON tsi.material_item_id = me.id
-                LEFT JOIN jsh_material m ON me.material_id = m.id
-                LEFT JOIN jsh_material_category mc ON m.category_id = mc.id
-                LEFT JOIN jsh_user u ON u.id = tsi.creator
+            LEFT JOIN jsh_user u ON tsi.creator = u.id
         WHERE
             tsi.delete_flag = 0
-            AND tsi.task_stocktaking_id = #{taskId}
-        ORDER BY
-            tsi.oper_time DESC,
-            tsi.id DESC
+            AND tsi.creator IS NOT NULL
+            AND tsi.task_stocktaking_id = #{taskId};
     </select>
 
 </mapper>

+ 21 - 4
src/main/resources/mapper_xml/TaskStocktakingMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.jsh.erp.datasource.mappers.TaskStocktakingMapper">
 
-    <select id="pdaList" resultType="com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO">
+    <select id="pdaList" parameterType="com.jsh.erp.datasource.pda.dto.PDATaskStocktakingDTO" resultType="com.jsh.erp.datasource.pda.vo.PDATaskStocktakingVO">
         SELECT
             ts.id AS id,
             ts.task_name AS task_name,
@@ -37,7 +37,7 @@
         </where>
     </select>
 
-    <select id="listBy" resultType="com.jsh.erp.datasource.vo.TaskStocktakingVO">
+    <select id="listBy" parameterType="com.jsh.erp.datasource.dto.TaskStocktakingQueryDTO" resultType="com.jsh.erp.datasource.vo.TaskStocktakingVO">
         SELECT
             ts.id AS id,
             ts.number AS number,
@@ -45,19 +45,36 @@
             ts.task_type AS task_type,
             d.`name` AS depot_name,
             ts.position_range AS position_range,
-            ju.username AS create_name,
+            ju.username AS create_by_name,
             ts.create_time AS create_time,
             u.username AS creator_name,
             ts.task_status AS task_status,
-            ts.oper_time AS oper_time
+            ts.oper_time AS oper_time,
+            count(tsi.id) AS item_count,
+            count(tsi.id) AS material_count
         FROM
             task_stocktaking ts
                 LEFT JOIN jsh_depot d ON ts.depot_id = d.id
                 LEFT JOIN jsh_user ju ON ts.create_by = ju.id
                 LEFT JOIN jsh_user ou ON ts.oper_by = ou.id
                 LEFT JOIN jsh_user u ON ts.creator = u.id
+                LEFT JOIN task_stocktaking_item tsi ON ts.id = tsi.task_stocktaking_id
         <where>
             ts.delete_flag = 0
+            <if test="number != null and number != ''">
+                AND ts.number LIKE CONCAT('%',#{number},'%')
+            </if>
+            <if test="taskStatus != null and taskStatus != 0">
+                AND ts.task_status = #{taskStatus}
+            </if>
+            <if test="depotId != null and depotId !=''">
+                AND ts.depot_id = #{depotId}
+            </if>
+            <if test="createName != null and createName !=''">
+                AND ju.username LIKE CONCAT('%',#{createName},'%')
+            </if>
+        GROUP BY
+            ts.id
         ORDER BY
             ts.create_time DESC,
             ts.id DESC