yangys
2024-10-30 25db770e621f1259b8d5b7fd514207f7481c2d0f
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
120
121
122
123
124
125
126
package com.qianwen.smartman.modules.cps.controller;
 
import java.util.List;
import java.util.Map;
 
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.smartman.common.enums.GlobalWcsTypeEnum;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.cps.convert.GlobalWcsConvert;
import com.qianwen.smartman.modules.cps.entity.GlobalWcs;
import com.qianwen.smartman.modules.cps.service.IGlobalWcsService;
import com.qianwen.smartman.modules.cps.vo.GlobalWcsVO;
import com.qianwen.smartman.modules.cps.vo.WcsAchievementsUpdateVO;
import com.qianwen.smartman.modules.cps.vo.WcsAndAchievementsVO;
import com.qianwen.smartman.modules.mdc.entity.WorkstationFeedbackDetail;
import com.qianwen.smartman.modules.mdc.enums.FeedbackDetailStatus;
import com.qianwen.smartman.modules.mdc.service.IWorkstationFeedbackDetailService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
 
@Api(value = "全局工况", tags = {"全局工况"})
@RestController
@ApiResource({"smis/global_wcs"})
@NonDS
public class GlobalWcsController {
    private final IGlobalWcsService globalWcsService;
    private final IWorkstationFeedbackDetailService feedbackDetailService;
 
 
    public GlobalWcsController(final IGlobalWcsService globalWcsService, final IWorkstationFeedbackDetailService feedbackDetailService) {
        this.globalWcsService = globalWcsService;
        this.feedbackDetailService = feedbackDetailService;
    }
 
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({@ApiImplicitParam(name = "code", value = "状态码", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "name", value = "名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "type", value = "类型1系统默认,2业务逻辑,4反馈", paramType = "query", dataType = "int")})
    @ApiOperation(value = "列表", notes = "传入globalWcs")
    @GetMapping({"/list"})
    public R<List<GlobalWcsVO>> list(@RequestParam @ApiIgnore Map<String, Object> globalWcs) {
        if (!globalWcs.containsKey("type")) {
            globalWcs.put("type", GlobalWcsTypeEnum.DEFAULT.getType());
        }
        List<GlobalWcs> list = this.globalWcsService.list(Condition.getQueryWrapper(globalWcs, GlobalWcs.class).lambda().orderByAsc(GlobalWcs::getSeq));
        return R.data(GlobalWcsConvert.INSTANCE.convert(list));
    }
 
    @GetResource({"/wcs-achievements"})
    @ApiOperation(value = "获取状态和绩效时间", notes = "")
    public R<List<WcsAndAchievementsVO>> getWcsAndAchievements() {
        return R.data(this.globalWcsService.getWcsAndAchievements());
    }
 
    @PostResource({"/update-wcs-achievements"})
    @ApiOperation(value = "编辑状态和绩效时间", notes = "传入wcsAchievementsUpdateVO")
    public R<WcsAchievementsUpdateVO> updateWcsAndAchievements(@Validated @RequestBody WcsAchievementsUpdateVO wcsAchievementsUpdateVO) {
        this.globalWcsService.updateWcsAndAchievements(wcsAchievementsUpdateVO);
        return R.data(wcsAchievementsUpdateVO);
    }
 
    @PostResource({"/add-wcs-achievements"})
    @ApiOperation(value = "添加人工反馈状态", notes = "传入FeedBackWcsAchievementsAddDTO")
    public R<WcsAchievementsUpdateVO> addFeedbackAchievements(@Validated @RequestBody WcsAchievementsUpdateVO wcsAchievementsUpdateVO) {
        return R.status(this.globalWcsService.insertWcsAndAchievements(wcsAchievementsUpdateVO));
    }
 
    @DeleteResource({"/delete-wcs-achievements/{code}"})
    @ApiOperation(value = "删除人工反馈状态", notes = "传入ID")
    public R<Boolean> delete(@PathVariable String code) {
        //ExtraLambdaQueryWrapper<WorkstationFeedbackDetail>  wra = Lambda.<WorkstationFeedbackDetail>eq(WorkstationFeedbackDetail::getWcs, code);
        //wra.nested(w -> w.eq(WorkstationFeedbackDetail::getStatus, Integer.valueOf(FeedbackDetailStatus.EFFECTED.getValue())));
        
        boolean exist = this.feedbackDetailService.count(Lambda.<WorkstationFeedbackDetail>eq(WorkstationFeedbackDetail::getWcs, code)
                .nested(w -> w.eq(WorkstationFeedbackDetail::getStatus, FeedbackDetailStatus.EFFECTED.getValue()))
                .or().eq(WorkstationFeedbackDetail::getStatus, FeedbackDetailStatus.WAIT_EFFECT.getValue())
                
                .eq(WorkstationFeedbackDetail::getCancel, false)) != 0;
               
            if (exist)
              throw new ServiceException(MessageUtils.message("workstation.wcs.delete.used", new Object[0])); 
            return R.status(this.globalWcsService.removeByCode(code, GlobalWcsTypeEnum.FEEDBACK));
            
            /*  
        boolean exist = this.feedbackDetailService.count(Lambda.<WorkstationFeedbackDetail>eq(WorkstationFeedbackDetail::getWcs, code).nested(w -> {
            ExtraLambdaQueryWrapper<WorkstationFeedbackDetail> extraLambdaQueryWrapper =  w.eq((v0) -> {
                return v0.getStatus();
            }, FeedbackDetailStatus.EFFECTED.getValue()).or()).eq((v0) -> {
                return v0.getStatus();
            }, Integer.valueOf(FeedbackDetailStatus.WAIT_EFFECT.getValue()));
        }.eq((v0) -> {
            return v0.getCancel();
        }, false)) != 0;
        
        if (exist) {
            throw new ServiceException(MessageUtils.message("workstation.wcs.delete.used", new Object[0]));
        }
        return R.status(this.globalWcsService.removeByCode(code, GlobalWcsTypeEnum.FEEDBACK));
        */
    }
 
    @PostResource({"update-wcs-seq"})
    @ApiOperation(value = "更新全局工况显示顺序", notes = "按顺序传入wcs的id")
    public R<Boolean> updateWcsSeq(@RequestBody List<String> codeList) {
        this.globalWcsService.updateWcsSeq(codeList);
        return R.status(true);
    }
}