zhaowenxuan
2024-12-26 c554eccf65b7c75b47bbd3fc9e6deb4e64262638
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
package com.ltkj.web.controller.system;
 
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.base.Joiner;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.utils.SecurityUtils;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.TjSummary;
import com.ltkj.hosp.domain.TjTollCollector;
import com.ltkj.hosp.service.ITjSummaryService;
import com.ltkj.hosp.service.ITjTollCollectorService;
import com.ltkj.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: zjh
 * @Date: 2023/10/16 09:02
 */
@RestController
@RequestMapping("/hosp/summary")
@Api(tags = "PC端  汇总结账接口")
public class TjSummaryController {
    @Resource
    private ITjTollCollectorService collectorService;
 
    @Resource
    private ITjSummaryService summaryService;
    @Resource
    private ISysConfigService configService;
 
 
    @GetMapping("/getTjSummaryList")
    @ApiOperation(value = "查询汇总单据信息接口")
    public AjaxResult getTjSummaryList(@RequestParam(required = false) @ApiParam(value = "收费员id") String tollCollectorId,
                           @RequestParam(required = false) @ApiParam(value = "起始时间") String accountBeginTime,
                           @RequestParam(required = false) @ApiParam(value = "起始时间") String accountEndTime) {
 
        LambdaQueryWrapper<TjSummary> wqq = new LambdaQueryWrapper<>();
        if (null != tollCollectorId) {
            wqq.eq(TjSummary::getHzUserId, tollCollectorId);
        }
        if (null != accountBeginTime && null != accountEndTime) {
            wqq.between(TjSummary::getCreateTime, accountBeginTime, accountEndTime);
        }
        wqq.orderByDesc(TjSummary::getCreateTime);
        List<TjSummary> list= summaryService.list(wqq);
        if(null !=list && list.size()>0){
            for (TjSummary summary : list) {
                String accountId = summary.getAccountId();
                String[] split = accountId.split(";");
                LambdaQueryWrapper<TjTollCollector> wq = new LambdaQueryWrapper<>();
                wq.in(TjTollCollector::getId, (Object[]) split);
                summary.setCollectorList(collectorService.list(wq));
            }
        }
        return AjaxResult.success(list);
    }
 
 
    @GetMapping("/list")
    @ApiOperation(value = "查询收费员日结未汇总单据信息")
    public AjaxResult list(@RequestParam(required = false) @ApiParam(value = "收费员id") String tollCollectorId,
                           @RequestParam(required = false) @ApiParam(value = "起始时间") String accountBeginTime,
                           @RequestParam(required = false) @ApiParam(value = "起始时间") String accountEndTime) {
 
        LambdaQueryWrapper<TjTollCollector> wqq = new LambdaQueryWrapper<>();
        if (null != tollCollectorId) {
            wqq.eq(TjTollCollector::getTollCollectorId, tollCollectorId);
        }
        if (null != accountBeginTime && null != accountEndTime) {
            wqq.between(TjTollCollector::getCreateTime, accountBeginTime, accountEndTime);
        }
        wqq.orderByDesc(TjTollCollector::getCreateTime);
        wqq.isNull(TjTollCollector::getIsHz);
        List<TjTollCollector> list= collectorService.list(wqq);
        return AjaxResult.success(list);
    }
 
 
 
    @PostMapping("/addTjSummary")
    @ApiOperation(value = "点击汇总 新增汇总信息接口")
    public AjaxResult addTjSummary(@RequestBody List<String> ids) {
 
        if(null !=ids && ids.size()>0){
            String accountId = "HZ" + SecurityUtils.getUsername() + (new SimpleDateFormat("yyMMddHHmmssSSS").format(new Date()));
            BigDecimal zshoukuan = new BigDecimal("0.00");
            BigDecimal ztuikuan = new BigDecimal("0.00");
            BigDecimal zyingjiao = new BigDecimal("0.00");
            for (String id : ids) {
                TjTollCollector collector = collectorService.getById(id);
                if(null !=collector){
                    zshoukuan=zshoukuan.add(collector.getAmountReceived());
                    ztuikuan=ztuikuan.add(collector.getRefundAmount());
                    zyingjiao=zyingjiao.add(collector.getPayable());
                    collector.setIsHz(accountId);
                    collectorService.updateById(collector);
                }
            }
            String join = Joiner.on(";").join(ids);
            TjSummary summary=new TjSummary();
            summary.setHzName(UserHoder.getLoginUser().getUser().getNickName());
            summary.setHzUserId(Long.valueOf(UserHoder.getLoginUser().getUserId()));
            summary.setHzCard(accountId);
            summary.setHzSj("汇总结账");
            summary.setAmountReceived(zshoukuan);
            summary.setRefundAmount(ztuikuan);
            summary.setPayable(zyingjiao);
            summary.setAccountId(join);
            summaryService.save(summary);
            return AjaxResult.success(accountId);
        }
        return AjaxResult.error("请选择汇总单据");
    }
 
 
    @DeleteMapping("/removeTjSummaryById")
    @ApiOperation(value = "汇总员撤销 汇总账单 接口")
    public AjaxResult removeTjSummaryById(@RequestParam @ApiParam(value = "结账id") String id,
                                          @RequestParam @ApiParam(value = "结账员id") String tollCollectorId) {
        String userId = SecurityUtils.getLoginUser().getUserId();
        if (!userId.equals(tollCollectorId)) {
            return AjaxResult.error("非当前用户禁止操作");
        }
        TjSummary summary = summaryService.getById(id);
        if (summaryService.removeById(id)) {
            if (null != summary) {
                String accountId = summary.getAccountId();
                String[] split = accountId.split(";");
                for (String s : split) {
                    TjTollCollector tollCollector = collectorService.getTjTollCollectorById(s);
                    tollCollector.setIsHz(null);
                    collectorService.updateById(tollCollector);
                }
                return AjaxResult.success("该账单已成功撤销");
            }
            return AjaxResult.success("该账单已撤销");
        }
        return AjaxResult.error("撤销失败");
    }
 
 
    @GetMapping("/getPrintSetUp")
    @ApiOperation(value = "查询打印设置 0小票 1 发票")
    public AjaxResult getPrintSetUp() {
        String printSetUp = configService.selectConfigByKey("print_set_up");
        return AjaxResult.success(printSetUp);
    }
 
 
    @GetMapping("/getLastTime")
    @ApiOperation(value = "获取汇总时间起始时间")
    public AjaxResult getLastTime() {
        LambdaQueryWrapper<TjSummary> wq = new LambdaQueryWrapper<>();
        wq.orderByDesc(TjSummary::getCreateTime);
        List<TjSummary> list = summaryService.list(wq);
        if (null != list && list.size() > 0) return AjaxResult.success(list.get(0).getCreateTime());
        String dateStr = "2023-10-01 00:00:00";
        Date date = DateUtil.parse(dateStr, "yyyy-MM-dd HH:mm:ss");
        return AjaxResult.success(date);
    }
 
}