| | |
| | | import com.aps.common.log.annotation.Log; |
| | | import com.aps.common.log.enums.BusinessType; |
| | | import com.aps.common.security.annotation.RequiresPermissions; |
| | | import com.aps.common.security.utils.DictUtils; |
| | | import com.aps.core.domain.ApsShop; |
| | | import com.aps.core.domain.ApsStandardProcess; |
| | | import com.aps.core.service.IApsShopService; |
| | | import com.aps.core.service.IApsStandardProcessService; |
| | | import com.aps.system.api.domain.SysDictData; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.SneakyThrows; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.ss.usermodel.WorkbookFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ByteArrayResource; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 标准工序Controller |
| | | * |
| | | * |
| | | * @author hjy |
| | | * @date 2025-04-23 |
| | | */ |
| | | |
| | | |
| | | @Tag(name = "标准工序", description = "标准工序接口") |
| | | @RestController |
| | | @RequestMapping("/standardProcess") |
| | | public class ApsStandardProcessController extends BaseController |
| | | { |
| | | public class ApsStandardProcessController extends BaseController { |
| | | @Autowired |
| | | private IApsStandardProcessService apsStandardProcessService; |
| | | |
| | | @Autowired |
| | | IApsShopService apsShopService; |
| | | |
| | | /** |
| | | * 查询标准工序列表 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:list") |
| | | @Operation(summary = "查询标准工序列表", description = "分页查询") |
| | | @RequiresPermissions("aps:standardProcess:list") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(ApsStandardProcess apsStandardProcess) |
| | | { |
| | | public TableDataInfo list(ApsStandardProcess apsStandardProcess) { |
| | | startPage(); |
| | | List<ApsStandardProcess> list = apsStandardProcessService.selectApsStandardProcessList(apsStandardProcess); |
| | | List<ApsShop> apsShops = apsShopService.findShopByCodes(list.stream().map(ApsStandardProcess::getWorkShop) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet())); |
| | | list.forEach(temp -> { |
| | | temp.setWorkShop(apsShops.stream() |
| | | .filter(tempShop -> Objects.equals(tempShop.getShopCode(), temp.getWorkShop())) |
| | | .map(ApsShop::getShopName) |
| | | .findFirst() |
| | | .orElse(null)); |
| | | }); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 导出标准工序列表 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:export") |
| | | @Operation(summary = "导出标准工序列表", description = "导出Excel") |
| | | @RequiresPermissions("aps:standardProcess:export") |
| | | @Log(title = "标准工序", businessType = BusinessType.EXPORT) |
| | | @PostMapping("/export") |
| | | public void export(HttpServletResponse response, ApsStandardProcess apsStandardProcess) |
| | | { |
| | | public void export(HttpServletResponse response, ApsStandardProcess apsStandardProcess) { |
| | | List<ApsStandardProcess> list = apsStandardProcessService.selectApsStandardProcessList(apsStandardProcess); |
| | | ExcelUtil<ApsStandardProcess> util = new ExcelUtil<ApsStandardProcess>(ApsStandardProcess.class); |
| | | util.exportExcel(response, list, "标准工序数据"); |
| | |
| | | /** |
| | | * 获取标准工序详细信息 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:query") |
| | | @Operation(summary = "获取标准工序详细信息", description = "根据id获取") |
| | | @RequiresPermissions("aps:standardProcess:query") |
| | | @GetMapping(value = "/{id}") |
| | | public AjaxResult getInfo(@PathVariable("id") Long id) |
| | | { |
| | | public AjaxResult getInfo(@PathVariable("id") Long id) { |
| | | return success(apsStandardProcessService.selectApsStandardProcessById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 新增标准工序 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:add") |
| | | @Operation(summary = "新增标准工序", description = "单个增加") |
| | | @RequiresPermissions("aps:standardProcess:add") |
| | | @Log(title = "标准工序", businessType = BusinessType.INSERT) |
| | | @PostMapping |
| | | public AjaxResult add(@RequestBody ApsStandardProcess apsStandardProcess) |
| | | { |
| | | public AjaxResult add(@RequestBody ApsStandardProcess apsStandardProcess) { |
| | | return toAjax(apsStandardProcessService.insertApsStandardProcess(apsStandardProcess)); |
| | | } |
| | | |
| | | /** |
| | | * 修改标准工序 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:edit") |
| | | @Operation(summary = "修改标准工序", description = "单个修改") |
| | | @RequiresPermissions("aps:standardProcess:edit") |
| | | @Log(title = "标准工序", businessType = BusinessType.UPDATE) |
| | | @PutMapping |
| | | public AjaxResult edit(@RequestBody ApsStandardProcess apsStandardProcess) |
| | | { |
| | | public AjaxResult edit(@RequestBody ApsStandardProcess apsStandardProcess) { |
| | | return toAjax(apsStandardProcessService.updateApsStandardProcess(apsStandardProcess)); |
| | | } |
| | | |
| | | /** |
| | | * 删除标准工序 |
| | | */ |
| | | @RequiresPermissions("core:standardProcess:remove") |
| | | @Operation(summary = "删除标准工序", description = "批量删除") |
| | | @RequiresPermissions("aps:standardProcess:remove") |
| | | @Log(title = "标准工序", businessType = BusinessType.DELETE) |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult remove(@PathVariable Long[] ids) |
| | | { |
| | | @DeleteMapping("/{ids}") |
| | | public AjaxResult remove(@PathVariable Long[] ids) { |
| | | return toAjax(apsStandardProcessService.deleteApsStandardProcessByIds(ids)); |
| | | } |
| | | |
| | | /** |
| | | * 导入标准工序数据 |
| | | */ |
| | | @Operation(summary = "导入标准工序数据", description = "增量导入") |
| | | // @RequiresPermissions("aps:standardProcess:importData") |
| | | @PostMapping("/importData") |
| | | public AjaxResult importData(MultipartFile file) throws Exception { |
| | | ExcelUtil<ApsStandardProcess> util = new ExcelUtil<>(ApsStandardProcess.class); |
| | | List<ApsStandardProcess> tempList = util.importExcel(file.getInputStream()); |
| | | //判断导入数据是否为空 |
| | | if (!tempList.isEmpty()) { |
| | | Boolean res = apsStandardProcessService.importData(tempList); |
| | | if (res) { |
| | | return AjaxResult.success("导入成功!"); |
| | | } else { |
| | | return AjaxResult.error("导入失败!"); |
| | | } |
| | | } else { |
| | | return AjaxResult.error("模板内容为空"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据车间查询标准工序列表 |
| | | */ |
| | | @Operation(summary = "根据车间查询标准工序列表", description = "全量查询") |
| | | @RequiresPermissions("aps:standardProcess:listByWorkShop") |
| | | @GetMapping("/listByWorkShop") |
| | | public TableDataInfo listByWorkShop(ApsStandardProcess apsStandardProcess) { |
| | | List<ApsStandardProcess> list = apsStandardProcessService.selectApsStandardProcessList(apsStandardProcess); |
| | | return getDataTable(list); |
| | | } |
| | | |
| | | /** |
| | | * 下载标准工序数据导入模板 |
| | | */ |
| | | @SneakyThrows |
| | | @Operation(summary = "下载标准工序数据导入模板", description = "下载标准工序数据导入模板") |
| | | // @RequiresPermissions("gasPipeline:prediction:template") |
| | | // @Log(title = "下载气体预测数据导入模板", businessType = BusinessType.EXPORT) |
| | | @GetMapping("/template") |
| | | public ResponseEntity<ByteArrayResource> exportTemplate() { |
| | | byte[] file = IOUtils.resourceToByteArray("/templates/标准工序数据模板v1.0.xlsx"); |
| | | Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(file)); |
| | | Sheet sheet = workbook.getSheet("字典-工厂"); |
| | | List<SysDictData> sysDictDataList = DictUtils.getDictCache("aps_factory"); |
| | | boolean changed = false; |
| | | if (sysDictDataList != null) { |
| | | for (int i = 0; i < sysDictDataList.size(); i++) { |
| | | Row row = sheet.createRow(i + 1); |
| | | row.createCell(0).setCellValue(sysDictDataList.get(i).getDictValue()); |
| | | row.createCell(1).setCellValue(sysDictDataList.get(i).getDictLabel()); |
| | | } |
| | | |
| | | sheet = workbook.getSheet("字典-车间"); |
| | | List<ApsShop> shops = apsShopService.findAllShops(); |
| | | for (int i = 0; i < shops.size(); i++) { |
| | | Row row = sheet.createRow(i + 1); |
| | | ApsShop shop = shops.get(i); |
| | | row.createCell(0).setCellValue(sysDictDataList |
| | | .stream() |
| | | .filter(d -> d.getDictValue().equals(shop.getPlantCode())) |
| | | .map(SysDictData::getDictLabel) |
| | | .findFirst() |
| | | .orElse(null)); |
| | | row.createCell(1).setCellValue(shops.get(i).getShopCode()); |
| | | row.createCell(2).setCellValue(shops.get(i).getShopName()); |
| | | } |
| | | changed = true; |
| | | } |
| | | sheet = workbook.getSheet("字典-专业"); |
| | | sysDictDataList = DictUtils.getDictCache("aps_domain"); |
| | | if (sysDictDataList != null) { |
| | | for (int i = 0; i < sysDictDataList.size(); i++) { |
| | | Row row = sheet.createRow(i + 1); |
| | | row.createCell(0).setCellValue(sysDictDataList.get(i).getDictValue()); |
| | | row.createCell(1).setCellValue(sysDictDataList.get(i).getDictLabel()); |
| | | } |
| | | |
| | | changed = true; |
| | | } |
| | | if (changed) { |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | workbook.write(baos); |
| | | file = baos.toByteArray(); |
| | | } |
| | | workbook.close(); |
| | | ByteArrayResource resource = new ByteArrayResource(file); |
| | | return ResponseEntity.ok() |
| | | .header("Access-Control-Expose-Headers", HttpHeaders.CONTENT_DISPOSITION) |
| | | .header(HttpHeaders.CONTENT_DISPOSITION, |
| | | String.format("attachment;filename=%s", URLEncoder.encode("气体预测数据模板.xlsx", StandardCharsets.UTF_8))) |
| | | .header(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") |
| | | .contentLength(file.length) |
| | | .body(resource); |
| | | } |
| | | } |