ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.base.controller;
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import jnpf.base.ActionResult;
import jnpf.base.SystemApi;
import jnpf.base.entity.CommonWordsEntity;
import jnpf.base.entity.SystemEntity;
import jnpf.base.model.base.SystemApiByIdsModel;
import jnpf.base.model.commonword.ComWordsPagination;
import jnpf.base.model.commonword.CommonWordsForm;
import jnpf.base.model.commonword.CommonWordsVO;
import jnpf.base.service.CommonWordsService;
import jnpf.base.vo.ListVO;
import jnpf.base.vo.PageListVO;
import jnpf.base.vo.PaginationVO;
import jnpf.constant.MsgCode;
import jnpf.util.JsonUtil;
import jnpf.util.RandomUtil;
import jnpf.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 常用语控制类
 *
 * @author JNPF开发平台组 YanYu
 * @version v3.4.6
 * @copyrignt 引迈信息技术有限公司
 * @date 2023-01-06
 */
@Tag(name = "审批常用语", description = "commonWords")
@RestController
@RequestMapping("/CommonWords")
public class CommonWordsController extends SuperController<CommonWordsService, CommonWordsEntity> {
 
    @Autowired
    private CommonWordsService commonWordsService;
    @Autowired
    private SystemApi systemService;
 
 
    /**
     * 列表
     *
     * @param comWordsPagination 页面参数对象
     * @return 列表结果集
     */
    @Operation(summary = "当前系统应用列表")
    @GetMapping()
    public ActionResult<PageListVO<CommonWordsVO>> getList(@Valid ComWordsPagination comWordsPagination) {
        List<CommonWordsEntity> entityList = commonWordsService.getSysList(comWordsPagination, false);
        List<CommonWordsVO> voList = JsonUtil.getJsonToList(entityList, CommonWordsVO.class);
        formatSystemNames(voList);
        return ActionResult.page(voList, JsonUtil.getJsonToBean(comWordsPagination, PaginationVO.class));
    }
 
    /**
     * 获取信息
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "获取信息")
    @Parameter(name = "id", description = "主键", required = true)
    @GetMapping("/{id}")
    public ActionResult<CommonWordsVO> getInfo(@PathVariable String id) {
        CommonWordsEntity entity = commonWordsService.getById(id);
        if (StringUtil.isNotEmpty(entity.getSystemIds())) {
            String[] sysIds = entity.getSystemIds().split(",");
            List<String> ids = new ArrayList<>();
            for (String sysId : sysIds) {
                if (!StringUtil.isEmpty(sysId)) {
                    SystemEntity systemEntity = systemService.getInfoById(sysId);
                    if (systemEntity != null && systemEntity.getEnabledMark() == 1) {
                        ids.add(sysId);
                    }
                }
            }
            if (ids.size() > 0) {
                entity.setSystemIds(StringUtil.join(ids, ","));
            } else {
                entity.setSystemIds(null);
            }
        }
        CommonWordsVO vo = JsonUtil.getJsonToBean(entity, CommonWordsVO.class);
        return ActionResult.success(vo);
    }
 
    /**
     * 下拉列表
     *
     * @return
     */
    @Operation(summary = "下拉列表")
    @GetMapping("/Selector")
    public ActionResult<ListVO<CommonWordsVO>> getSelect(String type) {
        List<CommonWordsVO> voList = JsonUtil.getJsonToList(commonWordsService.getListModel(type), CommonWordsVO.class);
        formatSystemNames(voList);
        return ActionResult.success(new ListVO<>(voList));
    }
 
    /**
     * 新建
     *
     * @param commonWordsForm 实体模型
     * @return
     */
    @Operation(summary = "新建")
    @Parameter(name = "commonWordsForm", description = "实体模型", required = true)
    @PostMapping("")
    public ActionResult<CommonWordsForm> create(@RequestBody CommonWordsForm commonWordsForm) {
        if (commonWordsService.existCommonWord(null, commonWordsForm.getCommonWordsText(), commonWordsForm.getCommonWordsType())) {
            return ActionResult.fail(MsgCode.SYS105.get());
        }
        CommonWordsEntity entity = JsonUtil.getJsonToBean(commonWordsForm, CommonWordsEntity.class);
        entity.setId(RandomUtil.uuId());
        entity.setUsesNum(0l);
        commonWordsService.save(entity);
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    /**
     * 修改
     *
     * @param commonWordsForm 实体模型
     * @return
     */
    @Operation(summary = "修改")
    @Parameters({
            @Parameter(name = "commonWordsForm", description = "实体模型", required = true)
    })
    @PutMapping("/{id}")
    public ActionResult<CommonWordsForm> update(@RequestBody CommonWordsForm commonWordsForm) {
        if (commonWordsService.existCommonWord(commonWordsForm.getId(), commonWordsForm.getCommonWordsText(), commonWordsForm.getCommonWordsType())) {
            return ActionResult.fail(MsgCode.SYS105.get());
        }
        CommonWordsEntity entity = JsonUtil.getJsonToBean(commonWordsForm, CommonWordsEntity.class);
        entity.setId(commonWordsForm.getId());
        commonWordsService.updateById(entity);
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 删除
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "删除")
    @Parameters({
            @Parameter(name = "id", description = "主键", required = true)
    })
    @DeleteMapping("/{id}")
    public ActionResult<CommonWordsForm> delete(@PathVariable String id) {
        //对象存在判断
        if (commonWordsService.getById(id) != null) {
            commonWordsService.removeById(id);
            return ActionResult.success(MsgCode.SU003.get());
        } else {
            return ActionResult.fail(MsgCode.FA003.get());
        }
    }
 
    @Operation(summary = "常用语使用")
    @Parameters({
            @Parameter(name = "commonWordsForm", description = "实体模型")
    })
    @PostMapping("/UsesNum")
    public ActionResult<CommonWordsForm> addCommonWordsNum(@RequestBody CommonWordsForm commonWordsForm) {
        commonWordsService.addCommonWordsNum(commonWordsForm.getCommonWordsText());
        return ActionResult.success(MsgCode.SU000.get());
    }
 
    private void formatSystemNames(List<CommonWordsVO> voList) {
        voList.forEach(vo -> {
            if (StringUtil.isNotEmpty(vo.getSystemIds())) {
                List<String> sysNameList = systemService.getListByIds(new SystemApiByIdsModel(vo.getSystemIds(), null,1)).stream()
                        .map(SystemEntity::getFullName).collect(Collectors.toList());
                vo.setSystemNames(StringUtil.join(sysNameList, ","));
            }
        });
    }
 
}