Commit 47fb12a2 by 杨清松

账单明细导出

parent 3e0e4d88
package com.xyst.dinas.finance.internal.service;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
......@@ -28,8 +44,7 @@ public class StatementAccountServiceImpl implements StatementAccountService{
private StatementAccountDao statementAccountDao;
@Override
public Object queryStatementAccountByContractId(JSONObject jsonObject) {
try {
public Map<String, Object> queryStatementAccountByContractId(JSONObject jsonObject) {
Map<String, Object> map = new HashMap<>();
List<KObject> artificialRechargeList = statementAccountDao.queryStatementAccountByContractId(jsonObject, ArtificialRechargeConstant.ENTITY);
List<StatementAccount> statementAccounts = new ArrayList<StatementAccount>();
......@@ -115,10 +130,62 @@ public class StatementAccountServiceImpl implements StatementAccountService{
}
map.put("salesAmount", salesAmount);
map.put("statementAccounts", statementAccounts);
return ResponseObj.success("查询成功", map);
return map;
}
@Value("classpath:template/statementAccount.xlsx")
private Resource statementAccountResource;
@Override
public void exportStatementAccountDetails(HttpServletResponse response, JSONObject param) {
Map<String, Object> statementAccountMap = queryStatementAccountByContractId(param);
Workbook xssfWorkbook = null;
try {
xssfWorkbook = new XSSFWorkbook(statementAccountResource.getInputStream());
CellStyle textStyle = xssfWorkbook.createCellStyle();
textStyle.setBorderBottom(CellStyle.BORDER_THIN);
textStyle.setBorderTop(CellStyle.BORDER_THIN);
textStyle.setBorderLeft(CellStyle.BORDER_THIN);
textStyle.setBorderRight(CellStyle.BORDER_THIN);
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");
//设置字体
Font createFont = xssfWorkbook.createFont();
createFont.setFontHeightInPoints((short) 10);
createFont.setFontName("黑体");
textStyle.setFont(createFont);
Sheet sheetAt = xssfWorkbook.getSheetAt(0);
List<StatementAccount> statementAccounts = (List<StatementAccount>) statementAccountMap.get("statementAccounts");
for (int i = 0; i < statementAccounts.size(); i++) {
StatementAccount statementAccount = statementAccounts.get(i);
//从第2行开始写数据
Row row = sheetAt.createRow(1 + i);
Cell cell = row.createCell(0);
cell.setCellValue(1 + i);
cell.setCellStyle(textStyle);
Cell cell1 = row.createCell(1);
cell1.setCellValue(statementAccount.getDealDate());
cell1.setCellStyle(textStyle);
Cell cell2 = row.createCell(2);
cell2.setCellValue(statementAccount.getDealType());
cell2.setCellStyle(textStyle);
Cell cell3 = row.createCell(3);
cell3.setCellValue(statementAccount.getDealAmount().doubleValue());
cell3.setCellStyle(textStyle);
}
String fileName = URLEncoder.encode("对账单明细.xlsx", "utf-8");
response.setHeader("Content-Disposition", "attachment; filename =" + fileName);
ServletOutputStream outputStream = response.getOutputStream();
xssfWorkbook.write(outputStream);
xssfWorkbook.close();
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
return ResponseObj.error();
}
}
......
package com.xyst.dinas.finance.service;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
public interface StatementAccountService {
Object queryStatementAccountByContractId(JSONObject jsonObject);
Map<String, Object> queryStatementAccountByContractId(JSONObject jsonObject);
void exportStatementAccountDetails(HttpServletResponse response, JSONObject param);
}
package com.xyst.dinas.finance.web;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -12,10 +17,11 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.finance.service.StatementAccountService;
/**
* 费用调整
* 对账单
*
* @author yangqingsong
* @date 2021年4月25日
......@@ -30,7 +36,34 @@ public class StatementAccountController {
@ResponseBody
@RequestMapping(value = "/sand/user/finance/statementAccount/queryStatementAccountByContractId", method = RequestMethod.POST)
public Object queryStatementAccountByContractId(@RequestBody String body) {
return statementAccountService.queryStatementAccountByContractId(new JSONObject(body));
try{
Map<String, Object> statementAccountByContract = statementAccountService.queryStatementAccountByContractId(new JSONObject(body));
return ResponseObj.success("查询成功", statementAccountByContract);
} catch(Exception e) {
return ResponseObj.error();
}
}
@ResponseBody
@RequestMapping(value = "/sand/user/finance/exportStatementAccountDetails", method = RequestMethod.POST)
public Object exportStatementAccountDetails(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.setCharacterEncoding("utf-8");
String exportParamStr = request.getParameter("exportParamStr");
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-www-form-urlencoded");
JSONObject obj = new JSONObject();
try {
obj.put("code", 200);
JSONObject param = new JSONObject(exportParamStr);
statementAccountService.exportStatementAccountDetails(response, param);
} catch(Exception e) {
e.printStackTrace();
return ResponseObj.error();
}
return obj.toString();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment