parent
9c83e02237
commit
25fa982cde
9 changed files with 491 additions and 65 deletions
@ -0,0 +1,56 @@ |
||||
package org.jeecg.modules.productplan.controller; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.jeecg.common.api.vo.Result; |
||||
import org.jeecg.common.aspect.annotation.AutoLog; |
||||
import org.jeecg.common.system.base.controller.JeecgController; |
||||
import org.jeecg.common.system.query.QueryGenerator; |
||||
import org.jeecg.modules.productplan.entity.ZyProductPlan; |
||||
import org.jeecg.modules.productplan.entity.vo.PaiWeiTuVo; |
||||
import org.jeecg.modules.productplan.service.IZyProductPlanAutoService; |
||||
import org.jeecg.modules.productplan.service.IZyProductPlanService; |
||||
import org.jeecg.modules.system.entity.SysDepart; |
||||
import org.jeecg.modules.system.entity.SysUser; |
||||
import org.jeecg.modules.system.service.ISysDepartService; |
||||
import org.jeecg.modules.system.service.ISysUserService; |
||||
import org.jeecg.modules.workproduct.entity.ZyProduct; |
||||
import org.jeecg.modules.workproduct.service.IZyProductService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.*; |
||||
import org.springframework.web.servlet.ModelAndView; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.Arrays; |
||||
|
||||
/** |
||||
* @Description: 生产计划自动化 |
||||
* @Author: jeecg-boot |
||||
* @Date: 2023-2-22 |
||||
* @Version: V1.0 |
||||
*/ |
||||
@Api(tags = "生产计划自动化") |
||||
@RestController |
||||
@RequestMapping("/zyProductPlanAuto") |
||||
@Slf4j |
||||
public class ZyProductPlanAutoController extends JeecgController<ZyProductPlan, IZyProductPlanService> { |
||||
|
||||
@Autowired |
||||
private IZyProductPlanAutoService iZyProductPlanAutoService; |
||||
|
||||
@ApiOperation(value = "生产计划自动化", notes = "生产计划自动化") |
||||
@GetMapping(value = "/auto") |
||||
public Result<?> auto(HttpServletRequest req) { |
||||
iZyProductPlanAutoService.doAuto(req); |
||||
return Result.OK(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,20 @@ |
||||
package org.jeecg.modules.productplan.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService; |
||||
import org.jeecg.modules.productplan.entity.ZyProductPlan; |
||||
import org.jeecg.modules.productplan.entity.vo.PaiWeiTuVo; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
|
||||
/** |
||||
* @Description: 生产计划 |
||||
* @Author: jeecg-boot |
||||
* @Date: 2022-12-12 |
||||
* @Version: V1.0 |
||||
*/ |
||||
public interface IZyProductPlanAutoService extends IService<ZyProductPlan> { |
||||
|
||||
void doAuto(HttpServletRequest req); |
||||
|
||||
void filling4Auto(String planId); |
||||
} |
@ -0,0 +1,281 @@ |
||||
package org.jeecg.modules.productplan.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import org.jeecg.common.exception.JeecgBootException; |
||||
import org.jeecg.modules.demo.pro.entity.ZyProcessMachine; |
||||
import org.jeecg.modules.demo.pro.service.IZyProcessMachineService; |
||||
import org.jeecg.modules.productplan.entity.ZyPlanProcess; |
||||
import org.jeecg.modules.productplan.entity.ZyProductPlan; |
||||
import org.jeecg.modules.productplan.enums.ProductPlanStatusEnum; |
||||
import org.jeecg.modules.productplan.mapper.ZyProductPlanMapper; |
||||
import org.jeecg.modules.productplan.service.IZyPlanProcessService; |
||||
import org.jeecg.modules.productplan.service.IZyProductPlanAutoService; |
||||
import org.jeecg.modules.productplan.service.IZyProductPlanService; |
||||
import org.jeecg.modules.system.entity.SysDepart; |
||||
import org.jeecg.modules.system.entity.SysUser; |
||||
import org.jeecg.modules.system.service.ISysDepartService; |
||||
import org.jeecg.modules.system.service.ISysUserService; |
||||
import org.jeecg.modules.team.entity.Groupx; |
||||
import org.jeecg.modules.team.entity.Station; |
||||
import org.jeecg.modules.team.entity.StationMachine; |
||||
import org.jeecg.modules.team.service.IGroupxService; |
||||
import org.jeecg.modules.team.service.IStationMachineService; |
||||
import org.jeecg.modules.team.service.IStationService; |
||||
import org.jeecg.modules.workorder.entity.WorkOrder; |
||||
import org.jeecg.modules.workorder.enums.WorkOrderStatusEnum; |
||||
import org.jeecg.modules.workorder.service.IWorkOrderService; |
||||
import org.jeecg.modules.workproduct.entity.ZyProduct; |
||||
import org.jeecg.modules.workproduct.service.IZyProductService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.*; |
||||
import java.util.concurrent.atomic.AtomicBoolean; |
||||
import java.util.concurrent.atomic.AtomicInteger; |
||||
import java.util.stream.Collectors; |
||||
|
||||
|
||||
@Service |
||||
public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapper, ZyProductPlan> implements IZyProductPlanAutoService { |
||||
|
||||
@Autowired |
||||
private IWorkOrderService iWorkOrderService; |
||||
|
||||
@Autowired |
||||
private IZyProductPlanService iZyProductPlanService; |
||||
|
||||
@Autowired |
||||
private IZyPlanProcessService zyPlanProcessService; |
||||
|
||||
@Autowired |
||||
private IZyProductService iZyProductService; |
||||
|
||||
@Autowired |
||||
private ISysDepartService iSysDepartService; |
||||
|
||||
@Autowired |
||||
private ISysUserService iSysUserService; |
||||
|
||||
@Autowired |
||||
private IGroupxService iGroupxService; |
||||
|
||||
@Autowired |
||||
private IStationService iStationService; |
||||
|
||||
@Autowired |
||||
private IZyProcessMachineService iZyProcessMachineService; |
||||
@Autowired |
||||
private IStationMachineService iStationMachineService; |
||||
|
||||
@Transactional(rollbackFor = Exception.class, readOnly = false) |
||||
List<ZyProductPlan> saveProductPlan(List<WorkOrder> workOrderList) { |
||||
|
||||
if (ObjectUtils.isEmpty(workOrderList)) return Collections.EMPTY_LIST; |
||||
|
||||
Set<String> zyProductPlanProductCodes = new LinkedHashSet<>(); |
||||
List<SysDepart> sysDepartList = iSysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getOrgCategory, "2")); |
||||
List<SysDepart> sysDepartList2 = this.copyList(workOrderList, sysDepartList); |
||||
|
||||
AtomicInteger i = new AtomicInteger(0); |
||||
workOrderList.stream().forEach(e -> { |
||||
String productCode = e.getProductCode(); |
||||
ZyProduct zyProduct = iZyProductService.getOne(new LambdaQueryWrapper<ZyProduct>() |
||||
.eq(ZyProduct::getWorkOrderId, productCode)); |
||||
Optional.ofNullable(zyProduct).orElseThrow(() -> new JeecgBootException(productCode + ":产品不存在")); |
||||
|
||||
//2,保存生产计划
|
||||
ZyProductPlan zyProductPlan = new ZyProductPlan(); |
||||
zyProductPlan.setProductCode(productCode); |
||||
//生产时长,取zy_product表生产时间
|
||||
zyProductPlan.setDuration(zyProduct.getProduceTime()); |
||||
SysDepart sysDepart = sysDepartList2.get(i.get()); |
||||
i.set(i.get() + 1); |
||||
List<String> sysDeparts = new LinkedList<>(); |
||||
sysDeparts.add(sysDepart.getId()); |
||||
List<SysUser> sysUserList = iSysUserService.getUserByDepIds(sysDeparts, null); |
||||
if (!ObjectUtils.isEmpty(sysUserList)) { |
||||
SysUser sysUser = sysUserList.get(0); |
||||
//车间负责人
|
||||
zyProductPlan.setResponsiblePerson(sysUser.getRealname()); |
||||
} |
||||
//车间
|
||||
zyProductPlan.setWorkshopId(sysDepart.getId()); |
||||
List<Groupx> groupxList = iGroupxService.list(new LambdaQueryWrapper<Groupx>().eq(Groupx::getDepartId, sysDepart)); |
||||
if (!ObjectUtils.isEmpty(groupxList)) { |
||||
Groupx groupx = groupxList.get(0); |
||||
//班组
|
||||
zyProductPlan.setTeamId(groupx.getId()); |
||||
//班长
|
||||
zyProductPlan.setTeamLeader(groupx.getEnterprisesManager()); |
||||
} |
||||
//保存生产计划
|
||||
iZyProductPlanService.create(zyProductPlan); |
||||
zyProductPlanProductCodes.add(productCode); |
||||
}); |
||||
//根据productCode,查询本次创建生产计划
|
||||
List<ZyProductPlan> productPlanList = iZyProductPlanService.list(new LambdaQueryWrapper<ZyProductPlan>() |
||||
.eq(ZyProductPlan::getStatus, ProductPlanStatusEnum.UNAUDITED.getCode()) |
||||
.in(ZyProductPlan::getStatus, zyProductPlanProductCodes)); |
||||
return productPlanList; |
||||
} |
||||
|
||||
private List<SysDepart> copyList(List<WorkOrder> workOrderList, List<SysDepart> sysDepartList) { |
||||
if (ObjectUtils.isEmpty(workOrderList) || ObjectUtils.isEmpty(sysDepartList)) return Collections.EMPTY_LIST; |
||||
int size = workOrderList.size(); |
||||
List<SysDepart> sysDepartList2 = new LinkedList<>(); |
||||
sysDepartList2.addAll(sysDepartList); |
||||
int size2 = sysDepartList2.size(); |
||||
while (size2 < size) { |
||||
sysDepartList2.addAll(sysDepartList); |
||||
size2 = sysDepartList2.size(); |
||||
} |
||||
return sysDepartList2; |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
List list = new LinkedList(); |
||||
List list2 = new LinkedList(); |
||||
list.add("1"); |
||||
list.add("2"); |
||||
list.add("3"); |
||||
list.add("4"); |
||||
list.add("5"); |
||||
list.add("6"); |
||||
list.add("7"); |
||||
list.add("8"); |
||||
|
||||
list2.add("a"); |
||||
list2.add("b"); |
||||
list2.add("c"); |
||||
list2.add("c"); |
||||
list2.add("c"); |
||||
list2.add("c"); |
||||
|
||||
int size = list.size(); |
||||
List<String> sysDepartList2 = new LinkedList<>(); |
||||
sysDepartList2.addAll(list2); |
||||
int size2 = sysDepartList2.size(); |
||||
|
||||
while (size2 < size) { |
||||
sysDepartList2.addAll(list2); |
||||
size2 = sysDepartList2.size(); |
||||
} |
||||
|
||||
System.out.println("sysDepartList2 = " + sysDepartList2.size()); |
||||
System.out.println("list2 = " + list2.size()); |
||||
System.out.println("list = " + list.size()); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void doAuto(HttpServletRequest req) { |
||||
|
||||
//1,获取未排产工单
|
||||
List<WorkOrder> workOrderList = iWorkOrderService.list(new LambdaQueryWrapper<WorkOrder>() |
||||
.eq(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.UNAUDITED.getCode())); |
||||
|
||||
//2,保存生产计划
|
||||
List<ZyProductPlan> productPlanList = this.saveProductPlan(workOrderList); |
||||
if (ObjectUtils.isEmpty(productPlanList)) return; |
||||
|
||||
//3,保存计划生产工序
|
||||
productPlanList.stream().forEach(f -> { |
||||
ZyPlanProcess zyPlanProcess = new ZyPlanProcess(); |
||||
zyPlanProcess.setPlanId(f.getId()); |
||||
zyPlanProcessService.syncProductBaseProcess(zyPlanProcess); |
||||
}); |
||||
|
||||
//4,自动排位
|
||||
productPlanList.stream().forEach(k -> { |
||||
this.filling4Auto(k.getId()); |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 匹配车间工位设备与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
||||
* 匹配车间工位工具与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
||||
* |
||||
* @param planId |
||||
*/ |
||||
@Override |
||||
public void filling4Auto(String planId) { |
||||
ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); |
||||
if (ObjectUtils.isEmpty(zyProductPlan)) { |
||||
throw new JeecgBootException("生产计划不存在!"); |
||||
} |
||||
|
||||
List<ZyPlanProcess> planProcessList = zyPlanProcessService.list(new LambdaQueryWrapper<ZyPlanProcess>().eq(ZyPlanProcess::getPlanId, planId)); |
||||
//是否有计划工序
|
||||
if (ObjectUtils.isEmpty(planProcessList)) return; |
||||
|
||||
//生产计划车间工位列表
|
||||
List<Station> stationList = iStationService.list(new LambdaQueryWrapper<Station>().eq(Station::getDepartId, zyProductPlan.getWorkshopId())); |
||||
|
||||
/** |
||||
* 遍历计划工序: |
||||
* 用工序设备表数据与工位设备进行匹配 |
||||
* 依次用该生产计划的车间工位设备循环与工序设备比对【(工位设备包含工序设备即是匹配成功,则自动填充工位、设备字段数据,匹配不上则不自动填充,由用户自己录入)】 |
||||
* 根据工序,查询工序设备表zy_process_machine, |
||||
*/ |
||||
if(this.diffMachine(planProcessList, stationList, planId)){ |
||||
//TODO 匹配工具
|
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 工位设备与产品工序设备匹配 |
||||
* 只要有一个工序匹配不上就算匹配失败,撤回前面匹配的工序。标记该工单异常,然后匹配下一个工单。 |
||||
* |
||||
* @param planProcessList |
||||
* @param stationList |
||||
*/ |
||||
@Transactional(rollbackFor = Exception.class, readOnly = false) |
||||
public boolean diffMachine(List<ZyPlanProcess> planProcessList, List<Station> stationList, final String planId) { |
||||
if (ObjectUtils.isEmpty(stationList) || ObjectUtils.isEmpty(planProcessList)) return false; |
||||
|
||||
AtomicBoolean b = new AtomicBoolean(true); |
||||
List<ZyPlanProcess> updateList = new LinkedList<>(); |
||||
k: if (b.get()) { |
||||
f: for (int i = 0; i < planProcessList.size(); i++) { |
||||
ZyPlanProcess obj = planProcessList.get(i); |
||||
List<ZyProcessMachine> machineList = iZyProcessMachineService.list(new LambdaQueryWrapper<ZyProcessMachine>().eq(ZyProcessMachine::getProcessId, obj.getProcessId())); |
||||
List<String> zyProcessMachineIds = machineList.stream().map(ZyProcessMachine::getMachineId).collect(Collectors.toList()); |
||||
for (int j = 0; j < stationList.size(); j++) { |
||||
Station station = stationList.get(j); |
||||
List<StationMachine> stationMachineList = iStationMachineService.list(new LambdaQueryWrapper<StationMachine>().eq(StationMachine::getStationId, station.getId())); |
||||
List<String> stationMachineIds = Optional.ofNullable(stationMachineList).orElse(new ArrayList<>()).stream() |
||||
.map(StationMachine::getMachineId).collect(Collectors.toList()); |
||||
// 设备匹配成功
|
||||
if (stationMachineIds.containsAll(zyProcessMachineIds)) { |
||||
String collect = zyProcessMachineIds.stream().collect(Collectors.joining(",")); |
||||
obj.setMachineIds(collect); |
||||
obj.setMachineNames(iStationMachineService.convertByMachineIds(zyProcessMachineIds)); |
||||
obj.setStationId(station.getId()); |
||||
obj.setStationName(station.getStationName()); |
||||
obj.setStationNum(station.getStationNum()); |
||||
updateList.add(obj); |
||||
break f; |
||||
} else { |
||||
// 作工单异常处理,删除该工单的生产计划,删除生产计划工序
|
||||
ZyProductPlan zyProductPlan = iZyProductPlanService.getById(planId); |
||||
iWorkOrderService.lambdaUpdate() |
||||
.set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.EXCEPTION.getCode()) |
||||
.eq(WorkOrder::getProductCode, zyProductPlan.getProductCode()).update(); |
||||
zyPlanProcessService.remove(new LambdaQueryWrapper<ZyPlanProcess>().in(ZyPlanProcess::getPlanId, planId)); |
||||
iZyProductPlanService.remove(new LambdaQueryWrapper<ZyProductPlan>().in(ZyProductPlan::getId, planId)); |
||||
b.set(false); |
||||
break k; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
if (b.get()) { |
||||
zyPlanProcessService.saveOrUpdateBatch(updateList); |
||||
} |
||||
return b.get(); |
||||
} |
||||
} |
@ -0,0 +1,67 @@ |
||||
package org.jeecg.modules.workorder.enums; |
||||
|
||||
/** |
||||
* 工单状态枚举 |
||||
*/ |
||||
public enum WorkOrderStatusEnum { |
||||
|
||||
UNAUDITED("0", "未排产"), |
||||
REVIEWED("1", "已排产"), |
||||
PRODUCTION("2", "生产中"), |
||||
COMPLETED("3", "已完成"), |
||||
REVOKED("8", "已撤销"), |
||||
EXCEPTION("9", "异常"); |
||||
|
||||
private String code; |
||||
|
||||
private String val; |
||||
|
||||
private WorkOrderStatusEnum(String code, String val) { |
||||
this.code = code; |
||||
this.val = val; |
||||
} |
||||
|
||||
public String getCode() { |
||||
return code; |
||||
} |
||||
|
||||
public void setCode(String code) { |
||||
this.code = code; |
||||
} |
||||
|
||||
public String getVal() { |
||||
return val; |
||||
} |
||||
|
||||
public void setVal(String val) { |
||||
this.val = val; |
||||
} |
||||
|
||||
public static String getValueByCode(String code) { |
||||
WorkOrderStatusEnum[] values = WorkOrderStatusEnum.values(); |
||||
for (WorkOrderStatusEnum type : values) { |
||||
if (type.code.equals(code)) { |
||||
return type.val; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static String getCodeByValue(String value) { |
||||
WorkOrderStatusEnum[] values = WorkOrderStatusEnum.values(); |
||||
for (WorkOrderStatusEnum type : values) { |
||||
if (type.val.equals(value)) { |
||||
return type.code; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return "ProductPlanStatusEnum{" + |
||||
"code='" + code + '\'' + |
||||
", val='" + val + '\'' + |
||||
'}'; |
||||
} |
||||
} |
Loading…
Reference in new issue