Эх сурвалжийг харах

add: sop 设备发货管理

caozixuan 1 жил өмнө
parent
commit
7cb5c8ee6b

+ 17 - 36
sop-api/src/main/java/com/qmth/sop/server/api/TBDeviceDeliveryController.java

@@ -4,7 +4,6 @@ package com.qmth.sop.server.api;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
-import com.qmth.sop.business.bean.params.TBDeviceDeliveryParam;
 import com.qmth.sop.business.bean.result.ProjectExchangeResult;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.TBDeviceDelivery;
@@ -19,8 +18,8 @@ import com.qmth.sop.common.util.Result;
 import com.qmth.sop.common.util.ResultUtil;
 import com.qmth.sop.common.util.ServletUtil;
 import io.swagger.annotations.*;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -31,6 +30,7 @@ import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -51,20 +51,22 @@ public class TBDeviceDeliveryController {
     @ApiOperation(value = "设备发货列表分页查询")
     @RequestMapping(value = "/page", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = ProjectExchangeResult.class)})
-    public Result list(@ApiParam(value = "服务单元id") @RequestParam(required = false) Long serviceId,
+    public Result list(@ApiParam(value = "服务单元id") @RequestParam(required = false) String serviceId,
                        @ApiParam(value = "用途类型") @RequestParam(required = false) DeviceUsageTypeEnum usageType,
                        @ApiParam(value = "项目单号") @RequestParam(required = false) String crmNo,
                        @ApiParam(value = "发货状态") @RequestParam(required = false) DeviceDeliveryStatusEnum status,
-                       @ApiParam(value = "发货人id") @RequestParam(required = false) Long deliverUserId,
+                       @ApiParam(value = "发货人id") @RequestParam(required = false) String deliverUserId,
                        @ApiParam(value = "发货开始时间") @RequestParam(required = false) Long deliverStartTime,
                        @ApiParam(value = "发货结束时间") @RequestParam(required = false) Long deliverEndTime,
                        @ApiParam(value = "设备序列号") @RequestParam(required = false) String serialNo,
-                       @ApiParam(value = "供应商id") @RequestParam(required = false) Long supplierId,
+                       @ApiParam(value = "供应商id") @RequestParam(required = false) String supplierId,
                        @ApiParam(value = "签收开始时间") @RequestParam(required = false) Long receiveStartTime,
                        @ApiParam(value = "签收结束时间") @RequestParam(required = false) Long receiveEndTime,
                        @ApiParam(value = "页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                        @ApiParam(value = "页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) throws Exception {
-        return ResultUtil.ok(tbDeviceDeliveryService.page(new Page<>(pageNumber, pageSize), serviceId, usageType, crmNo, status, deliverUserId, deliverStartTime, deliverEndTime, serialNo, supplierId, receiveStartTime, receiveEndTime));
+        return ResultUtil.ok(tbDeviceDeliveryService.page(new Page<>(pageNumber, pageSize), SystemConstant.convertIdToLong(serviceId),
+                usageType, crmNo, status, SystemConstant.convertIdToLong(deliverUserId), deliverStartTime, deliverEndTime,
+                serialNo, SystemConstant.convertIdToLong(supplierId), receiveStartTime, receiveEndTime));
     }
 
     @ApiOperation(value = "设备发货保存接口")
@@ -80,12 +82,11 @@ public class TBDeviceDeliveryController {
         return ResultUtil.ok();
     }
 
-    @ApiOperation(value = "设备发货编辑接口")
-    @RequestMapping(value = "/edit", method = RequestMethod.POST)
+    @ApiOperation(value = "设备发货查询单个记录接口")
+    @RequestMapping(value = "/find/by/id", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = TBDeviceDelivery.class)})
-    @Transactional
-    public Result edit(@ApiParam(value = "设备发货id", required = true) @RequestParam Long id) throws Exception {
-        TBDeviceDelivery tbDeviceDelivery = tbDeviceDeliveryService.getById(id);
+    public Result edit(@ApiParam(value = "设备发货id", required = true) @RequestParam String id) throws Exception {
+        TBDeviceDelivery tbDeviceDelivery = tbDeviceDeliveryService.getById(SystemConstant.convertIdToLong(id));
         Optional.ofNullable(tbDeviceDelivery).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未找到设备发货信息"));
         return ResultUtil.ok(tbDeviceDelivery);
     }
@@ -95,33 +96,13 @@ public class TBDeviceDeliveryController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     @OperationLog(logType = LogTypeEnum.UPDATE)
     @Transactional
-    public Result statusUpdate(@ApiParam(value = "设备发货id", required = true) @RequestParam Long id,
+    public Result statusUpdate(@ApiParam(value = "设备发货id", required = true) @RequestParam List<String> idList,
                                @ApiParam(value = "设备发货状态", required = true) @RequestParam DeviceDeliveryStatusEnum status) {
-        TBDeviceDelivery tbDeviceDelivery = tbDeviceDeliveryService.getById(id);
-        Optional.ofNullable(tbDeviceDelivery).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未找到设备发货信息"));
-        tbDeviceDelivery.setStatus(status);
-        return ResultUtil.ok(tbDeviceDeliveryService.updateById(tbDeviceDelivery));
-    }
-
-    @ApiOperation(value = "设备发货状态批量修改接口")
-    @RequestMapping(value = "/status/batch/update", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
-    @OperationLog(logType = LogTypeEnum.UPDATE)
-    @Transactional
-    public Result statusBatchUpdate(@Valid @ApiParam(value = "设备发货修改信息", required = true) @RequestBody TBDeviceDeliveryParam tbDeviceDeliveryParam, BindingResult bindingResult) {
-        if (bindingResult.hasErrors()) {
-            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        if (CollectionUtils.isNotEmpty(idList)) {
+            tbDeviceDeliveryService.updateStatus(idList.stream().map(SystemConstant::convertIdToLong).collect(Collectors.toList()), status, requestUser.getId());
         }
-        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        List<TBDeviceDelivery> tbDeviceDeliveryList = tbDeviceDeliveryService.listByIds(tbDeviceDeliveryParam.getIds());
-        if (!CollectionUtils.isEmpty(tbDeviceDeliveryList)) {
-            for (TBDeviceDelivery t : tbDeviceDeliveryList) {
-                t.setStatus(tbDeviceDeliveryParam.getStatus());
-                t.updateInfo(sysUser.getId());
-            }
-            tbDeviceDeliveryService.updateBatchById(tbDeviceDeliveryList);
-        }
-        return ResultUtil.ok(true);
+        return ResultUtil.ok();
     }
 
     @ApiOperation(value = "设备发货导入")

BIN
sop-api/src/main/resources/static/delivery.xlsx


+ 9 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBDeviceDeliveryService.java

@@ -106,4 +106,13 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @param deviceInOutFormList 设备信息
      */
     void updateOutRecord(List<DeviceInOutForm> deviceInOutFormList);
+
+    /**
+     * 更新设备发货状态
+     *
+     * @param deviceDeliveryIdList 设备发货id集合
+     * @param status               状态
+     * @param requestUserId        请求人id
+     */
+    void updateStatus(List<Long> deviceDeliveryIdList, DeviceDeliveryStatusEnum status, Long requestUserId);
 }

+ 67 - 3
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDeviceDeliveryServiceImpl.java

@@ -62,6 +62,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     @Transactional
     @Override
     public void deviceDeliveryImport(MultipartFile file) throws IOException {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         InputStream inputStream = file.getInputStream();
         LinkedMultiValueMap<String, DeviceDeliveryImportDto> deviceDeliveryImportDtoLinkedMultiValueMap = new LinkedMultiValueMap<>();
 
@@ -136,7 +137,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                     sysDeviceService.save(willAddSysDevice);
                 }
 
-                // 查询是否有发货设备
+                // 查询是否有处于发货过程中设备
                 TBDeviceDelivery dbDeviceDelivery = this.getOne(new QueryWrapper<TBDeviceDelivery>()
                         .lambda()
                         .eq(TBDeviceDelivery::getSerialNo, serialNo)
@@ -144,7 +145,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                         .last(SystemConstant.LIMIT1));
 
                 if (Objects.nonNull(dbDeviceDelivery)) {
-                    throw ExceptionResultEnum.EXCEPTION_ERROR.exception(String.format("excel中存在已发货的设备(序列号)[%s]", serialNo));
+                    throw ExceptionResultEnum.EXCEPTION_ERROR.exception(String.format("excel中存在已发货过程中的设备(序列号)[%s]", serialNo));
                 }
 
                 TBDeviceDelivery tbDeviceDelivery = new TBDeviceDelivery();
@@ -164,6 +165,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                 tbDeviceDelivery.setEffect(true);
                 tbDeviceDelivery.setDeliveryType(InOutTypeEnum.OUT);
                 tbDeviceDelivery.setStatus(DeviceDeliveryStatusEnum.UN_DELIVER);
+                tbDeviceDelivery.setCreateId(requestUser.getId());
                 this.save(tbDeviceDelivery);
             }
         }
@@ -243,7 +245,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
             fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
             EasyExcel.write(fileTemp, TBDeviceDeliveryResult.class).sheet("设备发货管理列表").doWrite(datasource);
             HttpServletResponse response = ServletUtil.getResponse();
-            FileUtil.outputFile(response, fileTemp, "设备发货管理列表导出");
+            FileUtil.outputFile(response, fileTemp, "设备发货管理列表导出.xlsx");
         } finally {
             if (Objects.nonNull(fileTemp)) {
                 fileTemp.delete();
@@ -321,6 +323,68 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
         }
     }
 
