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();
|
}
|
}
|
|
}
|