Browse Source

设备管理

haogh 1 năm trước cách đây
mục cha
commit
d470c972bd

+ 13 - 3
sop-api/src/main/java/com/qmth/sop/server/api/DeviceDeliveryManageController.java

@@ -5,12 +5,13 @@ import com.qmth.sop.business.bean.params.DevicePlaceParam;
 import com.qmth.sop.business.bean.result.DevicePlaceResult;
 import com.qmth.sop.business.bean.result.DeviceSignResult;
 import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.business.entity.TBDeviceDelivery;
 import com.qmth.sop.business.service.TBDeviceDeliveryService;
 import com.qmth.sop.common.annotation.OperationLog;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.DeviceStatusEnum;
 import com.qmth.sop.common.enums.LogTypeEnum;
-import com.qmth.sop.common.enums.TransferModeEnum;
+import com.qmth.sop.common.enums.MailTypeEnum;
 import com.qmth.sop.common.util.Result;
 import com.qmth.sop.common.util.ResultUtil;
 import com.qmth.sop.common.util.ServletUtil;
@@ -62,6 +63,8 @@ public class DeviceDeliveryManageController {
     @OperationLog(logType = LogTypeEnum.UPDATE)
     public Result signEdit(@ApiParam(value = "设备发货id", required = true) @RequestParam String id,
                            @ApiParam(value = "设备状态", required = true) @RequestParam DeviceStatusEnum deviceStatus) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        tbDeviceDeliveryService.signEdit(id, deviceStatus, requestUser.getId());
         return ResultUtil.ok();
     }
 
@@ -69,7 +72,7 @@ public class DeviceDeliveryManageController {
     @RequestMapping(value = "/place/list", method = RequestMethod.POST)
     @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = DevicePlaceResult.class) })
     public Result placeList(@ApiParam(value = "派单号") @RequestParam String crmNo) {
-        return ResultUtil.ok();
+        return ResultUtil.ok(tbDeviceDeliveryService.placeList(crmNo));
     }
 
 
@@ -78,8 +81,11 @@ public class DeviceDeliveryManageController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     @OperationLog(logType = LogTypeEnum.UPDATE)
     public Result in(@ApiParam(value = "设备发货id", required = true) @RequestParam String id,
+                     @ApiParam(value = "入库方式", required = true) @RequestParam MailTypeEnum inMode,
                      @ApiParam(value = "快递单号:入库方式-选择邮寄不能为空", required = false) @RequestParam String expressNo,
                      @ApiParam(value = "备注:入库方式-选择其他的时候不能为空", required = false) @RequestParam String remark) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        tbDeviceDeliveryService.in(id, inMode, expressNo, remark, requestUser.getId());
         return ResultUtil.ok();
     }
 
@@ -88,10 +94,12 @@ public class DeviceDeliveryManageController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     @OperationLog(logType = LogTypeEnum.UPDATE)
     public Result transfer(@ApiParam(value = "设备发货id", required = true) @RequestParam String id,
-                           @ApiParam(value = "中转方式", required = true) @RequestParam TransferModeEnum transferMode,
+                           @ApiParam(value = "中转方式", required = true) @RequestParam MailTypeEnum transferMode,
                            @ApiParam(value = "快递单号", required = false) @RequestParam String expressNo,
                            @ApiParam(value = "接收方单号", required = true) @RequestParam String receiveCrmNo,
                            @ApiParam(value = "备注", required = false) @RequestParam String remark) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        tbDeviceDeliveryService.transfer(id, transferMode, expressNo, receiveCrmNo, remark, requestUser.getId());
         return ResultUtil.ok();
     }
 
@@ -100,6 +108,8 @@ public class DeviceDeliveryManageController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = Object.class)})
     @OperationLog(logType = LogTypeEnum.UPDATE)
     public Result placeEdit(@Valid @ApiParam(value = "设备去处编辑信息", required = true) @RequestBody DevicePlaceParam devicePlaceParam) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        tbDeviceDeliveryService.devicePlaceEdit(devicePlaceParam, requestUser.getId());
         return ResultUtil.ok();
     }
 

+ 4 - 4
sop-business/src/main/java/com/qmth/sop/business/bean/params/DevicePlaceParam.java

