2024.10.9
完善由合同来直接生成制令的代码
public void insertOrdersByContract(Contracts contract) {
//查询刚刚插入的合同
contract = contractsMapper.selectContractsList(contract).get(0);
// 1.根据合同生成唯一的总制令
Orders orders = new Orders();
orders.setContractId(contract.getContractId());
orders.setType("总制令");
orders.setOrderNumber(Long.toString(orderNumber));
// 1. 获取当前日期
String currentDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
// 2. 生成生产批次号 (合同编号 + 当前日期 + (制令类型))
orders.setBatchNumber(contract.getContractId() + "-" + currentDate + "-1");
orders.setStatus("待生产");
// 3. 插入数据库
ordersMapper.insertOrders(orders);
// 4. 查询生成的总制令
orders = ordersMapper.selectOrdersList(orders).get(0);
// 5. orderNumber + 1
orderNumber++;
// 2. 根据产品生成不同的分制令
int i = 1;
for (ProductDetails product : contract.getProductDetails()) {
Orders orders1 = new Orders();
orders1.setType("分制令");
orders1.setStatus("待生产");
orders1.setParentId(orders.getId());
orders1.setOrderNumber(orderNumber + "");
orders1.setProductId(product.getProductId());
orders1.setQuantity(product.getQuantity());
orders1.setBatchNumber(contract.getContractId() + "-" + currentDate + "-2-" + i++);
ordersMapper.insertOrders(orders1);
orders1 = ordersMapper.selectOrdersList(orders1).get(0);
orderNumber++;
// //根据员工数量 将产品平均分给各个员工
// //查询角色为员工的id编号
// //此处100为角色为员工的id号
// int userNumber = sysUserRoleMapper.countUserRoleByRoleId(100L);
// //将产品平均分给各个员工
// AtomicInteger count = new AtomicInteger(0);
//根据不同的产品 判断需要几道工序 来生成子制令
//根据产品id查询产品种类
Products products = productMapper.selectProductsByProductId(product.getProductId());
//工序数量 n
int n = Integer.parseInt(products.getCategory()) + 3;
for (int j = 0; j < n; j++) {
Orders orders2 = new Orders();
orders2.setType("子制令");
orders2.setStatus("待生产");
orders2.setParentId(orders1.getId());
orders2.setOrderNumber(orderNumber++ + "");
orders2.setBatchNumber(contract.getContractId() + "-" + currentDate + "-3-" + i++);
ordersMapper.insertOrders(orders2);
}
}
}