|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 补充结果信息
|
|
|
*
|