gaoluyang
5 分钟以前 ce5f8a87bb5d411bae67c39b269d879677bb98da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package cn.iocoder.yudao.module.mes.controller.admin.pro.worktime;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.pro.worktime.vo.MesProWorktimeAuxPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.worktime.vo.MesProWorktimeAuxRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.pro.worktime.vo.MesProWorktimeAuxSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.md.workstation.MesMdWorkstationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.process.MesProProcessDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.pro.worktime.MesProWorktimeAuxDO;
import cn.iocoder.yudao.module.mes.service.md.workstation.MesMdWorkstationService;
import cn.iocoder.yudao.module.mes.service.pro.process.MesProProcessService;
import cn.iocoder.yudao.module.mes.service.pro.worktime.MesProWorktimeAuxService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
 
@Tag(name = "管理后台 - MES 辅助工时配置")
@RestController
@RequestMapping("/mes/pro/worktime-aux")
@Validated
public class MesProWorktimeAuxController {
 
    @Resource
    private MesProWorktimeAuxService worktimeAuxService;
    @Resource
    private MesProProcessService processService;
    @Resource
    private MesMdWorkstationService workstationService;
 
    @PostMapping("/create")
    @Operation(summary = "创建辅助工时项目")
    @PreAuthorize("@ss.hasPermission('mes:pro-worktime-aux:create')")
    public CommonResult<Long> createWorktimeAux(@Valid @RequestBody MesProWorktimeAuxSaveReqVO createReqVO) {
        return success(worktimeAuxService.createWorktimeAux(createReqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "更新辅助工时项目")
    @PreAuthorize("@ss.hasPermission('mes:pro-worktime-aux:update')")
    public CommonResult<Boolean> updateWorktimeAux(@Valid @RequestBody MesProWorktimeAuxSaveReqVO updateReqVO) {
        worktimeAuxService.updateWorktimeAux(updateReqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除辅助工时项目")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-worktime-aux:delete')")
    public CommonResult<Boolean> deleteWorktimeAux(@RequestParam("id") Long id) {
        worktimeAuxService.deleteWorktimeAux(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得辅助工时项目")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:pro-worktime-aux:query')")
    public CommonResult<MesProWorktimeAuxRespVO> getWorktimeAux(@RequestParam("id") Long id) {
        MesProWorktimeAuxDO aux = worktimeAuxService.getWorktimeAux(id);
        if (aux == null) {
            return success(null);
        }
        return success(buildRespVOList(Collections.singletonList(aux)).get(0));
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得辅助工时项目分页")
    @PreAuthorize("@ss.hasPermission('mes:pro-worktime-aux:query')")
    public CommonResult<PageResult<MesProWorktimeAuxRespVO>> getWorktimeAuxPage(@Valid MesProWorktimeAuxPageReqVO pageReqVO) {
        PageResult<MesProWorktimeAuxDO> pageResult = worktimeAuxService.getWorktimeAuxPage(pageReqVO);
        return success(new PageResult<>(buildRespVOList(pageResult.getList()), pageResult.getTotal()));
    }
 
    @GetMapping("/list-applicable")
    @Operation(summary = "获得工序+机台可用的辅助工时项目,报工表单使用")
    @Parameter(name = "processId", description = "工序编号", required = true)
    @Parameter(name = "workstationId", description = "工作站(机台)编号")
    @PreAuthorize("@ss.hasPermission('mes:pro-feedback:create')")
    public CommonResult<List<MesProWorktimeAuxRespVO>> getApplicableList(@RequestParam("processId") Long processId,
                                                                        @RequestParam(value = "workstationId", required = false) Long workstationId) {
        List<MesProWorktimeAuxDO> list = worktimeAuxService.getApplicableList(processId, workstationId);
        return success(buildRespVOList(list));
    }
 
    private List<MesProWorktimeAuxRespVO> buildRespVOList(List<MesProWorktimeAuxDO> list) {
        if (CollUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        Set<Long> processIds = convertSet(list, MesProWorktimeAuxDO::getProcessId);
        processIds.remove(null);
        Map<Long, MesProProcessDO> processMap = processService.getProcessMap(processIds);
        Set<Long> workstationIds = convertSet(list, MesProWorktimeAuxDO::getWorkstationId);
        workstationIds.remove(null);
        Map<Long, MesMdWorkstationDO> workstationMap = workstationService.getWorkstationMap(workstationIds);
        return BeanUtils.toBean(list, MesProWorktimeAuxRespVO.class, vo -> {
            findAndThen(processMap, vo.getProcessId(), process -> vo.setProcessName(process.getName()));
            findAndThen(workstationMap, vo.getWorkstationId(),
                    workstation -> vo.setWorkstationName(workstation.getName()));
        });
    }
 
}