zjh
2025-03-25 b9ec0ddbda9381e4587426a0cb7cf400cfb8c972
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
package com.ltkj.web.controller.system;
 
import java.nio.channels.NonReadableChannelException;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltkj.common.annotation.Excel;
import com.ltkj.common.core.domain.entity.SysDept;
import com.ltkj.common.utils.StringUtils;
import com.ltkj.common.utils.poi.ExcelUtil;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.TjAdvice;
import com.ltkj.hosp.domain.TjAdviceKjbq;
import com.ltkj.hosp.domain.TjProject;
import com.ltkj.hosp.domain.TjUserAdvice;
import com.ltkj.hosp.service.ITjAdviceService;
import com.ltkj.hosp.service.ITjProjectService;
import com.ltkj.hosp.service.TjAdviceKjbqService;
import com.ltkj.hosp.service.TjUserAdviceService;
import com.ltkj.system.service.ISysDeptService;
import com.ltkj.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.BusinessType;
 
/**
 * adviceController
 *
 * @author ltkj
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/advice/advice")
@Api(tags = "体检建议管理接口")
public class TjAdviceController {
    @Resource
    private ITjAdviceService tjAdviceService;
    @Resource
    private ITjProjectService tjProjectService;
    @Resource
    private TjAdviceKjbqService kjbqService;
    @Resource
    private TjUserAdviceService userAdviceService;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private ISysDeptService sysDeptService;
 
    @PostMapping("/addTjAdviceKjbq")
    @ApiOperation(value = "新增体检建议快捷标签接口")
    public AjaxResult addTjAdviceKjbq(@RequestBody TjAdviceKjbq adviceKjbq) {
 
        return AjaxResult.success(kjbqService.save(adviceKjbq));
    }
 
    @DeleteMapping("/deletedTjAdviceKjbq")
    @ApiOperation(value = "根据id删除体检建议快捷标签接口")
    public AjaxResult deletedTjAdviceKjbq(@RequestParam Long adviceKjbqId) {
        return AjaxResult.success(kjbqService.removeById(adviceKjbqId));
    }
 
    @PutMapping("/updateTjAdviceKjbq")
    @ApiOperation(value = "修改体检建议快捷标签接口")
    public AjaxResult updateTjAdviceKjbq(@RequestBody TjAdviceKjbq adviceKjbq) {
        return AjaxResult.success(kjbqService.updateById(adviceKjbq));
    }
 
    @PostMapping("/updateQybzTjAdviceKjbqById")
    @ApiOperation(value = "修改体检建议快捷标签启用状态接口")
    public AjaxResult updateQybzTjAdviceKjbqById(@RequestParam int qybz, @RequestParam Long id) {
        TjAdviceKjbq kjbq = kjbqService.getById(id);
        kjbq.setQyzt(String.valueOf(qybz));
        return AjaxResult.success(kjbqService.updateById(kjbq));
    }
 
    @GetMapping("/getTjAdviceKjbqByFl")
    @ApiOperation(value = "根据标签分类查询体检建议快捷标签接口")
    public AjaxResult getTjAdviceKjbqByFl(@RequestParam(required = false) @ApiParam(value = "用户id  传当前登录人  超管登录时不传 为null") String userId,
                                          @RequestParam(required = false) @ApiParam(value = "启用状态 0启用 1停用") Integer qyzt,
                                          @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page,
                                          @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<TjAdviceKjbq> wq = new LambdaQueryWrapper<>();
        Page<TjAdviceKjbq> page1 = new Page<>(page, pageSize);
        if (null != userId && !StringUtils.isBlank(userId)) {
            wq.eq(TjAdviceKjbq::getUserId, userId);
        }
        if (null != qyzt) {
            wq.eq(TjAdviceKjbq::getQyzt, qyzt);
        }
        Page<TjAdviceKjbq> kjbqPage = kjbqService.page(page1, wq);
        if (null != kjbqPage.getRecords() && !kjbqPage.getRecords().isEmpty()) {
            for (TjAdviceKjbq record : kjbqPage.getRecords()) {
                if (null != record.getUserId()) {
                    record.setUserName(userService.getById(record.getUserId()).getNickName());
                }
 
            }
        }
        return AjaxResult.success(kjbqPage);
    }
 
 
    @GetMapping("/getKjTjAdviceKjbqBySex")
    @ApiOperation(value = "根据体检人性别和是否为总检查询体检建议接口")
    public AjaxResult getKjTjAdviceKjbqBySex(@RequestParam String sex, @RequestParam @ApiParam(value = "1常规医生 0总检") String isZj,
                                             @RequestParam(required = false) @ApiParam(value ="建议内容") String jynr,
                                             @RequestParam(required = false) @ApiParam(value ="建议标题") String jybt,
                                             @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page,
                                             @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<TjAdvice> wq = new LambdaQueryWrapper<>();
        Page<TjAdvice> page1 = new Page<>(page, pageSize);
//        wq.eq(TjAdvice::getAdSex, sex).or().isNull(TjAdvice::getAdSex);
        wq.eq(TjAdvice::getIsZj, isZj);
        if(StringUtil.isNotBlank(jynr)) wq.like(TjAdvice::getAdvice,jynr);
        if(StringUtil.isNotBlank(jybt)) wq.like(TjAdvice::getTitle,jybt);
//        wq.and(i -> i.eq(TjAdvice::getAdSex, sex).or().isNull(TjAdvice::getAdSex));
        Page<TjAdvice> kjbqPage = tjAdviceService.page(page1, wq);
        return AjaxResult.success(kjbqPage);
    }
 
 
    @GetMapping("/getCyTjAdviceKjbqBySex")
    @ApiOperation(value = "根据当前登录人id获取常用建议")
    public AjaxResult getCyTjAdviceKjbqBySex(@RequestParam(required = false) String sex, @RequestParam @ApiParam(value = "用户id 传当前登录人") Long userId,
                                             @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page,
                                             @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<TjAdvice> wq = new LambdaQueryWrapper<>();
        Page<TjAdvice> page1 = new Page<>(page, pageSize);
//        wq.eq(TjAdvice::getAdSex,sex).or().eq(TjAdvice::getAdSex,"2");
        if (null != userId) {
            LambdaQueryWrapper<TjUserAdvice> wq0 = new LambdaQueryWrapper<>();
            wq0.eq(TjUserAdvice::getUserId, userId);
            List<TjUserAdvice> list = userAdviceService.list(wq0);
            if (null != list && !list.isEmpty()) {
                List<Long> longs = list.stream().map(TjUserAdvice::getAdviceId).collect(Collectors.toList());
                wq.in(TjAdvice::getId,longs);
//                wq.last("and (ad_sex=1 OR ad_sex=2)");
                Page<TjAdvice> kjbqPage = tjAdviceService.page(page1,wq);
                return AjaxResult.success(kjbqPage);
            }
        }
        return AjaxResult.success("该用户暂时没有常用建议!");
    }
 
 
    @GetMapping("/addCyTjAdviceByUserId")
    @ApiOperation(value = "添加当前登录人常用建议接口")
    public AjaxResult addCyTjAdviceByUserId(@RequestParam @ApiParam(value = "所选建议主键id数组") List<Long> adviceIds) {
        String userId = UserHoder.getLoginUser().getUserId();
        if (null != adviceIds && !adviceIds.isEmpty()) {
            for (Long id : adviceIds) {
                TjUserAdvice tjUserAdvice = userAdviceService.getTjUserAdviceByUserId(Long.valueOf(userId), id);
                if (null == tjUserAdvice) {
                    TjUserAdvice userAdvice = new TjUserAdvice();
                    userAdvice.setAdviceId(id);
                    userAdvice.setUserId(Long.valueOf(userId));
                    userAdviceService.save(userAdvice);
                }
            }
            return AjaxResult.success("添加成功!");
        }
        return AjaxResult.success("请选择您要添加的建议!");
    }
 
 
    @GetMapping("/edaitCyTjAdviceByUserId")
    @ApiOperation(value = "修改当前登录人常用建议接口")
    public AjaxResult edaitCyTjAdviceByUserId(@RequestParam @ApiParam(value = "所选建议主键id数组") List<Long> adviceIds) {
        String userId = UserHoder.getLoginUser().getUserId();
        if (null != adviceIds && !adviceIds.isEmpty()) {
            LambdaQueryWrapper<TjUserAdvice> wq=new LambdaQueryWrapper<>();
            wq.eq(TjUserAdvice::getUserId,userId);
            userAdviceService.remove(wq);
            for (Long id : adviceIds) {
                TjUserAdvice tjUserAdvice = userAdviceService.getTjUserAdviceByUserId(Long.valueOf(userId), id);
                if (null == tjUserAdvice) {
                    TjUserAdvice userAdvice = new TjUserAdvice();
                    userAdvice.setAdviceId(id);
                    userAdvice.setUserId(Long.valueOf(userId));
                    userAdviceService.save(userAdvice);
                }
            }
            return AjaxResult.success("添加成功!");
        }
        return AjaxResult.success("请选择您要添加的建议!");
    }
 
 
 
    @PostMapping("/addCyTjAdvice")
    @ApiOperation(value = "添加常用建议接口")
    public AjaxResult addCyTjAdvice(@RequestBody TjAdvice adviceId) {
        String userId = UserHoder.getLoginUser().getUserId();
        if (null != adviceId) {
            if (tjAdviceService.save(adviceId)) {
                TjUserAdvice tjUserAdvice = userAdviceService.getTjUserAdviceByUserId(Long.valueOf(userId),adviceId.getId());
                if (null == tjUserAdvice) {
                    TjUserAdvice userAdvice = new TjUserAdvice();
                    userAdvice.setAdviceId(adviceId.getId());
                    userAdvice.setUserId(Long.valueOf(userId));
                    userAdviceService.save(userAdvice);
                }
            }
            return AjaxResult.success("操作成功!");
        }
        return AjaxResult.success("请选择您要添加的建议!");
    }
 
 
 
//    ================/**/==================================================================================================================================
    /**
     * 查询advice列表
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:list')")
    @GetMapping("/list")
    @ApiOperation(value = "体检建议列表查询")
    public AjaxResult list(@RequestParam(required = false) @ApiParam(value = "项目名") String proName,
                           @ApiParam(value = "标题") @RequestParam(required = false) String bt,
                           @ApiParam(value = "建议") @RequestParam(required = false) String nr,
                           @ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer page,
                           @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize,
                           @RequestParam(required = false)String deptId) {
//        LambdaQueryWrapper<SysDept> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(SysDept::getParentId, 0);
//        SysDept sysDept = sysDeptService.getOne(wrapper);
//        Page<TjAdvice> page1 = new Page<>(page, pageSize);
//        Map<String, Object> map = new HashMap<>();
//        List<TjAdvice> list = null;
//        long total = 0;
//        if (null != proName) {
//            LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
//            list = new ArrayList<>();
//            wq.like(TjProject::getProName, proName);
//            List<TjProject> projectList = tjProjectService.list(wq);
//            if (null != projectList && !projectList.isEmpty()) {
//                for (TjProject project : projectList) {
//                    LambdaQueryWrapper<TjAdvice> wqq = new LambdaQueryWrapper<>();
//                    wqq.eq(TjAdvice::getProId, project.getProId());
//                    if (!deptId.equals(String.valueOf(sysDept.getDeptId()))) {
//                        wqq.eq(TjAdvice::getDept_id, deptId);
//                    }
//                    IPage<TjAdvice> adviceList = tjAdviceService.page(page1, wqq);
//                    if (null != adviceList.getRecords() && !adviceList.getRecords().isEmpty()) {
//                        for (TjAdvice record : adviceList.getRecords()) {
//                            record.setProName(project.getProName());
//                            String kjbq = record.getKjbq();
//                            if(null !=kjbq && !kjbq.isEmpty()){
//                                String[] split = kjbq.split(",");
//                                record.setKjbqz(Arrays.asList(split));
//                            }
//                        }
//                        list.addAll(adviceList.getRecords());
//                    }
//                    total = adviceList.getTotal();
//                }
//            }
//            map.put("list", list);
//            map.put("total", total);
//            List<TjAdvice> list1 =  tjAdviceService.selectList(proName,deptId,(page -1) * pageSize,pageSize);
//            return AjaxResult.success(map);
//        }
//        LambdaQueryWrapper<TjAdvice> wq=new LambdaQueryWrapper<>();
//        if(!StringUtil.isBlank(bt)) wq.like(TjAdvice::getTitle,bt);
//        if(!StringUtil.isBlank(nr)) wq.like(TjAdvice::getAdvice,nr);
//        if (!deptId.equals(String.valueOf(sysDept.getDeptId()))) {
//            wq.eq(TjAdvice::getDept_id, deptId);
//        }
//        Page<TjAdvice> page2 = tjAdviceService.page(page1,wq);
//        list = page2.getRecords();
//        if (null != list && !list.isEmpty()) {
//            for (TjAdvice advice : list) {
//                TjProject tjProject = tjProjectService.getById(advice.getProId());
//                if (null != tjProject) {
//                    advice.setProName(tjProject.getProName());
//                }
//                String kjbq = advice.getKjbq();
//                if(null !=kjbq && !kjbq.equals("")){
//                    String[] split = kjbq.split(",");
//                    advice.setKjbqz(Arrays.asList(split));
//                }
//            }
//        }
//        map.put("list", list);
//        map.put("total", page2.getTotal());
        List<TjAdvice> tjAdvices = tjAdviceService.selectList(proName, deptId, (page - 1) * pageSize, pageSize,bt,nr);
        Integer count = tjAdviceService.selectListCount(proName, deptId,bt,nr);
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("list",tjAdvices);
        hashMap.put("total",count);
        return AjaxResult.success(hashMap);
    }
 
    /**
     * 导出advice列表
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:export')")
    @Log(title = "advice", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TjAdvice tjAdvice) {
        List<TjAdvice> list = tjAdviceService.selectTjAdviceList(tjAdvice);
        ExcelUtil<TjAdvice> util = new ExcelUtil<TjAdvice>(TjAdvice.class);
        util.exportExcel(response, list, "advice数据");
    }
 
    /**
     * 获取advice详细信息
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "根据主键id获取advice详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        TjAdvice advice = tjAdviceService.getById(id);
        if(null !=advice){
            String kjbq = advice.getKjbq();
            if(null !=kjbq && !kjbq.equals("")){
                String[] split = kjbq.split(",");
                advice.setKjbqz(Arrays.asList(split));
            }
        }
        return AjaxResult.success(advice);
    }
 
    /**
     * 新增advice
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:add')")
    @Log(title = "advice", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增体检建议接口")
    public AjaxResult add(@RequestBody TjAdvice tjAdvice) {
        return AjaxResult.success(tjAdviceService.save(tjAdvice));
    }
 
    /**
     * 修改advice
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:edit')")
    @Log(title = "advice", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改体检建议接口")
    public AjaxResult edit(@RequestBody TjAdvice tjAdvice) {
        return AjaxResult.success(tjAdviceService.updateById(tjAdvice));
    }
 
    /**
     * 删除advice
     */
//    @PreAuthorize("@ss.hasPermi('advice:advice:remove')")
    @Log(title = "advice", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.success(tjAdviceService.deleteTjAdviceByIds(ids));
    }
}