|
@@ -2,6 +2,7 @@ package com.fjhx.mes.service.production.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -109,13 +110,18 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
|
|
|
wrapper.isNotNull("po.produce_time");
|
|
|
//工序id过滤
|
|
|
wrapper.eq(ProductionScheduling::getProcessesId, dto.getProcessesId());
|
|
|
+ //任务Id过滤
|
|
|
+ wrapper.eq(ProductionScheduling::getTaskId, dto.getTaskId());
|
|
|
|
|
|
//权限过滤:生产排程-1
|
|
|
wrapper.in("po", ProductionOrder::getCompanyId, SecurityUtils.getCompanyIds());
|
|
|
wrapper.eq("po", ProductionOrder::getCompanyId, dto.getCompanyId());
|
|
|
|
|
|
- //排程日期过滤
|
|
|
- wrapper.eq("ps", ProductionScheduling::getSchedulingDate, DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd"));
|
|
|
+// //排程日期过滤
|
|
|
+// wrapper.eq("ps", ProductionScheduling::getSchedulingDate, DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd"));
|
|
|
+ //排程时间范围过滤
|
|
|
+ wrapper.ge("ps", ProductionScheduling::getSchedulingDate, dto.getBeginTime());
|
|
|
+ wrapper.le("ps", ProductionScheduling::getSchedulingDate, dto.getEndTime());
|
|
|
|
|
|
wrapper.orderByDesc("ps.scheduling_date");
|
|
|
|
|
@@ -137,6 +143,11 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<ProductionSchedulingVo> getList(IWrapper wrapper) {
|
|
|
+ return baseMapper.getList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Map<String, List<ProductionSchedulingVo>> listMap(ProductionSchedulingSelectDto dto) {
|
|
|
IWrapper<ProductionScheduling> wrapper = getWrapper();
|
|
|
//权限过滤:生产排程统计
|
|
@@ -156,24 +167,41 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
- public synchronized void add(List<ProductionScheduling> dtoList) {
|
|
|
- for (ProductionScheduling dto : dtoList) {
|
|
|
- dto.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
-
|
|
|
- //检查是否重复排程
|
|
|
- long count = this.count(q -> q
|
|
|
- .eq(ProductionScheduling::getTaskId, dto.getTaskId())
|
|
|
- .eq(ProductionScheduling::getProcessesId, dto.getProcessesId())
|
|
|
- .eq(ProductionScheduling::getSchedulingDate, dto.getSchedulingDate())
|
|
|
- );
|
|
|
- if (count > 0) {
|
|
|
- throw new ServiceException(DateUtil.format(dto.getSchedulingDate(), "yyyy-MM-dd") + "已有排程信息,请前往删除重新排程!");
|
|
|
- }
|
|
|
- this.save(dto);
|
|
|
+ public synchronized void add(ProductionScheduling dto) {
|
|
|
+ Assert.notEmpty(dto.getTaskId(), "任务id不能为空");
|
|
|
+ Assert.notEmpty(dto.getProcessesId(), "工序id不能为空");
|
|
|
+ Assert.notEmpty(dto.getSchedulingDate(), "排程日期不能为空");
|
|
|
+ Assert.notEmpty(dto.getQuantity(), "排程数量不能为空");
|
|
|
+
|
|
|
+
|
|
|
+ dto.setCompanyId(SecurityUtils.getCompanyId());
|
|
|
|
|
|
- //如果是第一道工序 创建生产领料待出库
|
|
|
- createProdStockWait(dto);
|
|
|
+ ProductionScheduling oldData = this.getOne(q -> q
|
|
|
+ .eq(ProductionScheduling::getTaskId, dto.getTaskId())
|
|
|
+ .eq(ProductionScheduling::getProcessesId, dto.getProcessesId())
|
|
|
+ .eq(ProductionScheduling::getSchedulingDate, dto.getSchedulingDate())
|
|
|
+ );
|
|
|
+ if (ObjectUtil.isNotEmpty(oldData)) {
|
|
|
+ dto.setId(oldData.getId());
|
|
|
+ }
|
|
|
+ //排程为0直接删除
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getId()) && dto.getQuantity() == 0) {
|
|
|
+ delete(dto.getId());
|
|
|
+ return;
|
|
|
}
|
|
|
+ this.saveOrUpdate(dto);
|
|
|
+
|
|
|
+ //排程数校验
|
|
|
+ ProductionOrderDetail taskById = produceOrderDetailService.getById(dto.getTaskId());
|
|
|
+ Assert.notEmpty(taskById, "查询不到排程信息");
|
|
|
+ List<ProductionScheduling> psList = this.list(q -> q.eq(ProductionScheduling::getTaskId, dto.getTaskId()).eq(ProductionScheduling::getProcessesId, dto.getProcessesId()));
|
|
|
+ BigDecimal reduce = BigDecimal.valueOf(psList.stream().map(ProductionScheduling::getQuantity).reduce(Integer::sum).orElse(0));
|
|
|
+ if (reduce.compareTo(taskById.getQuantity()) > 0) {
|
|
|
+ throw new ServiceException(StrUtil.format("排程总数量不能大于订单数量,排程总数量:{},订单数量:{}!", reduce, taskById.getQuantity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果是第一道工序 创建生产领料待出库
|
|
|
+ createProdStockWait(dto);
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
@@ -212,9 +240,6 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
|
|
|
item.setProductHeight(productInfo.getHeight());
|
|
|
item.setProductColor(productInfo.getColor());
|
|
|
});
|
|
|
-
|
|
|
- //赋值任务信息
|
|
|
-
|
|
|
return voList;
|
|
|
}
|
|
|
|
|
@@ -231,7 +256,6 @@ public class ProductionSchedulingServiceImpl extends ServiceImpl<ProductionSched
|
|
|
/**
|
|
|
* 根据排程创建生产待出库
|
|
|
*/
|
|
|
- @DSTransactional
|
|
|
private synchronized void createProdStockWait(ProductionScheduling dto) {
|
|
|
ProductionOrderDetail task = produceOrderDetailService.getById(dto.getTaskId());
|
|
|
Assert.notEmpty(task, "查询不到任务信息!");
|