|
|
@ -37,6 +37,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
@ -89,8 +90,7 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IZyPlanProcessAccessoriesService iZyPlanProcessAccessoriesService; |
|
|
|
private IZyPlanProcessAccessoriesService iZyPlanProcessAccessoriesService; |
|
|
|
|
|
|
|
|
|
|
|
// @Transactional(rollbackFor = Exception.class, readOnly = false)
|
|
|
|
@Transactional(rollbackFor = Exception.class, readOnly = false) |
|
|
|
@Transactional |
|
|
|
|
|
|
|
List<ZyProductPlan> saveProductPlan(List<WorkOrder> workOrderList) { |
|
|
|
List<ZyProductPlan> saveProductPlan(List<WorkOrder> workOrderList) { |
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(workOrderList)) return Collections.EMPTY_LIST; |
|
|
|
if (ObjectUtils.isEmpty(workOrderList)) return Collections.EMPTY_LIST; |
|
|
@ -109,8 +109,14 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
//2,保存生产计划
|
|
|
|
//2,保存生产计划
|
|
|
|
ZyProductPlan zyProductPlan = new ZyProductPlan(); |
|
|
|
ZyProductPlan zyProductPlan = new ZyProductPlan(); |
|
|
|
zyProductPlan.setProductCode(productCode); |
|
|
|
zyProductPlan.setProductCode(productCode); |
|
|
|
// zyProductPlan.setProductNo(StringUtils.isNotBlank(zyProduct.getProductCode()) ? zyProduct.getProductCode() : "");
|
|
|
|
zyProductPlan.setProductNo(zyProduct.getProductCode()); |
|
|
|
zyProductPlan.setProductName(zyProduct.getProductName()); |
|
|
|
zyProductPlan.setProductName(zyProduct.getProductName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(zyProduct.getEnterprisesId())) { |
|
|
|
|
|
|
|
SysDepart sysDepart = iSysDepartService.getById(zyProduct.getEnterprisesId()); |
|
|
|
|
|
|
|
//生产企业
|
|
|
|
|
|
|
|
zyProductPlan.setProductOrg(StringUtils.isNotBlank(sysDepart.getDepartName()) ? sysDepart.getDepartName() : ""); |
|
|
|
|
|
|
|
} |
|
|
|
//生产时长,取zy_product表生产时间
|
|
|
|
//生产时长,取zy_product表生产时间
|
|
|
|
zyProductPlan.setDuration(zyProduct.getProduceTime()); |
|
|
|
zyProductPlan.setDuration(zyProduct.getProduceTime()); |
|
|
|
SysDepart sysDepart = sysDepartList2.get(i.get()); |
|
|
|
SysDepart sysDepart = sysDepartList2.get(i.get()); |
|
|
@ -121,7 +127,7 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
if (!ObjectUtils.isEmpty(sysUserList)) { |
|
|
|
if (!ObjectUtils.isEmpty(sysUserList)) { |
|
|
|
SysUser sysUser = sysUserList.get(0); |
|
|
|
SysUser sysUser = sysUserList.get(0); |
|
|
|
//车间负责人
|
|
|
|
//车间负责人
|
|
|
|
zyProductPlan.setResponsiblePerson(sysUser.getRealname()); |
|
|
|
zyProductPlan.setResponsiblePerson(sysUser.getUsername()); |
|
|
|
} |
|
|
|
} |
|
|
|
//车间
|
|
|
|
//车间
|
|
|
|
zyProductPlan.setWorkshopId(sysDepart.getId()); |
|
|
|
zyProductPlan.setWorkshopId(sysDepart.getId()); |
|
|
@ -131,17 +137,106 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
//班组
|
|
|
|
//班组
|
|
|
|
zyProductPlan.setTeamId(groupx.getId()); |
|
|
|
zyProductPlan.setTeamId(groupx.getId()); |
|
|
|
//班长
|
|
|
|
//班长
|
|
|
|
zyProductPlan.setTeamLeader(groupx.getEnterprisesManager()); |
|
|
|
SysUser sysUser = iSysUserService.getById(groupx.getEnterprisesManager()); |
|
|
|
|
|
|
|
zyProductPlan.setTeamLeader(sysUser.getUsername()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
|
|
|
//开始时间
|
|
|
|
|
|
|
|
zyProductPlan.setWorkTime(date); |
|
|
|
|
|
|
|
//审核人
|
|
|
|
|
|
|
|
zyProductPlan.setAuditBy("admin"); |
|
|
|
|
|
|
|
//审核时间
|
|
|
|
|
|
|
|
zyProductPlan.setAuditTimr(date); |
|
|
|
|
|
|
|
//生产计划状态为未审核
|
|
|
|
|
|
|
|
zyProductPlan.setStatus(new Integer(ProductPlanStatusEnum.UNAUDITED.getCode())); |
|
|
|
//保存生产计划
|
|
|
|
//保存生产计划
|
|
|
|
|
|
|
|
iZyProductPlanService.save(zyProductPlan); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新work_order表work_order_status为“1” (不能为其新增生产计划)
|
|
|
|
|
|
|
|
iWorkOrderService.lambdaUpdate().set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.REVIEWED.getCode()).update(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
zyProductPlanProductCodes.add(productCode); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//根据productCode,查询本次创建生产计划
|
|
|
|
|
|
|
|
List<ZyProductPlan> productPlanList = iZyProductPlanService.list(new LambdaQueryWrapper<ZyProductPlan>() |
|
|
|
|
|
|
|
.eq(ZyProductPlan::getStatus, ProductPlanStatusEnum.UNAUDITED.getCode()) |
|
|
|
|
|
|
|
.in(ZyProductPlan::getStatus, zyProductPlanProductCodes)); |
|
|
|
|
|
|
|
return productPlanList; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 模拟测试方法 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param workOrderList |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class, readOnly = false) |
|
|
|
|
|
|
|
List<ZyProductPlan> saveProductPlan4Mock(List<WorkOrder> workOrderList) { |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(workOrderList)) return Collections.EMPTY_LIST; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> zyProductPlanProductCodes = new LinkedHashSet<>(); |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 模拟测试 车间、负责人、班组、组长使用固定值 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
zyProductPlan.setProductNo(zyProduct.getProductCode()); |
|
|
|
|
|
|
|
zyProductPlan.setProductName(zyProduct.getProductName()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(zyProduct.getEnterprisesId())) { |
|
|
|
|
|
|
|
SysDepart sysDepart = iSysDepartService.getById(zyProduct.getEnterprisesId()); |
|
|
|
|
|
|
|
//生产企业
|
|
|
|
|
|
|
|
zyProductPlan.setProductOrg(StringUtils.isNotBlank(sysDepart.getDepartName()) ? sysDepart.getDepartName() : ""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//生产时长,取zy_product表生产时间
|
|
|
|
|
|
|
|
zyProductPlan.setDuration(zyProduct.getProduceTime()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysDepart sysDepart = iSysDepartService.getOne(new LambdaQueryWrapper<SysDepart>() |
|
|
|
|
|
|
|
.eq(SysDepart::getOrgCategory, "2") |
|
|
|
|
|
|
|
.eq(SysDepart::getDepartName, "测试生产企业")); |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(sysDepart)) throw new JeecgBootException("生产计划自动化-mock-[企业信息]数据异常!"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//车间
|
|
|
|
|
|
|
|
zyProductPlan.setWorkshopId(sysDepart.getId()); |
|
|
|
|
|
|
|
List<String> sysDepartIds = new LinkedList<>(); |
|
|
|
|
|
|
|
sysDepartIds.add(sysDepart.getId()); |
|
|
|
|
|
|
|
List<SysUser> sysUserList = iSysUserService.getUserByDepIds(sysDepartIds, null); |
|
|
|
|
|
|
|
//车间负责人
|
|
|
|
|
|
|
|
zyProductPlan.setResponsiblePerson(sysUserList.get(0).getUsername()); |
|
|
|
|
|
|
|
Groupx groupx = iGroupxService.getOne(new LambdaQueryWrapper<Groupx>().eq(Groupx::getDepartId, sysDepart.getId()).eq(Groupx::getGroupName, "测试班组")); |
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(groupx)) throw new JeecgBootException("生产计划自动化-mock-[班组]数据异常!"); |
|
|
|
|
|
|
|
//班组
|
|
|
|
|
|
|
|
zyProductPlan.setTeamId(groupx.getId()); |
|
|
|
|
|
|
|
//班长
|
|
|
|
|
|
|
|
SysUser sysUser = iSysUserService.getById(groupx.getEnterprisesManager()); |
|
|
|
|
|
|
|
zyProductPlan.setTeamLeader(sysUser.getUsername()); |
|
|
|
|
|
|
|
Date date = new Date(); |
|
|
|
|
|
|
|
//开始时间
|
|
|
|
|
|
|
|
zyProductPlan.setWorkTime(date); |
|
|
|
|
|
|
|
//审核人
|
|
|
|
|
|
|
|
zyProductPlan.setAuditBy("admin"); |
|
|
|
|
|
|
|
//审核时间
|
|
|
|
|
|
|
|
zyProductPlan.setAuditTimr(date); |
|
|
|
|
|
|
|
//生产计划状态为未审核
|
|
|
|
zyProductPlan.setStatus(new Integer(ProductPlanStatusEnum.UNAUDITED.getCode())); |
|
|
|
zyProductPlan.setStatus(new Integer(ProductPlanStatusEnum.UNAUDITED.getCode())); |
|
|
|
|
|
|
|
//保存生产计划
|
|
|
|
iZyProductPlanService.save(zyProductPlan); |
|
|
|
iZyProductPlanService.save(zyProductPlan); |
|
|
|
|
|
|
|
|
|
|
|
//更新work_order表work_order_status为“1” (不能为其新增生产计划)
|
|
|
|
//更新work_order表work_order_status为“1” (不能为其新增生产计划)
|
|
|
|
iWorkOrderService.lambdaUpdate().set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.REVIEWED.getCode()).update(); |
|
|
|
iWorkOrderService.lambdaUpdate().set(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.REVIEWED.getCode()).update(); |
|
|
|
|
|
|
|
|
|
|
|
zyProductPlanProductCodes.add(productCode); |
|
|
|
zyProductPlanProductCodes.add(productCode); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//根据productCode,查询本次创建生产计划
|
|
|
|
//根据productCode,查询本次创建生产计划
|
|
|
|
List<ZyProductPlan> productPlanList = iZyProductPlanService.list(new LambdaQueryWrapper<ZyProductPlan>() |
|
|
|
List<ZyProductPlan> productPlanList = iZyProductPlanService.list(new LambdaQueryWrapper<ZyProductPlan>() |
|
|
|
.eq(ZyProductPlan::getStatus, ProductPlanStatusEnum.UNAUDITED.getCode()) |
|
|
|
.eq(ZyProductPlan::getStatus, ProductPlanStatusEnum.UNAUDITED.getCode()) |
|
|
@ -162,50 +257,28 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
return sysDepartList2; |
|
|
|
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 |
|
|
|
@Override |
|
|
|
public void doAuto(HttpServletRequest req) { |
|
|
|
@Transactional(rollbackFor = Exception.class, readOnly = false) |
|
|
|
|
|
|
|
public void doAuto(List<String> workOrderList4Mock) { |
|
|
|
|
|
|
|
|
|
|
|
//1,获取未排产工单
|
|
|
|
//1,获取未排产工单
|
|
|
|
List<WorkOrder> workOrderList = iWorkOrderService.list(new LambdaQueryWrapper<WorkOrder>() |
|
|
|
List<WorkOrder> workOrderList; |
|
|
|
.eq(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.UNAUDITED.getCode())); |
|
|
|
if (ObjectUtils.isEmpty(workOrderList4Mock)) { |
|
|
|
|
|
|
|
workOrderList = iWorkOrderService.list(new LambdaQueryWrapper<WorkOrder>() |
|
|
|
|
|
|
|
.eq(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.UNAUDITED.getCode())); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
workOrderList = iWorkOrderService.list(new LambdaQueryWrapper<WorkOrder>() |
|
|
|
|
|
|
|
.eq(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.UNAUDITED.getCode()) |
|
|
|
|
|
|
|
.in(WorkOrder::getId, workOrderList4Mock)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List<WorkOrder> workOrderList = iWorkOrderService.list(new LambdaQueryWrapper<WorkOrder>()
|
|
|
|
|
|
|
|
// .eq(WorkOrder::getWorkOrderStatus, WorkOrderStatusEnum.UNAUDITED.getCode()));
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(workOrderList)) return; |
|
|
|
|
|
|
|
|
|
|
|
//2,保存生产计划
|
|
|
|
//2,保存生产计划
|
|
|
|
List<ZyProductPlan> productPlanList = this.saveProductPlan(workOrderList); |
|
|
|
// List<ZyProductPlan> productPlanList = this.saveProductPlan(workOrderList);
|
|
|
|
|
|
|
|
List<ZyProductPlan> productPlanList = this.saveProductPlan4Mock(workOrderList); |
|
|
|
if (ObjectUtils.isEmpty(productPlanList)) return; |
|
|
|
if (ObjectUtils.isEmpty(productPlanList)) return; |
|
|
|
|
|
|
|
|
|
|
|
//3,同步计划生产工序、同步生产计划工序面料、同步生产计划辅料
|
|
|
|
//3,同步计划生产工序、同步生产计划工序面料、同步生产计划辅料
|
|
|
@ -219,21 +292,24 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
// 匹配工序设备、工序工具有一个工序失败,则工单作为异常处理,删除生产计划及相关子表
|
|
|
|
// 匹配工序设备、工序工具有一个工序失败,则工单作为异常处理,删除生产计划及相关子表
|
|
|
|
//只有一个生产计划的设备、工具都匹配成功才进行一下操作(生成物料单、发送到仓库)
|
|
|
|
//只有一个生产计划的设备、工具都匹配成功才进行一下操作(生成物料单、发送到仓库)
|
|
|
|
productPlanList.stream().forEach(k -> { |
|
|
|
productPlanList.stream().forEach(k -> { |
|
|
|
|
|
|
|
//TODO 数据不完整,测试时注释
|
|
|
|
// boolean b = this.filling4Auto(k.getId());
|
|
|
|
// boolean b = this.filling4Auto(k.getId());
|
|
|
|
// if (b) {
|
|
|
|
// if (b) {
|
|
|
|
List<ZyPlanProcess> planProcessList = zyPlanProcessService.list(new LambdaQueryWrapper<ZyPlanProcess>().eq(ZyPlanProcess::getPlanId, k.getId())); |
|
|
|
List<ZyPlanProcess> planProcessList = zyPlanProcessService.list(new LambdaQueryWrapper<ZyPlanProcess>().eq(ZyPlanProcess::getPlanId, k.getId())); |
|
|
|
Optional.ofNullable(planProcessList).orElse(new LinkedList<>()).forEach(e -> { |
|
|
|
Optional.ofNullable(planProcessList).orElse(new LinkedList<>()).forEach(e -> { |
|
|
|
// 5,生成物料单
|
|
|
|
// 5,生成物料单
|
|
|
|
zyPlanProcessService.createMaterialBill(e); |
|
|
|
zyPlanProcessService.createMaterialBill(e); |
|
|
|
// 5,发送到仓库
|
|
|
|
// 5,发送到仓库
|
|
|
|
zyPlanProcessService.sendToRepository(e); |
|
|
|
zyPlanProcessService.sendToRepository(e); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 匹配设备&工具&工人 |
|
|
|
|
|
|
|
* <p> |
|
|
|
* 匹配车间工位设备与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
|
|
|
* 匹配车间工位设备与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
|
|
|
* 匹配车间工位工具与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
|
|
|
* 匹配车间工位工具与工序设备,工位设备包含工序设备即匹配成功,匹配失败做异常处理 |
|
|
|
* |
|
|
|
* |
|
|
@ -265,8 +341,9 @@ public class IZyProductPlanAutoServiceImpl extends ServiceImpl<ZyProductPlanMapp |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ZyPlanProcess> planProcessList2 = zyPlanProcessService.list(new LambdaQueryWrapper<ZyPlanProcess>().eq(ZyPlanProcess::getPlanId, planId)); |
|
|
|
//匹配工人
|
|
|
|
//匹配工人
|
|
|
|
this.diffWorker(planProcessList, planId); |
|
|
|
this.diffWorker(planProcessList2, planId); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|