8 天以前 1c1daebcb9f89138a84e9a7643d1909bb1a5a342
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
package cn.iocoder.yudao.module.mes.controller.admin.cal.plan;
 
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.team.MesCalPlanTeamRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.cal.plan.vo.team.MesCalPlanTeamSaveReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.cal.plan.MesCalPlanTeamDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.cal.team.MesCalTeamDO;
import cn.iocoder.yudao.module.mes.service.cal.plan.MesCalPlanTeamService;
import cn.iocoder.yudao.module.mes.service.cal.team.MesCalTeamService;
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.List;
import java.util.Map;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 
@Tag(name = "管理后台 - MES 计划班组关联")
@RestController
@RequestMapping("/mes/cal/plan-team")
@Validated
public class MesCalPlanTeamController {
 
    @Resource
    private MesCalPlanTeamService planTeamService;
    @Resource
    private MesCalTeamService teamService;
 
    @PostMapping("/create")
    @Operation(summary = "创建计划班组关联")
    @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')")
    public CommonResult<Long> createPlanTeam(@Valid @RequestBody MesCalPlanTeamSaveReqVO createReqVO) {
        return success(planTeamService.createPlanTeam(createReqVO));
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除计划班组关联")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:cal-plan:update')")
    public CommonResult<Boolean> deletePlanTeam(@RequestParam("id") Long id) {
        planTeamService.deletePlanTeam(id);
        return success(true);
    }
 
    @GetMapping("/list-by-plan")
    @Operation(summary = "获得指定排班计划的班组列表")
    @Parameter(name = "planId", description = "排班计划编号", required = true)
    @PreAuthorize("@ss.hasPermission('mes:cal-plan:query')")
    public CommonResult<List<MesCalPlanTeamRespVO>> getPlanTeamListByPlan(@RequestParam("planId") Long planId) {
        List<MesCalPlanTeamDO> list = planTeamService.getPlanTeamListByPlanId(planId);
        List<MesCalPlanTeamRespVO> respList = BeanUtils.toBean(list, MesCalPlanTeamRespVO.class);
        // 拼装班组编码/名称
        // TODO @AI:if return
        if (CollUtil.isNotEmpty(respList)) {
            Map<Long, MesCalTeamDO> teamMap = teamService.getTeamMap(
                    convertList(respList, MesCalPlanTeamRespVO::getTeamId));
            respList.forEach(resp -> {
                // TODO @AI:findand then
                MesCalTeamDO team = teamMap.get(resp.getTeamId());
                if (team != null) {
                    resp.setTeamCode(team.getCode()).setTeamName(team.getName());
                }
            });
        }
        return success(respList);
    }
 
}