123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657 |
- package com.ruoyi.project.pssr.controller;
- import com.alibaba.fastjson.JSON;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.file.ExcelUtils;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- import com.ruoyi.framework.aspectj.lang.annotation.Log;
- import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
- import com.ruoyi.framework.web.controller.BaseController;
- import com.ruoyi.framework.web.domain.AjaxResult;
- import com.ruoyi.framework.web.page.TableDataInfo;
- import com.ruoyi.project.listener.pssr.ConfirmTaskCreateListener;
- import com.ruoyi.project.pssr.domain.TPssrApprove;
- import com.ruoyi.project.pssr.domain.TPssrInstrumentCalibration;
- import com.ruoyi.project.pssr.domain.TPssrSubcontent;
- import com.ruoyi.project.pssr.domain.TPssrTurndown;
- import com.ruoyi.project.pssr.mapper.TPssrInstrumentCalibrationMapper;
- import com.ruoyi.project.pssr.service.*;
- import com.ruoyi.project.system.domain.SysDept;
- import com.ruoyi.project.system.domain.SysUser;
- import com.ruoyi.project.system.service.ISysDeptService;
- import com.ruoyi.project.system.service.ISysUserService;
- import org.activiti.engine.*;
- import org.activiti.engine.impl.identity.Authentication;
- import org.activiti.engine.runtime.ProcessInstance;
- import org.activiti.engine.task.Task;
- import org.apache.commons.collections4.CollectionUtils;
- import org.apache.poi.ss.usermodel.*;
- import org.apache.poi.xssf.usermodel.XSSFSheet;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import javax.annotation.Resource;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 仪表校验Controller
- *
- * @author ssy
- * @date 2024-09-18
- */
- @RestController
- @RequestMapping("/pssr/instrumentCalibration")
- public class TPssrInstrumentCalibrationController extends BaseController {
- @Autowired
- private ITPssrFileService tPssrFileService;
- @Resource
- private TPssrInstrumentCalibrationMapper tPssrInstrumentCalibrationMapper;
- @Autowired
- private ITPssrTurndownService tPssrTurndownService;
- @Autowired
- private ITPssrInstrumentCalibrationService tPssrInstrumentCalibrationService;
- @Autowired
- private ITPssrApproveService tPssrApproveService;
- @Autowired
- private ITPssrSubcontentService tPssrSubcontentService;
- @Autowired
- private ISysUserService sysUserService;
- private String forShort = "ybjy";
- @Autowired
- private ISysDeptService iSysDeptService;
- @Autowired
- private ISysUserService userService;
- @Autowired
- private RuntimeService runtimeService;
- @Autowired
- private HistoryService historyService;
- /**
- * 批量导入
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:add')")
- @PostMapping("/importData")
- public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException {
- //获取操作人员ID
- Long userId = getUserId();
- //报错行数统计
- List<Integer> failRow = new ArrayList<Integer>();
- Workbook workbook = ExcelUtils.getWorkBook(file);
- Sheet sheet = workbook.getSheetAt(0);
- List<TPssrInstrumentCalibration> list = new ArrayList<TPssrInstrumentCalibration>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- //部门查询
- List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
- int rowNum = sheet.getPhysicalNumberOfRows();
- int failNumber = 0;
- for (int i = 2; i <= rowNum; i++) {
- try {
- logger.info("读取行数:" + i);
- Row row = sheet.getRow(i);
- int cellNum = row.getLastCellNum();
- TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
- entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
- entity.setSubId(subId);
- entity.setApproveStatus(0L);
- for (int j = 0; j < cellNum; j++) {
- Cell cell = row.getCell(j);
- String cellValue = ExcelUtils.getCellValue(cell);
- logger.info("cellValue:" + cellValue);
- if (j == 0) {
- entity.setUnit(cellValue);
- } else if (j == 1) {
- entity.setDevNo(cellValue);
- } else if (j == 2) {
- if ("流量计".equals(cellValue)) {
- entity.setDevType("1");
- } else if ("调节阀".equals(cellValue)) {
- entity.setDevType("3");
- } else if ("液位计".equals(cellValue)) {
- entity.setDevType("2");
- }
- }
- }
- entity.setCreaterCode(userId.toString());
- logger.info("entity:" + entity);
- list.add(entity);
- } catch (Exception e) {
- failNumber++;
- failRow.add(i + 1);
- }
- }
- int successNumber = 0;
- int failNum = 0;
- for (TPssrInstrumentCalibration t : list
- ) {
- failNum++;
- try {
- this.add(t);
- successNumber++;
- } catch (Exception e) {
- failNumber++;
- logger.info("e:" + e);
- failRow.add(failNum + 1);
- }
- }
- logger.info("list:" + JSON.toJSONString(list));
- logger.info("successNumber:" + String.valueOf(successNumber));
- logger.info("failNumber:" + String.valueOf(failNumber));
- logger.info("failRow:" + String.valueOf(failRow));
- return AjaxResult.success("导入成功行数:" + String.valueOf(successNumber));
- }
- /**
- * 查询仪表校验列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:list')")
- @GetMapping("/list")
- public TableDataInfo list(TPssrInstrumentCalibration tPssrInstrumentCalibration) {
- try {
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(tPssrInstrumentCalibration.getSubId());
- if (approve != null) {
- ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
- TaskService taskService = processEngine.getTaskService();
- Task task = processEngine.getTaskService()//获取任务service
- .createTaskQuery()//创建查询对象
- .taskAssignee(getUserId().toString())
- .processInstanceId(approve.getProcessId()).singleResult();
- if (task != null) {
- if (task.getName().equals("确认人1")){
- tPssrInstrumentCalibration.setConfirm1(getUserId().toString());
- }else if (task.getName().equals("确认人2")){
- tPssrInstrumentCalibration.setConfirm2(getUserId().toString());
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error("待办确认人查询报错:{}",e.getMessage());
- }
- startPage();
- List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration);
- list.forEach(item -> {
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "ybjy"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "ybjy"));
- });
- return getDataTable(list);
- }
- /**
- * 导出仪表校验列表
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:export')")
- @Log(title = "仪表校验", businessType = BusinessType.EXPORT)
- @GetMapping("/export")
- public AjaxResult export(TPssrInstrumentCalibration tPssrInstrumentCalibration) {
- List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration);
- if (tPssrInstrumentCalibration.getDevType().equals("1")) {
- if (list.size() != 0) {
- return AjaxResult.success(exportTmpl3(list));
- } else {
- return AjaxResult.error("暂无可导出数据");
- }
- } else if (tPssrInstrumentCalibration.getDevType().equals("2")) {
- if (list.size() != 0) {
- return AjaxResult.success(exportTmpl2(list));
- } else {
- return AjaxResult.error("暂无可导出数据");
- }
- } else if (tPssrInstrumentCalibration.getDevType().equals("3")) {
- if (list.size() != 0) {
- return AjaxResult.success(exportTmpl1(list));
- } else {
- return AjaxResult.error("暂无可导出数据");
- }
- }
- return AjaxResult.error("导出失败,请联系管理员!");
- }
- public String exportTmpl1(List<TPssrInstrumentCalibration> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/ybjytjf.xlsx"; // 模板文件
- InputStream is = null;
- is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
- XSSFWorkbook wb = null;
- wb = new XSSFWorkbook(is);
- XSSFSheet sheet = wb.getSheetAt(0);
- //填充数据
- int rowIndex = 2;
- int num = 1;
- Row originalRow = sheet.getRow(2);
- Cell originalcell = originalRow.getCell(0);
- // 获取单元格样式
- CellStyle originalStyle = originalcell.getCellStyle();
- for (TPssrInstrumentCalibration t : list) {
- Row row = sheet.createRow(rowIndex);
- row.setHeight((short) 800);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getUnit());
- row.createCell(2).setCellValue(t.getDevNo());
- row.createCell(3).setCellValue(t.getVisualInspection());
- row.createCell(4).setCellValue(t.getFlowCheck());
- row.createCell(5).setCellValue(t.getFileCheck());
- row.createCell(6).setCellValue(t.getFunctionalCheck());
- row.createCell(7);
- row.createCell(8);
- try {
- SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
- SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
- String confirm1 = sysUser.getSignUrl();
- String confirm2 = sysUser2.getSignUrl();
- ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 7, 1, 1);
- ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 8, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(9).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
- row.createCell(10).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 11; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = "PSSR_23_仪表校验_调节阀" + ".xlsx";
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- public String exportTmpl2(List<TPssrInstrumentCalibration> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/ybjyywj.xlsx"; // 模板文件
- InputStream is = null;
- is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
- XSSFWorkbook wb = null;
- wb = new XSSFWorkbook(is);
- XSSFSheet sheet = wb.getSheetAt(0);
- //填充数据
- int rowIndex = 3;
- int num = 1;
- Row originalRow = sheet.getRow(3);
- Cell originalcell = originalRow.getCell(0);
- // 获取单元格样式
- CellStyle originalStyle = originalcell.getCellStyle();
- for (TPssrInstrumentCalibration t : list) {
- Row row = sheet.createRow(rowIndex);
- row.setHeight((short) 800);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getUnit());
- row.createCell(2).setCellValue(t.getDevNo());
- row.createCell(3).setCellValue(t.getVisualInspection());
- row.createCell(4).setCellValue(t.getInstallationInspection());
- row.createCell(5).setCellValue(t.getFunctionalCheck());
- row.createCell(6);
- row.createCell(7);
- try {
- SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
- SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
- String confirm1 = sysUser.getSignUrl();
- String confirm2 = sysUser2.getSignUrl();
- ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
- ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 7, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(8).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
- row.createCell(9).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 10; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = "PSSR_23_仪表校验_液位计" + ".xlsx";
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- public String exportTmpl3(List<TPssrInstrumentCalibration> list) {
- OutputStream out = null;
- String filename = null;
- try {
- String tempUrl = "static/word/pssr/ybjyllj.xlsx"; // 模板文件
- InputStream is = null;
- is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
- XSSFWorkbook wb = null;
- wb = new XSSFWorkbook(is);
- XSSFSheet sheet = wb.getSheetAt(0);
- //填充数据
- int rowIndex = 2;
- int num = 1;
- Row originalRow = sheet.getRow(2);
- Cell originalcell = originalRow.getCell(0);
- // 获取单元格样式
- CellStyle originalStyle = originalcell.getCellStyle();
- for (TPssrInstrumentCalibration t : list) {
- Row row = sheet.createRow(rowIndex);
- row.setHeight((short) 800);
- row.createCell(0).setCellValue(num);
- row.createCell(1).setCellValue(t.getUnit());
- row.createCell(2).setCellValue(t.getDevNo());
- row.createCell(3).setCellValue(t.getVisualInspection());
- row.createCell(4).setCellValue(t.getInstallationInspection());
- row.createCell(5).setCellValue(t.getFunctionalCheck());
- row.createCell(6);
- row.createCell(7);
- try {
- SysUser sysUser = sysUserService.selectUserById(Long.valueOf(t.getConfirm1()));
- SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(t.getConfirm2()));
- String confirm1 = sysUser.getSignUrl();
- String confirm2 = sysUser2.getSignUrl();
- ExcelUtils.insertPicture(wb, sheet, confirm1, row.getRowNum(), 6, 1, 1);
- ExcelUtils.insertPicture(wb, sheet, confirm2, row.getRowNum(), 7, 1, 1);
- } catch (NumberFormatException e) {
- throw new RuntimeException(e);
- }
- row.createCell(8).setCellValue(DateUtils.dateTime(t.getConfirmationDate()));
- row.createCell(9).setCellValue(t.getRemarks());
- //渲染样式
- for (int i = 0; i < 10; i++) {
- row.getCell(i).setCellStyle(originalStyle);
- }
- num++;
- rowIndex++;
- }
- filename = "PSSR_23_仪表校验_流量计" + ".xlsx";
- out = new FileOutputStream(ExcelUtil.getAbsoluteFile(filename));
- wb.write(out);
- wb.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return filename;
- }
- /**
- * 获取仪表校验详细信息
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:query')")
- @GetMapping(value = "/{id}")
- public AjaxResult getInfo(@PathVariable("id") Long id) {
- TPssrInstrumentCalibration item = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(id);
- item.setFileList(tPssrFileService.selectTPssrFileListByItem(item.getSubId(), item.getId(), "ybjy"));
- if (item.getApproveStatus() != 2)
- item.setReason(tPssrTurndownService.selectTPssrTurndownByItem(item.getSubId(), item.getId(), "ybjy"));
- return AjaxResult.success(item);
- }
- /**
- * 新增仪表校验
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:add')")
- @Log(title = "仪表校验", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
- if (StringUtils.isNotEmpty(tPssrInstrumentCalibration.getConfirm1()) && tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- tPssrInstrumentCalibration.setApproveStatus(0L);
- return toAjax(insertOrUpdate(tPssrInstrumentCalibration));
- }
- //导入时判断更新或新增
- private int insertOrUpdate(TPssrInstrumentCalibration item) {
- TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
- entity.setSubId(item.getSubId());
- entity.setDevNo(item.getDevNo());
- List<TPssrInstrumentCalibration> list = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(entity);
- if (CollectionUtils.isNotEmpty(list)) {
- item.setId(list.get(0).getId());
- return tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
- } else {
- return tPssrInstrumentCalibrationService.insertTPssrInstrumentCalibration(item);
- }
- }
- /**
- * 修改仪表校验
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
- @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
- TPssrInstrumentCalibration entity = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(tPssrInstrumentCalibration.getId());
- if (entity.getApproveStatus() != 1 && entity.getApproveStatus() != 0) {
- return AjaxResult.error("当前状态不可修改!");
- }
- if (tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- tPssrFileService.updateFileRelevance(tPssrInstrumentCalibration.getFileIds(), "ybjy", tPssrInstrumentCalibration.getId(), tPssrInstrumentCalibration.getSubId());
- return toAjax(tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(tPssrInstrumentCalibration));
- }
- /**
- * 修改仪表校验
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
- @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
- @PutMapping("/editBatch")
- public AjaxResult editb(@RequestBody TPssrInstrumentCalibration tPssrInstrumentCalibration) {
- if (tPssrInstrumentCalibration.getConfirm1().equals(tPssrInstrumentCalibration.getConfirm2())) {
- return AjaxResult.error("确认人不能为同一人,请重新选择!");
- }
- return toAjax(tPssrInstrumentCalibrationMapper.updateTPssrInstrumentCalibrationByIds(tPssrInstrumentCalibration));
- }
- /**
- * 删除仪表校验
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:remove')")
- @Log(title = "仪表校验", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids) {
- return toAjax(tPssrInstrumentCalibrationService.deleteTPssrInstrumentCalibrationByIds(ids));
- }
- /**
- * 确认仪表校验
- */
- @PreAuthorize("@ss.hasPermi('pssr:instrumentCalibration:edit')")
- @Log(title = "仪表校验", businessType = BusinessType.UPDATE)
- @PutMapping("/confirmInstrumentCalibration")
- public AjaxResult confirmInstrumentCalibration(@RequestBody TPssrInstrumentCalibration
- tPssrInstrumentCalibration) {
- long queryStatus = 0;
- long approveStatus = 0;
- Date date = null;
- TPssrInstrumentCalibration lock = new TPssrInstrumentCalibration();
- if (tPssrInstrumentCalibration.getTaskType() == 4) {
- //拆锁确认
- queryStatus = 1;
- approveStatus = 3;
- lock.setConfirm1(getUserId().toString());
- date = new Date();
- } else if (tPssrInstrumentCalibration.getTaskType() == 5) {
- //上锁确认
- queryStatus = 3;
- approveStatus = 2;
- lock.setConfirm2(getUserId().toString());
- date = new Date();
- }
- // 修改状态
- if (tPssrInstrumentCalibration.getIds() != null && tPssrInstrumentCalibration.getIds().length > 0) {
- for (Long id : tPssrInstrumentCalibration.getIds()) {
- TPssrInstrumentCalibration item = tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationById(id);
- item.setApproveStatus(approveStatus);
- if (queryStatus == 3) {
- item.setConfirmationDate(date);
- }
- tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
- }
- } else {
- lock.setSubId(tPssrInstrumentCalibration.getSubId());
- lock.setApproveStatus(queryStatus);
- lock.setDevType(tPssrInstrumentCalibration.getDevType());
- for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(lock)) {
- if (queryStatus == 3) {
- item.setConfirmationDate(date);
- }
- item.setApproveStatus(approveStatus);
- tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);
- }
- }
- //查询当前待审批的确认人
- TPssrInstrumentCalibration entity = new TPssrInstrumentCalibration();
- entity.setSubId(tPssrInstrumentCalibration.getSubId());
- entity.setApproveStatus(queryStatus);
- for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(entity)) {
- if (tPssrInstrumentCalibration.getTaskType() == 4) {
- if (item.getConfirm1().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- } else if (tPssrInstrumentCalibration.getTaskType() == 5) {
- if (item.getConfirm2().equals(getUserId().toString())) {
- return AjaxResult.success();
- }
- }
- }
- //无待审批任务结束当前用户流程
- // 因为流程关系所以approve一定会有且只有一条数据
- TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(tPssrInstrumentCalibration.getSubId());
- TPssrApproveController.handleConfirmApprove(tPssrApprove, getUserId().toString());
- return AjaxResult.success();
- }
- /**
- * 驳回仪表校验
- */
- @PutMapping("/turnDownInstrumentCalibration")
- public AjaxResult turnDownInstrumentCalibration
- (@RequestBody List<TPssrInstrumentCalibration> tPssrInstrumentCalibration) {
- if (CollectionUtils.isNotEmpty(tPssrInstrumentCalibration)) {
- String userId = getUserId().toString();
- Long subId = tPssrInstrumentCalibration.get(0).getSubId();
- // 修改已选择数据的状态
- for (TPssrInstrumentCalibration item : tPssrInstrumentCalibration) {
- TPssrInstrumentCalibration blind = new TPssrInstrumentCalibration();
- blind.setId(item.getId());
- blind.setApproveStatus(1L);
- blind.setUpdatedate(new Date());
- blind.setUpdaterCode(getUserId().toString());
- tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(blind);
- // 新增驳回原因数据
- TPssrTurndown turndown = new TPssrTurndown();
- turndown.setForShort(forShort);
- turndown.setSubId(item.getSubId());
- turndown.setItemId(item.getId());
- turndown.setReason(item.getReason());
- turndown.setCreatedate(new Date());
- turndown.setCreaterCode(getUserId().toString());
- tPssrTurndownService.insertTPssrTurndown(turndown);
- }
- // 查询当前流程
- TPssrApprove approve = tPssrApproveService.selectTPssrApproveBySubId(subId);
- try {
- runtimeService.deleteProcessInstance(approve.getProcessId(), "pssr2confirm");
- historyService.deleteHistoricProcessInstance(approve.getProcessId());
- } catch (Exception e) {
- logger.info("无运行时流程");
- }
- // 驳回 查询所有待审批的人员
- TPssrInstrumentCalibration blind = new TPssrInstrumentCalibration();
- blind.setSubId(subId);
- blind.setApproveStatus(1L);
- Set<String> installer = new HashSet<>();
- Set<String> remover = new HashSet<>();
- for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(blind)) {
- // 安装人员
- installer.add(item.getConfirm1());
- //拆除人员
- remover.add(item.getConfirm2());
- }
- //处理流程节点
- // 开始申请流程
- long businessKey = approve.getApproveId();
- //开始工作流、监听
- Authentication.setAuthenticatedUserId(userId);//设置当前申请人
- Map<String, Object> variables = new HashMap<>();
- variables.put("applyUser", userId);
- variables.put("confirmUsers1", installer);
- variables.put("confirmUsers2", remover);
- variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
- variables.put("chargePerson", approve.getSubCharge());
- //采用key来启动流程定义并设置流程变量,返回流程实例
- ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr2confirm", String.valueOf(businessKey), variables);
- approve.setProcessId(pi.getProcessInstanceId());
- tPssrApproveService.updateTPssrApprove(approve);
- // 修改审批表和sub表
- approve.setApproveStatus(1L);
- approve.setUpdatedate(new Date());
- approve.setUpdaterCode(getUserId().toString());
- tPssrApproveService.updateTPssrApprove(approve);
- TPssrSubcontent subcontent = new TPssrSubcontent();
- subcontent.setId(approve.getSubId());
- subcontent.setApproveStatus(1L);
- subcontent.setUpdatedate(new Date());
- subcontent.setUpdaterCode(getUserId().toString());
- tPssrSubcontentService.updateTPssrSubcontent(subcontent);
- return AjaxResult.success();
- }
- return AjaxResult.error();
- }
- }
|