@@ -3,7 +3,7 @@ package com.qmth.sop.business.bean.params;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.sop.common.enums.DeviceUseStatusEnum;
-import com.qmth.sop.common.enums.TransferModeEnum;
+import com.qmth.sop.common.enums.MailTypeEnum;
 import io.swagger.annotations.ApiModelProperty;
 import org.hibernate.validator.constraints.Range;
 
@@ -26,7 +26,7 @@ public class DevicePlaceParam {
     private DeviceUseStatusEnum transferStatus;
 
     @ApiModelProperty("中转方式: MAIL-邮寄,OTHER-其他")
-    private TransferModeEnum transferMode;
+    private MailTypeEnum transferMode;
 
     @ApiModelProperty("快递单号")
     private String expressNo;
@@ -53,11 +53,11 @@ public class DevicePlaceParam {
         this.transferStatus = transferStatus;
     }
 
-    public TransferModeEnum getTransferMode() {
+    public MailTypeEnum getTransferMode() {
         return transferMode;
     }
 
-    public void setTransferMode(TransferModeEnum transferMode) {
+    public void setTransferMode(MailTypeEnum transferMode) {
         this.transferMode = transferMode;
     }
 

+ 28 - 17
sop-business/src/main/java/com/qmth/sop/business/bean/result/DevicePlaceResult.java

@@ -26,9 +26,6 @@ public class DevicePlaceResult implements Serializable {
     @ApiModelProperty("设备归属")
     private String supplierName;
 
-    @ApiModelProperty("设备归属")
-    private String remark;
-
     @ApiModelProperty("设备使用状态")
     private DeviceDeliveryStatusEnum status;
 
@@ -38,8 +35,14 @@ public class DevicePlaceResult implements Serializable {
     @ApiModelProperty("运输方式")
     private String transportMode;
 
-    @ApiModelProperty("是否可编辑,1:可编辑 0:不可编辑")
-    private Boolean canEdit;
+    @ApiModelProperty("是否被签收,针对设备使用状态为入库、中转")
+    private Boolean haveSign;
+
+    @ApiModelProperty("其他运输方式说明")
+    private String remark;
+
+    @ApiModelProperty("中转的快递单号")
+    private String transferExpressNo;
 
     public Long getId() {
         return id;
@@ -81,14 +84,6 @@ public class DevicePlaceResult implements Serializable {
         this.supplierName = supplierName;
     }
 
-    public String getRemark() {
-        return remark;
-    }
-
-    public void setRemark(String remark) {
-        this.remark = remark;
-    }
-
     public DeviceDeliveryStatusEnum getStatus() {
         return status;
     }
@@ -113,11 +108,27 @@ public class DevicePlaceResult implements Serializable {
         this.transportMode = transportMode;
     }
 
-    public Boolean getCanEdit() {
-        return canEdit;
+    public Boolean getHaveSign() {
+        return haveSign;
+    }
+
+    public void setHaveSign(Boolean haveSign) {
+        this.haveSign = haveSign;
+    }
+
+    public String getRemark() {
+        return remark;
+    }
+
+    public void setRemark(String remark) {
+        this.remark = remark;
+    }
+
+    public String getTransferExpressNo() {
+        return transferExpressNo;
     }
 
-    public void setCanEdit(Boolean canEdit) {
-        this.canEdit = canEdit;
+    public void setTransferExpressNo(String transferExpressNo) {
+        this.transferExpressNo = transferExpressNo;
     }
 }

+ 13 - 4
sop-business/src/main/java/com/qmth/sop/business/entity/TBDeviceDelivery.java

@@ -3,10 +3,7 @@ package com.qmth.sop.business.entity;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.qmth.sop.common.base.BaseEntity;
-import com.qmth.sop.common.enums.DeviceDeliveryStatusEnum;
-import com.qmth.sop.common.enums.DeviceStatusEnum;
-import com.qmth.sop.common.enums.DeviceUsageTypeEnum;
-import com.qmth.sop.common.enums.InOutTypeEnum;
+import com.qmth.sop.common.enums.*;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 
@@ -103,6 +100,9 @@ public class TBDeviceDelivery extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "其他的运输方式说明")
     private String remark;
 
+    @ApiModelProperty(value = "邮寄的方式")
+    private MailTypeEnum mailType;
+
     public String getExpressNo() {
         return expressNo;
     }
@@ -286,4 +286,13 @@ public class TBDeviceDelivery extends BaseEntity implements Serializable {
     public void setRemark(String remark) {
         this.remark = remark;
     }
+
+
+    public MailTypeEnum getMailType() {
+        return mailType;
+    }
+
+    public void setMailType(MailTypeEnum mailType) {
+        this.mailType = mailType;
+    }
 }

+ 13 - 1
sop-business/src/main/java/com/qmth/sop/business/mapper/TBDeviceDeliveryMapper.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.qmth.sop.business.bean.result.DevicePlaceResult;
 import com.qmth.sop.business.bean.result.DeviceSignResult;
 import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
 import com.qmth.sop.business.entity.TBDeviceDelivery;
@@ -91,5 +92,16 @@ public interface TBDeviceDeliveryMapper extends BaseMapper<TBDeviceDelivery> {
      * @param statusList  设备状态
      * @return 查询结果
      */
-    List<DeviceSignResult> listDeviceSign(@Param("crmNo") String crmNo, @Param("statusList") List<DeviceDeliveryStatusEnum> statusList);
+    List<DeviceSignResult> listDeviceSign(@Param("crmNo") String crmNo,
+            @Param("statusList") List<DeviceDeliveryStatusEnum> statusList);
+
+    /**
+     * 设备去处列表
+     *
+     * @param crmNo      派单号
+     * @param statusList 设备状态
+     * @return 查询结果
+     */
+    List<DevicePlaceResult> listDevicePlace(@Param("crmNo") String crmNo,
+            @Param("statusList") List<DeviceDeliveryStatusEnum> statusList, @Param("deliveryType") InOutTypeEnum deliveryType);
 }

+ 44 - 3
sop-business/src/main/java/com/qmth/sop/business/service/TBDeviceDeliveryService.java

@@ -4,14 +4,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
 import com.qmth.sop.business.bean.params.DeviceInOutForm;
+import com.qmth.sop.business.bean.params.DevicePlaceParam;
+import com.qmth.sop.business.bean.result.DevicePlaceResult;
 import com.qmth.sop.business.bean.result.DeviceSignResult;
 import com.qmth.sop.business.bean.result.FlowTaskResult;
 import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.TBDeviceDelivery;
-import com.qmth.sop.common.enums.DeviceDeliveryStatusEnum;
-import com.qmth.sop.common.enums.DeviceUsageTypeEnum;
-import com.qmth.sop.common.enums.InOutTypeEnum;
+import com.qmth.sop.common.enums.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.IOException;
@@ -209,4 +209,45 @@ public interface TBDeviceDeliveryService extends IService<TBDeviceDelivery> {
      * @param userId 操作用户ID
      */
     void unsigned(String id, Long userId);
+
+    /**
+     * @param  id 设备出库ID
+     * @param  deviceStatus 设备状态
+     * @param userId 操作用户ID
+     */
+    void signEdit(String id, DeviceStatusEnum deviceStatus, Long userId);
+
+    /**
+     * @param crmNo 派单号
+     * @return 设备去处登记列表
+     */
+    List<DevicePlaceResult> placeList(String crmNo);
+
+    /**
+     *
+     * @param id 设备出库ID
+     * @param inMode 入库方式
+     * @param expressNo 快递单号
+     * @param remark  备注
+     * @param userId 登录用户
+     */
+    void in(String id, MailTypeEnum inMode, String expressNo, String remark, Long userId);
+
+    /**
+     *
+     * @param id 设备出库ID
+     * @param transferMode 中转方式
+     * @param expressNo 快递单号
+     * @param receiveCrmNo 接收方单号
+     * @param remark 备注
+     * @param userId 登录用户
+     */
+    void transfer(String id, MailTypeEnum transferMode, String expressNo, String receiveCrmNo, String remark, Long userId);
+
+    /**
+     *
+     * @param devicePlaceParam 编辑参数
+     * @param userId 用户ID
+     */
+    void devicePlaceEdit(DevicePlaceParam devicePlaceParam, Long userId);
 }

+ 206 - 4
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBDeviceDeliveryServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,10 +14,8 @@ import com.qmth.sop.business.bean.dto.DeviceInfoDto;
 import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
 import com.qmth.sop.business.bean.params.DeviceInOutForm;
 import com.qmth.sop.business.bean.params.DeviceInOutSubmitParam;
-import com.qmth.sop.business.bean.result.DeviceSignResult;
-import com.qmth.sop.business.bean.result.FlowFormWidgetResult;
-import com.qmth.sop.business.bean.result.FlowTaskResult;
-import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
+import com.qmth.sop.business.bean.params.DevicePlaceParam;
+import com.qmth.sop.business.bean.result.*;
 import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.TBDeviceDeliveryMapper;
 import com.qmth.sop.business.service.*;
@@ -26,9 +25,11 @@ import com.qmth.sop.common.enums.*;
 import com.qmth.sop.common.util.FileUtil;
 import com.qmth.sop.common.util.GsonUtil;
 import com.qmth.sop.common.util.ServletUtil;
+import com.sun.org.apache.xpath.internal.operations.Bool;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedMultiValueMap;
@@ -737,6 +738,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     }
 
     @Override
+    @Transactional
     public void sign(String id, Long userId) {
         TBDeviceDelivery deviceDelivery = getById(id);
         if (Objects.isNull(deviceDelivery)) {
@@ -769,6 +771,7 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
     }
 
     @Override
+    @Transactional
     public void unsigned(String id, Long userId) {
         TBDeviceDelivery deviceDelivery = getById(id);
         if (Objects.isNull(deviceDelivery)) {
@@ -797,6 +800,205 @@ public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMap
                 .set(TBDeviceDelivery::getUpdateId, userId).set(TBDeviceDelivery::getUpdateTime, now));
     }
 
+    @Override
+    @Transactional
+    public void signEdit(String id, DeviceStatusEnum deviceStatus, Long userId) {
+        TBDeviceDelivery deviceDelivery = getById(id);
+        if (Objects.isNull(deviceDelivery)) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("设备发货记录不存在,ID:[%s]", id));
+        }
+        if (deviceDelivery.getDeviceStatus().equals(deviceStatus)) {
+            throw ExceptionResultEnum.ERROR.exception("未做改动");
+        }
+        //更新设备发货记录饿设备状态
+        this.update(new UpdateWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getId, id)
+                .set(TBDeviceDelivery::getDeviceStatus, deviceStatus).set(TBDeviceDelivery::getUpdateId, userId)
+                .set(TBDeviceDelivery::getUpdateTime, System.currentTimeMillis()));
+        SysDevice sysDevice = sysDeviceService.getOne(
+                new QueryWrapper<SysDevice>().lambda().eq(SysDevice::getSerialNo, deviceDelivery.getSerialNo())
+                        .last(SystemConstant.LIMIT1));
+        if (Objects.isNull(sysDevice)) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("serialNo:[%s]在设备配置表不存在", deviceDelivery.getSerialNo()));
+        }
+        //更新设备配置表的状态
+        LambdaUpdateWrapper<SysDevice> updateWrapper = new LambdaUpdateWrapper<SysDevice>().eq(SysDevice::getSerialNo,
+                        deviceDelivery.getSerialNo()).set(SysDevice::getStatus, deviceStatus).set(SysDevice::getUpdateId, userId)
+                .set(SysDevice::getUpdateTime, System.currentTimeMillis());
+        sysDeviceService.update(updateWrapper);
+    }
+
+    @Override
+    public List<DevicePlaceResult> placeList(String crmNo) {
+        List<DevicePlaceResult> devicePlaceResults = baseMapper.listDevicePlace(crmNo,
+                Arrays.asList(DeviceDeliveryStatusEnum.USING, DeviceDeliveryStatusEnum.TRANSFER, DeviceDeliveryStatusEnum.IN),
+                InOutTypeEnum.OUT);
+        for (DevicePlaceResult result : devicePlaceResults) {
+            result.setHaveSign(Boolean.FALSE);
+
+            //使用状态:入库
+            if (result.getStatus().equals(DeviceDeliveryStatusEnum.IN)) {
+
+                TBDeviceDelivery inDeviceDelivery = baseMapper.selectOne(
+                        new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getCrmNo, crmNo)
+                                .eq(TBDeviceDelivery::getSerialNo, result.getSerialNo())
+                                .eq(TBDeviceDelivery::getDeliveryType, InOutTypeEnum.IN));
+                if (Objects.isNull(inDeviceDelivery)) {
+                    throw ExceptionResultEnum.ERROR.exception(
+                            String.format("派单号crmNo:[%s],设备序列号serialNo:[%s]未有入库记录", crmNo, result.getSerialNo()));
+                }
+                result.setTransportMode(getTransportMode(inDeviceDelivery.getExpressNo(), inDeviceDelivery.getRemark()));
+                //设备是否已经被签收
+                result.setHaveSign(inDeviceDelivery.getStatus().equals(DeviceDeliveryStatusEnum.RECEIVE) ? Boolean.TRUE : Boolean.FALSE);
+            }
+
+            //使用状态:中转
+            if (result.getStatus().equals(DeviceDeliveryStatusEnum.TRANSFER)) {
+                TBDeviceDelivery transferDeviceDelivery = baseMapper.selectOne(
+                        new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getSourceId, result.getId()));
+                if (Objects.isNull(transferDeviceDelivery)) {
+                    throw ExceptionResultEnum.ERROR.exception(String.format("中转的设备找不到接收方,发货设备ID:[%s]", result.getId()));
+                }
+                result.setReceiveCrmNo(transferDeviceDelivery.getCrmNo());
+                result.setTransportMode(getTransportMode(result.getTransferExpressNo(), result.getRemark()));
+                //设备是否已经被签收
+                result.setHaveSign(result.getStatus().equals(DeviceDeliveryStatusEnum.TRANSFER_SIGN) ? Boolean.TRUE : Boolean.FALSE);
+            }
+
+        }
+        return devicePlaceResults;
+    }
+
+    @Override
+    @Transactional
+    public void in(String id, MailTypeEnum inMode, String expressNo, String remark, Long userId) {
+        checkInAndTransfer(inMode, expressNo, remark, InOutTypeEnum.IN);
+        TBDeviceDelivery deviceDelivery = getById(id);
+        if (Objects.isNull(deviceDelivery)) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("设备发货记录不存在,ID:[%s]", id));
+        }
+        TBDeviceDelivery existDeviceDelivery = baseMapper.selectOne(
+                new QueryWrapper<TBDeviceDelivery>().lambda().eq(TBDeviceDelivery::getCrmNo, deviceDelivery.getCrmNo())
+                        .eq(TBDeviceDelivery::getSerialNo, deviceDelivery.getSerialNo())
+                        .eq(TBDeviceDelivery::getDeliveryType, InOutTypeEnum.IN));
+        if (existDeviceDelivery != null) {
+            this.update(new UpdateWrapper<TBDeviceDelivery>().lambda().set(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.IN)
+                    .set(TBDeviceDelivery::getExpressNo, expressNo).set(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.IN)
+                    .set(TBDeviceDelivery::getDeliverTime, System.currentTimeMillis()).set(TBDeviceDelivery::getDeliverUserId, userId)
+                    .set(TBDeviceDelivery::getEffect, Boolean.FALSE).set(TBDeviceDelivery::getUpdateId, userId)
+                    .set(TBDeviceDelivery::getUpdateTime, System.currentTimeMillis())
+                    .set(TBDeviceDelivery::getDeviceStatus, deviceDelivery.getDeviceStatus()).set(TBDeviceDelivery::getRemark, remark)
+                    .eq(TBDeviceDelivery::getId, existDeviceDelivery.getId()));
+        } else {
+            //新建入库记录
+            TBDeviceDelivery inDeviceDelivery = new TBDeviceDelivery();
+            inDeviceDelivery.setCrmNo(deviceDelivery.getCrmNo());
+            inDeviceDelivery.setSerialNo(deviceDelivery.getSerialNo());
+            inDeviceDelivery.setUsageType(deviceDelivery.getUsageType());
+            inDeviceDelivery.setSupplierId(deviceDelivery.getSupplierId());
+            inDeviceDelivery.setExpressNo(expressNo);
+            inDeviceDelivery.setDeliveryType(InOutTypeEnum.IN);
+            inDeviceDelivery.setStatus(DeviceDeliveryStatusEnum.IN);
+            inDeviceDelivery.setDeliverTime(System.currentTimeMillis());
+            inDeviceDelivery.setDeliverUserId(userId);
+            inDeviceDelivery.setCreateTime(System.currentTimeMillis());
+            inDeviceDelivery.setCreateId(userId);
+            inDeviceDelivery.setEffect(Boolean.FALSE);
+            inDeviceDelivery.setDeviceStatus(deviceDelivery.getDeviceStatus());
+            inDeviceDelivery.setRemark(remark);
+            save(inDeviceDelivery);
+        }
+
+        //更改设备使用状态为入库
+        this.update(new UpdateWrapper<TBDeviceDelivery>().lambda().set(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.IN)
+                .set(TBDeviceDelivery::getMailType, inMode).set(TBDeviceDelivery::getRemark, remark)
+                .set(TBDeviceDelivery::getEffect, Boolean.FALSE).set(TBDeviceDelivery::getUpdateId, userId)
+                .set(TBDeviceDelivery::getUpdateTime, System.currentTimeMillis()).eq(TBDeviceDelivery::getId, id));
+    }
+
+    private void checkInAndTransfer(MailTypeEnum inMode, String expressNo, String remark, InOutTypeEnum inOutType) {
+        if (inMode == null) {
+            throw ExceptionResultEnum.ERROR.exception("请选择" + (inOutType.equals(InOutTypeEnum.IN) ? "入库" : "中转") + "方式");
+        }
+        if (inMode.equals(MailTypeEnum.MAIL) && StringUtils.isBlank(expressNo)) {
+            throw ExceptionResultEnum.ERROR.exception("快递单号不能为空");
+        }
+        if (inMode.equals(MailTypeEnum.OTHER) && StringUtils.isBlank(remark)) {
+            throw ExceptionResultEnum.ERROR.exception("备注不能为空");
+        }
+    }
+
+    @Override
+    @Transactional
+    public void transfer(String id, MailTypeEnum transferMode, String expressNo, String receiveCrmNo, String remark, Long userId) {
+        checkInAndTransfer(transferMode, expressNo, remark, InOutTypeEnum.OUT);
+        TBDeviceDelivery deviceDelivery = getById(id);
+        if (Objects.isNull(deviceDelivery)) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("设备发货记录不存在,ID:[%s]", id));
+        }
+        if (!deviceDelivery.getStatus().equals(DeviceDeliveryStatusEnum.USING)) {
+            throw ExceptionResultEnum.ERROR.exception("使用中的设备才能进行中转");
+        }
+        TBCrm crm = tbCrmService.getOne(
+                new QueryWrapper<TBCrm>().lambda().eq(TBCrm::getCrmNo, receiveCrmNo).eq(TBCrm::getEnable, Boolean.TRUE)
+                        .last(SystemConstant.LIMIT1));
+        if (Objects.isNull(crm)) {
+            throw ExceptionResultEnum.ERROR.exception(String.format("接受方单号[%s]不存在", receiveCrmNo));
+        }
+        //更新使用状态为中转
+        this.update(new UpdateWrapper<TBDeviceDelivery>().lambda().set(TBDeviceDelivery::getStatus, DeviceDeliveryStatusEnum.TRANSFER)
+                .set(TBDeviceDelivery::getEffect, Boolean.FALSE).set(TBDeviceDelivery::getRemark, remark)
+                .set(TBDeviceDelivery::getMailType, transferMode).set(TBDeviceDelivery::getUpdateId, userId)
+                .set(TBDeviceDelivery::getUpdateTime, System.currentTimeMillis()).eq(TBDeviceDelivery::getId, id));
+
+        //新增一条发货记录
+        TBDeviceDelivery newDeviceDelivery = new TBDeviceDelivery();
+        newDeviceDelivery.setCrmNo(receiveCrmNo);
+        newDeviceDelivery.setSerialNo(deviceDelivery.getSerialNo());
+        newDeviceDelivery.setUsageType(deviceDelivery.getUsageType());
+        newDeviceDelivery.setSupplierId(deviceDelivery.getSupplierId());
+        newDeviceDelivery.setExpressNo(expressNo);
+        newDeviceDelivery.setDeliveryType(InOutTypeEnum.OUT);
+        newDeviceDelivery.setStatus(DeviceDeliveryStatusEnum.DELIVER);
+        newDeviceDelivery.setDeliverTime(System.currentTimeMillis());
+        newDeviceDelivery.setDeliverUserId(userId);
+        newDeviceDelivery.setCreateTime(System.currentTimeMillis());
+        newDeviceDelivery.setCreateId(userId);
+        newDeviceDelivery.setEffect(Boolean.FALSE);
+        newDeviceDelivery.setDeviceStatus(deviceDelivery.getDeviceStatus());
+        newDeviceDelivery.setRemark(remark);
+        save(newDeviceDelivery);
+    }
+
+    @Override
+    @Transactional
+    public void devicePlaceEdit(DevicePlaceParam devicePlaceParam, Long userId) {
+        if (devicePlaceParam.getTransferStatus() == null) {
+            throw ExceptionResultEnum.ERROR.exception("请选择使用状态");
+        }
+        //TODO 业务需要考虑使用状态变更的情况
+        //使用状态为中转
+        if (devicePlaceParam.getTransferStatus().equals(DeviceUseStatusEnum.TRANSFER)) {
+            transfer(devicePlaceParam.getId().toString(), devicePlaceParam.getTransferMode(), devicePlaceParam.getExpressNo(),
+                    devicePlaceParam.getReceiveCrmNo(), devicePlaceParam.getRemark(), userId);
+        }
+
+        //使用状态为入库
+        if (devicePlaceParam.getTransferStatus().equals(DeviceUseStatusEnum.IN)) {
+            in(devicePlaceParam.getId().toString(), devicePlaceParam.getTransferMode(), devicePlaceParam.getExpressNo(),
+                    devicePlaceParam.getRemark(), userId);
+        }
+    }
+
+    private @NotNull String getTransportMode(String expressNo, String remark) {
+        String transportMode;
+        if (StringUtils.isNotEmpty(expressNo)) {
+            transportMode = MailTypeEnum.MAIL.getTitle() + "-" + expressNo;
+        } else {
+            transportMode = MailTypeEnum.OTHER.getTitle() + "-" + ((StringUtils.isEmpty(remark)) ? "" : remark);
+        }
+        return transportMode;
+    }
+
     /**
      * 补充结果信息
      *

+ 6 - 1
sop-business/src/main/resources/db/log/haoguanghui_update_log.sql

@@ -6,4 +6,9 @@ ALTER TABLE t_b_device_delivery
 
 -- 2024-05-16
 ALTER TABLE t_b_device_delivery
-    ADD COLUMN `remark` varchar(200) NULL COMMENT '其他的运输方式说明' AFTER `source_id`;
+    ADD COLUMN `remark` varchar(200) NULL COMMENT '其他的运输方式说明' AFTER `source_id`;
+
+-- 2024-05-17
+ALTER TABLE t_b_device_delivery
+    ADD COLUMN `mail_type` varchar(20) NULL COMMENT '邮寄方式:邮寄、其他' AFTER `remark`;
+

+ 27 - 0
sop-business/src/main/resources/mapper/TBDeviceDeliveryMapper.xml

@@ -215,4 +215,31 @@
         ORDER BY
             d.create_time DESC
     </select>
+
+    <select id="listDevicePlace" resultType="com.qmth.sop.business.bean.result.DevicePlaceResult">
+        SELECT
+            d.id,
+            d.serial_no serialNo,
+            sd.model,
+            sd.STATUS deviceStatus,
+            sp.NAME supplierName,
+            d.STATUS,
+            d.remark,
+            d.transfer_express_no transferExpressNo
+        FROM
+            t_b_device_delivery d,
+            sys_device sd,
+            sys_supplier sp
+        WHERE
+            d.serial_no = sd.serial_no
+          AND d.supplier_id = sp.id
+          AND d.crm_no = #{crmNo}
+          AND d.delivery_type=#{deliveryType}
+          AND d.status in
+        <foreach collection="statusList" item="status" open="(" separator="," close=")">
+            #{status}
+        </foreach>
+        ORDER BY
+           d.create_time DESC
+    </select>
 </mapper>

+ 3 - 3
sop-common/src/main/java/com/qmth/sop/common/enums/TransferModeEnum.java → sop-common/src/main/java/com/qmth/sop/common/enums/MailTypeEnum.java

@@ -1,11 +1,11 @@
 package com.qmth.sop.common.enums;
 
 /**
- * @Description: 中转方式
+ * @Description: 邮寄方式
  * @Author: haoguanghui
  * @Date: 2024/5/16
  */
-public enum TransferModeEnum {
+public enum MailTypeEnum {
 
     MAIL("邮寄"),
 
@@ -13,7 +13,7 @@ public enum TransferModeEnum {
 
     private String title;
 
-    TransferModeEnum(String title) {
+    MailTypeEnum(String title) {
         this.title = title;
     }