use of com.eservice.api.model.task.Task in project sinsim by WilsonHu.
the class AbnormalRecordController method update.
@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String abnormalRecord) {
AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
abnormalRecord1.setSolveTime(new Date());
if (abnormalRecord1.getSolution() == null || abnormalRecord1.getSolution().isEmpty()) {
// abnormalRecord1.setSolution("空");
return ResultGenerator.genFailResult("请填写解决内容");
}
// 修改对应工序的状态为"安装中"或者“质检中”,需要检查安装开始时间和质检开始时间,质检已开始则状态为质检中
AbnormalRecord completeInfo = abnormalRecordService.findById(abnormalRecord1.getId());
Integer taskRecordId = completeInfo.getTaskRecordId();
if (taskRecordId != null && taskRecordId > 0) {
TaskRecord tr = taskRecordService.findById(taskRecordId);
// MQTT 异常解决后,通知工序的安装组长
String taskName = tr.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();
}
tr.setStatus(Constant.TASK_INSTALLING);
taskRecordService.update(tr);
// 更新task record状态时候,必须去更新process record中对应task的状态
commonService.updateTaskRecordRelatedStatus(tr);
ProcessRecord pr = processRecordService.findById(tr.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_INSTALL_ABNORMAL_RESOLVE + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
} else {
throw new RuntimeException();
}
abnormalRecordService.update(abnormalRecord1);
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.task.Task 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.task.Task in project sinsim by WilsonHu.
the class TaskRecordController method addTrTqrQri.
/**
* 3个表 task_record/TaskQualityRecord/QualityRecordImage 更新。
* app端,上传质检异常状态,task_record(update),增加 TaskQualityRecord(add), QualityRecordImage (add)
* 没有质检员了,这个接口没在用。
*/
@Transactional(rollbackFor = Exception.class)
@PostMapping("/addTrTqrQri")
public Result addTrTqrQri(@RequestParam String taskRecord, @RequestParam String taskQualityRecord, @RequestParam MultipartFile[] files) {
// task_record(update)
TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
taskRecordService.update(taskRecord1);
TaskQualityRecord taskQualityRecord1 = JSON.parseObject(taskQualityRecord, TaskQualityRecord.class);
// 质检异常类型,目前未使用,default值为1
taskQualityRecord1.setAbnormalType(1);
taskQualityRecordService.saveAndGetID(taskQualityRecord1);
// 获取保存后分配到的id
Integer taskQualityRecordId = taskQualityRecord1.getId();
// 构建 qualityRecordImage1
QualityRecordImage qualityRecordImage1 = new QualityRecordImage();
File dir = new File(qualityImagesSavedDir);
if (!dir.exists()) {
dir.mkdir();
}
String machineID = machineService.searchMachineByTaskQualityRecordId(taskQualityRecordId).getMachineStrId();
Integer orderId = machineService.searchMachineByTaskQualityRecordId(taskQualityRecordId).getOrderId();
String orderNum = machineOrderService.findById(orderId).getOrderNum();
List<String> listResultPath = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
try {
listResultPath.add(commonService.saveFile(qualityImagesSavedDir, files[i], machineID, orderNum, Constant.QUALITY_IMAGE, i));
} catch (IOException e) {
e.printStackTrace();
// 抛异常引发回滚,防止数据只更新了前面部分。
throw new RuntimeException();
}
}
if (listResultPath.size() != files.length) {
throw new RuntimeException();
} else {
qualityRecordImage1.setTaskQualityRecordId(taskQualityRecordId);
qualityRecordImage1.setImage(listResultPath.toString());
qualityRecordImage1.setCreateTime(taskQualityRecord1.getCreateTime());
qualityRecordImageService.save(qualityRecordImage1);
}
// 找到工序对应的quality_user_id
String taskName = taskRecord1.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();
}
Integer prId = taskRecord1.getProcessRecordId();
if (prId == null || prId < 0) {
Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
} else {
// Update task record相关的状态
if (!commonService.updateTaskRecordRelatedStatus(taskRecord1)) {
// 更新出错进行事务回退
throw new RuntimeException();
}
}
ProcessRecord pr = processRecordService.findById(prId);
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
if (taskRecord1.getStatus().equals(Constant.TASK_QUALITY_ABNORMAL)) {
// MQTT 发生质检异常时,通知安装组长以及生产部管理员
mqttMessageHelper.sendToClient(Constant.S2C_QUALITY_ABNORMAL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
}
return ResultGenerator.genSuccessResult("3个表 task_record + TaskQualityRecord + QualityRecordImage 更新成功");
}
use of com.eservice.api.model.task.Task in project sinsim by WilsonHu.
the class TaskRecordController method addTrArAi.
/**
* task_record, abnormal_record, abnormal_image 3个表一起更新。
* app端,在安装异常时需要更新task_record(update),增加 abnormal_record(add), abnormal_image (add)
*
* app扫码报异常时,调用addTrArAi (app报正常时,调用的是 updateTaskInfo, 少了异常记录和文件两个参数)
*/
@Transactional(rollbackFor = Exception.class)
@PostMapping("/addTrArAi")
public Result addTrArAi(@RequestParam String taskRecord, @RequestParam String abnormalRecord, @RequestParam MultipartFile[] files) {
// task_record(update)
TaskRecord taskRecord1 = JSON.parseObject(taskRecord, TaskRecord.class);
taskRecordService.update(taskRecord1);
// abnormal_record add:
AbnormalRecord abnormalRecord1 = JSON.parseObject(abnormalRecord, AbnormalRecord.class);
// 在安装异常时,并没有SolutionUser,即还不知道SolutionUser,所以这里设为null
abnormalRecord1.setSolutionUser(null);
// 在47服务器saveAndGetID执行成功,但是实际没有数据保存在数据库 --是因为数据库从5.7改为了最新的8,改回旧的mysql docker即可。
abnormalRecordService.saveAndGetID(abnormalRecord1);
// 获取保存后分配到的id
Integer abnormalRecordId = abnormalRecord1.getId();
// if(abnormalRecord1 !=null) {
// logger.info("abnormalRecordId: " + abnormalRecordId);
// AbnormalRecord abInserted = null;
// abInserted = abnormalRecordService.findById(abnormalRecordId);
// if(abInserted == null){
// logger.info("刚刚尝试插入的数据,却没有在数据库里找到");
//
// } else { logger.info("刚刚尝试插入的数据,却没有在数据库里找到");
// logger.info("刚刚尝试插入的数据,可以根据abnormalRecordId找到");
// }
// } else {
// logger.error("异常,生成 abnormalRecord1 为null");
// }
/**
* abnormal_image add
* 因为此时从app端无法知道 abnormal_record_id,所以需要在服务端获取abnormal_record_id
* abnormal_image的create_time和abnormal_record.create_time一样
*/
AbnormalImage abnormalImage1 = new AbnormalImage();
File dir = new File(imagesSavedDir);
if (!dir.exists()) {
dir.mkdir();
}
String machineID = machineService.searchMachineByAbnormalRecordId(abnormalRecordId).getMachineStrId();
Integer orderId = machineService.searchMachineByAbnormalRecordId(abnormalRecordId).getOrderId();
String orderNum = machineOrderService.findById(orderId).getOrderNum();
List<String> listResultPath = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
try {
listResultPath.add(commonService.saveFile(imagesSavedDir, files[i], machineID, orderNum, Constant.ABNORMAL_IMAGE, i));
} catch (IOException e) {
e.printStackTrace();
// 抛异常引发回滚,防止数据只更新了前面部分。
throw new RuntimeException();
}
}
if (listResultPath.size() != files.length) {
throw new RuntimeException();
} else {
abnormalImage1.setImage(listResultPath.toString());
abnormalImage1.setAbnormalRecordId(abnormalRecordId);
abnormalImage1.setCreateTime(abnormalRecord1.getCreateTime());
abnormalImageService.save(abnormalImage1);
}
// 找到工序对应的quality_user_id
String taskName = taskRecord1.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();
}
Integer prId = taskRecord1.getProcessRecordId();
if (prId == null || prId < 0) {
Logger.getLogger("").log(Level.INFO, "processrecord Id 为空");
} else {
// Update task record相关的状态
if (!commonService.updateTaskRecordRelatedStatus(taskRecord1)) {
// 更新出错进行事务回退
throw new RuntimeException();
}
}
ProcessRecord pr = processRecordService.findById(prId);
Machine machine = machineService.findById(pr.getMachineId());
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
if (taskRecord1.getStatus().equals(Constant.TASK_INSTALL_ABNORMAL)) {
// MQTT 发生安装异常时,通知生产部管理员
// mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL + taskList.get(0).getGroupId(), JSON.toJSONString(msg));
// MQTT 发生安装异常时,通知对应质检员
mqttMessageHelper.sendToClient(Constant.S2C_INSTALL_ABNORMAL_TO_QUALITY + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
}
// createInstallPlanActual(taskRecord1);
return ResultGenerator.genSuccessResult("3个表 task_record + abnormal_record + abnormal_image更新成功");
}
use of com.eservice.api.model.task.Task in project sinsim by WilsonHu.
the class TaskQualityRecordController method update.
/**
* web在提交解决方案时“在用”,但是因为 app没有在用, 即没有提交质检结果的地方。所以实际上没有作用。
* 三期采用新的质检体系,这些都不会再被用
*/
// /
@PostMapping("/update")
public Result update(String taskQualityRecord) {
TaskQualityRecord taskQualityRecord1 = JSON.parseObject(taskQualityRecord, TaskQualityRecord.class);
taskQualityRecord1.setSolveTime(new Date());
// 修改对应工序的状态为“质检中”
TaskQualityRecord completeInfo = taskQualityRecordService.findById(taskQualityRecord1.getId());
Integer taskRecordId = completeInfo.getTaskRecordId();
if (taskRecordId != null && taskRecordId > 0) {
TaskRecord tr = taskRecordService.findById(taskRecordId);
// MQTT 异常解决后,通知工序的质检员
String taskName = tr.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();
}
tr.setStatus(Constant.TASK_QUALITY_DOING);
taskRecordService.update(tr);
// 更新task record状态时候,必须去更新process record中对应task的状态
commonService.updateTaskRecordRelatedStatus(tr);
ProcessRecord pr = processRecordService.findById(tr.getProcessRecordId());
Machine machine = machineService.findById(pr.getMachineId());
ServerToClientMsg msg = new ServerToClientMsg();
MachineOrder machineOrder = machineOrderService.findById(machine.getOrderId());
msg.setOrderNum(machineOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
mqttMessageHelper.sendToClient(Constant.S2C_QUALITY_ABNORMAL_RESOLVE + taskList.get(0).getQualityUserId(), JSON.toJSONString(msg));
} else {
throw new RuntimeException();
}
taskQualityRecordService.update(taskQualityRecord1);
return ResultGenerator.genSuccessResult();
}
Aggregations