|
@@ -1,19 +1,34 @@
|
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.qmth.sop.business.bean.result.TBDeviceDeliveryResult;
|
|
|
-import com.qmth.sop.business.entity.SysUser;
|
|
|
+import com.qmth.sop.business.bean.dto.DeviceDeliveryImportDto;
|
|
|
+import com.qmth.sop.business.bean.dto.DeviceInfoDto;
|
|
|
+import com.qmth.sop.business.bean.params.DeviceDeliveryParam;
|
|
|
+import com.qmth.sop.business.entity.SysDevice;
|
|
|
+import com.qmth.sop.business.entity.SysSupplier;
|
|
|
import com.qmth.sop.business.entity.TBDeviceDelivery;
|
|
|
import com.qmth.sop.business.mapper.TBDeviceDeliveryMapper;
|
|
|
+import com.qmth.sop.business.service.SysDeviceModelService;
|
|
|
+import com.qmth.sop.business.service.SysDeviceService;
|
|
|
+import com.qmth.sop.business.service.SysSupplierService;
|
|
|
import com.qmth.sop.business.service.TBDeviceDeliveryService;
|
|
|
-import com.qmth.sop.common.enums.DeviceDeliveryStatusEnum;
|
|
|
-import com.qmth.sop.common.enums.DeviceUsageTypeEnum;
|
|
|
-import com.qmth.sop.common.util.ServletUtil;
|
|
|
+import com.qmth.sop.business.util.excel.BasicExcelListener;
|
|
|
+import com.qmth.sop.common.contant.SystemConstant;
|
|
|
+import com.qmth.sop.common.enums.*;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -25,27 +40,135 @@ import java.util.Objects;
|
|
|
*/
|
|
|
@Service
|
|
|
public class TBDeviceDeliveryServiceImpl extends ServiceImpl<TBDeviceDeliveryMapper, TBDeviceDelivery> implements TBDeviceDeliveryService {
|
|
|
+ @Resource
|
|
|
+ private SysDeviceService sysDeviceService;
|
|
|
+ @Resource
|
|
|
+ private SysDeviceModelService sysDeviceModelService;
|
|
|
+ @Resource
|
|
|
+ private SysSupplierService sysSupplierService;
|
|
|
|
|
|
- /**
|
|
|
- * 设备发货管理列表
|
|
|
- *
|
|
|
- * @param iPage
|
|
|
- * @param serviceId
|
|
|
- * @param usageType
|
|
|
- * @param crmNo
|
|
|
- * @param status
|
|
|
- * @param deliverUserId
|
|
|
- * @param crmStartTime
|
|
|
- * @param crmEndTime
|
|
|
- * @param serialNo
|
|
|
- * @param supplierId
|
|
|
- * @param receiveStartTime
|
|
|
- * @param receiveEndTime
|
|
|
- * @return
|
|
|
- */
|
|
|
+ @Transactional
|
|
|
@Override
|
|
|
- public IPage<TBDeviceDeliveryResult> list(IPage<Map> iPage, Long serviceId, DeviceUsageTypeEnum usageType, String crmNo, DeviceDeliveryStatusEnum status, Long deliverUserId, Long crmStartTime, Long crmEndTime, String serialNo, Long supplierId, Long receiveStartTime, Long receiveEndTime) {
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- return this.baseMapper.list(iPage, serviceId, Objects.nonNull(usageType) ? usageType.name() : null, crmNo, Objects.nonNull(status) ? status.name() : null, deliverUserId, crmStartTime, crmEndTime, serialNo, supplierId, receiveStartTime, receiveEndTime, sysUser.getId());
|
|
|
+ public void deviceDeliveryImport(MultipartFile file) throws IOException {
|
|
|
+ InputStream inputStream = file.getInputStream();
|
|
|
+ LinkedMultiValueMap<String, DeviceDeliveryImportDto> deviceDeliveryImportDtoLinkedMultiValueMap = new LinkedMultiValueMap<>();
|
|
|
+
|
|
|
+ StringJoiner errorData = new StringJoiner("");
|
|
|
+ EasyExcel.read(inputStream, DeviceDeliveryImportDto.class, new BasicExcelListener<DeviceDeliveryImportDto>() {
|
|
|
+ @Override
|
|
|
+ public void handle(LinkedMultiValueMap<String, DeviceDeliveryImportDto> dataList, StringJoiner errorDataSj, Exception exception) {
|
|
|
+ deviceDeliveryImportDtoLinkedMultiValueMap.addAll(dataList);
|
|
|
+ errorData.add(errorDataSj.toString());
|
|
|
+ }
|
|
|
+ }).headRowNumber(2).sheet(0).doRead();
|
|
|
+
|
|
|
+ List<DeviceDeliveryImportDto> deviceDeliveryImportDtoList = deviceDeliveryImportDtoLinkedMultiValueMap.get(BasicExcelListener.SUCCESS);
|
|
|
+ if (CollectionUtils.isNotEmpty(deviceDeliveryImportDtoList)) {
|
|
|
+ List<SysSupplier> sysSupplierList = sysSupplierService.list(new QueryWrapper<SysSupplier>().lambda().eq(SysSupplier::getType, SupplierTypeEnum.DEVICE));
|
|
|
+ // 供应商map
|
|
|
+ Map<String, Long> supplierMap = sysSupplierList.stream().collect(Collectors.toMap(SysSupplier::getName, SysSupplier::getId));
|
|
|
+
|
|
|
+ // serialNo - obj
|
|
|
+ Map<String, DeviceInfoDto> deviceMap = new HashMap<>();
|
|
|
+ for (DeviceDeliveryImportDto deviceDeliveryImportDto : deviceDeliveryImportDtoList) {
|
|
|
+ String serialNo = deviceDeliveryImportDto.getSerialNo();
|
|
|
+ String deviceNo = deviceDeliveryImportDto.getDeviceNo();
|
|
|
+ // 品牌
|
|
|
+ String brand = deviceDeliveryImportDto.getBrand();
|
|
|
+ // 型号
|
|
|
+ String model = deviceDeliveryImportDto.getModel();
|
|
|
+ if (deviceMap.containsKey(serialNo)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("excel中存在重复的设备序列号[%s]", serialNo));
|
|
|
+ } else {
|
|
|
+ DeviceInfoDto deviceInfo = new DeviceInfoDto();
|
|
|
+ deviceInfo.setSerialNo(serialNo);
|
|
|
+ deviceInfo.setDeviceNo(deviceNo);
|
|
|
+ deviceInfo.setBrand(brand);
|
|
|
+ deviceInfo.setModel(model);
|
|
|
+ deviceMap.put(serialNo, deviceInfo);
|
|
|
+ }
|
|
|
+ String crmNo = deviceDeliveryImportDto.getCrmNo();
|
|
|
+
|
|
|
+ String supplierName = deviceDeliveryImportDto.getSupplierName();
|
|
|
+ Long supplierId = supplierMap.get(supplierName);
|
|
|
+ if (supplierId == null || supplierId == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("excel中存在系统中不存在的供应商名称[%s]", supplierName));
|
|
|
+ }
|
|
|
+
|
|
|
+ String mailingAddress = deviceDeliveryImportDto.getMailingAddress();
|
|
|
+ String consignee = deviceDeliveryImportDto.getConsignee();
|
|
|
+ String consigneePhone = deviceDeliveryImportDto.getConsigneePhone();
|
|
|
+ String expressNo = deviceDeliveryImportDto.getExpressNo();
|
|
|
+
|
|
|
+ // 查询设备表是否有该设备
|
|
|
+ SysDevice sysDevice = sysDeviceService.getOne(new QueryWrapper<SysDevice>()
|
|
|
+ .lambda()
|
|
|
+ .eq(SysDevice::getSerialNo, serialNo)
|
|
|
+ .last(SystemConstant.LIMIT1));
|
|
|
+
|
|
|
+ if (Objects.isNull(sysDevice)) {
|
|
|
+ // 设备表不存在该设备 -> 新增设备
|
|
|
+ sysDeviceModelService.findOrAddDeviceModel(brand, model);
|
|
|
+
|
|
|
+ SysDevice willAddSysDevice = new SysDevice();
|
|
|
+ willAddSysDevice.setDeviceCode(deviceNo);
|
|
|
+ willAddSysDevice.setSerialNo(serialNo);
|
|
|
+ willAddSysDevice.setBrand(brand);
|
|
|
+ willAddSysDevice.setModel(model);
|
|
|
+ willAddSysDevice.setBuyTime(System.currentTimeMillis());
|
|
|
+ willAddSysDevice.setSupplierId(supplierId);
|
|
|
+ willAddSysDevice.setStatus(DeviceStatusEnum.NORMAL);
|
|
|
+ willAddSysDevice.setLocation(supplierName);
|
|
|
+ willAddSysDevice.setBound(InOutTypeEnum.IN);
|
|
|
+ willAddSysDevice.setEnable(true);
|
|
|
+ sysDeviceService.save(willAddSysDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询是否有发货设备
|
|
|
+ TBDeviceDelivery dbDeviceDelivery = this.getOne(new QueryWrapper<TBDeviceDelivery>()
|
|
|
+ .lambda()
|
|
|
+ .eq(TBDeviceDelivery::getSerialNo, serialNo)
|
|
|
+ .eq(TBDeviceDelivery::getEffect, true)
|
|
|
+ .last(SystemConstant.LIMIT1));
|
|
|
+
|
|
|
+ if (Objects.nonNull(dbDeviceDelivery)) {
|
|
|
+ throw ExceptionResultEnum.EXCEPTION_ERROR.exception(String.format("excel中存在已发货的设备(序列号)[%s]", serialNo));
|
|
|
+ }
|
|
|
+
|
|
|
+ TBDeviceDelivery tbDeviceDelivery = new TBDeviceDelivery();
|
|
|
+ if (crmNo != null && crmNo.length() > 0) {
|
|
|
+ tbDeviceDelivery.setCrmNo(crmNo);
|
|
|
+ tbDeviceDelivery.setUsageType(DeviceUsageTypeEnum.PROJECT);
|
|
|
+ } else {
|
|
|
+ tbDeviceDelivery.setUsageType(DeviceUsageTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ tbDeviceDelivery.setSerialNo(serialNo);
|
|
|
+ tbDeviceDelivery.setSupplierId(supplierId);
|
|
|
+ tbDeviceDelivery.setMailingAddress(mailingAddress);
|
|
|
+ tbDeviceDelivery.setConsignee(consignee);
|
|
|
+ tbDeviceDelivery.setConsigneePhone(consigneePhone);
|
|
|
+ tbDeviceDelivery.setExpressNo(expressNo);
|
|
|
+ tbDeviceDelivery.setEnable(true);
|
|
|
+ tbDeviceDelivery.setEffect(true);
|
|
|
+ this.save(tbDeviceDelivery);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void editDeviceDelivery(DeviceDeliveryParam deviceDeliveryParam) {
|
|
|
+ Long id = deviceDeliveryParam.getId();
|
|
|
+ String mailingAddress = deviceDeliveryParam.getMailingAddress();
|
|
|
+ String consignee = deviceDeliveryParam.getConsignee();
|
|
|
+ String consigneePhone = deviceDeliveryParam.getConsigneePhone();
|
|
|
+ String expressNo = deviceDeliveryParam.getExpressNo();
|
|
|
+
|
|
|
+ this.update(new UpdateWrapper<TBDeviceDelivery>().lambda()
|
|
|
+ .eq(TBDeviceDelivery::getId, id)
|
|
|
+ .set(TBDeviceDelivery::getMailingAddress, mailingAddress)
|
|
|
+ .set(TBDeviceDelivery::getConsignee, consignee)
|
|
|
+ .set(TBDeviceDelivery::getConsigneePhone, consigneePhone)
|
|
|
+ .set(TBDeviceDelivery::getExpressNo, expressNo));
|
|
|
}
|
|
|
}
|