use of com.eservice.api.model.abnormal_image.AbnormalImage in project sinsim by WilsonHu.
the class AbnormalImageController method list.
@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
PageHelper.startPage(page, size);
List<AbnormalImage> list = abnormalImageService.findAll();
PageInfo pageInfo = new PageInfo(list);
return ResultGenerator.genSuccessResult(pageInfo);
}
use of com.eservice.api.model.abnormal_image.AbnormalImage in project sinsim by WilsonHu.
the class AbnormalImageController method add.
/**
* 增加abnormalImage时,也保存了图片,可以多张图片。
* @param abnormalImage
* @param files
* @return
*/
@PostMapping("/add")
public Result add(@RequestParam String abnormalImage, @RequestParam MultipartFile[] files) {
AbnormalImage abnormalImage1 = JSON.parseObject(abnormalImage, AbnormalImage.class);
Integer abnormalRecordId = abnormalImage1.getAbnormalRecordId();
File dir = new File(imagesSavedDir);
if (!dir.exists()) {
dir.mkdir();
}
String machineID = searchMachineByAbnormalRecordId(abnormalRecordId);
if (machineID == null) {
return ResultGenerator.genFailResult("Error: no machine found by the abnormalRecordId, no records saved");
}
List<String> listResultPath = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
try {
listResultPath.add(commonService.saveFile(imagesSavedDir, files[i], machineID, null, Constant.ABNORMAL_IMAGE, i));
} catch (IOException e) {
e.printStackTrace();
}
}
if (listResultPath.size() == 0) {
return ResultGenerator.genFailResult("failed to save file, no records saved");
} else {
abnormalImage1.setImage(listResultPath.toString());
abnormalImageService.save(abnormalImage1);
}
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.abnormal_image.AbnormalImage 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)
*/
@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);
abnormalRecordService.saveAndGetID(abnormalRecord1);
/**
* 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();
}
// 获取保存后分配到的id
Integer abnormalRecordId = abnormalRecord1.getId();
String machineID = machineService.searchMachineByAbnormalRecordId(abnormalRecordId).getMachineStrId();
List<String> listResultPath = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
try {
listResultPath.add(commonService.saveFile(imagesSavedDir, files[i], machineID, null, 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);
}
return ResultGenerator.genSuccessResult("3个表更新成功");
}
use of com.eservice.api.model.abnormal_image.AbnormalImage in project sinsim by WilsonHu.
the class AbnormalRecordController method updateAbnormalRecordDetail.
/**
* 根据传入的strAbnormalRecordDetail,更新对应多表:
* "machine_id":"", --> machine.machine_id
* "安装是否异常":"", --> task_record.status task状态,“1”==>未开始, “2”==>进行中,“3”==>安装完成, “4”==>质检完成,“5“===>异常
* "异常类型":"", --> abnormal_record.abnormal_type
* "异常原因":"", --> abnormal_record.comment
* "异常照片":"", -->abnormal_image.image
* "安装完成":"", --> task_record.status或machine.status都可以,反正这两个表都更新
* 注意:有外键的字段,需要上传实际存在的外键数据。
* 一项update失败的情况下,全部update无效(事务OK)
*
* @param strAbnormalRecordDetail
* @return
*/
@PostMapping("/updateAbnormalRecordDetail")
@Transactional
public Result updateAbnormalRecordDetail(@RequestParam String strAbnormalRecordDetail) {
// 获取整体detail
AbnormalRecordDetail abnormalRecordDetail1 = JSON.parseObject(strAbnormalRecordDetail, AbnormalRecordDetail.class);
Integer abnormalRecordDetail_ID = abnormalRecordDetail1.getId();
AbnormalRecord abnormalRecord = abnormalRecordService.findById(abnormalRecordDetail_ID);
abnormalRecord.setAbnormalType(abnormalRecordDetail1.getAbnormalType());
abnormalRecord.setTaskRecordId(abnormalRecordDetail1.getTaskRecordId());
abnormalRecord.setSubmitUser(abnormalRecordDetail1.getSubmitUser());
abnormalRecord.setSolutionUser(abnormalRecordDetail1.getSolutionUser());
abnormalRecord.setComment(abnormalRecordDetail1.getComment());
abnormalRecord.setSolution(abnormalRecordDetail1.getSolution());
Abnormal abnormal = abnormalRecordDetail1.getAbnormal();
AbnormalImage abnormalImage = abnormalRecordDetail1.getAbnormalImage();
TaskRecord taskRecord = abnormalRecordDetail1.getTaskRecord();
Machine machine = abnormalRecordDetail1.getMachine();
abnormalRecordService.update(abnormalRecord);
abnormalService.update(abnormal);
abnormalImageService.update(abnormalImage);
taskRecordService.update(taskRecord);
machineService.update(machine);
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.abnormal_image.AbnormalImage in project sinsim by WilsonHu.
the class AbnormalImageController method update.
@PostMapping("/update")
public Result update(String abnormalImage) {
AbnormalImage abnormalImage1 = JSON.parseObject(abnormalImage, AbnormalImage.class);
abnormalImageService.update(abnormalImage1);
return ResultGenerator.genSuccessResult();
}
Aggregations