zhaowenxuan
2025-03-21 a34be58cdf00e92607edefb3130bdfd979390c16
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
package com.ltkj.web.controller.system;
 
 
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.aspectj.weaver.AjAttribute;
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.ArrayList;
import java.util.List;
 
/**
 * 体检单位缴费主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 ITjPackageService packageService;
    @Resource
    private IDictCompService compService;
    @Resource
    private ITjReservationService reservationService;
    @Resource
    private ITjOrderService orderService;
    @Resource
    private ITjCustomerService customerService;
    @Resource
    private ITjDwDeptService dwDeptService;
    /**
     * 团体体检收费接口
     */
    @PostMapping
    @ApiOperation(value = "团体体检收费接口")
    public AjaxResult add(@RequestBody TjCompPayInfo compPayInfo) {
        if (null==compPayInfo) {
            return AjaxResult.error();
        }
        compPayInfo.setPayee(String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName()));
        TjCompPay tjCompPay =compPayService.getById(compPayInfo.getTjCompPayId());
        BigDecimal paidIn = tjCompPay.getPaidIn();
                   paidIn =paidIn.add(compPayInfo.getTransactionAmount());
        if(paidIn.compareTo(tjCompPay.getCopeWith())>0 || tjCompPay.getDifference().compareTo(BigDecimal.valueOf(0))==0){
            return AjaxResult.error("暂无收费需求");
        }
        if (getAjaxResult(compPayInfo, tjCompPay)) return AjaxResult.success("收费成功");
        return AjaxResult.error("操作失败");
    }
 
    /**
     * 团体体检退费接口
     */
    @PostMapping("/refund")
    @ApiOperation(value = "团体体检退费接口")
    public AjaxResult refund(@RequestBody TjCompPayInfo compPayInfo) {
        if (null==compPayInfo) {
            return AjaxResult.error();
        }
        compPayInfo.setPayee(String.valueOf(SecurityUtils.getLoginUser().getUser().getNickName()));
        TjCompPay tjCompPay =compPayService.getById(compPayInfo.getTjCompPayId());
        BigDecimal paidIn = tjCompPay.getPaidIn();
        paidIn =paidIn.add(compPayInfo.getTransactionAmount());
        //判断实付金额和交易金额的数值
        if(paidIn.compareTo(BigDecimal.valueOf(0.00))==0 || compPayInfo.getTransactionAmount().compareTo(tjCompPay.getPaidIn())>0 ){
            return AjaxResult.error("暂无退费需求");
        }
        compPayInfo.setTransactionAmount(BigDecimal.valueOf(0.00).subtract(compPayInfo.getTransactionAmount()));
        compPayInfo.setPaymentMethod(3L);
        if (getAjaxResult(compPayInfo, tjCompPay)) return AjaxResult.success("退费成功");
        return AjaxResult.error("操作失败");
    }
 
    private boolean getAjaxResult(@RequestBody TjCompPayInfo compPayInfo, TjCompPay tjCompPay) {
        if(payInfoService.saveOrUpdate(compPayInfo)){
            LambdaQueryWrapper<TjCompPayInfo> wq=new LambdaQueryWrapper<>();
            wq.eq(TjCompPayInfo::getTjCompPayId,tjCompPay.getId());
            List<TjCompPayInfo> list = payInfoService.list(wq);
            BigDecimal bigDecimal=new BigDecimal("0.00");
            if(null !=list && list.size()>0){
                for (TjCompPayInfo payInfo : list) {
                    bigDecimal=bigDecimal.add(payInfo.getTransactionAmount());
                }
            }
            tjCompPay.setCreateBy(String.valueOf(SecurityUtils.getLoginUser().getUserId()));
            if(bigDecimal.compareTo(BigDecimal.valueOf(0.00))>= 0){
                tjCompPay.setPaidIn(bigDecimal);
            }else {
                tjCompPay.setPaidIn(BigDecimal.valueOf(0.00));
            }
            tjCompPay.setDifference(tjCompPay.getCopeWith().subtract(bigDecimal));
            compPayService.updateById(tjCompPay);
            LambdaQueryWrapper<TjTeamSelectRecord>wq0=new LambdaQueryWrapper<>();
            wq0.eq(TjTeamSelectRecord::getTeamNo,tjCompPay.getTeamNo());
            wq0.eq(TjTeamSelectRecord::getCompId,tjCompPay.getCompId());
            TjTeamSelectRecord record = selectRecordService.getOne(wq0);
            record.setTransactionAmount(tjCompPay.getPaidIn());
            selectRecordService.updateById(record);
            return true;
        }
        return false;
    }
 
    /**
     * 所有公司体检收费数据查询接口
     */
    @GetMapping
    @ApiOperation(value = "所有公司体检收费数据查询接口")
    public AjaxResult list(@RequestParam(required = false) @ApiParam(value = "单位id") String compId) {
        LambdaQueryWrapper<TjTeamSelectRecord>wq0=new LambdaQueryWrapper<>();
        if(null !=compId){
            wq0.eq(TjTeamSelectRecord::getCompId,compId);
        }
        wq0.ne(TjTeamSelectRecord::getDifference,0);
        List<TjTeamSelectRecord> selectRecordList = selectRecordService.list(wq0);
        if(null !=selectRecordList && selectRecordList.size()>0){
            for(TjTeamSelectRecord selectRecord : selectRecordList){
                TjDwDept dwDept = dwDeptService.getById(selectRecord.getPacId());
                if(null !=dwDept){
                    selectRecord.setPacName(dwDept.getDwDeptName());
                    selectRecord.setSigningPrice(dwDept.getSigningPrice());
                }
                LambdaQueryWrapper<TjCompPay>wq1=new LambdaQueryWrapper<>();
                wq1.eq(TjCompPay::getCompId,compId);
                wq1.eq(TjCompPay::getTeamNo,selectRecord.getTeamNo());
                TjCompPay compPay = compPayService.getOne(wq1);
                if (null !=compPay) {
                    LambdaQueryWrapper<TjCompPayInfo>wq=new LambdaQueryWrapper<>();
                    wq.eq(TjCompPayInfo::getTjCompPayId,compPay.getId());
                    selectRecord.setPayInfoList(payInfoService.list(wq));
                    selectRecord.setCopeWith(compPay.getCopeWith());
                    selectRecord.setDifference(compPay.getDifference());
                    selectRecord.setPayer(compService.getById(compPay.getCompId()).getContactPerson());
                    selectRecord.setSjCount(orderService.count(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getTeamNo,compPay.getTeamNo())));
                    TjCompPayInfo payInfo = new TjCompPayInfo();
                    payInfo.setTjCompPayId(compPay.getId());
                    selectRecord.setPayInfo(payInfo);
                }
            }
        }
        return AjaxResult.success(selectRecordList);
    }
 
 
 
    /**
     * 所有公司体检收费数据查询接口
     */
    @GetMapping("/getTeamTjPeopleList")
    @ApiOperation(value = "根据团队体检编号团队人员体检情况查询")
    public AjaxResult getTeamTjPeopleList(@RequestParam @ApiParam(value = "团队编号") String teamNo) {
 
        List<TjReservation> reservationList = reservationService.list(new LambdaQueryWrapper<TjReservation>().eq(TjReservation::getTeamNo,teamNo));
        if (null != reservationList && reservationList.size() > 0) {
            List<TeamTjPeopleVo> voList = new ArrayList<>();
            for (TjReservation reservation : reservationList) {
                TeamTjPeopleVo vo = new TeamTjPeopleVo();
                vo.setName(reservation.getName());
                TjCustomer customer = customerService.getOne(new LambdaQueryWrapper<TjCustomer>().eq(TjCustomer::getCusIdcard, reservation.getIdCard()));
                if (null != customer) {
                    TjOrder tjOrder = orderService.getOne(new LambdaQueryWrapper<TjOrder>().eq(TjOrder::getUserId, customer.getCusId()).eq(TjOrder::getTeamNo, teamNo));
                    if (null != tjOrder) {
                        if (null != tjOrder.getFinishTime()) {
                            vo.setTjStatus("已完成");
                            vo.setTjTime(tjOrder.getFinishTime());
                        } else {
                            vo.setTjStatus("未完成");
                        }
                    } else {
                        vo.setTjStatus("未 检");
                    }
                } else {
                    vo.setTjStatus("未 检");
                }
                voList.add(vo);
            }
            return AjaxResult.success(voList);
        }
        return AjaxResult.success(null);
    }
}