liujie
2023-04-06 30cb1d32796a1b482d44bd424fdfe28c26b87be9
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
package com.stylefeng.guns.modular.system.controller;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.system.model.TVariancesVo;
import com.stylefeng.guns.modular.system.utils.ExcelUtil;
import com.stylefeng.guns.modular.system.utils.tips.SuccessTip;
import io.swagger.annotations.Api;
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.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.modular.system.model.TVariances;
import com.stylefeng.guns.modular.system.service.ITVariancesService;
 
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2022-12-29 15:38:26
 */
@Controller
@Api(tags = "发票差异")
@RequestMapping("/api/tVariances")
public class TVariancesController extends BaseController {
 
 
    @Autowired
    private ITVariancesService tVariancesService;
 
 
 
    /**
     * 获取列表
     */
    @ApiOperation(value = "发票差异列表",notes="发票差异列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
            @ApiImplicitParam(name = "pageNumber", value = "pageNumber", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "pageSize", required = true, dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "time", value = "时间  2020-01-01 - 2022-01-01", required = false, dataType = "String"),
            @ApiImplicitParam(name = "orderId", value = "订单id", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "salesGroup", value = "分组名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "salesRep", value = "销售", required = false, dataType = "String"),
            @ApiImplicitParam(name = "customer", value = "用户", required = false, dataType = "String"),
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public Object list(int pageNumber,int pageSize,String time,Integer orderId,String salesGroup,String salesRep,String customer) {
        Page<TVariancesVo> tVariancesVoPage = new Page<>(pageNumber, pageSize);
        List<TVariancesVo> list =  tVariancesService.getList(tVariancesVoPage,time,orderId,salesGroup,salesRep,customer);
        tVariancesVoPage.setRecords(list);
        return new SuccessTip(tVariancesVoPage);
    }
 
 
 
    @ApiOperation(value = "发票差异列表导出",notes="发票差异列表导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9....."),
    })
    @PostMapping(value = "/exportList")
    @ResponseBody
    public Object exportList( String ids, HttpServletResponse response) {
        try {
            Date date = new Date();
            DateFormat format = new SimpleDateFormat("yyyyMMdd");
            String time1 = format.format(date);
            String fileName = "Variance"+time1+".xls";
            String[] title = new String[] {"CUSTOMER","ORDER ID","SALES REP","CARRIER COMPANY","ORIGIN","DESTINATION",
                    "VARIANCE AMOUNT","INVOICE TOTAL","CARRIER QUOTE","CUSTOMER QUOTE","DATE CREATED"};
            List<TVariancesVo> list =  tVariancesService.getListExport(ids);
            String[][] values = new String[list.size()][];
            for (int i = 0; i < list.size(); i++) {
                TVariancesVo d = list.get(i);
                values[i] = new String[title.length];
                values[i][0] = d.getUserName();
                values[i][1] = d.getOrderId().toString();
                values[i][2] = d.getSalesName();
                values[i][3] = d.getTruckingCompanyName();
                values[i][4] = d.getOrigin();
                values[i][5] = d.getDestination();
                values[i][6] = d.getVarianceAmount().toString();
                values[i][7] = d.getInvoiceTotal().toString();
                values[i][8] = d.getCarrierQuote().toString();
                values[i][9] = d.getCustomerQuote().toString();
                values[i][10] = new SimpleDateFormat("dd/MM/yyyy HH:ss").format(d.getCreateTime());
            }
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("Variance"+time1, title, values, null);
            this.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS_TIP;
    }
 
 
    public static void main(String[] args) {
        String a ="13123.2";
        String substring = a.substring(0, a.length() - 2);
        System.out.println(substring);
    }
    private void setResponseHeader(HttpServletResponse response, String fileName) {
        try {
            /*try {
                fileName = new String(fileName.getBytes(), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }*/
            response.setContentType("application/octet-stream;charset=UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes(),"iso-8859-1"));
            response.addHeader("Pargam", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
}