zjh
2024-06-20 21bc96d8f12701c187a667a2b66176db04421d06
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
package com.ltkj.web.controller.system;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.domain.entity.SysUser;
import com.ltkj.common.core.redis.RedisCache;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.system.service.ISysConfigService;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: lige
 * @Date: 2023/4/12 11:57
 */
@RestController
@RequestMapping("/hosp/return")
@Api(tags = "复检接口")
@Slf4j
public class TjReturnController extends BaseController {
    @Resource
    private ITjOrderService tjOrderService;
    @Resource
    private ITjOrderDetailService tjOrderDetailService;
    @Resource
    private IDictCompService iDictCompService;
    @Resource
    private ITjPackageService tjPackageService;
    @Resource
    private ITjCustomerService tjCustomerService;
    @Resource
    private ITjProjectService projectService;
 
    @Resource
    private ITjOrderRemarkService orderRemarkService;
    @Resource
    private ISysUserService userService;
 
    @GetMapping("/getReturnOrderList")
    @ApiOperation(value = "查询体检记录列表")
    public AjaxResult getOrderList(@ApiParam(value = "页码数(默认1)") @RequestParam(defaultValue = "1") Integer pageNum,
                                   @ApiParam(value = "显示条数(默认10)") @RequestParam(defaultValue = "10") Integer pageSize,
                                   @ApiParam(value = "体检号)") @RequestParam(required = false) String tjNum,
                                   @ApiParam(value = "姓名)") @RequestParam(required = false) String name,
                                   @ApiParam(value = "登记开始时间") @RequestParam(required = false) Date djbeginTime,
                                   @ApiParam(value = "登记结束时间") @RequestParam(required = false) Date djendTime,
                                   @ApiParam(value = "报告开始时间") @RequestParam(required = false) Date bgbeginTime,
                                   @ApiParam(value = "报告结束时间") @RequestParam(required = false) Date bgendTime){
        Map<String,Object> map=new HashMap<>();
        if(null !=name){
            LambdaQueryWrapper<TjCustomer> wqq=new LambdaQueryWrapper<>();
            wqq.like(TjCustomer::getCusName,name);
            List<TjCustomer> customerList = tjCustomerService.list(wqq);
            if(null !=customerList && customerList.size()>0){
                List<TjOrder> list=new ArrayList<>();
                for (TjCustomer customer : customerList) {
                    LambdaQueryWrapper<TjOrder> wq=new LambdaQueryWrapper<>();
                    if(null !=djbeginTime && null !=djendTime){
                        wq.between(TjOrder::getCreateTime, DateUtil.beginOfDay(djbeginTime),DateUtil.endOfDay(djendTime));
                    }
                    wq.eq(TjOrder::getUserId,customer.getCusId());
                    list.addAll(tjOrderService.list(wq));
                }
                List<TjOrder> collect =null;
                if(list.size()>0){
                    for (TjOrder order : list) {
                        TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                        if (null != tjCustomer) {
                            order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                            order.setTjCustomerSex(tjCustomer.getCusSex());
                            order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                            order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                            order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                        }
                        String firmId = order.getFirmId();
                        if (firmId != null && null !=iDictCompService.getById(String.valueOf(order.getFirmId()))) {
                            order.setDictCompName(iDictCompService.getById(String.valueOf(order.getFirmId())).getCnName());
                        }
                        if (null != order.getPacId() && null !=tjPackageService.getById(order.getPacId())) {
                            order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                        }
                    }
                    collect = list.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
                }
                if (null != collect) {
                    map.put("total", collect.size());
                } else {
                    map.put("total",0);
                }
                map.put("list",collect);
                return AjaxResult.success(map);
            }
 
        }
        Page<TjOrder> page1=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<TjOrder> wq=new LambdaQueryWrapper<>();
        if(null !=djbeginTime && null !=djendTime){
            wq.between(TjOrder::getCreateTime,DateUtil.beginOfDay(djbeginTime),DateUtil.endOfDay(djendTime));
        }
        if(null !=bgbeginTime && null !=bgendTime){
            wq.between(TjOrder::getCreateTime,DateUtil.beginOfDay(bgbeginTime),DateUtil.endOfDay(bgendTime));
        }
        if(null !=tjNum){
            wq.eq(TjOrder::getTjNumber,tjNum);
        }
        Page<TjOrder> page2 = tjOrderService.page(page1,wq);
        List<TjOrder> list =page2.getRecords();
        if (list != null) {
            for (TjOrder order : list) {
                TjCustomer tjCustomer = tjCustomerService.getById(order.getUserId());
                if (null != tjCustomer) {
                    order.setTjCustomerName(MatchUtils.hideCusName(tjCustomer.getCusName()));
                    order.setTjCustomerSex(tjCustomer.getCusSex());
                    order.setTjCustomerAge(DateUtil.ageOfNow(tjCustomer.getCusBrithday()));
                    order.setTjCustomerPhone(MatchUtils.hidePhoneNum(tjCustomer.getCusPhone()));
                    order.setTjCusIdCard(MatchUtils.hideIdCardNum(tjCustomer.getCusIdcard()));
                }
                String firmId = order.getFirmId();
                if (firmId != null && null !=iDictCompService.getById(String.valueOf(order.getFirmId()))) {
                    order.setDictCompName(iDictCompService.getById(String.valueOf(order.getFirmId())).getCnName());
                }
                if (null != order.getPacId() && null !=tjPackageService.getById(order.getPacId())) {
                    order.setPacName(tjPackageService.getById(order.getPacId()).getPacName());
                }
            }
        }
        map.put("list",list);
        map.put("total",page2.getTotal());
        return AjaxResult.success(map);
    }
 
    /**
     * 根据获取复检详细项目列表
     */
    @GetMapping(value = "/{orderId}")
    @ApiOperation(value = "获取复检详细项目列表")
    public AjaxResult getListByOrderId(@PathVariable("orderId") Long orderId) {
        LambdaQueryWrapper<TjOrderDetail> wq=new LambdaQueryWrapper<>();
        wq.eq(TjOrderDetail::getOrderId,orderId);
        wq.eq(TjOrderDetail::getIsReturn,1);
        List<TjOrderDetail> list = tjOrderDetailService.list(wq);
 
        if (list!=null&&list.size()>0){
            for (TjOrderDetail tjOrderDetail : list) {
                final TjProject byId = projectService.getById(tjOrderDetail.getProId());
                if (byId!=null){
                    tjOrderDetail.setProject(byId);
                    tjOrderDetail.setProName(byId.getProName());
                    //根据父项目再remark表里查到医生名字
                    LambdaQueryWrapper<TjOrderRemark> wqq=new LambdaQueryWrapper<>();
                    wqq.eq(TjOrderRemark::getProId,byId.getProParentId());
                    wqq.eq(TjOrderRemark::getTjNumber,tjOrderService.getById(orderId).getTjNumber());
                    TjOrderRemark one = orderRemarkService.getOne(wqq);
                    if (one!=null){
                        SysUser byId1 = userService.getById(one.getDoctorName());
                        if (byId1!=null){
                            tjOrderDetail.setDoctorName(byId1.getNickName());
                        }
 
                    }else {
                        tjOrderDetail.setDoctorName(tjOrderDetail.getUpdateBy());
                    }
                }
            }
        }
        return AjaxResult.success(list);
    }
}