puzhibing
2023-06-30 f58cca364b731eac2d60a440ffaa804be3cd43fd
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
package com.stylefeng.guns.modular.system.controller.general;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.controller.resp.TDriverResp;
import com.stylefeng.guns.modular.system.controller.util.ExcelUtil;
import com.stylefeng.guns.modular.system.enums.TBillStateEnum;
import com.stylefeng.guns.modular.system.model.TDriver;
import com.stylefeng.guns.modular.system.model.TOrder;
import com.stylefeng.guns.modular.system.service.ITOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.TBill;
import com.stylefeng.guns.modular.system.service.ITBillService;
 
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2023-03-14 15:15:19
 */
@Controller
@RequestMapping("/tBill")
public class TBillController extends BaseController {
 
    private String PREFIX = "/system/tBill/";
 
    @Autowired
    private ITBillService tBillService;
    @Autowired
    private ITOrderService tOrderService;
 
    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tBill.html";
    }
 
    /**
     * 跳转到添加
     */
    @RequestMapping("/tBill_add")
    public String tBillAdd() {
        return PREFIX + "tBill_add.html";
    }
 
    /**
     * 跳转到修改
     */
    @RequestMapping("/tBill_update/{tBillId}")
    public String tBillUpdate(@PathVariable Integer tBillId, Model model) {
        TBill tBill = tBillService.selectById(tBillId);
        model.addAttribute("item",tBill);
        LogObjectHolder.me().set(tBill);
        return PREFIX + "tBill_edit.html";
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String createTime,String addresseePhone,Integer state,Integer billType,Integer billHeaderType) {
//        EntityWrapper<TBill> wrapper = tBillService.getPageListWrapper(createTime,addresseePhone,state,billType,billHeaderType);
//        return tBillService.selectList(wrapper);
        return tBillService.getPageList(createTime,addresseePhone,state,billType,billHeaderType);
    }
 
    /**
     * 确认通过发票
     */
    @RequestMapping(value = "/confirm")
    @ResponseBody
    public Object confirm(Integer tBillId) {
        TBill tBill = tBillService.selectById(tBillId);
        tBill.setState(TBillStateEnum.FINISH_BILL.getCode());
        tBillService.updateById(tBill);
        return SUCCESS_TIP;
    }
 
    /**
     * 开通发票失败
     */
    @RequestMapping(value = "/cancel")
    @ResponseBody
    public Object cancel(Integer tBillId) {
        TBill tBill = tBillService.selectById(tBillId);
        tBill.setState(TBillStateEnum.FAIL_BILL.getCode());
        tBillService.updateById(tBill);
        TOrder tOrder = tOrderService.selectById(tBill.getOrderId());
        if(Objects.nonNull(tOrder)){
            tOrder.setIsInvoice(0);
            tOrderService.updateById(tOrder);
        }
        return SUCCESS_TIP;
    }
 
    /**
     * 获取列表
     */
    @RequestMapping(value = "/list-back")
    @ResponseBody
    public Object listBack(String condition) {
        return tBillService.selectList(null);
    }
 
    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TBill tBill) {
        tBillService.insert(tBill);
        return SUCCESS_TIP;
    }
 
    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tBillId) {
        tBillService.deleteById(tBillId);
        return SUCCESS_TIP;
    }
 
    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TBill tBill) {
        tBillService.updateById(tBill);
        return SUCCESS_TIP;
    }
 
    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{tBillId}")
    @ResponseBody
    public Object detail(@PathVariable("tBillId") Integer tBillId) {
        return tBillService.selectById(tBillId);
    }
 
    @ApiOperation(value = "导出发票列表",notes="导出发票列表")
    @RequestMapping(value = "/export")
    @ResponseBody
    public void export(String createTime,String addresseePhone,Integer state,Integer billType,Integer billHeaderType, HttpServletResponse response) {
        try {
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyyMMdd");
            String time1 = format.format(date);
            String fileName = "BillInfo"+time1+".xls";
            String[] title = new String[] {"申请时间","发票类型","抬头类型","发票抬头","公司税号","发票内容",
                    "发票金额","收件人姓名","收件人电话","收件人邮箱","开票状态"};
            EntityWrapper<TBill> wrapper = tBillService.getPageListWrapper(createTime,addresseePhone,state,billType,billHeaderType);
            List<TBill> tBills = tBillService.selectList(wrapper);
            String[][] values = new String[tBills.size()][];
            for (int i = 0; i < tBills.size(); i++) {
                TBill d = tBills.get(i);
                values[i] = new String[title.length];
                values[i][0] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d.getCreateTime());
                Integer billType1 = d.getBillType();
                if(1 == billType1){
                    values[i][1] = "电子发票";
                }
                Integer billHeaderType1 = d.getBillHeaderType();
                if(1 == billHeaderType1){
                    values[i][2] = "公司";
                } else if (2 == billHeaderType1) {
                    values[i][2] = "个人";
                }
                values[i][3] = d.getCompanyName();
                values[i][4] = d.getCompanyTaxNumber();
                values[i][5] = d.getBillContent();
                values[i][6] = String.valueOf(Objects.nonNull(d.getBillAmount())?d.getBillAmount(): BigDecimal.ZERO);
                values[i][7] = d.getAddresseeName();
                values[i][8] = d.getAddresseePhone();
                values[i][9] = d.getAddresseeEmail();
                Integer state1 = d.getState();
                if(1 == state1){
                    values[i][10] = "待开票";
                } else if (2 == state1) {
                    values[i][10] = "已开票";
                } else if (3 == state1) {
                    values[i][10] = "开票失败";
                }
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
            ExcelUtil.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}