use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.
the class TaskPlanServiceImpl method addTaskPlans.
// 每新增1个工序,调用一次。
@Transactional(rollbackFor = Exception.class)
public boolean addTaskPlans(@RequestParam List<Integer> taskRecordIds, Integer planType, String machineStrId, Date planDate, Integer userId) {
for (int i = 0; i < taskRecordIds.size(); i++) {
Condition tempCondition = new Condition(TaskPlan.class);
Integer id = taskRecordIds.get(i);
tempCondition.createCriteria().andCondition("task_record_id = ", id);
List<TaskPlan> existPlans = findByCondition(tempCondition);
if (existPlans.size() > 0) {
return false;
}
TaskPlan plan = new TaskPlan();
plan.setCreateTime(new Date());
plan.setUserId(userId);
plan.setTaskRecordId(id);
plan.setPlanType(Constant.DAILY_PLAN);
if (planType.intValue() == Constant.DAILY_PLAN.intValue()) {
plan.setPlanTime(planDate);
} else if (planType.intValue() == Constant.FLEX_PLAN.intValue()) {
plan.setDeadline(planDate);
}
save(plan);
// 更改task record状态为已计划
TaskRecord taskRecord = taskRecordService.findById(id);
if (taskRecord != null) {
// 检查是否为第一个计划项,如果是,需要设置为待安装状态
Integer processRecordId = taskRecord.getProcessRecordId();
ProcessRecord processRecord = processRecordService.findById(processRecordId);
List<LinkDataModel> linkDataList = JSON.parseArray(processRecord.getLinkData(), LinkDataModel.class);
for (LinkDataModel item : linkDataList) {
if (item.getTo().equals(taskRecord.getNodeKey().intValue())) {
if (item.getFrom() == null || item.getFrom() == -1) {
taskRecord.setUpdateTime(new Date());
taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
break;
} else {
// TODO:如果是重新配置流程项,比如:改单、拆单以后再最后增加了安装项,则需要设置成待安装状态
List<Integer> parentNodeList = new ArrayList<>();
String nodeData = processRecord.getNodeData();
List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
for (LinkDataModel tmp : linkDataList) {
if (tmp.getTo() == taskRecord.getNodeKey().intValue()) {
parentNodeList.add(tmp.getFrom());
}
}
boolean allParentFinished = true;
for (Integer parentNodeKey : parentNodeList) {
for (NodeDataModel nodeDataModel : ndList) {
if (parentNodeKey.intValue() == Integer.valueOf(nodeDataModel.getKey())) {
if (Integer.valueOf(nodeDataModel.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue()) {
allParentFinished = false;
break;
}
}
}
if (!allParentFinished) {
break;
}
}
if (allParentFinished) {
taskRecord.setUpdateTime(new Date());
taskRecord.setStatus(Constant.TASK_INSTALL_WAITING);
}
}
}
}
if (taskRecord.getStatus().equals(Constant.TASK_INITIAL)) {
taskRecord.setStatus(Constant.TASK_PLANED);
}
taskRecordService.update(taskRecord);
// 更新task_record以外,但是跟task record相关的状态,机器状态,process_record中的task_status
commonService.updateTaskRecordRelatedStatus(taskRecord);
if (taskRecord.getStatus().equals(Constant.TASK_INSTALL_WAITING)) {
// MQTT 计划后,通知安装组长,可以进行安装
String taskName = taskRecord.getTaskName();
Condition condition = new Condition(Task.class);
condition.createCriteria().andCondition("task_name = ", taskName);
List<Task> taskList = taskService.findByCondition(condition);
if (taskList == null || taskList.size() <= 0) {
throw new RuntimeException();
}
ProcessRecord pr = processRecordService.findById(taskRecord.getProcessRecordId());
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
mqttMessageHelper.sendToClient(Constant.S2C_TASK_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
}
// /在”计划管理“中 添加计划安排时,自动添加了 总装排产 InstallPlan。 (InstallPlanActual则在app扫码完成工序时添加)
// 因为把总装排产,合并到“计划管理”,所以需要在安排计划时 自动生成总装排产(这样在app上扫码完成时,才能有总装完成自动填充完成头数)
InstallPlan installPlan1 = new InstallPlan();
installPlan1.setType(Constant.STR_INSTALL_TYPE_WHOLE);
InstallGroup installGroup = installGroupService.getInstallGroupByTaskName(taskRecord.getTaskName());
installPlan1.setInstallGroupId(installGroup.getId());
installPlan1.setInstallDatePlan(plan.getPlanTime());
ProcessRecord pr = processRecordService.findById(taskRecord.getProcessRecordId());
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
installPlan1.setOrderId(machineOrder.getId());
installPlan1.setMachineId(machine.getId());
installPlan1.setValid(Byte.valueOf("1"));
installPlan1.setCreateDate(new Date());
installPlanService.save(installPlan1);
logger.info("自动添加了 总装排产 for 铭牌号: " + machine.getNameplate() + ", 工序: " + taskRecord.getTaskName());
} else {
// 进行事务操作
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException();
}
}
if (taskRecordIds.size() > 0 && machineStrId != null) {
List<Machine> machineList = machineService.selectMachines(null, null, null, machineStrId, null, null, null, null, null, null, false);
if (machineList.size() == 1) {
// 如果机器状态小于计划中,则更新为计划中
Machine machine = machineList.get(0);
if (machine.getStatus() < Constant.MACHINE_PLANING) {
machine.setStatus(Constant.MACHINE_PLANING);
machineService.update(machine);
}
} else {
// 进行事务rollback操作
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new RuntimeException();
}
}
return true;
}
use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.
the class ContactFormController method checkTheContactFormValid.
@PostMapping("/checkTheContactFormValid")
public Result checkTheContactFormValid(String contactForm) {
if (contactForm == null) {
return ResultGenerator.genFailResult("参数 contactFormDetail 不能为null ");
}
ContactForm contactForm1 = JSON.parseObject(contactForm, ContactForm.class);
if (contactForm1 == null) {
return ResultGenerator.genFailResult("错误,解析得到的 contactForm1为 null!");
}
/**
* 逐一检查各个必要参数的合法性
*/
if (contactForm1.getApplicantDepartment() == null) {
return ResultGenerator.genFailResult("错误,getApplicantDepartment 为 null!");
}
if (contactForm1.getContactTitle() == null) {
return ResultGenerator.genFailResult("错误,getContactTitle 为 null!");
}
// if(contactForm1.getOrderNum() == null){
// return ResultGenerator.genFailResult("错误,orderNum 为 null!");
// }
// 根据订单号找订单
MachineOrder machineOrder = machineOrderService.getMachineOrder(contactForm1.getOrderNum());
if (machineOrder == null) {
return ResultGenerator.genFailResult("错误,根据该订单号 找不到对应的订单 ");
}
return ResultGenerator.genSuccessResult("OK");
}
use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.
the class MachineController method processMachineExport.
@PostMapping("/processMachineExport")
public Result processMachineExport(Integer order_id, String orderNum, String contractNum, String machine_strid, String nameplate, String location, String status, String query_start_time, String query_finish_time, // 工序集合,逗号分隔,支持UI按多个工序查询
String taskNameList, @RequestParam(defaultValue = "true") Boolean is_fuzzy) {
List<MachineInfo> list = machineService.selectProcessMachine(order_id, orderNum, contractNum, machine_strid, nameplate, location, status, query_start_time, query_finish_time, taskNameList, is_fuzzy);
InputStream fs = null;
POIFSFileSystem pfs = null;
HSSFWorkbook wb = null;
FileOutputStream out = null;
String downloadPath = "";
/*
返回给docker外部下载
*/
String downloadPathForNginx = "";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy/MM/dd HH:mm");
String dateString;
try {
// 生成一个空的Excel文件
wb = new HSSFWorkbook();
Sheet sheet1 = wb.createSheet("sheet1");
// 设置标题行格式
HSSFCellStyle headcellstyle = wb.createCellStyle();
HSSFFont headfont = wb.createFont();
headfont.setFontHeightInPoints((short) 10);
// 粗体显示
headfont.setBold(true);
headcellstyle.setFont(headfont);
Row row;
// 创建行和列
for (int r = 0; r < list.size() + 1; r++) {
// 新创建一行,行号为row+1
row = sheet1.createRow(r);
// 序号,机器编号,机型,订单号,位置,当前工序,已完成/总工序,安装状态,开始时间,计划交货日期
for (int c = 0; c < 10; c++) {
// 创建一个单元格,列号为col+1
row.createCell(c);
sheet1.getRow(0).getCell(c).setCellStyle(headcellstyle);
sheet1.setColumnWidth(c, 4500);
sheet1.setColumnWidth(0, 2500);
}
}
// 第一行为标题
sheet1.getRow(0).getCell(0).setCellValue("序号");
sheet1.getRow(0).getCell(1).setCellValue("机器编号");
sheet1.getRow(0).getCell(2).setCellValue("机型");
sheet1.getRow(0).getCell(3).setCellValue("订单号");
sheet1.getRow(0).getCell(4).setCellValue("位置");
// sheet1.getRow(0).getCell(5).setCellValue("当前工序");
// sheet1.getRow(0).getCell(6).setCellValue("已完成/总工序");
sheet1.getRow(0).getCell(7).setCellValue("安装状态");
sheet1.getRow(0).getCell(8).setCellValue("开始时间");
sheet1.getRow(0).getCell(9).setCellValue("计划交货日期");
// 第二行开始,填入值
Machine machine = null;
MachineOrder machineOrder = null;
MachineType machineType1 = null;
Byte machineStatus = 0;
for (int r = 0; r < list.size(); r++) {
// 序号,机器编号,机型,订单号,位置,当前工序,已完成/总工序,安装状态,开始时间,计划交货日期
row = sheet1.getRow(r + 1);
row.getCell(0).setCellValue(r + 1);
// 机器编号
if (list.get(r).getMachineStrId() != null) {
row.getCell(1).setCellValue(list.get(r).getNameplate());
}
// 机型
int machineTypeID = list.get(r).getMachineType();
// machine = machineService.selectMachinesByNameplate(list.get(r).getNameplate());
/**
* 获取机型类型的名称 machine_type.name
*/
machineType1 = machineTypeService.findById(machineTypeID);
if (machineType1 != null) {
// 机型
row.getCell(2).setCellValue(machineType1.getName());
}
// 订单号
if (list.get(r).getOrderNum() != null) {
row.getCell(3).setCellValue(list.get(r).getOrderNum());
}
// 位置
if (list.get(r).getLocation() != null) {
row.getCell(4).setCellValue(list.get(r).getLocation());
}
// 当前工序
// /todo: 从 nodeData中解析出工序? 注意可能有多个。
// 已完成/总工序
// / todo: 从 nodeData中解析计算?
// 状态
machineStatus = list.get(r).getStatus();
if (machineStatus == Constant.MACHINE_INITIAL) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_INITIAL);
} else if (machineStatus == Constant.MACHINE_CONFIGURED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_CONFIGURED);
} else if (machineStatus == Constant.MACHINE_PLANING) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_PLANING);
} else if (machineStatus == Constant.MACHINE_INSTALLING) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_INSTALLING);
} else if (machineStatus == Constant.MACHINE_INSTALLED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_INSTALLED);
} else if (machineStatus == Constant.MACHINE_CHANGED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_CHANGED);
} else if (machineStatus == Constant.MACHINE_SPLITED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_SPLITED);
} else if (machineStatus == Constant.MACHINE_CANCELED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_CANCELED);
} else if (machineStatus == Constant.MACHINE_INSTALLING_INCLUDE_SKIP_TASK) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_INSTALLING_INCLUDE_SKIP_TASK);
} else if (machineStatus == Constant.MACHINE_SHIPPED) {
row.getCell(7).setCellValue(Constant.STR_MACHINE_SHIPPED);
}
// 的开始时间
if (list.get(r).getProcessCreateTime() != null) {
dateString = formatter2.format(list.get(r).getProcessCreateTime());
row.getCell(8).setCellValue(dateString);
}
// 计划交货日期
if (list.get(r).getPlanShipDate() != null) {
dateString = formatter.format(list.get(r).getPlanShipDate());
row.getCell(9).setCellValue(dateString);
}
}
downloadPath = machinePorcessExcelOutputDir + "安装进度" + ".xls";
downloadPathForNginx = "/excel/" + "安装进度" + ".xls";
out = new FileOutputStream(downloadPath);
wb.write(out);
out.close();
//
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if ("".equals(downloadPath)) {
return ResultGenerator.genFailResult("异常导出失败!");
} else {
return ResultGenerator.genSuccessResult(downloadPathForNginx);
}
}
use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.
the class CommonService method updateTaskRecordRelatedStatus.
public boolean updateTaskRecordRelatedStatus(TaskRecord tr) {
if (tr == null || tr.getProcessRecordId() == null) {
return false;
} else {
Integer prId = tr.getProcessRecordId();
ProcessRecord pr = processRecordService.findById(prId);
Machine machine = machineService.findById(pr.getMachineId());
boolean isNeedUpdateMachine = false;
if (pr != null) {
String nodeData = pr.getNodeData();
List<NodeDataModel> ndList = JSON.parseArray(nodeData, NodeDataModel.class);
NodeDataModel ndItem = null;
Integer index = -1;
for (int i = 0; i < ndList.size(); i++) {
if (Integer.parseInt(ndList.get(i).getKey()) == tr.getNodeKey()) {
index = i;
break;
}
}
if (index > -1) {
ndItem = ndList.get(index);
ndItem.setTaskStatus(tr.getStatus().toString());
if (tr.getStatus().intValue() == Constant.TASK_PLANED.intValue() || tr.getStatus().intValue() == Constant.TASK_INSTALL_WAITING.intValue()) {
if (tr.getInstallBeginTime() == null) {
String date = Utils.getFormatStringDate(new Date(), "yyyy-MM-dd HH:mm:ss");
ndItem.setBeginTime(date);
}
}
if (tr.getInstallBeginTime() != null) {
String date = Utils.getFormatStringDate(tr.getInstallBeginTime(), "yyyy-MM-dd HH:mm:ss");
ndItem.setBeginTime(date);
}
// 质检完成,工序才算完成
if (tr.getQualityEndTime() != null) {
String date = Utils.getFormatStringDate(tr.getQualityEndTime(), "yyyy-MM-dd HH:mm:ss");
ndItem.setEndTime(date);
}
// 组长信息
if (tr.getLeader() != null && tr.getLeader().length() > 0) {
ndItem.setLeader(tr.getLeader());
}
// 工作人员信息
if (tr.getWorkerList() != null && tr.getWorkerList().length() > 0) {
ndItem.setWorkList(tr.getWorkerList());
}
ndList.set(index, ndItem);
// 如果当前工序是质检完成状态或者跳过状态,需要检查其子节点是否可以开始 -->3期时,工序安装完成,状态不再是“质检完成”而是“安装完成”
if (tr.getStatus().intValue() == Constant.TASK_QUALITY_DONE.intValue() || tr.getStatus().intValue() == Constant.TASK_INSTALLED.intValue() || tr.getStatus().intValue() == Constant.TASK_SKIP.intValue()) {
List<LinkDataModel> linkDataList = JSON.parseArray(pr.getLinkData(), LinkDataModel.class);
for (LinkDataModel item : linkDataList) {
if (String.valueOf(item.getFrom()).equals(String.valueOf(ndItem.getKey()))) {
for (NodeDataModel childNode : ndList) {
// 先找到子节点
if (childNode.getKey().equals(String.valueOf(item.getTo()))) {
// 找到子节点的所有父节点
boolean allParentFinished = true;
for (LinkDataModel parentOfChild : linkDataList) {
if (!allParentFinished) {
break;
}
if (String.valueOf(parentOfChild.getTo()).equals(childNode.getKey())) {
for (NodeDataModel parentOfChildNode : ndList) {
if (!allParentFinished) {
break;
}
if (String.valueOf(parentOfChild.getFrom()).equals(parentOfChildNode.getKey())) {
if (parentOfChildNode.getCategory() != null && (parentOfChildNode.getCategory().equals("Start") || parentOfChildNode.getCategory().equals("End"))) {
break;
}
// 3期质检,安装完成是真的“安装完成”。3期之前,安装完成时,状态是“质检完成”
if ((Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue() && Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_INSTALLED.intValue()) && Integer.valueOf(parentOfChildNode.getTaskStatus()) != Constant.TASK_SKIP.intValue()) {
allParentFinished = false;
}
}
}
}
}
// 子节点的所有父节点都已经完成,则更新子节点的状态
if (allParentFinished) {
// 如果子工序不是结束“End”
if (!"End".equals(childNode.getCategory())) {
if (Integer.valueOf(childNode.getTaskStatus()) < Constant.TASK_INSTALL_WAITING.intValue()) {
String dateStr = Utils.getFormatStringDate(new Date(), "yyyy-MM-dd HH:mm:ss");
childNode.setBeginTime(dateStr);
childNode.setTaskStatus(Constant.TASK_INSTALL_WAITING.toString());
List<TaskRecord> taskRecordList = taskRecordService.getTaskRecordData(null, prId);
for (TaskRecord record : taskRecordList) {
if (String.valueOf(record.getNodeKey().intValue()).equals(childNode.getKey())) {
record.setUpdateTime(new Date());
record.setStatus(Constant.TASK_INSTALL_WAITING);
taskRecordService.update(record);
// MQTT 通知下一道工序可以开始安装
ServerToClientMsg msg = new ServerToClientMsg();
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
// 找到工序对应的group_id
String taskName = record.getTaskName();
Condition condition = new Condition(Task.class);
condition.createCriteria().andCondition("task_name = ", taskName);
List<Task> taskList = taskService.findByCondition(condition);
if (taskList == null || taskList.size() <= 0) {
throw new RuntimeException();
}
mqttMessageHelper.sendToClient(Constant.S2C_TASK_INSTALL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
// 这个break需要去掉,因为存在多个子工序可以安装的情况
// break;
}
}
}
}
}
}
}
}
}
}
}
Boolean isFinished = true;
for (int i = 0; i < ndList.size() && isFinished; i++) {
// 开始和结束节点不考虑在内
if (ndList.get(i).getCategory() != null && (ndList.get(i).getCategory().equals("Start") || ndList.get(i).getCategory().equals("End"))) {
continue;
}
if (ndList.get(i).getTaskStatus() != null && (Integer.parseInt(ndList.get(i).getTaskStatus()) != Constant.TASK_QUALITY_DONE.intValue() && Integer.parseInt(ndList.get(i).getTaskStatus()) != Constant.TASK_INSTALLED.intValue())) {
isFinished = false;
}
}
// 所有工序完成
if (isFinished && (tr.getStatus() == Constant.TASK_QUALITY_DONE.intValue() || tr.getStatus() == Constant.TASK_INSTALLED.intValue())) {
pr.setEndTime(new Date());
// 安装完成
machine.setStatus(Constant.MACHINE_INSTALLED);
isNeedUpdateMachine = true;
}
if (machine.getStatus().equals(Constant.MACHINE_PLANING)) {
// 安装中
machine.setStatus(Constant.MACHINE_INSTALLING);
isNeedUpdateMachine = true;
}
if (isNeedUpdateMachine) {
machine.setUpdateTime(new Date());
machineService.update(machine);
}
pr.setNodeData(JSON.toJSONString(ndList));
processRecordService.update(pr);
return true;
} else {
return false;
}
}
}
use of com.eservice.api.model.machine_order.MachineOrder in project sinsim by WilsonHu.
the class CommonService method createMachineByContractId.
/**
* 根据合同编号对应的需求单的机器
* 目前 合同签核已经不存在了,即,只对订单进行签核。即应该已经不调用了。
*
* @param contractId
*/
public void createMachineByContractId(Integer contractId) {
Condition condition = new Condition(MachineOrder.class);
condition.createCriteria().andCondition("contract_id = ", contractId);
List<MachineOrder> orderList = machineOrderService.findByCondition(condition);
for (MachineOrder orderItem : orderList) {
// 选取有效需求单,无效需求单对应的机器数不cover在内
if (orderItem.getStatus().equals(Constant.ORDER_CHECKING_FINISHED) || orderItem.getStatus().equals(Constant.ORDER_SPLITED)) {
Condition tempCondition = new Condition(Machine.class);
tempCondition.createCriteria().andCondition("order_id = ", orderItem.getId());
List<Machine> machineExistList = machineService.findByCondition(tempCondition);
int haveToCreate = orderItem.getMachineNum() - machineExistList.size();
int i = 1;
while (i <= haveToCreate) {
Machine machine = new Machine();
machine.setMachineStrId(Utils.createMachineBasicId() + i);
machine.setOrderId(orderItem.getId());
machine.setMachineType(orderItem.getMachineType());
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_INITIAL)));
machine.setCreateTime(new Date());
machineService.save(machine);
i++;
}
}
}
}
Aggregations