|
@@ -1,16 +1,19 @@
|
|
|
package com.fjhx.service.water.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
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.constants.StatusConstant;
|
|
|
import com.fjhx.entity.water.WaterBatch;
|
|
|
-import com.fjhx.params.water.WaterBatchVo;
|
|
|
import com.fjhx.mapper.water.WaterBatchMapper;
|
|
|
+import com.fjhx.params.water.WaterBatchVo;
|
|
|
import com.fjhx.service.water.WaterBatchService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.utils.Assert;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -25,30 +28,105 @@ import java.util.Map;
|
|
|
public class WaterBatchServiceImpl extends ServiceImpl<WaterBatchMapper, WaterBatch> implements WaterBatchService {
|
|
|
|
|
|
@Override
|
|
|
- public Page<WaterBatch> getPage(Map<String, String> condition) {
|
|
|
+ public Map<String, Object> getDetailsByContract(Long contractId) {
|
|
|
+ Map<String, Object> result = baseMapper.getMaterialInfo(contractId);
|
|
|
+
|
|
|
+ Assert.notEmpty(result, "没有找到合同信息");
|
|
|
+
|
|
|
+ List<WaterBatch> list = list(WaterBatch::getContractId, contractId);
|
|
|
|
|
|
- QueryWrapper<WaterBatch> wrapper = Wrappers.query();
|
|
|
+ // 二维码个数
|
|
|
+ int tagTotal = 0;
|
|
|
+ // 生成总数量
|
|
|
+ BigDecimal quantityTotal = BigDecimal.ZERO;
|
|
|
+ // 已发货
|
|
|
+ BigDecimal shipped = BigDecimal.ZERO;
|
|
|
+ // 未发货
|
|
|
+ BigDecimal unshipped = BigDecimal.ZERO;
|
|
|
|
|
|
- WrapperUtil.init(condition, wrapper)
|
|
|
- .createTimeDesc();
|
|
|
+ for (WaterBatch waterBatch : list) {
|
|
|
+ tagTotal += waterBatch.getTagCount();
|
|
|
|
|
|
- Page<WaterBatch> page = page(condition, wrapper);
|
|
|
- return page;
|
|
|
+ BigDecimal tagQuantitySum = waterBatch.getTagQuantitySum();
|
|
|
+ quantityTotal = quantityTotal.add(tagQuantitySum);
|
|
|
+
|
|
|
+ if (StatusConstant.YES.equals(waterBatch.getShipmentStatus())) {
|
|
|
+ shipped = shipped.add(tagQuantitySum);
|
|
|
+ } else {
|
|
|
+ unshipped = unshipped.add(tagQuantitySum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 出货金额
|
|
|
+ BigDecimal amountMoney = shipped.multiply(Convert.toBigDecimal(result.get("price")));
|
|
|
+
|
|
|
+ result.put("tagTotal", tagTotal);
|
|
|
+ result.put("quantityTotal", quantityTotal);
|
|
|
+ result.put("shipped", shipped);
|
|
|
+ result.put("unshipped", unshipped);
|
|
|
+ result.put("amountMoney", amountMoney);
|
|
|
+ result.put("list", list);
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void add(WaterBatchVo waterBatchVo) {
|
|
|
+ public synchronized void add(WaterBatchVo waterBatchVo) {
|
|
|
+ String contractCode = waterBatchVo.getContractCode();
|
|
|
+ String code = getCode(contractCode);
|
|
|
+ waterBatchVo.setCode(code);
|
|
|
+
|
|
|
+ waterBatchVo.setTagCount(0);
|
|
|
+ waterBatchVo.setTagQuantitySum(BigDecimal.ZERO);
|
|
|
+ waterBatchVo.setShipmentStatus(StatusConstant.NO);
|
|
|
+
|
|
|
save(waterBatchVo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void edit(WaterBatchVo waterBatchVo) {
|
|
|
- updateById(waterBatchVo);
|
|
|
+ public void delete(WaterBatchVo waterBatchVo) {
|
|
|
+ Long id = waterBatchVo.getId();
|
|
|
+ WaterBatch waterBatch = getById(id);
|
|
|
+ Integer tagCount = waterBatch.getTagCount();
|
|
|
+ Assert.eqZero(tagCount, "存在标签的批次不允许删除");
|
|
|
+
|
|
|
+ removeById(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void delete(WaterBatchVo waterBatchVo) {
|
|
|
- removeById(waterBatchVo.getId());
|
|
|
+ public void shipment(WaterBatch waterBatch) {
|
|
|
+ Assert.notEmpty(waterBatch.getId(), "批次id不能为空");
|
|
|
+ Assert.notEmpty(waterBatch.getShipmentWay(), "出货方式不能为空");
|
|
|
+
|
|
|
+ waterBatch.setShipmentStatus(StatusConstant.YES);
|
|
|
+ waterBatch.setShipmentTime(new Date());
|
|
|
+ updateById(waterBatch);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getCode(String contractCode) {
|
|
|
+
|
|
|
+ Assert.notEmpty(contractCode, "合同编码不能为空");
|
|
|
+
|
|
|
+ String codePrefix = contractCode + "-";
|
|
|
+
|
|
|
+ WaterBatch waterBatch = getOne(Wrappers.<WaterBatch>lambdaQuery()
|
|
|
+ .likeRight(WaterBatch::getCode, codePrefix)
|
|
|
+ .orderByDesc(WaterBatch::getCode)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+
|
|
|
+ if (waterBatch == null) {
|
|
|
+ return codePrefix + "001";
|
|
|
+ }
|
|
|
+
|
|
|
+ int codeSuffix = Convert.toInt(waterBatch.getCode().replace(codePrefix, "")) + 1;
|
|
|
+
|
|
|
+ if (codeSuffix < 10) {
|
|
|
+ return codePrefix + "00" + codeSuffix;
|
|
|
+ } else if (codeSuffix < 100) {
|
|
|
+ return codePrefix + "0" + codeSuffix;
|
|
|
+ }
|
|
|
+ return codePrefix + codeSuffix;
|
|
|
}
|
|
|
|
|
|
}
|