+    @Transactional
+    @Override
+    public void updateStatus(List<Long> deviceDeliveryIdList, DeviceDeliveryStatusEnum status, Long requestUserId) {
+        if (CollectionUtils.isNotEmpty(deviceDeliveryIdList)) {
+            // 只有在生命周期的才能被操作
+            List<TBDeviceDelivery> tbDeviceDeliveryList = this.list(new QueryWrapper<TBDeviceDelivery>()
+                    .lambda()
+                    .in(TBDeviceDelivery::getId, deviceDeliveryIdList));
+
+            switch (status) {
+                case DELIVER:
+                    // 变更为已发货状态(供应商点击批量发货时触发 UN_DELIVER -> DELIVER(或sop入库新增记录触发))
+                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER, "发货"));
+                    }
+                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                        Long currenTime = System.currentTimeMillis();
+                        e.setDeliverUserId(requestUserId);
+                        e.setUpdateId(requestUserId);
+                        e.setDeliverTime(currenTime);
+                        e.setUpdateTime(currenTime);
+                        e.setStatus(DeviceDeliveryStatusEnum.DELIVER);
+                    }).collect(Collectors.toList());
+                    this.updateBatchById(tbDeviceDeliveryList);
+                    break;
+                case RECEIVE:
+                    // 变更为已签收状态(设备发货列表点击签收触发||sop现场测试签收 -> DELIVER -> RECEIVE)
+                    // 入库签收终止该入库记录的生命周期(出库签收不终止,设备发货出库生命周期的终止是在设备出库提交,生成设备发货入库记录时触发)
+                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.DELIVER, "签收"));
+                    }
+                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                        Long currenTime = System.currentTimeMillis();
+                        e.setReceiveUserId(requestUserId);
+                        e.setUpdateId(requestUserId);
+                        e.setReceiveTime(currenTime);
+                        e.setUpdateTime(currenTime);
+                        e.setStatus(DeviceDeliveryStatusEnum.RECEIVE);
+                        if (InOutTypeEnum.IN.equals(e.getDeliveryType())) {
+                            e.setEffect(false);
+                        }
+                    }).collect(Collectors.toList());
+                    this.updateBatchById(tbDeviceDeliveryList);
+                    break;
+                case CANCEL:
+                    // 变更为已作废状态(只有带发货状态能被作废)
+                    // 作废触发时该出库生命周期终止
+                    if (tbDeviceDeliveryList.stream().anyMatch(e -> !DeviceDeliveryStatusEnum.UN_DELIVER.equals(e.getStatus()) || !e.getEffect())) {
+                        throw ExceptionResultEnum.ERROR.exception(String.format("只有[出入库过程中]且[%s]的发货记录才能[%s]", DeviceDeliveryStatusEnum.UN_DELIVER, "作废"));
+                    }
+                    tbDeviceDeliveryList = tbDeviceDeliveryList.stream().peek(e -> {
+                        e.setUpdateId(requestUserId);
+                        e.setUpdateTime(System.currentTimeMillis());
+                        e.setStatus(DeviceDeliveryStatusEnum.CANCEL);
+                        e.setEffect(false);
+                    }).collect(Collectors.toList());
+                    this.updateBatchById(tbDeviceDeliveryList);
+                    break;
+            }
+        }
+    }
+
 
     /**
      * 补充结果信息

+ 19 - 0
sop-business/src/main/resources/db/log/caozixuan_update_log.sql

@@ -459,3 +459,22 @@ update t_b_device_in_out tbdio set device_no = (select serial_no from sys_device
 
 ALTER TABLE t_b_device_in_out
     CHANGE COLUMN device_no device_serial_no VARCHAR(50) CHARACTER SET 'utf8mb4' NULL DEFAULT NULL COMMENT '设备序列号';
+
+-- 2023-12-02
+DELETE FROM sys_privilege WHERE (id = '3067');
+UPDATE sys_privilege SET parent_id = '3053' WHERE (id = '3065');
+UPDATE sys_privilege SET parent_id = '3053' WHERE (id = '3066');
+UPDATE sys_privilege SET name = '设备发货保存接口' WHERE (id = '3065');
+UPDATE sys_privilege SET id = '3072' WHERE (id = '3068');
+INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3067', '设备发货列表分页查询', '/api/admin/device/delivery/page', 'URL', '3053', '3', 'AUTH', '1', '1', '0');
+INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3068', '设备发货查询单个记录接口', '/api/admin/device/delivery/find/by/id', 'URL', '3053', '4', 'AUTH', '1', '1', '0');
+INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3069', '设备发货导入', '/api/admin/device/delivery/import', 'URL', '3053', '5', 'AUTH', '1', '1', '0');
+INSERT INTO sys_privilege (id, name, url, type, parent_id, sequence, property, enable, default_auth, front_display) VALUES ('3070', '设备发货导出', '/api/admin/device/delivery/export', 'URL', '3053', '6', 'AUTH', '1', '1', '0');
+UPDATE sys_privilege SET related = '3067' WHERE (id = '3054');
+UPDATE sys_privilege SET related = '3067' WHERE (id = '3055');
+UPDATE sys_privilege SET related = '3069' WHERE (id = '3056');
+UPDATE sys_privilege SET related = '3070' WHERE (id = '3057');
+UPDATE sys_privilege SET related = '3066' WHERE (id = '3058');
+UPDATE sys_privilege SET related = '3066' WHERE (id = '3059');
+UPDATE sys_privilege SET related = '3066' WHERE (id = '3060');
+UPDATE sys_privilege SET related = '3065,3068' WHERE (id = '3061');

+ 3 - 1
sop-common/src/main/java/com/qmth/sop/common/enums/ImportTemplateEnum.java

@@ -13,7 +13,9 @@ public enum ImportTemplateEnum {
 
     TEMPLATE_CUSTOM("custom.xlsx", "客户导入模板.xlsx"),
 
-    TEMPLATE_DEVICE("device.xlsx", "设备导入模板.xlsx");
+    TEMPLATE_DEVICE("device.xlsx", "设备导入模板.xlsx"),
+
+    TEMPLATE_DELIVERY("delivery.xlsx", "设备发货导入模板.xlsx");
 
     ImportTemplateEnum(String templateName, String fileName) {
         this.templateName = templateName;