/* * Copyright (c) 2018-2025, ztt All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the pig4cloud.com developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: ztt */ package com.chinaztt.mes.technology.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.read.builder.ExcelReaderBuilder; import com.alibaba.excel.read.metadata.ReadSheet; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.chinaztt.mes.basic.util.DictUtils; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.mes.technology.dto.RoutingDTO; import com.chinaztt.mes.technology.dto.RoutingOperationDTO; import com.chinaztt.mes.technology.entity.RoutingOperationTemplate; import com.chinaztt.mes.technology.excel.RoutingData; import com.chinaztt.mes.technology.excel.RoutingExcelData; import com.chinaztt.mes.technology.excel.RoutingFormUploadListener; import com.chinaztt.mes.technology.excel.RoutingUploadListener; import com.chinaztt.mes.technology.service.RoutingService; import com.chinaztt.ztt.common.core.util.R; import com.chinaztt.ztt.common.log.annotation.SysLog; import com.chinaztt.ztt.common.security.annotation.Inner; import com.chinaztt.ztt.common.security.service.ZttUser; import com.chinaztt.ztt.common.security.util.SecurityUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; /** * 工艺 * * @author zhangxy * @date 2020-08-19 09:36:29 */ @RestController @AllArgsConstructor @RequestMapping("/routing") @Api(value = "routing", tags = "工艺管理") public class RoutingController { private final RoutingService routingService; private final DictUtils dictUtils; /** * 工序详情 * * @param operationId * @param routingOperationId * @return */ @ApiOperation(value = "工序详情", notes = "工序详情") @GetMapping("/operationDetail") @PreAuthorize("@pms.hasPermission('technology_routing_view')") public R operationDetail(Long operationId, Long routingOperationId) { return R.ok(routingService.operationDetail(operationId, routingOperationId)); } /** * 分页查询 * * @param page 分页对象 * @param routing 工艺 * @return */ @ApiOperation(value = "分页查询", notes = "分页查询") @GetMapping("/page") @PreAuthorize("@pms.hasPermission('technology_routing_view')") public R getRoutingPage(Page page, RoutingDTO routing) { return R.ok(routingService.getPage(page, QueryWrapperUtil.gen(routing))); } /** * 修改工作中心 * * @param * @return R */ @ApiOperation(value = "修改工作中心", notes = "修改工作中心") @SysLog("修改工作中心") @PostMapping("/routingOperationChange") public R routingOperationChange(@RequestBody RoutingOperationDTO routingOperation) { return R.ok(routingService.routingOperationChange(routingOperation)); } /** * 通过id查询工艺 * * @param id id * @return R */ @ApiOperation(value = "通过id查询", notes = "通过id查询") @GetMapping("/{id}") @PreAuthorize("@pms.hasPermission('technology_routing_view')") public R getById(@PathVariable("id") Long id) { return R.ok(routingService.getRoutingById(id)); } /** * 批量对接IFS * * @param ids * @return R */ @ApiOperation(value = "批量对接IFS", notes = "批量对接IFS") @PostMapping("/routingIfsSync") public R routingIfsSync(@RequestBody List ids) { return R.ok(routingService.routingIfsSync(ids)); } /** * 工艺路线替代提前计算 * * @param ids * @return R */ @ApiOperation(value = "工艺路线替代提前计算", notes = "工艺路线替代提前计算") @PostMapping("/routingIfsCal") public R routingIfsCal(@RequestBody List ids) { return R.ok(routingService.routingIfsCal(ids)); } /** * 新增工艺 * * @param routing 工艺 * @return R */ @ApiOperation(value = "新增工艺", notes = "新增工艺") @SysLog("新增工艺") @PostMapping @PreAuthorize("@pms.hasPermission('technology_routing_add')") public R save(@RequestBody RoutingDTO routing) { return R.ok(routingService.fullSave(routing)); } /** * 修改工艺 * * @param routing 工艺 * @return R */ @ApiOperation(value = "修改工艺", notes = "修改工艺") @SysLog("修改工艺") @PutMapping @PreAuthorize("@pms.hasPermission('technology_routing_edit')") public R updateById(@RequestBody RoutingDTO routing) { return R.ok(routingService.fullUpdate(routing)); } /** * 通过id删除工艺 * * @param ids ids * @return R */ @ApiOperation(value = "通过id删除工艺", notes = "通过id删除工艺") @SysLog("通过id删除工艺") @DeleteMapping @PreAuthorize("@pms.hasPermission('technology_routing_del')") public R removeById(@RequestBody List ids) { return R.ok(routingService.removeByIds(ids)); } /** * 批准、作废 * * @param id * @return */ @ApiOperation(value = "更改状态", notes = "更改状态") @SysLog("更改状态") @PostMapping("/state/{id}/{event}") @PreAuthorize("@pms.hasPermission('technology_routing_edit')") public R changeState(@PathVariable Long id, @PathVariable String event) { return routingService.changeState(id, event); } /** * 批准、作废 * * @param * @return */ @ApiOperation(value = "更改状态", notes = "更改状态") @SysLog("更改状态") @PostMapping("/state/{event}") public R changeState(@RequestBody List ids, @PathVariable String event) { return R.ok(routingService.changeState(ids, event)); } /** * 根据工艺id和工序id获取复制的工序模板 * * @param routingDTO * @return */ @ApiOperation(value = "根据工艺id和工序id获取复制的工序模板", notes = "根据工艺id和工序id获取复制的工序模板") @GetMapping("/routingTemplate") public R getOperationTemplate(RoutingDTO routingDTO) { return R.ok(routingService.getOperationTemplate(routingDTO)); } /** * 获取工艺工序参数集 * * @param page * @param routingOperationTemplate * @return */ @ApiOperation(value = "获取工艺工序参数集", notes = "获取工艺工序参数集") @GetMapping("/routingOperationTemplate/page") public R getRoutingOperationTemplatePage(Page page, RoutingOperationTemplate routingOperationTemplate) { return R.ok(routingService.getRoutingOperationTemplatePage(page, QueryWrapperUtil.gen(routingOperationTemplate))); } /** * 根据工艺工序id和工序模板id获取工序参数 * * @param routingDTO * @return */ @ApiOperation(value = "根据工艺工序id和工序模板id获取工序参数", notes = "根据工艺工序id和工序模板id获取工序参数") @GetMapping("/routingTemplateParam") public R getOperationTemplateParam(RoutingDTO routingDTO) { return R.ok(routingService.getOperationTemplateParam(routingDTO)); } /** * 复制工艺路线 * * @param routing 工艺 * @return R */ @ApiOperation(value = "复制工艺路线", notes = "复制工艺路线") @SysLog("复制工艺路线") @PostMapping("/copy") public R copyRoutingSave(@RequestBody List routing) { return routingService.copyRoutingSave(routing); } /** * 根据工艺工序id关联添加工序模板 * * @param routingDTO * @return */ @ApiOperation(value = "根据工艺工序id关联添加工序模板", notes = "根据工艺工序id关联添加工序模板") @PostMapping("/addRoutingTemplate") public R addOperationTemplate(@RequestBody RoutingDTO routingDTO) { return R.ok(routingService.addOperationTemplate(routingDTO)); } /** * 根据复制工序模板的id删除工序模板 * * @param id * @return */ @ApiOperation(value = "根据复制工序模板的id删除工序模板", notes = "根据复制工序模板的id删除工序模板") @DeleteMapping("/deleteRoutingTemplate/{id}") public R deleteOperationTemplate(@PathVariable Long id) { return R.ok(routingService.deleteOperationTemplate(id)); } /** * 根据工艺工序id和工序模板id关联添加工序参数 * * @param routingDTO * @return */ @ApiOperation(value = "根据工艺工序id和工序模板id关联添加工序参数", notes = "根据工艺工序id和工序模板id关联添加工序参数") @PostMapping("/addRoutingTemplateParam") public R addOperationTemplateParam(@RequestBody RoutingDTO routingDTO) { return R.ok(routingService.addOperationTemplateParam(routingDTO)); } /** * 根据复制工序参数的id删除工序参数 * * @param id * @return */ @ApiOperation(value = "根据复制工序参数的id删除工序参数", notes = "根据复制工序参数的id删除工序参数") @DeleteMapping("/deleteRoutingTemplateParam/{id}") public R deleteOperationTemplateParam(@PathVariable Long id) { return R.ok(routingService.deleteOperationTemplateParam(id)); } /** * 工序参数的参数值的修改 * * @param routing 工艺 * @return R */ @ApiOperation(value = "工序参数的参数值的修改", notes = "工序参数的参数值的修改") @SysLog("工序参数的参数值的修改") @PutMapping("routingTemplateParam") public R updateRoutingTemplateParamById(@RequestBody RoutingDTO routing) { return routingService.updateRoutingTemplateParamById(routing); } /** * excel上传 * * @return */ @PostMapping("/uploadExcel") public R uploadExcel(@RequestParam("file") MultipartFile file) { ZttUser currentUser = SecurityUtils.getUser(); System.out.println(currentUser); //初始化监听器 RoutingFormUploadListener routingFormUploadListener = new RoutingFormUploadListener(routingService); HashMap result = new HashMap<>(); try { ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream()); ExcelReader excelReader = excelReaderBuilder.build(); List sheets = excelReader.excelExecutor().sheetList(); List readSheetList = new ArrayList<>(); for (ReadSheet sheet : sheets) { ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(new RoutingFormUploadListener(routingService)).build(); readSheetList.add(readSheet); } excelReader.read(readSheetList); // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的 excelReader.finish(); } catch (IOException e) { e.printStackTrace(); return R.failed(e.getMessage()); } return R.ok(); } /** * 竖着导入 * * @param file * @return */ @PostMapping("/upload") public R simpleRead(@RequestParam("file") MultipartFile file) { ExcelReader excelReader = null; try { excelReader = EasyExcel.read(file.getInputStream(), RoutingExcelData.class, new RoutingUploadListener(routingService, dictUtils)).build(); ReadSheet readSheet = EasyExcel.readSheet(0).build(); excelReader.read(readSheet); } catch (IOException e) { e.printStackTrace(); return R.failed(e.getMessage()); } finally { if (excelReader != null) { // 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的 excelReader.finish(); } } return R.ok(); } /** * 查询模板与参数 * * @param routingOperationId * @return */ @GetMapping("/templateAndParam/{routingOperationId}") public R getOperationTemplateAndParam(@PathVariable Long routingOperationId) { return routingService.getOperationTemplateAndParam(routingOperationId); } /** * 导入模板下载 * * @return */ @ApiOperation(value = "导入模板下载", notes = "导入模板下载") @GetMapping("/exportModel") public void exportModel(HttpServletResponse response) throws IOException { routingService.exportModel(response); } /** * 根据工艺文件id和工序id查询工艺路线 * * @param documentId * @param operationId * @return */ @GetMapping("/getRoutingByDocumentIdAndOperationId") public R getRoutingByDocumentIdAndOperationId(Long documentId, Long operationId) { return R.ok(routingService.getRoutingByDocumentIdAndOperationId(documentId, operationId)); } }