package cn.iocoder.yudao.module.mes.controller.admin.pd.seal; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.mes.controller.admin.pd.project.MesPdProjectController; import cn.iocoder.yudao.module.mes.service.pd.project.MesPdProjectService; import cn.iocoder.yudao.module.mes.service.pd.seal.PdSealService; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @RestController @RequestMapping("/mes/pd/seal") public class PdSealController { @Resource private PdSealService service; @Resource private MesPdProjectService projectService; @Resource private MesPdProjectController projectController; @GetMapping("/list") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')") public CommonResult>> list(){ return success(service.seals(false)); } @GetMapping("/available") @PreAuthorize("@ss.hasPermission('mes:pd-project:export')") public CommonResult>> available(){ return success(service.seals(true)); } @PostMapping("/upload") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')") public CommonResult upload(@RequestParam String name,@RequestParam MultipartFile file) throws Exception { return success(service.upload(name,file,getLoginUserId())); } @PutMapping("/enabled") @PreAuthorize("@ss.hasPermission('mes:pd-seal:manage')") public CommonResult enabled(@RequestParam long id,@RequestParam boolean enabled){service.setEnabled(id,enabled);return success(true);} public record ApplyReq(Long projectId, Long sealId, String reason) {} @PostMapping("/apply") @PreAuthorize("@ss.hasPermission('mes:pd-project:export')") public CommonResult apply(@RequestBody ApplyReq req) throws Exception { if(req.projectId()==null || req.sealId()==null) throw new cn.iocoder.yudao.framework.common.exception.ServiceException(1_040_990_001,"请选择项目和印章"); var project=projectService.getProject(req.projectId()); if(project==null) throw new cn.iocoder.yudao.framework.common.exception.ServiceException(1_040_990_001,"项目不存在"); return success(service.apply(req.projectId(),project.getTaskCode(),req.sealId(),req.reason(),getLoginUserId(),projectController.createTrackingSnapshot(req.projectId()))); } @GetMapping("/applications") @PreAuthorize("@ss.hasPermission('mes:pd-project:export')") public CommonResult>> applications(@RequestParam(required=false) Long projectId){ return success(service.applications(getLoginUserId(),projectId)); } @GetMapping("/download") @PreAuthorize("@ss.hasPermission('mes:pd-project:export')") public void download(@RequestParam long id,HttpServletResponse response) throws Exception {byte[] bytes=service.download(id,getLoginUserId()); response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"); response.setHeader("Content-Disposition","attachment; filename=tracking.docx"); response.getOutputStream().write(bytes);} }