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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package com.qianwen.smartman.modules.cps.controller;
 
import java.util.List;
import java.util.Map;
 
import javax.validation.Valid;
 
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.excel.util.ExcelUtil;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.PostResource;
import com.qianwen.core.scanner.modular.annotation.PutResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.secure.annotation.PreAuth;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.api.ResultCode;
import com.qianwen.core.tool.node.ForestNodeMerger;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.common.constant.CommonConstant;
import com.qianwen.smartman.common.utils.MessageUtils;
import com.qianwen.smartman.modules.cps.convert.CommonGroupConvert;
import com.qianwen.smartman.modules.cps.entity.CommonGroup;
import com.qianwen.smartman.modules.cps.excel.CommonGroupImport;
import com.qianwen.smartman.modules.cps.service.ICommonGroupService;
import com.qianwen.smartman.modules.cps.vo.CommonGroupFtpVO;
import com.qianwen.smartman.modules.cps.vo.CommonGroupTypeVO;
import com.qianwen.smartman.modules.cps.vo.CommonGroupVO;
import com.qianwen.smartman.modules.cps.vo.CreateCommonGroupVO;
import com.qianwen.smartman.modules.cps.vo.JimuTreeVO;
import com.qianwen.smartman.modules.cps.vo.MdcWorkStationGroupVO;
import com.qianwen.smartman.modules.cps.vo.TagCommonGroupVO;
import com.qianwen.smartman.modules.cps.vo.UpdateCommonGroupVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationInGroupVO;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;
 
@ApiResource({"smis/group"})
@Api(value = "组", tags = {"组"})
@RestController
public class CommonGroupController {
    private final ICommonGroupService groupService;
 
    public CommonGroupController(ICommonGroupService groupService) {
        this.groupService = groupService;
    }
 
