package com.qianwen.smartman.modules.coproduction.service.impl;
|
|
import cn.hutool.core.util.StrUtil;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.google.common.collect.Lists;
|
import java.lang.invoke.SerializedLambda;
|
import java.math.BigDecimal;
|
import java.math.RoundingMode;
|
import java.util.ArrayList;
|
import java.util.Collection;
|
import java.util.Date;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.constant.CommonConstant;
|
import com.qianwen.smartman.common.constant.ExcelConstant;
|
import com.qianwen.smartman.common.utils.MessageUtils;
|
import com.qianwen.core.log.exception.ServiceException;
|
import com.qianwen.core.mp.base.BaseServiceImpl;
|
import com.qianwen.core.oss.model.BladeFile;
|
import com.qianwen.core.tool.utils.DateUtil;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.modules.coproduction.convert.OrderConvert;
|
import com.qianwen.smartman.modules.coproduction.dto.PlanAndOrderDTO;
|
import com.qianwen.smartman.modules.coproduction.entity.Order;
|
import com.qianwen.smartman.modules.coproduction.entity.OrderProcess;
|
import com.qianwen.smartman.modules.coproduction.entity.OrderReportRecord;
|
import com.qianwen.smartman.modules.coproduction.entity.Plan;
|
import com.qianwen.smartman.modules.coproduction.enums.CoProductionEnum;
|
import com.qianwen.smartman.modules.coproduction.enums.OrderStatusEnum;
|
import com.qianwen.smartman.modules.coproduction.enums.PlanStatusEnum;
|
import com.qianwen.smartman.modules.coproduction.mapper.OrderMapper;
|
import com.qianwen.smartman.modules.coproduction.service.IOrderProcessService;
|
import com.qianwen.smartman.modules.coproduction.service.IOrderReportRecordService;
|
import com.qianwen.smartman.modules.coproduction.service.IOrderService;
|
import com.qianwen.smartman.modules.coproduction.service.IOrderWorkstationService;
|
import com.qianwen.smartman.modules.coproduction.service.IPlanService;
|
import com.qianwen.smartman.modules.coproduction.vo.OrderAndProcessInfoVO;
|
import com.qianwen.smartman.modules.coproduction.vo.OrderAssignVO;
|
import com.qianwen.smartman.modules.coproduction.vo.OrderProcessDetailVO;
|
import com.qianwen.smartman.modules.coproduction.vo.OrderQueryVO;
|
import com.qianwen.smartman.modules.coproduction.vo.OrderVO;
|
import com.qianwen.smartman.modules.cps.entity.Workstation;
|
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
|
import com.qianwen.smartman.modules.mdc.utils.ExcelStrategyUtil;
|
import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder;
|
import com.qianwen.smartman.modules.system.constant.FieldConstant;
|
import com.qianwen.smartman.modules.system.service.ICodeGeneratorService;
|
import com.qianwen.smartman.modules.tpm.enums.MetaTypeEnum;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.multipart.MultipartFile;
|
|
@Service
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/coproduction/service/impl/OrderServiceImpl.class */
|
public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implements IOrderService {
|
@Autowired
|
@Lazy
|
private IPlanService planService;
|
@Autowired
|
private ICodeGeneratorService codeGeneratorService;
|
@Autowired
|
@Lazy
|
private IOrderProcessService orderProcessService;
|
@Autowired
|
private IOrderWorkstationService orderWorkstationService;
|
@Autowired
|
private IWorkstationService workstationService;
|
@Autowired
|
@Lazy
|
private IOrderReportRecordService reportRecordService;
|
@Autowired
|
private OssBuilder ossBuilder;
|
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public List<OrderVO> list(OrderQueryVO orderQueryVO) {
|
return this.baseMapper.list(orderQueryVO);
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
@Transactional(rollbackFor = {Exception.class})
|
public Boolean remove(List<Long> ids, Long planId) {
|
|
long count = count(Wrappers.<Order>lambdaQuery().in(Order::getId, ids).ne(Order::getOrderStatus, OrderStatusEnum.NOT_STARTED.getCode()));
|
if (count > 0L)
|
throw new ServiceException(MessageUtils.message("production.order.can.not.delete", new Object[0]));
|
List<Order> orderList = listByIds(ids);
|
removeBatchByIds(ids);
|
int allAssignNum = orderList.stream().mapToInt(Order::getAssignNum).sum();
|
Plan plan = (Plan)this.planService.getById(planId);
|
plan.setUnassignedNum(Integer.valueOf(allAssignNum + plan.getUnassignedNum().intValue()));
|
if (plan.getPlanNum().equals(plan.getUnassignedNum())) {
|
plan.setPlanStatus(PlanStatusEnum.WAIT_PUBLISH.getCode());
|
}
|
return Boolean.valueOf(this.planService.updateById(plan));
|
/*
|
long count = count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getId();
|
}, ids)).ne((v0) -> {
|
return v0.getOrderStatus();
|
}, OrderStatusEnum.NOT_STARTED.getCode()));
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("production.order.can.not.delete", new Object[0]));
|
}
|
List<Order> orderList = listByIds(ids);
|
removeBatchByIds(ids);
|
int allAssignNum = orderList.stream().mapToInt((v0) -> {
|
return v0.getAssignNum();
|
}).sum();
|
Plan plan = (Plan) this.planService.getById(planId);
|
plan.setUnassignedNum(Integer.valueOf(allAssignNum + plan.getUnassignedNum().intValue()));
|
if (plan.getPlanNum().equals(plan.getUnassignedNum())) {
|
plan.setPlanStatus(PlanStatusEnum.WAIT_PUBLISH.getCode());
|
}
|
return Boolean.valueOf(this.planService.updateById(plan));
|
*/
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
@Transactional(rollbackFor = {Exception.class})
|
public OrderVO assign(OrderAssignVO orderAssignVO) {
|
Plan plan = (Plan) this.planService.getById(orderAssignVO.getPlanId());
|
assignCheck(plan, orderAssignVO);
|
Order order = generateOrder(orderAssignVO);
|
List<OrderProcess> orderProcessList = this.orderProcessService.generateOrderProcess(orderAssignVO, order);
|
this.orderWorkstationService.generateOrderWorkstation(orderProcessList);
|
updatePlan(plan, orderAssignVO.getAssignNum());
|
return OrderConvert.INSTANCE.convert(order);
|
}
|
|
private void updatePlan(Plan plan, Integer assignNum) {
|
if (PlanStatusEnum.WAIT_PUBLISH.getCode().equals(plan.getPlanStatus())) {
|
plan.setPlanStatus(PlanStatusEnum.WAIT_MACHINE.getCode());
|
}
|
plan.setUnassignedNum(Integer.valueOf(plan.getUnassignedNum().intValue() - assignNum.intValue()));
|
this.planService.updateById(plan);
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
@Transactional(rollbackFor = {Exception.class})
|
public void reportOrder(Integer orderQualifyNum, Integer orderScrappedNum, Order order, Boolean isDel) {
|
Integer oldQualifyNum = order.getQualifyNum();
|
Integer oldScrappedNum = order.getScrappedNum();
|
Long orderId = order.getId();
|
Integer newQualifyNum = Integer.valueOf(orderQualifyNum.intValue() + oldQualifyNum.intValue());
|
Integer newScrappedNum = Integer.valueOf(orderScrappedNum.intValue() + oldScrappedNum.intValue());
|
Integer assignNum = order.getAssignNum();
|
Integer reportNum = Integer.valueOf(newQualifyNum.intValue() + newScrappedNum.intValue());
|
if (assignNum.intValue() < reportNum.intValue()) {
|
throw new ServiceException(MessageUtils.message("production.report.fail.order.report.num.not.exceed.assign.num", new Object[0]));
|
}
|
order.setQualifyNum(newQualifyNum);
|
order.setScrappedNum(newScrappedNum);
|
|
LambdaUpdateWrapper<Order> orderLambdaUpdateWrapper = Wrappers.<Order>lambdaUpdate().eq(Order::getId, order.getId());
|
|
boolean isOrderCompleted = false;
|
if (assignNum.equals(reportNum)) {
|
isOrderCompleted = true;
|
}
|
if (isOrderCompleted) {
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getOrderStatus();
|
}, CoProductionEnum.OrderStatus.COMPLETED.getCode());
|
Date endTime = null;
|
OrderReportRecord latestRecord = this.reportRecordService.getLatestRecord(null, orderId, null);
|
if (latestRecord != null) {
|
endTime = latestRecord.getWorkshopTime();
|
}
|
if (endTime == null) {
|
endTime = DateUtil.now();
|
}
|
order.setEndTime(endTime);
|
}
|
if (assignNum.intValue() > reportNum.intValue() && CoProductionEnum.OrderStatus.COMPLETED.getCode().equals(order.getOrderStatus())) {
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getOrderStatus();
|
}, CoProductionEnum.OrderStatus.PROCESSING.getCode());
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getEndTime();
|
}, (Object) null);
|
}
|
if (isDel.booleanValue()) {
|
updateOrderStartTime(order, orderLambdaUpdateWrapper);
|
}
|
update(order, orderLambdaUpdateWrapper);
|
}
|
|
private void updateOrderStartTime(Order currentOrder, LambdaUpdateWrapper<Order> orderLambdaUpdateWrapper) {
|
Date startTime = null;
|
OrderReportRecord earliestRecord = this.reportRecordService.getEarliestRecord(null, currentOrder.getId(), null, null);
|
if (earliestRecord != null) {
|
startTime = earliestRecord.getStartTime();
|
}
|
if (startTime == null) {
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getStartTime();
|
}, (Object) null);
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getOrderStatus();
|
}, CoProductionEnum.OrderStatus.TOBE_START.getCode());
|
}
|
if (!currentOrder.getStartTime().equals(startTime)) {
|
orderLambdaUpdateWrapper.set((v0) -> {
|
return v0.getStartTime();
|
}, startTime);
|
}
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public void updateOrderByStart(Order order, Date startTime) {
|
if (OrderStatusEnum.NOT_STARTED.getCode().equals(order.getOrderStatus())) {
|
order.setOrderStatus(OrderStatusEnum.IN_EXECUTION.getCode());
|
if (Func.isEmpty(order.getStartTime())) {
|
order.setStartTime(startTime);
|
}
|
updateById(order);
|
}
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public PlanAndOrderDTO getPlanAndOrderByOrderId(Long orderId) {
|
Order order = (Order) getById(orderId);
|
if (order == null) {
|
throw new ServiceException(MessageUtils.message("cps.coproduction.order.is.not.exist", new Object[0]));
|
}
|
Plan plan = (Plan) this.planService.getById(order.getPlanId());
|
if (plan == null) {
|
throw new ServiceException(MessageUtils.message("cps.coproduction.plan.is.not.exist", new Object[0]));
|
}
|
PlanAndOrderDTO planAndOrderDTO = new PlanAndOrderDTO();
|
planAndOrderDTO.setPlan(plan);
|
planAndOrderDTO.setOrder(order);
|
return planAndOrderDTO;
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public List<OrderVO> planOrderList(OrderQueryVO orderQueryVO) {
|
QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("plan_id", orderQueryVO.getPlanId());
|
if (Func.isNotEmpty(orderQueryVO.getSortName()) && Func.isNotEmpty(orderQueryVO.getOrder())) {
|
queryWrapper.orderBy(Boolean.TRUE.booleanValue(), orderQueryVO.getOrder().equals(FieldConstant.ASC), StrUtil.toUnderlineCase(orderQueryVO.getSortName()));
|
} else {
|
queryWrapper.orderBy(Boolean.TRUE.booleanValue(), Boolean.TRUE.booleanValue(), "order_code");
|
}
|
List<Order> orderList = list(queryWrapper);
|
List<OrderVO> orderVOList = OrderConvert.INSTANCE.convert(orderList);
|
List<OrderProcess> orderProcessList = this.orderProcessService.list(Wrappers.<OrderProcess>lambdaQuery()
|
.in(OrderProcess::getOrderId, orderVOList.stream().map(OrderVO::getId).collect(Collectors.toList()))
|
.orderByAsc(OrderProcess::getSort));
|
/*
|
List<OrderProcess> orderProcessList = this.orderProcessService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getOrderId();
|
}, (Collection) orderVOList.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList()))).orderByAsc((v0) -> {
|
return v0.getSort();
|
}));*/
|
|
Map<Long, List<OrderProcess>> orderProcessMap = orderProcessList.stream().collect(Collectors.groupingBy(OrderProcess::getOrderId));
|
/*
|
Map<Long, List<OrderProcess>> orderProcessMap = (Map) orderProcessList.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getOrderId();
|
}));*/
|
orderVOList.forEach(orderVO -> {
|
List<OrderProcess> orderProcesses = orderProcessMap.get(orderVO.getId());
|
if (Func.isNotEmpty(orderProcesses)) {
|
String reportSituation = (String) orderProcesses.stream().map(orderProcess -> {
|
return String.valueOf(orderProcess.getQualifyNum().intValue() + orderProcess.getScrappedNum().intValue());
|
}).collect(Collectors.joining("/"));
|
orderVO.setReportSituation(reportSituation);
|
}
|
});
|
return orderVOList;
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public OrderAndProcessInfoVO getOrderAndProcessList(Long orderId) {
|
OrderAndProcessInfoVO result = new OrderAndProcessInfoVO();
|
Order order = (Order) getById(orderId);
|
if (Func.isNotEmpty(order)) {
|
result.setAssignNum(order.getAssignNum());
|
result.setOrderCode(order.getOrderCode());
|
|
result.setOrderProcessList(this.orderProcessService.list(Wrappers.<OrderProcess>lambdaQuery().eq(OrderProcess::getOrderId, orderId)));
|
/*
|
result.setOrderProcessList(this.orderProcessService.list((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getOrderId();
|
}, orderId)));*/
|
}
|
return result;
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
@Transactional(rollbackFor = {Exception.class})
|
public Order reportOrderData(Order order) {
|
List<OrderProcess> mainProcess = (List) order.getOrderProcessList().stream().filter(s -> {
|
return Func.isEmpty(s.getMainSequenceId());
|
}).collect(Collectors.toList());
|
Integer scrappedNumSum = (Integer) mainProcess.stream().map((v0) -> {
|
return v0.getScrappedNum();
|
}).reduce(0, (v0, v1) -> {
|
return Integer.sum(v0, v1);
|
});
|
Integer assignNum = order.getAssignNum();
|
Integer reportNum = Integer.valueOf(order.getQualifyNum().intValue() + scrappedNumSum.intValue());
|
if (assignNum.intValue() < reportNum.intValue()) {
|
throw new ServiceException(MessageUtils.message("production.report.fail.order.report.num.not.exceed.assign.num", new Object[0]));
|
}
|
order.setQualifyNum(order.getQualifyNum());
|
order.setScrappedNum(scrappedNumSum);
|
boolean isOrderCompleted = false;
|
if (assignNum.equals(reportNum)) {
|
isOrderCompleted = true;
|
}
|
if (isOrderCompleted) {
|
order.setOrderStatus(CoProductionEnum.OrderStatus.COMPLETED.getCode());
|
Date endTime = null;
|
OrderReportRecord latestRecord = this.reportRecordService.getLatestRecord(null, order.getId(), null);
|
if (latestRecord != null) {
|
endTime = latestRecord.getWorkshopTime();
|
}
|
if (endTime == null) {
|
endTime = DateUtil.now();
|
}
|
order.setEndTime(endTime);
|
}
|
if (!isOrderCompleted) {
|
order.setOrderStatus(CoProductionEnum.OrderStatus.PROCESSING.getCode());
|
order.setEndTime(null);
|
}
|
return order;
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
@Transactional(rollbackFor = {Exception.class})
|
public Order delReportOrderData(Order order, List<Long> removeRecordIds) {
|
List<OrderProcess> mainProcess = (List) order.getOrderProcessList().stream().filter(s -> {
|
return Func.isEmpty(s.getMainSequenceId());
|
}).collect(Collectors.toList());
|
Integer scrappedNumSum = (Integer) mainProcess.stream().map((v0) -> {
|
return v0.getScrappedNum();
|
}).reduce(0, (v0, v1) -> {
|
return Integer.sum(v0, v1);
|
});
|
Integer delNum = Integer.valueOf(order.getDelOrderNum() == null ? 0 : order.getDelOrderNum().intValue());
|
Integer assignNum = order.getAssignNum();
|
Integer reportNum = Integer.valueOf(order.getQualifyNum().intValue() + scrappedNumSum.intValue() + delNum.intValue());
|
if (assignNum.intValue() < reportNum.intValue()) {
|
throw new ServiceException(MessageUtils.message("production.report.fail.order.report.num.not.exceed.assign.num", new Object[0]));
|
}
|
order.setQualifyNum(Integer.valueOf(order.getQualifyNum().intValue() + delNum.intValue()));
|
order.setScrappedNum(scrappedNumSum);
|
boolean isOrderCompleted = false;
|
if (assignNum.equals(reportNum)) {
|
isOrderCompleted = true;
|
}
|
delOrderStartTime(order, removeRecordIds);
|
if (!isOrderCompleted && order.getStartTime() != null) {
|
order.setOrderStatus(CoProductionEnum.OrderStatus.PROCESSING.getCode());
|
order.setEndTime(null);
|
}
|
if (order.getStartTime() == null) {
|
order.setEndTime(null);
|
}
|
return order;
|
}
|
|
private void delOrderStartTime(Order currentOrder, List<Long> removeRecordIds) {
|
Date startTime = null;
|
OrderReportRecord earliestRecord = this.reportRecordService.getEarliestRecord(null, currentOrder.getId(), null, removeRecordIds);
|
if (earliestRecord != null) {
|
startTime = earliestRecord.getStartTime();
|
}
|
if (startTime == null) {
|
currentOrder.setStartTime(null);
|
currentOrder.setOrderStatus(CoProductionEnum.OrderStatus.TOBE_START.getCode());
|
}
|
Date currentOrderStartTime = currentOrder.getStartTime();
|
if (startTime != null && currentOrderStartTime != null && !currentOrderStartTime.equals(startTime)) {
|
currentOrder.setStartTime(startTime);
|
}
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public BladeFile export(Long orderId) {
|
try {
|
List<List<String>> orderHead = buildOrderHead();
|
List<List<String>> processHead = buildProcessHead();
|
List<List<Object>> orderData = new ArrayList<>();
|
List<List<Object>> processData = new ArrayList<>();
|
if (Func.isNotEmpty(orderId)) {
|
OrderVO orderVO = list(new OrderQueryVO().setOrderId(orderId)).get(0);
|
List<OrderProcessDetailVO> orderProcessDetailVOList = this.orderProcessService.listDetailByOrderId(orderId);
|
orderData = buildOrderData(Lists.newArrayList(new OrderVO[]{orderVO}));
|
processData = buildProcessData(orderProcessDetailVOList);
|
}
|
String fileName = String.format("%s-%s.xlsx", ExcelConstant.ORDER, DateUtil.time());
|
MultipartFile multipartFile = ExcelStrategyUtil.customerTwoHeadExport(fileName, ExcelConstant.ORDER, orderHead, processHead, orderData, processData);
|
return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
} catch (Exception ex) {
|
throw new RuntimeException(ex);
|
}
|
}
|
|
@Override // org.springblade.modules.coproduction.service.IOrderService
|
public BladeFile exportList(OrderQueryVO orderQueryVO) {
|
List<OrderVO> orderVOList = list(orderQueryVO);
|
List<List<String>> head = buildOrderHead();
|
List<List<Object>> data = buildOrderData(orderVOList);
|
String fileName = String.format("%s-%s.xlsx", ExcelConstant.ORDER, DateUtil.time());
|
MultipartFile multipartFile;
|
try {
|
multipartFile = ExcelStrategyUtil.customerExport(fileName, ExcelConstant.ORDER, head, data);
|
} catch (Exception e) {
|
log.error("导出列表错误",e);
|
e.printStackTrace();
|
throw new RuntimeException(e);
|
}
|
return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile);
|
}
|
|
private List<List<String>> buildOrderHead() {
|
List<List<String>> orderHead = new ArrayList<>();
|
orderHead.add(Lists.newArrayList(new String[]{"工单编号"}));
|
orderHead.add(Lists.newArrayList(new String[]{"本次派发数量"}));
|
orderHead.add(Lists.newArrayList(new String[]{"合格数"}));
|
orderHead.add(Lists.newArrayList(new String[]{"报废数"}));
|
orderHead.add(Lists.newArrayList(new String[]{"待加工数量"}));
|
orderHead.add(Lists.newArrayList(new String[]{"计划开始时间"}));
|
orderHead.add(Lists.newArrayList(new String[]{"计划结束时间"}));
|
orderHead.add(Lists.newArrayList(new String[]{"状态"}));
|
return orderHead;
|
}
|
|
private List<List<String>> buildProcessHead() {
|
List<List<String>> processHead = new ArrayList<>();
|
processHead.add(Lists.newArrayList(new String[]{"工序编号"}));
|
processHead.add(Lists.newArrayList(new String[]{"工序名称"}));
|
processHead.add(Lists.newArrayList(new String[]{"工序顺序"}));
|
processHead.add(Lists.newArrayList(new String[]{"报工数量"}));
|
processHead.add(Lists.newArrayList(new String[]{"合格数量"}));
|
processHead.add(Lists.newArrayList(new String[]{"报废数量"}));
|
processHead.add(Lists.newArrayList(new String[]{"合格率"}));
|
processHead.add(Lists.newArrayList(new String[]{"开工时间"}));
|
processHead.add(Lists.newArrayList(new String[]{"报工时间"}));
|
processHead.add(Lists.newArrayList(new String[]{"指派工位"}));
|
processHead.add(Lists.newArrayList(new String[]{"加工人员"}));
|
return processHead;
|
}
|
|
private List<List<Object>> buildOrderData(List<OrderVO> orderVOList) {
|
List<List<Object>> orderData = new ArrayList<>();
|
orderVOList.forEach(orderVO -> {
|
ArrayList arrayList = new ArrayList();
|
arrayList.add(orderVO.getOrderCode());
|
arrayList.add(orderVO.getAssignNum());
|
arrayList.add(orderVO.getQualifyNum());
|
arrayList.add(orderVO.getScrappedNum());
|
arrayList.add(Integer.valueOf((orderVO.getAssignNum().intValue() - orderVO.getQualifyNum().intValue()) - orderVO.getScrappedNum().intValue()));
|
arrayList.add(Func.isNotEmpty(orderVO.getPlanStartTime()) ? DateUtil.format(orderVO.getPlanStartTime(), "yyyy/MM/dd") : null);
|
arrayList.add(Func.isNotEmpty(orderVO.getPlanEndTime()) ? DateUtil.format(orderVO.getPlanEndTime(), "yyyy/MM/dd") : null);
|
arrayList.add(orderVO.getOrderStatusStr());
|
orderData.add(arrayList);
|
});
|
return orderData;
|
}
|
|
private List<List<Object>> buildProcessData(List<OrderProcessDetailVO> orderProcessDetailVOList) {
|
List<List<Object>> processData = new ArrayList<>();
|
orderProcessDetailVOList.forEach(o -> {
|
ArrayList arrayList = new ArrayList();
|
arrayList.add(o.getProcessCode());
|
arrayList.add(o.getProcessName());
|
arrayList.add(o.getSort());
|
int reportNum = o.getQualifyNum().intValue() + o.getScrappedNum().intValue();
|
arrayList.add(Integer.valueOf(reportNum));
|
arrayList.add(o.getQualifyNum());
|
arrayList.add(o.getScrappedNum());
|
if (reportNum == CommonConstant.ZERO.intValue()) {
|
arrayList.add("-");
|
} else {
|
arrayList.add(BigDecimal.valueOf(o.getQualifyNum().intValue()).multiply(BigDecimal.valueOf(100L)).divide(BigDecimal.valueOf(reportNum), RoundingMode.HALF_UP).intValue() + "%");
|
}
|
arrayList.add(Func.isNotEmpty(o.getStartTime()) ? DateUtil.format(o.getStartTime(), "yyyy/MM/dd HH:mm") : null);
|
arrayList.add(Func.isNotEmpty(o.getEndTime()) ? DateUtil.format(o.getStartTime(), "yyyy/MM/dd HH:mm") : null);
|
arrayList.add(o.getWorkstationName());
|
arrayList.add(o.getProducerUserName());
|
processData.add(arrayList);
|
});
|
return processData;
|
}
|
|
private Order generateOrder(OrderAssignVO orderAssignVO) {
|
String orderCode = orderAssignVO.getOrderCode();
|
if (Func.isEmpty(orderCode)) {
|
orderCode = this.codeGeneratorService.getGeneratorCode(orderAssignVO, MetaTypeEnum.ORDER.getCode());
|
}
|
checkCode(orderCode);
|
Order order = new Order(orderAssignVO.getPlanId(), orderCode, orderAssignVO.getAssignNum());
|
save(order);
|
return order;
|
}
|
|
private void checkCode(String orderCode) {
|
long count = count(Wrappers.<Order>lambdaQuery().eq(Order::getOrderCode, orderCode));
|
/*
|
long count = count((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
|
return v0.getOrderCode();
|
}, orderCode));
|
*/
|
if (count > 0) {
|
throw new ServiceException(MessageUtils.message("production.order.code.already.exists", new Object[0]));
|
}
|
}
|
|
private void assignCheck(Plan plan, OrderAssignVO orderAssignVO) {
|
if (Func.isEmpty(plan)) {
|
throw new ServiceException(MessageUtils.message("production.plan.not.exists", new Object[0]));
|
}
|
List<Integer> canNotAssignPlanStatus = Lists.newArrayList(new Integer[]{PlanStatusEnum.CLOSE.getCode(), PlanStatusEnum.FINISHED.getCode(), PlanStatusEnum.PAUSE.getCode()});
|
if (canNotAssignPlanStatus.contains(plan.getPlanStatus())) {
|
throw new ServiceException(MessageUtils.message("production.plan.status.not.met", new Object[0]));
|
}
|
if (orderAssignVO.getAssignNum().intValue() > plan.getUnassignedNum().intValue()) {
|
throw new ServiceException(MessageUtils.message("production.assign.num.exceed.plan.unassigned.num", new Object[0]));
|
}
|
Set<Long> workstationIdSet = new HashSet<>();
|
orderAssignVO.getPlanProcessWorkStationAssignVOList().forEach(p -> {
|
String workstationId = p.getWorkstationId();
|
if (Func.isNotEmpty(workstationId)) {
|
String[] split = workstationId.split(",");
|
for (String s : split) {
|
workstationIdSet.add(Long.valueOf(s));
|
}
|
}
|
});
|
if (Func.isNotEmpty(workstationIdSet)) {
|
long workstationNum = this.workstationService.count(Wrappers.<Workstation>lambdaQuery().in(Workstation::getId, workstationIdSet));
|
/*
|
long workstationNum = this.workstationService.count((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getId();
|
}, workstationIdSet));
|
*/
|
if (workstationNum < workstationIdSet.size()) {
|
throw new ServiceException(MessageUtils.message("production.assign.workstation.not.exists", new Object[0]));
|
}
|
}
|
}
|
}
|