zjh
4 天以前 cc25bc0eec2d50da39d62f9896ed4d5e66805366
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
package com.ltkj.web.controller.system;
 
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.framework.config.MatchUtils;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import com.ltkj.hosp.vodomain.TeamTjPeopleVo;
import com.mysql.cj.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jodd.util.StringUtil;
import org.aspectj.weaver.AjAttribute;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.ltkj.common.core.controller.BaseController;
import oshi.hardware.platform.mac.MacUsbDevice;
 
import javax.annotation.Resource;
import java.lang.annotation.ElementType;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
import static com.ltkj.framework.datasource.DynamicDataSourceContextHolder.log;
 
/**
 * 体检单位缴费主Controller
 *
 * @author ltkj
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/team/pay")
@Api(tags = "团体体检收费管理")
public class TjCompPayController extends BaseController {
    @Resource
    private ITjCompPayService compPayService;
    @Resource
    private ITjCompPayInfoService payInfoService;
    @Resource
    private ITjTeamSelectRecordService selectRecordService;
    @Resource
    private IDictCompService compService;
    @Resource
    private ITjReservationService reservationService;
    @Resource
    private ITjOrderService orderService;
    @Resource
    private ITjCustomerService customerService;
    @Resource
    private ITjDwGroupingService dwGroupingService;
    @Resource
    private ITjOrderRemarkService remarkService;
    @Resource
    private ITjFlowingWaterService tjFlowingWaterService;
    @Resource
    private ITbTransitionService transitionService;
    /**
     * 团体体检收费接口
     */
    @PostMapping
    @ApiOperation(value = "团体体检收费接口")
    @Transactional
    public AjaxResult add(@RequestBody TjCompPay compPay) {
        try {
            if (null==compPay.getTjhs() || compPay.getTjhs().isEmpty()) {
                return AjaxResult.error("请选择结账人员!");
            }
            Date date = DateUtil.date();
            String s = String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName());
            compPay.setPayee(s);
            compPay.setSerialNumber("TT"+SecurityUtils.getUsername() + DateUtil.format(date, "yyMMddHHmmssSSS"));
            compPay.setInvoiceNo("FP" + DateUtil.format(date, "yyMMddHHmmssSSS"));
            if(compPayService.save(compPay)){
                for (String tjh : compPay.getTjhs()) {
                    TjOrder tjOrder = orderService.getOrderByTjNum(tjh);
                    if(null != tjOrder){
                        TjFlowingWater water = tjFlowingWaterService.getOne(new LambdaQueryWrapper<TjFlowingWater>()
                                .eq(TjFlowingWater::getOrderId, tjOrder.getOrderId()).eq(TjFlowingWater::getIsAddition, "N"));
                        if(null != water){
                            TjCompPayInfo payInfo =  new TjCompPayInfo();
                            payInfo.setTjh(tjh);
                            payInfo.setTjCompPayId(compPay.getId());
                            payInfo.setTransactionAmount(water.getPaidIn());
                            payInfo.setPaymentMethod(compPay.getPaymentMethod());
                            payInfo.setCardNo(compPay.getCardNo());
                            payInfo.setPayer(compPay.getPayer());
                            payInfo.setPayee(compPay.getPayee());
                            payInfoService.save(payInfo);
                            water.setSfjs("1");
                            water.setJsdh(compPay.getSerialNumber());
                            water.setJsrq(DateUtil.date());
                            water.setJsrxm(s);
                            water.setJsrdm(SecurityUtils.getLoginUser().getUser().getUserId().toString());
                            tjFlowingWaterService.updateById(water);
                        }
                    }
 
                }
                return AjaxResult.success("收费成功");
            }
            return AjaxResult.error("操作失败");
        } catch (Exception e) {
            log.error("收费异常", e);
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 团体体检退费接口
     */
    @PostMapping("/refund")
    @ApiOperation(value = "团体体检退费接口")
    @Transactional
    public AjaxResult refund(@RequestBody TjCompPay compPay) {
        try {
            if(null !=compPay){
                if (compPayService.removeById(compPay)) {
                    LambdaQueryWrapper<TjCompPayInfo>wq=new LambdaQueryWrapper<>();
                    wq.eq(TjCompPayInfo::getTjCompPayId,compPay.getId());
                    payInfoService.remove(wq);
                    LambdaQueryWrapper<TjFlowingWater> waterLambdaQueryWrappe=new LambdaQueryWrapper<>();
                    waterLambdaQueryWrappe.eq(TjFlowingWater::getJsdh,compPay.getSerialNumber());
                    List<TjFlowingWater> waterList = tjFlowingWaterService.list(waterLambdaQueryWrappe);
                    if(null != waterList && !waterList.isEmpty()){
                        for (TjFlowingWater water : waterList) {
                            water.setSfjs("0");
                            water.setJsdh(null);
                            water.setJsrq(null);
                            water.setJsrxm(null);
                            water.setJsrdm(null);
                            tjFlowingWaterService.updateById(water);
                        }
                    }
                    return AjaxResult.success("操作成功");
                }
            }
            return AjaxResult.error("操作失败");
        } catch (Exception e) {
            log.error("操作失败", e);
            throw new RuntimeException(e);
        }
    }
 
    /**
     * 所有公司体检收费数据查询接口
     */
    @GetMapping
    @ApiOperation(value = "所有公司体检收费数据查询接口")
    public AjaxResult list(@RequestParam(required = false) @ApiParam(value = "单位id") String compId) {
 
        List<TjReservation> rightList = reservationService.list(new LambdaQueryWrapper<TjReservation>().eq(TjReservation::getCompanyId, compId));
 
        Map<String, List<TjReservation>> collect = rightList.stream().collect(Collectors.groupingBy(TjReservation::getPacId));
 
        if (!collect.isEmpty()) {
            for (Map.Entry<String, List<TjReservation>> entry : collect.entrySet()) {
                BigDecimal compPay = new BigDecimal("0.00");
                for (TjReservation reservation : entry.getValue()) {
                    TjDwGrouping dwGrouping = dwGroupingService.getById(reservation.getGroupingId());
                    compPay = compPay.add(dwGrouping.getYsPrice());
                }
                LambdaQueryWrapper<TjTeamSelectRecord> wq = new LambdaQueryWrapper<>();
                wq.eq(TjTeamSelectRecord::getTeamNo, entry.getValue().get(0).getTeamNo());
                wq.eq(TjTeamSelectRecord::getPacId, entry.getKey());
                wq.eq(TjTeamSelectRecord::getCompId,compId);
                TjTeamSelectRecord recordServiceOne = selectRecordService.getOne(wq);
                if (null == recordServiceOne) {
                    TjTeamSelectRecord selectRecord = new TjTeamSelectRecord();
                    selectRecord.setCompId(compId);
                    selectRecord.setPacId(entry.getKey());
                    selectRecord.setTeamNo(entry.getValue().get(0).getTeamNo());
                    selectRecord.setTransactionAmount(new BigDecimal("0.00"));
                    selectRecord.setCopeWith(compPay);
                    selectRecord.setCount(entry.getValue().size());
                    selectRecord.setDifference(compPay);
                    selectRecordService.save(selectRecord);
                }
            }
        }
 
        LambdaQueryWrapper<TjTeamSelectRecord>wq0=new LambdaQueryWrapper<>();
        if(null !=compId){
            wq0.eq(TjTeamSelectRecord::getCompId,compId);
        }
        List<TjTeamSelectRecord> selectRecordList = selectRecordService.list(wq0);
        if(null !=selectRecordList && !selectRecordList.isEmpty()){
            for(TjTeamSelectRecord selectRecord : selectRecordList){
                selectRecord.setSjCount(orderService.count(new LambdaQueryWrapper<TjOrder>()
                        .eq(TjOrder::getTeamNo,selectRecord.getTeamNo()).eq(TjOrder::getPacId,selectRecord.getPacId())));
 
                TjDwGrouping dwGrouping = dwGroupingService.getById(selectRecord.getPacId());
                if(null !=dwGrouping){
                    selectRecord.setPacName(dwGrouping.getGroupingName());
                    selectRecord.setSigningPrice(dwGrouping.getSigningPrice());
                }
                LambdaQueryWrapper<TjCompPay>wq1=new LambdaQueryWrapper<>();
                wq1.eq(TjCompPay::getCompId,compId);
                wq1.eq(TjCompPay::getTeamNo,selectRecord.getTeamNo());
                wq1.eq(TjCompPay::getPacId,selectRecord.getPacId());
                List<TjCompPay> compPay = compPayService.list(wq1);
                BigDecimal sumZje = compPayService.sumZje(compId,selectRecord.getTeamNo(),selectRecord.getPacId());
                List<String> SerialNumbers = compPayService.serialNumbers(compId,selectRecord.getTeamNo(),selectRecord.getPacId());
                if (null !=compPay && !compPay.isEmpty()) {
                    selectRecord.setTransactionAmount(sumZje);
                    selectRecord.setDifference(selectRecord.getCopeWith().subtract(sumZje));
                    selectRecord.setYjsrs(tjFlowingWaterService.count(new LambdaQueryWrapper<TjFlowingWater>()
                            .in(TjFlowingWater::getJsdh,SerialNumbers)));
                }else {
                    selectRecord.setYjsrs(0);
                }
            }
        }
        return AjaxResult.success(selectRecordList);
    }
 
 
 
    /**
     * 所有公司体检收费数据查询接口
     */
    @GetMapping("/getTeamTjPeopleList")
    @ApiOperation(value = "根据团队体检编号团队人员体检情况查询")
    public AjaxResult getTeamTjPeopleList(@RequestParam @ApiParam(value = "团队编号") String teamNo,
                                          @RequestParam(required = false) @ApiParam(value = "单位id") String pacId) {
 
        try {
            Map<String,Object> map=new HashMap<>();
            LambdaQueryWrapper<TjReservation> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(TjReservation::getTeamNo, teamNo);
            if(StringUtil.isNotBlank(pacId))wrapper.eq(TjReservation::getPacId, pacId);
            List<TjReservation> reservationList = reservationService.list(wrapper);
            if (null != reservationList && !reservationList.isEmpty()) {
                List<TeamTjPeopleVo> syList = new ArrayList<>();
                List<TeamTjPeopleVo> yjwjzList = new ArrayList<>();
                List<TeamTjPeopleVo> wjList = new ArrayList<>();
                for (TjReservation reservation : reservationList) {
                    TeamTjPeopleVo vo = new TeamTjPeopleVo();
                    vo.setName(reservation.getName());
                    vo.setXb(reservation.getSex().toString());
                    vo.setDh(reservation.getPhoe());
                    TjCustomer customer = null;
                    try {
                        customer = customerService.getTjCustomerByCusIdCard( reservation.getIdCard());
                    } catch (Exception e) {
                        log.error("根据团队编号查询团队预约信息异常"+reservation.getIdCard());
                        throw new RuntimeException(e);
                    }
                    if (null != customer) {
                        TjOrder tjOrder = orderService.getOne(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getUserId, customer.getCusId()).eq(TjOrder::getTeamNo, teamNo));
                        if (null != tjOrder) {
                            TjFlowingWater water = tjFlowingWaterService.getOne(new LambdaQueryWrapper<TjFlowingWater>()
                                    .eq(TjFlowingWater::getOrderId, tjOrder.getOrderId()).eq(TjFlowingWater::getIsAddition, "N"));
                            if(null != water && water.getSfjs().equals("0") && water.getJsrq() ==null){
                                vo.setTjh(tjOrder.getTjNumber());
                                int sfwc = remarkService.panduaniswancheng(tjOrder.getTjNumber());
                                if (sfwc==0) {
                                    vo.setTjStatus("已完成");
                                    vo.setTjTime(DateUtil.format(tjOrder.getCreateTime(),"yyyy-MM-dd"));
                                    vo.setTjf(water.getPaidIn());
                                } else {
                                    vo.setTjTime(DateUtil.format(tjOrder.getCreateTime(),"yyyy-MM-dd"));
                                    vo.setTjf(water.getPaidIn());
                                    vo.setTjStatus("在 检");
                                }
                                yjwjzList.add(vo);
                            }
                        } else {
                            vo.setTjStatus("未 检");
                            vo.setTjf(transitionService.sumNowPrice(reservation.getIdCard()));
                            wjList.add(vo);
                        }
                    }else {
                        vo.setTjStatus("未 检");
                        vo.setTjf(transitionService.sumNowPrice(reservation.getIdCard()));
                        wjList.add(vo);
                    }
                    syList.add(vo);
 
                }
                map.put("syList",syList);
                map.put("yjwjzList",yjwjzList);
                map.put("wjList",wjList);
                return AjaxResult.success(map);
            }
            return AjaxResult.success(null);
        } catch (Exception e) {
            log.error("查询团队体检人员信息异常");
            throw new RuntimeException(e);
        }
    }
 
 
 
    @GetMapping("/getTjCompPay")
    @ApiOperation(value = "根据团队体检编号和套餐id获取结账信息")
    public AjaxResult getTjCompPay(@RequestParam @ApiParam(value = "团队编号") String teamNo,
                                          @RequestParam(required = false) @ApiParam(value = "单位id") String pacId) {
 
        try {
             LambdaQueryWrapper<TjCompPay> wq = new LambdaQueryWrapper<>();
             wq.eq(TjCompPay::getTeamNo, teamNo);
             wq.eq(TjCompPay::getCompId, pacId);
             List<TjCompPay> tjCompPays = compPayService.list(wq);
             if(null !=tjCompPays && !tjCompPays.isEmpty()){
                 for (TjCompPay pay : tjCompPays) {
                     LambdaQueryWrapper<TjCompPayInfo> wqInfo = new LambdaQueryWrapper<>();
                     wqInfo.eq(TjCompPayInfo::getTjCompPayId, pay.getId());
                     List<TjCompPayInfo> payInfos = payInfoService.list(wqInfo);
                     pay.setPayInfo(payInfos);
                 }
             }
            return AjaxResult.success(tjCompPays);
        } catch (Exception e) {
            log.error("查询团队体检人员信息异常");
            throw new RuntimeException(e);
        }
    }
}