    @ApiOperationSupport(order = 1)
    @GetMapping
    @ApiOperation(value = "详细", notes = "获取组详细")
    public R<CommonGroupVO> detail(@RequestParam @ApiParam(value = "主键", required = true) String id) {
        CommonGroup group = (CommonGroup) this.groupService.getById(id);
        CommonGroupVO commonGroup = CommonGroupConvert.INSTANCE.convert(group);
        return R.data(commonGroup);
    }
 
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({@ApiImplicitParam(name = "groupType", value = "组别", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "groupCategory", value = "组子类", paramType = "query", dataType = "int"), @ApiImplicitParam(name = "name", value = "组名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "fullName", value = "组全称", paramType = "query", dataType = "string")})
    @ApiOperation(value = "列表", notes = "传入group")
    @GetMapping({"/list"})
    public R<List<CommonGroupVO>> list(@RequestParam @ApiIgnore Map<String, Object> group, BladeUser bladeUser) {
        QueryWrapper<CommonGroup> queryWrapper = Condition.getQueryWrapper(group, CommonGroup.class);
        List<CommonGroup> list = this.groupService.list(!bladeUser.getTenantId().equals("000000") ? queryWrapper
            .lambda().eq(CommonGroup::getTenantId, bladeUser.getTenantId()).orderByAsc(CommonGroup::getSort) : queryWrapper
            .lambda().orderByAsc(CommonGroup::getSort));
        List<CommonGroupVO> vos = CommonGroupConvert.INSTANCE.convert(list);
        return R.data(vos);
        /*
        Wrapper wrapper;
        QueryWrapper<CommonGroup> queryWrapper = Condition.getQueryWrapper(group, CommonGroup.class);
        ICommonGroupService iCommonGroupService = this.groupService;
        if (!bladeUser.getTenantId().equals("000000")) {
            wrapper = (Wrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> {
                return v0.getTenantId();
            }, bladeUser.getTenantId())).orderByAsc((v0) -> {
                return v0.getSort();
            });
        } else {
            wrapper = (Wrapper) queryWrapper.lambda().orderByAsc((v0) -> {
                return v0.getSort();
            });
        }
        List<CommonGroup> list = iCommonGroupService.list(wrapper);
        List<CommonGroupVO> vos = CommonGroupConvert.INSTANCE.convert(list);
        return R.data(vos);
        */
    }
 
    @ApiOperationSupport(order = 3)
    @GetMapping({"/tree"})
    @ApiOperation(value = "树形结构", notes = "树形结构")
    public R<List<CommonGroupVO>> tree(@Validated CommonGroupTypeVO commonGroupTypeVO) {
        if (commonGroupTypeVO.getStatus() == null) {
              commonGroupTypeVO.setStatus(CommonConstant.ENABLE); 
        }
        List<CommonGroup> list = this.groupService.list(Wrappers.<CommonGroup>lambdaQuery()
            .eq(CommonGroup::getGroupType, commonGroupTypeVO.getGroupType())
            .eq(CommonGroup::getGroupCategory, commonGroupTypeVO.getGroupCategory())
            .eq(CommonGroup::getStatus, commonGroupTypeVO.getStatus())
            .orderByDesc(CommonGroup::getSort));
        List<CommonGroupVO> vos = CommonGroupConvert.INSTANCE.convert(list);
        return R.data(ForestNodeMerger.merge(vos));
        /*
        if (commonGroupTypeVO.getStatus() == null) {
            commonGroupTypeVO.setStatus(CommonConstant.ENABLE);
        }
        List<CommonGroup> list = this.groupService.list((Wrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getGroupType();
        }, commonGroupTypeVO.getGroupType())).eq((v0) -> {
            return v0.getGroupCategory();
        }, commonGroupTypeVO.getGroupCategory())).eq((v0) -> {
            return v0.getStatus();
        }, commonGroupTypeVO.getStatus())).orderByDesc((v0) -> {
            return v0.getSort();
        }));
        List<CommonGroupVO> vos = CommonGroupConvert.INSTANCE.convert(list);
        return R.data(ForestNodeMerger.merge(vos));
        */
    }
 
    @ApiOperationSupport(order = 4)
    @PostResource
    @ApiOperation(value = "新增", notes = "传入group")
    @PreAuth
    public R<CommonGroupVO> insert(@Valid @RequestBody CreateCommonGroupVO groupVO) {
        CommonGroup commonGroup = CommonGroupConvert.INSTANCE.convert(groupVO);
        this.groupService.insert(commonGroup);
        CommonGroupVO vo = CommonGroupConvert.INSTANCE.convert(commonGroup);
        return R.data(vo);
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @PutResource
    @ApiOperation(value = "修改", notes = "传入group")
    @PreAuth
    public R<CommonGroupVO> update(@Valid @RequestBody UpdateCommonGroupVO groupVO) {
        CommonGroup commonGroup = CommonGroupConvert.INSTANCE.convert(groupVO);
        this.groupService.update(commonGroup);
        CommonGroupVO vo = CommonGroupConvert.INSTANCE.convert(commonGroup);
        return R.data(vo);
    }
 
    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "删除", notes = "删除组")
    @PreAuth
    @DeleteResource
    public R<Void> delete(@RequestParam @ApiParam(value = "主键", required = true) String id) {
        CommonGroup group = (CommonGroup) this.groupService.getById(id);
        if (null != group) {
            this.groupService.removeGroup(id);
        }
        return R.success(MessageUtils.message("sys.operate.success", new Object[0]));
    }
 
    @PostMapping({"/move"})
    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "移动", notes = "移动组")
    public R move(@RequestParam @ApiParam(value = "当前组id", required = true) String id, @RequestParam @ApiParam(value = "目标父节点", required = true) String parentId, @RequestParam @ApiParam(value = "组别", required = true) String groupType, @RequestParam @ApiParam(value = "组子类", required = true) Integer groupCategory) {
        CommonGroup group = (CommonGroup) this.groupService.getById(id);
        CommonGroup targetGroup = (CommonGroup) this.groupService.getById(parentId);
        if (Func.isEmpty(group) || Func.isEmpty(targetGroup)) {
            throw new ServiceException(MessageUtils.message("cps.group.target.is.not.exist", new Object[0]));
        }
        this.groupService.move(group.getId(), targetGroup.getId(), groupType, groupCategory);
        return R.success(MessageUtils.message("sys.operate.success", new Object[0]));
    }
 
    @PostMapping({"/tag"})
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "设定标签", notes = "标签值来自 group_tag 字典")
    public R<CommonGroupVO> tag(@Valid @RequestBody TagCommonGroupVO tagCommonGroupVO) {
        CommonGroup group = (CommonGroup) this.groupService.getById(tagCommonGroupVO.getId());
        if (Func.isEmpty(group)) {
            return R.fail(ResultCode.NOT_FOUND);
        }
        group.setGroupTag(tagCommonGroupVO.getGroupTag());
        this.groupService.update(group);
        CommonGroupVO result = CommonGroupConvert.INSTANCE.convert(group);
        return R.data(result);
    }
 
    @ApiOperationSupport(order = 9)
    @PostResource({"/import"})
    @ApiOperation(value = "导入", notes = "导入组")
    @PreAuth
    public R<BladeFile> importCommonGroup(MultipartFile file, @Validated CommonGroupTypeVO commonGroupTypeVO) {
        List<CommonGroupImport> data = ExcelUtil.read(file, 0, 2, CommonGroupImport.class);
        return R.data(this.groupService.importCommonGroup(data, commonGroupTypeVO));
    }
 
    @PostMapping({"/groupWorkstation"})
    @ApiOperationSupport(order = 10)
    @ApiOperation(value = "查询所有组和工位", notes = "查询所有组和工位")
    public R<List<WorkstationInGroupVO>> groupWorkstationList(@Validated @RequestBody CommonGroupTypeVO commonGroupTypeVO) {
        return R.data(this.groupService.groupWorkstationList(commonGroupTypeVO));
    }
 
    @PostMapping({"/groupWorkstation/type"})
    @ApiOperationSupport(order = 11)
    @ApiOperation(value = "查询所有组和工位(机器工位)", notes = "查询所有组和工位")
    public R<List<WorkstationInGroupVO>> groupWorkstationListType(@Validated @RequestBody CommonGroupTypeVO commonGroupTypeVO) {
        return R.data(this.groupService.groupWorkstationListType(commonGroupTypeVO));
    }
 
    @ApiOperationSupport(order = 12)
    @GetMapping({"/groupWorkstation/lazy"})
    @ApiOperation(value = "查询所有组和工位(懒加载)", notes = "查询所有组和工位(懒加载)")
    public R<List<WorkstationInGroupVO>> groupWorkstationListLazy(@RequestParam Long groupId) {
        return R.data(this.groupService.groupWorkstationListLazy(groupId));
    }
 
    @ApiOperationSupport(order = 13)
    @GetMapping({"/getRootNode"})
    @ApiOperation(value = "获取根节点", notes = "获取根节点")
    public R<CommonGroup> getRootNode(String groupType, Integer groupCategory) {
        return R.data(this.groupService.getRootNode(groupType, groupCategory));
    }
 
    @ApiOperationSupport(order = 14)
    @GetMapping({"/get-mdc-group"})
    @ApiOperation(value = "采集分析实时看板工位组", notes = "采集分析实时看板工位组")
    public R<List<MdcWorkStationGroupVO>> getMdcGroup() {
        return R.data(this.groupService.getMdcGroup());
    }
 
    @ApiOperationSupport(order = 15)
    @ApiOperation("删除组后将子移动到默认组")
    @PreAuth
    @DeleteResource({"/deleteGroup"})
    public R<Boolean> deleteGroup(@RequestParam("groupId") String groupId) {
        return R.data(this.groupService.deleteGroup(Long.valueOf(groupId)));
    }
 
    @PostMapping({"/groupFtpDirectory/ftp"})
    @ApiOperationSupport(order = 16)
    @ApiOperation(value = "查询未被绑定目录的所有组和工位", notes = "查询所有组和工位")
    public R<List<WorkstationInGroupVO>> groupFtpDirectoryLazy(@Validated @RequestBody CommonGroupFtpVO commonGroupFtpVO) {
        return R.data(this.groupService.groupFtpDirectoryWorkstationList(commonGroupFtpVO));
    }
 
    @ApiOperationSupport(order = 11)
    @GetMapping({"/groupWorkstation/jimu"})
    @ApiOperation(value = "查询所有组和工位(机器工位)-用于积木报表树", notes = "查询所有组和工位-用于积木报表树")
    public List<JimuTreeVO> groupWorkstationListJimu(@RequestParam(name = "pid", required = false) String pid) {
        return this.groupService.groupWorkstationListJimu(pid);
    }
}