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
package com.by4cloud.platformx.business.controller;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.by4cloud.platformx.business.dto.*;
import com.by4cloud.platformx.business.entity.Contract;
import com.by4cloud.platformx.business.entity.ContractInvoice;
import com.by4cloud.platformx.business.entity.ContractOutBound;
import com.by4cloud.platformx.business.service.ContractInvoiceService;
import com.by4cloud.platformx.business.service.ContractService;
import com.by4cloud.platformx.common.core.util.R;
import com.by4cloud.platformx.common.data.mybatis.BaseModel;
import com.by4cloud.platformx.common.log.annotation.SysLog;
import com.by4cloud.platformx.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
/**
 * 合同开票
 *
 * @author syt
 * @date 2026年6月5日 08:13:55
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contractInvoice" )
@Tag(description = "contract" , name = "合同开票" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ContractInvoiceController {
 
    private final ContractService contractService;
    private final ContractInvoiceService contractInvoiceService;
 
    /**
     * 分页查询
     * @param page 分页对象
     * @param queryDTO 合同管理
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getContractPage(@ParameterObject Page page, @ParameterObject ContractQueryDTO queryDTO) {
//        LambdaQueryWrapper<Contract> wrapper = Wrappers.lambdaQuery();
//        wrapper.like(StringUtils.isNotBlank(queryDTO.getContractName()),Contract::getContractName,queryDTO.getContractName());
//        wrapper.like(StringUtils.isNotBlank(queryDTO.getPartyA()),Contract::getPartyA,queryDTO.getPartyA());
//        wrapper.eq(Contract::getBillingStatus,queryDTO.getBillingStatus());
//        if (StrUtil.equals(queryDTO.getInvoiceType(),"1")){
//            wrapper.eqSql(Contract::getBillingAmout,"(select sum(delivered_quantity*unit_price) from contract_subject_matter csm where csm.contract_id = contract.id)");
//        }else if (StrUtil.equals(queryDTO.getInvoiceType(),"0")){
//            wrapper.ltSql(Contract::getBillingAmout,"(select sum(delivered_quantity*unit_price) from contract_subject_matter csm where csm.contract_id = contract.id)");
//        }
//
//        if (StrUtil.equals(queryDTO.getBillingStatus(),"1")){
//            wrapper.orderByDesc(BaseModel::getCreateTime);
//        }else {
//            wrapper.orderByAsc(BaseModel::getCreateTime);
//        }
 
        return R.ok(contractInvoiceService.pageScope(page, queryDTO));
    }
 
    /**
     * 新增发票
     * @return R
     */
    @Operation(summary = "新增发票" , description = "新增发票" )
    @SysLog("新增发票" )
    @PostMapping
    public R save(@RequestBody ContractInvoice contractInvoice) {
        return contractInvoiceService.add(contractInvoice);
    }
 
    /**
     * 获取合同出库信息
     * @return
     */
    @GetMapping("/getContractOutBound/{contractId}" )
    public R getContractOutBound(@PathVariable("contractId")Long contractId) {
        return contractInvoiceService.getContractOutBound(contractId);
    }
 
    /**
     * 获取合同预开票信息
     * @return
     */
    @GetMapping("/getContractAdvance/{contractId}" )
    public R getContractAdvance(@PathVariable("contractId")Long contractId) {
        return contractInvoiceService.getContractAdvance(contractId);
    }
 
    /**
     * 获取合同房租 水电 费用信息
     * @return
     */
    @GetMapping("/getContractHouseWater/{contractId}" )
    public R getContractHouseWater(@PathVariable("contractId")Long contractId) {
        return contractInvoiceService.getContractHouseWater(contractId);
    }
 
    /**
     * 获取合并开票合同出库信息
     * @return
     */
    @PostMapping("/getMergeContractOutBound" )
    public R getMergeContractOutBound(@RequestBody Long[] ids) {
        return contractInvoiceService.getMergeContractOutBound(ids);
    }
 
    /**
     * 生成开票预览信息
     * @return
     */
    @PostMapping("/genInvoiceInfo" )
    public R genInvoiceInfo(@RequestBody GenInvoiceInfoDTO genInvoiceInfoDTO) {
        return contractInvoiceService.genInvoiceInfo(genInvoiceInfoDTO);
    }
 
    /**
     * 生成开票预览信息
     * @return
     */
    @PostMapping("/genMergeInvoiceInfo" )
    public R genMergeInvoiceInfo(@RequestBody GenMergeInvoiceDTO mergeInvoiceDTO) {
        return contractInvoiceService.genMergeInvoiceInfo(mergeInvoiceDTO);
    }
 
    /**
     * 开合并蓝票
     * @return
     */
    @PostMapping("/toMergeInvoice" )
    public R toMergeInvoice(@RequestBody ToMergeInvoiceDTO toMergeInvoiceDTO) {
        return contractInvoiceService.toMergeInvoice(toMergeInvoiceDTO);
    }
 
    /**
     * 开蓝票
     * @return
     */
    @PostMapping("/toInvoice" )
    public R toInvoice(@RequestBody ToInvoiceDTO toInvoiceDTO) {
        return contractInvoiceService.toInvoice(toInvoiceDTO);
    }
 
    /**
     * 获取已开发票
     * @return
     */
    @GetMapping("/getContractInvoiceList/{contractId}" )
    public R getContractInvoiceList(@PathVariable("contractId")Long contractId) {
        return contractInvoiceService.getContractInvoiceList(contractId);
    }
 
    /**
     * 蓝票查询
     * @return
     */
    @Inner(value = false)
    @GetMapping("/queryBlueInvoice")
    public R queryBlueInvoice() {
        return contractInvoiceService.queryBlueInvoice();
    }
 
    /**
     * 开红票
     * @return
     */
    @GetMapping("/toRedInvoice/{invoiceId}")
    public R toRedInvoice(@PathVariable("invoiceId")Long invoiceId) {
        return contractInvoiceService.toRedInvoice(invoiceId);
    }
 
    /**
     * 重新开票
     * @return
     */
    @GetMapping("/refresh/{invoiceId}")
    public R refresh(@PathVariable("invoiceId")Long invoiceId) {
        return contractInvoiceService.refresh(invoiceId);
    }
 
    /**
     * 手动推送bip
     * @return
     */
    @GetMapping("/bipPush/{invoiceId}")
    public R bipPush(@PathVariable("invoiceId")Long invoiceId) {
        return contractInvoiceService.bipPush(invoiceId);
    }
 
    /**
     * 手动推送bip
     * @return
     */
    @GetMapping("/bipPushPdf/{invoiceId}")
    public R bipPushPdf(@PathVariable("invoiceId")Long invoiceId) {
        return contractInvoiceService.bipPushPdf(invoiceId);
    }
 
    /**
     * 保存并推送
     * @return
     */
    @PostMapping("/saveAndPush")
    public R saveAndPush(@RequestBody ContractInvoiceUpateDTO upateDTO) {
        return contractInvoiceService.saveAndPush(upateDTO);
    }
 
    /**
     * 红票查询
     * @return
     */
    @Inner(value = false)
    @GetMapping("/queryRedInvoice")
    public R queryRedInvoice() {
        return contractInvoiceService.queryRedInvoice();
    }
 
    @GetMapping("/pageInvoice")
    public R pageInvoice(@ParameterObject Page page, @ParameterObject ContractInvoiceQueryDTO queryDTO) {
        return R.ok(contractInvoiceService.pageInvoice(page, queryDTO));
    }
 
    @GetMapping("/queryInvoice")
    public R queryInvoice(@ParameterObject Page page, @ParameterObject InvoiceQueryDTO queryDTO) {
        return contractInvoiceService.queryInvoice(page, queryDTO);
    }
 
    /**
     * 通过id查询
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(contractInvoiceService.getById(id));
    }
 
 
    /**
     * 通过key查询bip字典
     * @return R
     */
    @Operation(summary = "通过key查询bip字典" , description = "通过key查询bip字典" )
    @GetMapping("/selectBipByKey/{dictKey}" )
    public R selectBipByKey(@PathVariable("dictKey" ) String dictKey) {
        return contractInvoiceService.selectBipByKey(dictKey);
    }
}