|
@@ -1,17 +1,35 @@
|
|
|
package com.fjhx.service.water.impl;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.fjhx.utils.WrapperUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.base.Condition;
|
|
|
+import com.fjhx.base.StorageBaseEntity;
|
|
|
+import com.fjhx.constants.StatusConstant;
|
|
|
+import com.fjhx.entity.water.WaterBatch;
|
|
|
import com.fjhx.entity.water.WaterTag;
|
|
|
-import com.fjhx.params.water.WaterTagVo;
|
|
|
+import com.fjhx.enums.CheckStateEnum;
|
|
|
+import com.fjhx.enums.PurchaseProgressEnum;
|
|
|
import com.fjhx.mapper.water.WaterTagMapper;
|
|
|
+import com.fjhx.params.water.WaterTagVo;
|
|
|
+import com.fjhx.service.water.WaterBatchService;
|
|
|
import com.fjhx.service.water.WaterTagService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springblade.core.log.exception.ServiceException;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -24,31 +42,226 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class WaterTagServiceImpl extends ServiceImpl<WaterTagMapper, WaterTag> implements WaterTagService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private WaterBatchService waterBatchService;
|
|
|
+
|
|
|
@Override
|
|
|
- public Page<WaterTag> getPage(Map<String, String> condition) {
|
|
|
+ public Page<Map<String, Object>> getPage(Condition condition) {
|
|
|
|
|
|
- QueryWrapper<WaterTag> wrapper = Wrappers.query();
|
|
|
+ Long waterBatchId = condition.getLong("waterBatchId");
|
|
|
|
|
|
- WrapperUtil.init(condition, wrapper)
|
|
|
- .createTimeDesc();
|
|
|
+ QueryWrapper<WaterTag> wrapper = Wrappers.<WaterTag>query()
|
|
|
+ .eq(waterBatchId != null, "wt.water_batch_id", waterBatchId);
|
|
|
|
|
|
- Page<WaterTag> page = page(condition, wrapper);
|
|
|
- return page;
|
|
|
+ return baseMapper.getPage(condition.getPage(), wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void add(WaterTagVo waterTagVo) {
|
|
|
- save(waterTagVo);
|
|
|
+ public synchronized void add(WaterTagVo waterTagVo) {
|
|
|
+ BigDecimal quantity = waterTagVo.getQuantity();
|
|
|
+ Assert.notEmpty(quantity, "物料长度不能为空");
|
|
|
+
|
|
|
+ Long waterBatchId = waterTagVo.getWaterBatchId();
|
|
|
+ Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
+
|
|
|
+ // 标签数量
|
|
|
+ int num = waterTagVo.getNum() == null || waterTagVo.getNum() < 1 ? 1 : waterTagVo.getNum();
|
|
|
+
|
|
|
+ WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
+
|
|
|
+ List<WaterTag> waterTagList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (waterTag != null) {
|
|
|
+ Integer number = waterTag.getNumber();
|
|
|
+
|
|
|
+ for (int integer = 0; integer < num; integer++) {
|
|
|
+ number++;
|
|
|
+ WaterTag waterTagTemp = createWaterTag(waterTag.getMaterialId(), quantity, waterTag.getPrice(),
|
|
|
+ waterTag.getWaterBatchId(), waterTag.getWaterBatchCode(), number);
|
|
|
+ waterTagList.add(waterTagTemp);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
+ for (int i = 1; i <= num; i++) {
|
|
|
+ WaterTag waterTagTemp = createWaterTag(waterBatch.getMaterialId(), quantity, waterBatch.getPrice(),
|
|
|
+ waterBatch.getId(), waterBatch.getCode(), i);
|
|
|
+
|
|
|
+ waterTagList.add(waterTagTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveBatch(waterTagList);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void edit(WaterTagVo waterTagVo) {
|
|
|
- updateById(waterTagVo);
|
|
|
+ public void printer(List<Long> tagIdList) {
|
|
|
+ update(Wrappers.<WaterTag>lambdaUpdate()
|
|
|
+ .in(StorageBaseEntity::getId, tagIdList)
|
|
|
+ .set(WaterTag::getHadPrinter, StatusConstant.YES)
|
|
|
+ .set(StorageBaseEntity::getUpdateTime, new Date())
|
|
|
+ .set(StorageBaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void delete(WaterTagVo waterTagVo) {
|
|
|
- removeById(waterTagVo.getId());
|
|
|
+ public void bindingRfid(Long id, String rfidCode) {
|
|
|
+ update(Wrappers.<WaterTag>lambdaUpdate()
|
|
|
+ .eq(StorageBaseEntity::getId, id)
|
|
|
+ .set(WaterTag::getRfidCode, rfidCode)
|
|
|
+ .set(WaterTag::getLabelUserId, AuthUtil.getUserId())
|
|
|
+ .set(StorageBaseEntity::getUpdateTime, new Date())
|
|
|
+ .set(StorageBaseEntity::getUpdateUser, AuthUtil.getUserId())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void uploadTag(MultipartFile file, Long waterBatchId) {
|
|
|
+
|
|
|
+ Assert.notEmpty(waterBatchId, "批次id不能为空");
|
|
|
+
|
|
|
+ List<BigDecimal> quantityList = getQuantityListByExcel(file);
|
|
|
+
|
|
|
+ Assert.gtZero(quantityList.size(), "导入标签数量为空");
|
|
|
+
|
|
|
+ WaterTag waterTag = getNewestWaterTag(waterBatchId);
|
|
|
+
|
|
|
+ List<WaterTag> waterTagList = new ArrayList<>();
|
|
|
+
|
|
|
+ if (waterTag != null) {
|
|
|
+ Integer number = waterTag.getNumber();
|
|
|
+
|
|
|
+ for (BigDecimal quantity : quantityList) {
|
|
|
+ number++;
|
|
|
+ WaterTag waterTagTemp = createWaterTag(waterTag.getMaterialId(), quantity, waterTag.getPrice(),
|
|
|
+ waterTag.getWaterBatchId(), waterTag.getWaterBatchCode(), number);
|
|
|
+ waterTagList.add(waterTagTemp);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ WaterBatch waterBatch = waterBatchService.getById(waterBatchId);
|
|
|
+ for (int i = 1; i <= quantityList.size(); i++) {
|
|
|
+ WaterTag waterTagTemp = createWaterTag(waterBatch.getMaterialId(), quantityList.get(i), waterBatch.getPrice(),
|
|
|
+ waterBatch.getId(), waterBatch.getCode(), i);
|
|
|
+
|
|
|
+ waterTagList.add(waterTagTemp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ saveBatch(waterTagList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析文件中的数据
|
|
|
+ */
|
|
|
+ private List<BigDecimal> getQuantityListByExcel(MultipartFile file) {
|
|
|
+
|
|
|
+ List<BigDecimal> quantityList = new ArrayList<>();
|
|
|
+ InputStream inputStream = null;
|
|
|
+ Workbook workbook = null;
|
|
|
+ try {
|
|
|
+
|
|
|
+ inputStream = file.getInputStream();
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+ assert filename != null;
|
|
|
+
|
|
|
+ // 判断excel的后缀,不同的后缀用不同的对象去解析
|
|
|
+ if (filename.endsWith(".xls")) {
|
|
|
+ workbook = new XSSFWorkbook(inputStream);
|
|
|
+ }
|
|
|
+ // xlsx是高版本的Excel文件
|
|
|
+ if (filename.endsWith(".xlsx")) {
|
|
|
+ workbook = new XSSFWorkbook(inputStream);
|
|
|
+ }
|
|
|
+ if (workbook == null) {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取到excel 中的第一张工作表
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ if (sheet == null) {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 行
|
|
|
+ List<Integer> lineList = Arrays.asList(12, 15, 18, 21, 24, 27, 30, 33, 36, 39);
|
|
|
+
|
|
|
+ // 列
|
|
|
+ List<Integer> columnList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
|
|
|
+
|
|
|
+ for (Integer line : lineList) {
|
|
|
+
|
|
|
+ // 获取到这一行的数据
|
|
|
+ Row row = sheet.getRow(line);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 循环列
|
|
|
+ for (Integer column : columnList) {
|
|
|
+ Cell cell = row.getCell(column);
|
|
|
+ if (cell != null) {
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
+ BigDecimal bigDecimal = Convert.toBigDecimal(cell.getStringCellValue().trim());
|
|
|
+ if (bigDecimal != null && bigDecimal.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ // 获取数量
|
|
|
+ quantityList.add(bigDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new ServiceException("excel表格读取失败");
|
|
|
+ } finally {
|
|
|
+ // 关闭io流
|
|
|
+ IoUtil.close(inputStream);
|
|
|
+ IoUtil.close(workbook);
|
|
|
+ }
|
|
|
+
|
|
|
+ return quantityList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建标签
|
|
|
+ *
|
|
|
+ * @param materialId 物料id
|
|
|
+ * @param quantity 数量
|
|
|
+ * @param price 单价
|
|
|
+ * @param waterBatchId 批次id
|
|
|
+ * @param waterBatchCodee 批次编码
|
|
|
+ * @param number 二维码编码
|
|
|
+ */
|
|
|
+ private WaterTag createWaterTag(Long materialId, BigDecimal quantity, BigDecimal price,
|
|
|
+ Long waterBatchId, String waterBatchCodee, Integer number) {
|
|
|
+ WaterTag waterTagTemp = new WaterTag();
|
|
|
+ waterTagTemp.setMaterialId(materialId);
|
|
|
+ waterTagTemp.setQuantity(quantity);
|
|
|
+ waterTagTemp.setPrice(price);
|
|
|
+ waterTagTemp.setQrCode(UUID.fastUUID().toString());
|
|
|
+ waterTagTemp.setWaterBatchId(waterBatchId);
|
|
|
+ waterTagTemp.setWaterBatchCode(waterBatchCodee);
|
|
|
+ waterTagTemp.setNumber(number);
|
|
|
+ waterTagTemp.setHadPrinter(StatusConstant.NO);
|
|
|
+ waterTagTemp.setHadShipment(StatusConstant.NO);
|
|
|
+ waterTagTemp.setPurchaseProgress(PurchaseProgressEnum.CODING.getType());
|
|
|
+ waterTagTemp.setCheckState(CheckStateEnum.NO_QUALITY_INSPECTION.getType());
|
|
|
+ waterTagTemp.setInHouse(StatusConstant.NO);
|
|
|
+ return waterTagTemp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最新添加标签
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private WaterTag getNewestWaterTag(Long waterBatchId) {
|
|
|
+ return getOne(Wrappers.<WaterTag>lambdaQuery()
|
|
|
+ .eq(WaterTag::getWaterBatchId, waterBatchId)
|
|
|
+ .orderByDesc(WaterTag::getNumber)
|
|
|
+ .last("limit 1"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|