/*
|
* 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.common.wrapper.QueryWrapperUtil;
|
import com.chinaztt.mes.technology.dto.OperationDTO;
|
import com.chinaztt.mes.technology.entity.Operation;
|
import com.chinaztt.mes.technology.entity.OperationJoinStep;
|
import com.chinaztt.mes.technology.entity.OperationJoinTemplate;
|
import com.chinaztt.mes.technology.excel.OperationData;
|
import com.chinaztt.mes.technology.excel.OperationUploadListener;
|
import com.chinaztt.mes.technology.excel.TestStandardBindingUploadListener;
|
import com.chinaztt.mes.technology.service.OperationService;
|
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 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.List;
|
|
|
/**
|
* 工序
|
*
|
* @author zhangxy
|
* @date 2020-08-18 10:22:27
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/operation")
|
@Api(value = "operation", tags = "工序管理")
|
public class OperationController {
|
|
private final OperationService operationService;
|
|
/**
|
* 分页查询
|
*
|
* @param page 分页对象
|
* @param operation 工序
|
* @return
|
*/
|
@ApiOperation(value = "分页查询", notes = "分页查询")
|
@GetMapping("/page")
|
@PreAuthorize("@pms.hasPermission('technology_operation_view')")
|
public R getTechnologyOperationPage(Page page, Operation operation) {
|
return R.ok(operationService.getOperationPage(page, QueryWrapperUtil.gen(operation)));
|
}
|
|
/**
|
* 根据工序id和工序模板id删除关联表
|
*
|
* @param operationJoinTemplate 工序模板
|
* @return
|
*/
|
@ApiOperation(value = "根据工序id和工序模板id删除关联表", notes = "根据工序id和工序模板id删除关联表")
|
@PostMapping("/operationTemplate")
|
public R deleteOperationTemplate(@RequestBody OperationJoinTemplate operationJoinTemplate) {
|
return R.ok(operationService.deleteOperationTemplate(operationJoinTemplate));
|
}
|
|
/**
|
* 通过id查询工序
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id查询", notes = "通过id查询")
|
@GetMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('technology_operation_view')")
|
public R getById(@PathVariable("id") Long id) {
|
return R.ok(operationService.getFullById(id));
|
}
|
|
/**
|
* 新增工序
|
*
|
* @param operation 工序
|
* @return R
|
*/
|
@ApiOperation(value = "新增工序", notes = "新增工序")
|
@SysLog("新增工序")
|
@PostMapping
|
@PreAuthorize("@pms.hasPermission('technology_operation_add')")
|
public R save(@RequestBody OperationDTO operation) {
|
return operationService.fullSave(operation);
|
}
|
|
|
/**
|
* 修改工序
|
*
|
* @param operation 工序
|
* @return R
|
*/
|
@ApiOperation(value = "修改工序", notes = "修改工序")
|
@SysLog("修改工序")
|
@PutMapping
|
@PreAuthorize("@pms.hasPermission('technology_operation_edit')")
|
public R updateById(@RequestBody OperationDTO operation) {
|
return operationService.fullUpdate(operation);
|
}
|
|
/**
|
* 新增工序与模板的关联
|
*
|
* @param operation 工序
|
* @return R
|
*/
|
@ApiOperation(value = "新增工序与模板的关联", notes = "新增工序与模板的关联")
|
@SysLog("新增工序与模板的关联")
|
@PostMapping("saveOperationTemplate")
|
public R saveOperationTemplate(@RequestBody OperationDTO operation) {
|
return operationService.saveOperationTemplate(operation);
|
}
|
|
/**
|
* 新增工序与工步的关联
|
*
|
* @param operationJoinStepList 工序
|
* @return R
|
*/
|
@ApiOperation(value = "新增工序与工步的关联", notes = "新增工序与工步的关联")
|
@SysLog("新增工序与工步的关联")
|
@PostMapping("saveOperationStep/{id}")
|
public R saveOperationStep(@RequestBody List<OperationJoinStep> operationJoinStepList, @PathVariable("id") Long id) {
|
return R.ok(operationService.saveOperationStep(operationJoinStepList, id));
|
}
|
|
/**
|
* excel上传
|
*
|
* @return
|
*/
|
@PostMapping("/excel/upload")
|
public R upload(@RequestParam("file") MultipartFile file) {
|
try {
|
EasyExcel.read(file.getInputStream(), OperationData.class, new OperationUploadListener(operationService)).sheet().doRead();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
return R.ok();
|
}
|
|
/**
|
* 上传文件
|
*
|
* @param file
|
* @return
|
*/
|
@PostMapping("/upload")
|
public R upload(@RequestParam("operationId") Long operationId, @RequestParam("file") MultipartFile file) {
|
return operationService.uploadFile(file, operationId);
|
}
|
|
|
/**
|
* 通过id删除工序
|
*
|
* @param id id
|
* @return R
|
*/
|
@ApiOperation(value = "通过id删除工序", notes = "通过id删除工序")
|
@SysLog("通过id删除工序")
|
@DeleteMapping("/{id}")
|
@PreAuthorize("@pms.hasPermission('technology_operation_del')")
|
public R removeById(@PathVariable Long id) {
|
return operationService.fullDelete(id);
|
}
|
|
/**
|
* @param fileName
|
* @return
|
*/
|
@ApiOperation(value = "通过文件名删除附件", notes = "通过文件名删除附件")
|
@SysLog("通过文件名删除附件")
|
@DeleteMapping("/removeFile")
|
@PreAuthorize("@pms.hasPermission('technology_operation_edit')")
|
public R removeFileById(String fileName) {
|
return operationService.deleteFile(fileName);
|
}
|
|
|
/**
|
* 获取文件
|
*
|
* @param bucket 桶名称
|
* @param fileName 文件空间/名称
|
* @param response
|
* @return
|
*/
|
@Inner(false)
|
@GetMapping("/{bucket}/{fileName}")
|
public void file(@PathVariable String bucket, @PathVariable String fileName, HttpServletResponse response) {
|
operationService.getFile(bucket, fileName, response);
|
}
|
|
|
/**
|
* 获取ifs人工类别接口
|
*
|
* @param laborClassNo 人工类别接口
|
* @return R
|
*/
|
@ApiOperation(value = "获取ifs人工类别接口", notes = "获取ifs人工类别接口")
|
@SysLog("获取ifs人工类别接口")
|
@GetMapping("/getIfsLaborClass")
|
public R getIfsLaborClass(String laborClassNo) {
|
return operationService.getIfsLaborClass(laborClassNo);
|
}
|
|
/**
|
*
|
* @param file
|
* @return
|
*/
|
@PostMapping("/importTestStandardBindingExcel")
|
public R importTestStandardBindingExcel(@RequestParam("file") MultipartFile file) {
|
try {
|
ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file.getInputStream());
|
ExcelReader excelReader = excelReaderBuilder.build();
|
List<ReadSheet> sheets = excelReader.excelExecutor().sheetList();
|
List<ReadSheet> readSheetList = new ArrayList<>();
|
for (ReadSheet sheet : sheets) {
|
ReadSheet readSheet = EasyExcel.readSheet(sheet.getSheetName()).registerReadListener(
|
new TestStandardBindingUploadListener(operationService)).build();
|
readSheetList.add(readSheet);
|
}
|
excelReader.read(readSheetList);
|
// 这里千万别忘记关闭,读的时候会创建临时文件,到时磁盘会崩的
|
excelReader.finish();
|
} catch (IOException e) {
|
e.printStackTrace();
|
return R.failed(e.getMessage());
|
}
|
return R.ok();
|
}
|
|
|
}
|