赵文轩
2024-06-13 28ebb3d308c67a55051dda6137f6a165f9c1fa18
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
267
268
269
270
271
272
273
package com.ltkj.web.controller.system;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.checkerframework.checker.units.qual.A;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.BusinessType;
import com.ltkj.common.utils.poi.ExcelUtil;
import com.ltkj.common.core.page.TableDataInfo;
 
/**
 * 规则+病种Controller
 *
 * @author ltkj_赵佳豪&李格
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/hosp/rules")
@Api(tags = "规则+病种接口")
public class TjRulesController extends BaseController {
    @Autowired
    private ITjRulesService tjRulesService;
 
    @Autowired
    private ITjRuleAdviceService tjRuleAdviceService;
 
    @Resource
    private ITjOrderService orderService;
 
    @Resource
    private ITjCustomerService customerService;
 
    @Autowired
    private ITjGroupingProService groupingProService;
    @Resource
    private ITjProjectService projectService;
 
    /**
     * 查询规则+病种列表
     */
    //@PreAuthorize("@ss.hasPermi('hosp:rules:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询规则+病种列表")
    public TableDataInfo list(TjRules tjRules) {
        startPage();
        LambdaQueryWrapper<TjRules> wq = new LambdaQueryWrapper<>();
        if (tjRules.getProId() != null) {
            wq.eq(TjRules::getProId, tjRules.getProId());
        }
        if (tjRules.getProName() != null) {
            wq.like(TjRules::getProName, tjRules.getProName());
        }
        if (tjRules.getRuleType() != null) {
            wq.eq(TjRules::getRuleType, tjRules.getRuleType());
        }
        if (tjRules.getRuleStr() != null) {
            wq.like(TjRules::getRuleStr, tjRules.getRuleStr());
        }
        if (tjRules.getBingzhong() != null) {
            wq.like(TjRules::getBingzhong, tjRules.getBingzhong());
        }
        if (tjRules.getBzPinyin() != null) {
            wq.like(TjRules::getBzPinyin, tjRules.getBzPinyin());
        }
        if (tjRules.getSex() != null) {
            wq.eq(TjRules::getSex, tjRules.getSex());
        }
        wq.orderByAsc(TjRules::getSort);
        List<TjRules> list = tjRulesService.list(wq);
        if (list != null) {
            for (TjRules rules : list) {
                LambdaQueryWrapper<TjRuleAdvice> wq1 = new LambdaQueryWrapper<>();
                wq1.eq(TjRuleAdvice::getBz, rules.getAid());
                final List<TjRuleAdvice> list1 = tjRuleAdviceService.list(wq1);
                rules.setRuleAdvices(list1);
            }
        }
        return getDataTable(list);
    }
 
 
    /**
     * 查询规则+病种列表
     */
    @GetMapping("/listByRuleStr")
    @ApiOperation(value = "查询规则+病种列表")
    public TableDataInfo listByRuleStr(@ApiParam(value = "项目id") @RequestParam String proId,
                                       @ApiParam(value = "体检号") @RequestParam String tjNumber,
                                       @ApiParam(value = "体检号") @RequestParam String ruleStr) {
        TjOrder one = orderService.getOrderByTjNum(tjNumber);
        TjCustomer customer = customerService.getById(one.getUserId());
        LambdaQueryWrapper<TjRules> wq = new LambdaQueryWrapper<>();
        if (proId != null) {
            wq.eq(TjRules::getProId, proId);
        }
        if (ruleStr != null) {
            wq.like(TjRules::getRuleStr, ruleStr);
        }
        if (customer.getCusSex() != null) {
            wq.eq(TjRules::getSex, customer.getCusSex());
        }
        wq.orderByAsc(TjRules::getSort);
        List<TjRules> list = tjRulesService.list(wq);
        if (list != null) {
            for (TjRules rules : list) {
                LambdaQueryWrapper<TjRuleAdvice> wq1 = new LambdaQueryWrapper<>();
                wq1.eq(TjRuleAdvice::getBz, rules.getAid());
                final List<TjRuleAdvice> list1 = tjRuleAdviceService.list(wq1);
                rules.setRuleAdvices(list1);
            }
        }
        return getDataTable(list);
    }
 
    /**
     * 导出规则+病种列表
     */
    //@PreAuthorize("@ss.hasPermi('hosp:rules:export')")
    @Log(title = "规则+病种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出规则+病种列表")
    public void export(HttpServletResponse response, TjRules tjRules) {
        LambdaQueryWrapper<TjRules> wq = new LambdaQueryWrapper<>();
        if (tjRules.getProName() != null) {
            wq.like(TjRules::getProName, tjRules.getProName());
        }
        if (tjRules.getRuleType() != null) {
            wq.eq(TjRules::getRuleType, tjRules.getRuleType());
        }
        if (tjRules.getBingzhong() != null) {
            wq.like(TjRules::getBingzhong, tjRules.getBingzhong());
        }
        if (tjRules.getBzPinyin() != null) {
            wq.like(TjRules::getBzPinyin, tjRules.getBzPinyin());
        }
        if (tjRules.getSex() != null) {
            wq.eq(TjRules::getSex, tjRules.getSex());
        }
        List<TjRules> list = tjRulesService.list(wq);
        ExcelUtil<TjRules> util = new ExcelUtil<TjRules>(TjRules.class);
        util.exportExcel(response, list, "规则+病种数据");
    }
 
    /**
     * 获取规则+病种详细信息
     */
    //@PreAuthorize("@ss.hasPermi('hosp:rules:query')")
    @GetMapping(value = "/{aid}")
    @ApiOperation(value = "获取规则+病种详细信息")
    public AjaxResult getInfo(@PathVariable("aid") String aid) {
        return success(tjRulesService.getById(aid));
    }
 
    /**
     * 新增规则+病种
     */
    // @PreAuthorize("@ss.hasPermi('hosp:rules:add')")
    @Log(title = "规则+病种", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增规则+病种")
    public AjaxResult add(@RequestBody TjRules tjRules) {
        return toAjax(tjRulesService.save(tjRules));
    }
 
    /**
     * 修改规则+病种
     */
    //@PreAuthorize("@ss.hasPermi('hosp:rules:edit')")
    @Log(title = "规则+病种", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改规则+病种")
    public AjaxResult edit(@RequestBody TjRules tjRules) {
        return toAjax(tjRulesService.saveOrUpdate(tjRules));
    }
 
    /**
     * 删除规则+病种
     */
    //@PreAuthorize("@ss.hasPermi('hosp:rules:remove')")
    @Log(title = "规则+病种", businessType = BusinessType.DELETE)
    @DeleteMapping("/{aids}")
    @ApiOperation(value = "删除规则+病种")
    public AjaxResult remove(@PathVariable String[] aids) {
        for (String aid : aids) {
            tjRulesService.removeById(aid);
        }
        return toAjax(true);
    }
 
    /**
     * 规则自动计算
     */
    @GetMapping("/AutoGetRule")
    @ApiOperation(value = "规则自动计算")
    public AjaxResult AutoGetRule(@ApiParam(value = "项目") @RequestParam String proId,
                                  @ApiParam(value = "客户") @RequestParam String cusId,
                                  @ApiParam(value = "关键字") @RequestParam(required = false) String keyWord,
                                  @ApiParam(value = "结果值") @RequestParam(required = false) BigDecimal keyNum) {
 
        List<TjRules> res = new ArrayList<>();
        if (proId==null){
            return AjaxResult.success(res);
        }
        if (cusId==null){
            return AjaxResult.success(res);
        }
        TjCustomer byId = customerService.getById(cusId);
        if(byId==null){
            return AjaxResult.success(res);
        }
        LambdaQueryWrapper<TjRules> wq = new LambdaQueryWrapper<>();
        wq.eq(TjRules::getProId, proId);
        wq.lt(TjRules::getAgeLt, MatchUtils.getAgeByIdCard(byId.getCusIdcard()));
        wq.gt(TjRules::getAgeGt, MatchUtils.getAgeByIdCard(byId.getCusIdcard()));
        wq.in(TjRules::getSex, 0, byId.getCusSex());
        final List<TjRules> list = tjRulesService.list(wq);
        if (list==null){
            return AjaxResult.success(res);
        }
        for (TjRules tjRules : list) {
            //判断规则类型:数值/文字
            if ("2".equals(tjRules.getRuleType())) {
 
                if (new BigDecimal(0).equals(tjRules.getRuleLt()) && new BigDecimal(0).equals(tjRules.getRuleGt())) {
                    res.add(tjRules);
                } else {
                    if (keyNum != null) {
                        if (tjRules.getRuleLt().compareTo(keyNum) < 0 && tjRules.getRuleGt().compareTo(keyNum) > 0) {
                            res.add(tjRules);
                        }
                    }
                }
            } else if ("1".equals(tjRules.getRuleType())) {
                if (keyWord!=null){
                    if (tjRules.getRuleStr().contains(keyWord)) {
                        res.add(tjRules);
                    }
                }
 
            }
        }
        if (res!=null && res.size() > 0) {
            //建议赋值
            for (TjRules re : res) {
                LambdaQueryWrapper<TjRuleAdvice> wq1 = new LambdaQueryWrapper<>();
                wq1.eq(TjRuleAdvice::getBz, re.getAid());
                final List<TjRuleAdvice> list1 = tjRuleAdviceService.list(wq1);
                re.setRuleAdvices(list1);
            }
        }
        return AjaxResult.success(res);
    }
 
 
}