无关风月
2025-03-18 da81542b6dc8984f639687f30e7e610dc139b085
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
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.constant.DictConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.CodeGenerateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.BatchBillDTO;
import com.ruoyi.system.dto.TBillDto;
import com.ruoyi.system.dto.TInvoiceDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.TBillQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.TBillVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 租金账单 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-01-17
 */
@Api(tags = "缴费账单")
@RestController
@RequestMapping("/t-bill")
public class TBillController {
 
    @Autowired
    TBillService tBillService;
    @Autowired
    TBillDetailService billDetailService;
    @Autowired
    TContractService contractService;
    @Autowired
    THouseService houseService;
    @Autowired
    TInvoiceService invoiceService;
    @Autowired
    TInvoiceToBillService invoiceToBillService;
    @Autowired
    TokenService tokenService;
    @Autowired
    TTenantService tenantService;
 
    @ApiOperation(value = "缴费账单查询分页列表")
    @PostMapping("list")
    public R<PageInfo<TBillDto>> list(@RequestBody TBillQuery query){
        String userId = tokenService.getLoginUserApplet().getUserId();
        query.setUserId(userId);
        PageInfo<TBillDto> pageInfo = tBillService.queryPage(query);
        return R.ok(pageInfo);
    }
 
    public static void main(String[] args) {
        LocalDateTime localDateTime1 = LocalDateTime.now().withYear(2025).withMonth(11).withDayOfMonth(1);
        LocalDateTime localDateTime2 = LocalDateTime.now().withYear(2025).withMonth(11).withDayOfMonth(28);
        long allDays = ChronoUnit.DAYS.between(localDateTime1, localDateTime2);
        System.err.println(allDays);
    }
 
    @ApiOperation(value = "缴费账单查询列表")
    @PostMapping("/getBillIds")
    public R<List<String>> getBillIds(@RequestBody TBillQuery query){
        String userId = tokenService.getLoginUserApplet().getUserId();
        query.setUserId(userId);
        List<String> billIds = tBillService.getBillIds(query);
        return R.ok(billIds);
    }
 
    @ApiOperation(value = "跳转批量缴费")
    @PostMapping("/batchBill")
    public R<String> batchBill(@RequestBody BatchBillDTO dto){
        String userId = tokenService.getLoginUserApplet().getUserId();
        List<String> billIds = dto.getBillIds();
        Integer count = tBillService.batchBillCount(userId, billIds);
        if(count>0){
            return R.fail("请优先缴纳水电费");
        }
        return R.ok();
    }
 
    @ApiOperation(value = "查看缴费账单详情")
    @GetMapping(value = "/getDetailById")
    public R<TBillVO> getDetailById(@RequestParam String id) {
        TBill bill = tBillService.getById(id);
        TBillVO billVO = new TBillVO();
        BeanUtils.copyProperties(bill, billVO);
        // 查询水电费列表
        if("3".equals(bill.getBillType())){
            List<TBillDetail> list = billDetailService.list(Wrappers.lambdaQuery(TBillDetail.class)
                    .eq(TBillDetail::getBillId, id));
            billVO.setBillDetailList(list);
        }
        // 查询合同信息
        contractService.lambdaQuery().eq(TContract::getId, bill.getContractId()).oneOpt().ifPresent(contract -> {
            // 查询房屋信息
            billVO.setHouse(houseService.getById(contract.getHouseId()));
            billVO.setMonthRent(contract.getMonthRent());
            billVO.setPayType(contract.getPayType());
            billVO.setDeposit(contract.getDeposit());
            billVO.setPartyOnePerson(contract.getPartyOnePerson());
            billVO.setPartyOnePhone(contract.getPartyOnePhone());
            billVO.setConcatStartTime(contract.getStartTime());
            billVO.setConcatEndTime(contract.getEndTime());
        });
        billVO.setBillType(DictUtils.getDictLabel(DictConstants.DICT_TYPE_BILL_TYPE,billVO.getBillType()));
//        billVO.setPayFeesStatus(DictUtils.getDictLabel(DictConstants.DICT_TYPE_PAY_FEES_STATUS,billVO.getPayFeesStatus()));
        return R.ok(billVO);
    }
 
    @ApiOperation(value = "缴费账单开票")
    @PostMapping(value = "/invoice")
    public R<String> invoice(@RequestBody TInvoiceDTO dto) {
        String userId = tokenService.getLoginUserApplet().getUserId();
        dto.setApplyName(tenantService.getById(userId).getResidentName());
        String code;
        do {
            code = CodeGenerateUtils.generateVolumeSn();
        } while (invoiceService.count(Wrappers.lambdaQuery(TInvoice.class).eq(TInvoice::getInvoiceNumber, code)) > 0);
        dto.setInvoiceNumber(CodeGenerateUtils.generateVolumeSn());
        // 添加开票信息
        invoiceService.save(dto);
 
        // 添加开票信息中间表信息
        List<String> billIds = dto.getBillIds();
        List<TInvoiceToBill> sysInvoiceToBills = new ArrayList<>();
        for (String billId : billIds) {
            TInvoiceToBill tInvoiceToBill = new TInvoiceToBill();
            tInvoiceToBill.setInvoiceId(dto.getId());
            tInvoiceToBill.setBillId(billId);
            sysInvoiceToBills.add(tInvoiceToBill);
        }
        invoiceToBillService.saveBatch(sysInvoiceToBills);
        return R.ok();
    }
 
    @ApiOperation(value = "缴费账单开票列表")
    @PostMapping(value = "/invoiceList")
    public R<PageInfo<TBillDto>> invoiceList(@RequestBody TBillQuery query) {
 
        String userId = tokenService.getLoginUserApplet().getUserId();
        query.setUserId(userId);
        PageInfo<TBillDto> pageInfo = tBillService.invoiceList(query);
        return R.ok(pageInfo);
    }
 
}