Commit 75c22dd8 authored by hanfeng's avatar hanfeng

总业绩统计

parent 6369f14f
......@@ -5,13 +5,29 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Data
@ApiModel("订单业绩明细表")
public class Achievement {
public class Achievement implements Serializable {
private static final Map<Integer, String> orderTypeMap = new HashMap<>();
private static final Map<Integer, String> payWayMap = new HashMap<>();
static {
orderTypeMap.put(1, "租车");
orderTypeMap.put(2, "旅游");
orderTypeMap.put(3, "会员");
payWayMap.put(null, "微信");
payWayMap.put(1, "微信支付");
payWayMap.put(2, "支付宝支付");
payWayMap.put(3, "银联支付");
}
@ApiModelProperty(value = "下单用户真实姓名")
private String realname;
@ApiModelProperty(value = "用户手机号")
......@@ -27,8 +43,8 @@ public class Achievement {
@ApiModelProperty(value = "订单所属公司名")
private String companyName;
@ApiModelProperty(value = "优惠价格")
private BigDecimal favorablePrice;
@ApiModelProperty(value = "创建时间", hidden = true )
private BigDecimal favorablePrice = BigDecimal.ZERO;
@ApiModelProperty(value = "创建时间", hidden = true)
@Column(name = "crt_time")
private String crtTime;
@ApiModelProperty(value = "订单号")
......@@ -37,15 +53,24 @@ public class Achievement {
private Integer type;
@Column(name = "order_amount")
@ApiModelProperty("订单总额")
private BigDecimal orderAmount=BigDecimal.ZERO;
private BigDecimal orderAmount = BigDecimal.ZERO;
@ApiModelProperty(value = "实际订单额")
@Column(name = "real_amount")
private BigDecimal realAmount=BigDecimal.ZERO;
private BigDecimal realAmount = BigDecimal.ZERO;
@Column(name = "pay_way")
@ApiModelProperty(value = "支付方式")
private Integer payWay;
public void setCrtTime(Date crtTime) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
this.crtTime = dateFormat.format(crtTime);
}
public String getType() {
return orderTypeMap.get(type);
}
public String getPayWay() {
return payWayMap.get(payWay);
}
}
......@@ -9,12 +9,25 @@ import org.springframework.util.StringUtils;
import javax.persistence.Column;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Data
public class ReturnOrderAmount implements Serializable {
private static final long serialVersionUID = -8445943548965154778L;
private static final Map<Integer, String> orderTypeMap = new HashMap<>();
static {
orderTypeMap.put(1, "租车");
orderTypeMap.put(2, "旅游");
orderTypeMap.put(3, "会员");
}
@ApiModelProperty(value = "时间")
private String time;
private Long time;
@ApiModelProperty(value = "订单号")
private String no;
@ApiModelProperty(value = "订单类型")
......@@ -28,11 +41,22 @@ public class ReturnOrderAmount implements Serializable {
@ApiModelProperty(value = "退款说明")
private String refundInstruction;
@ApiModelProperty(value = "退款明细")
private BigDecimal refundAmount=BigDecimal.ZERO;
private BigDecimal refundAmount = BigDecimal.ZERO;
@ApiModelProperty("退还类型")
@Column(name = "account_type")
private Integer accountType;
public OrderAccountDetail getAccountDetail() {
return StringUtils.hasText(accountDetail)? JSON.parseObject(accountDetail,OrderAccountDetail.class):new OrderAccountDetail();
return StringUtils.hasText(accountDetail) ? JSON.parseObject(accountDetail, OrderAccountDetail.class) : new OrderAccountDetail();
}
public String getType() {
return orderTypeMap.get(type);
}
public String getTime() {
Date date = new Date(this.time);
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
}
......@@ -3,7 +3,9 @@ package com.xxfc.platform.order.biz;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.google.common.collect.Lists;
import com.jayway.jsonpath.internal.function.numeric.Sum;
import com.xxfc.platform.order.contant.enumerate.AccountTypeEnum;
import com.xxfc.platform.order.pojo.Achievement;
import com.xxfc.platform.order.pojo.QueryCriteria;
......@@ -12,9 +14,18 @@ import com.xxfc.platform.order.pojo.TotalOrderRevenue;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
......@@ -100,16 +111,15 @@ public class TotalPerformanceBiz {
return Lists.newArrayList();
}
//拆分明细
return splitReturnOrderAmountList(returnOrderAmounts,queryCriteria);
return splitReturnOrderAmountList(returnOrderAmounts);
}
/**
* 进行对支出记录拆分,拆分为-押金、订单和违章
* @param returnOrderAmounts
* @param queryCriteria
* @return
*/
private List<ReturnOrderAmount> splitReturnOrderAmountList(List<ReturnOrderAmount> returnOrderAmounts, QueryCriteria queryCriteria) {
private List<ReturnOrderAmount> splitReturnOrderAmountList(List<ReturnOrderAmount> returnOrderAmounts) {
ArrayList<ReturnOrderAmount> arrayList = Lists.newArrayList();
//进行遍历拆分出-押金、订单和违章
for (ReturnOrderAmount returnOrderAmount : returnOrderAmounts) {
......@@ -143,4 +153,205 @@ public class TotalPerformanceBiz {
}
/**
* 导出入账记录
* @param queryCriteria
* @param name
* @param outputStream
*/
public void exportEntry(QueryCriteria queryCriteria, String name, ServletOutputStream outputStream) throws IOException {
XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
XSSFSheet sheet = hssfWorkbook.createSheet("收入");
CellStyle generalCellStyle = createGeneralCellStyle(hssfWorkbook);
XSSFRow row1 = sheet.createRow(0);
String[] head =new String[]{"下单时间","订单ID","订单类型","应收金额","优惠金额","实收金额","客户姓名","客户手机号","邀约人/身份","要约人手机号","业绩所属公司","支付方式"};
createHeader(row1,0,head,generalCellStyle);
List<Achievement> achievements = baseOrderBiz.entryStatisticalData(queryCriteria);
if (CollectionUtil.isEmpty(achievements)) {
throw new BaseException("无数据");
}
List<String[]> achievementArray =getAchievementArrays(achievements,12);
createCellData(sheet,1,generalCellStyle,achievementArray);
//设置最后一行
int lastRowNum = sheet.getLastRowNum();
XSSFRow rown = sheet.createRow(lastRowNum);
//设置第一列
XSSFCell cell1 = rown.createCell(0);
cell1.setCellValue("合计");
//第五列求和
int[] cel= new int[]{3,4,5};
sum(sheet, lastRowNum,cel);
hssfWorkbook.write(outputStream);
hssfWorkbook.close();
}
public void sum(XSSFSheet sheet, int lastRowNum, int[] cel) {
for (int i : cel) {
String colString = CellReference.convertNumToColString(i);
//该求和公式的意思就是:sum(第几列+第几个 : 第几列+需要累计到的第几个单元格位置)
String sumstring = "SUM(" + colString + "2:" + colString + (lastRowNum) + ")";
sheet.getRow(lastRowNum).createCell(i).setCellFormula(sumstring);
}
}
/**
* 获取入账数组
* @param achievements
* @param length
* @return
*/
private List<String[]> getAchievementArrays(List<Achievement> achievements, int length) {
ArrayList<String[]> arrayList = Lists.newArrayList();
for (Achievement achievement : achievements) {
String [] data= new String[length];
data[0]=achievement.getCrtTime();
data[1]=achievement.getNo();
data[2]=achievement.getType();
data[3]=achievement.getOrderAmount().toString();
data[4]=achievement.getFavorablePrice().toString();
data[5]=achievement.getRealAmount().toString();
data[6]=achievement.getRealname();
data[7]=achievement.getUsername();
data[8]=String.format("%s/%s",achievement.getParentRealname()==null?"":achievement.getParentRealname(),achievement.getPositionName()==null?"":achievement.getPositionName());
data[9]=achievement.getParentUsername();
data[10]=achievement.getCompanyName();
data[11]=achievement.getPayWay();
arrayList.add(data);
}
return arrayList;
}
/**
* 导出支出
* @param queryCriteria
* @param name
* @param outputStream
*/
public void exportAccount(QueryCriteria queryCriteria, String name, ServletOutputStream outputStream) throws IOException {
XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
XSSFSheet sheet = hssfWorkbook.createSheet("支出");
CellStyle generalCellStyle = createGeneralCellStyle(hssfWorkbook);
XSSFRow row1 = sheet.createRow(0);
String[] head =new String[]{"退款日期","订单ID","订单类型","退还类型","退还押金","客户名","客户手机号"};
createHeader(row1,0,head,generalCellStyle);
List<ReturnOrderAmount> returnOrderAmounts = outStatisticalData(queryCriteria);
List<String[]> achievementArray =getReturnOrderAmountArrays(returnOrderAmounts,7);
if (CollectionUtil.isEmpty(achievementArray)) {
throw new BaseException("无数据");
}
createCellData(sheet,1,generalCellStyle,achievementArray);
//设置最后一行
int lastRowNum = sheet.getLastRowNum();
XSSFRow rown = sheet.createRow(lastRowNum);
//设置第一列
XSSFCell cell1 = rown.createCell(0);
cell1.setCellValue("合计");
//第五列求和
String colString = CellReference.convertNumToColString(4);
//该求和公式的意思就是:sum(第几列+第几个 : 第几列+需要累计到的第几个单元格位置)
String sumstring = "SUM(" + colString + "2:" + colString + (lastRowNum) + ")";
sheet.getRow(lastRowNum).createCell(4).setCellFormula(sumstring);
hssfWorkbook.write(outputStream);
hssfWorkbook.close();
}
/**
* 获取支出数组
* @param returnOrderAmounts
* @param length
* @return
*/
private List<String[]> getReturnOrderAmountArrays(List<ReturnOrderAmount> returnOrderAmounts, int length) {
ArrayList<String[]> arrayList = Lists.newArrayList();
for (ReturnOrderAmount returnOrderAmount : returnOrderAmounts) {
String [] data= new String[length];
data[0]=returnOrderAmount.getTime();
data[1]=returnOrderAmount.getNo();
data[2]=returnOrderAmount.getType();
data[3]=returnOrderAmount.getRefundInstruction();
data[4]=returnOrderAmount.getRefundAmount().toString();
data[5]=returnOrderAmount.getRealname();
data[6]=returnOrderAmount.getUsername();
arrayList.add(data);
}
return arrayList;
}
private CellStyle createGeneralCellStyle(XSSFWorkbook hssfWorkbook){
CellStyle cellStyleGeneral = createHeaderCellStyle(hssfWorkbook);
cellStyleGeneral.setWrapText(true);
XSSFFont generalFont = createFont(hssfWorkbook);
generalFont.setBold(false);
cellStyleGeneral.setFont(generalFont);
return cellStyleGeneral;
}
private void createHeader(Row row, int cellStartIndex, String[] header, CellStyle cellStyle){
for (int i =0 ;i<header.length;i++){
Cell cell = row.createCell(cellStartIndex);
//设置head填充色
CellStyle cellStyle1 = cell.getCellStyle();
cellStyle1.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex());
cellStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cell.setCellStyle(cellStyle1);
cell.setCellValue(header[i]);
cell.setCellStyle(cellStyle);
cellStartIndex+=1;
}
}
private CellStyle createHeaderCellStyle(XSSFWorkbook hssfWorkbook){
XSSFCellStyle cellStyleHeader = hssfWorkbook.createCellStyle();
cellStyleHeader.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,#0"));
cellStyleHeader.setAlignment(HorizontalAlignment.CENTER);
cellStyleHeader.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyleHeader.setLocked(false);
cellStyleHeader.setBorderBottom(CellStyle.BORDER_THIN);
cellStyleHeader.setBorderLeft(CellStyle.BORDER_THIN);
cellStyleHeader.setBorderTop(CellStyle.BORDER_THIN);
cellStyleHeader.setBorderRight(CellStyle.BORDER_THIN);
XSSFFont headerFont = createFont(hssfWorkbook);
cellStyleHeader.setFont(headerFont);
return cellStyleHeader;
}
private XSSFFont createFont(XSSFWorkbook hssfWorkbook){
XSSFFont font = hssfWorkbook.createFont();
font.setFontName("黑体");
font.setBold(true);
return font;
}
private void createCellData(Sheet sheet,int startRowIndex,CellStyle cellStyle,List<String[]> memberOrderList){
for (String[] data : memberOrderList) {
Row row = sheet.createRow(startRowIndex++);
createHeader(row,0,data,cellStyle);
}
}
}
......@@ -5,10 +5,10 @@ import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.msg.auth.PageResult;
import com.github.wxiaoqi.security.common.rest.CommonBaseController;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.biz.TotalPerformanceBiz;
import com.xxfc.platform.order.pojo.QueryCriteria;
import com.xxfc.platform.order.contant.enumerate.BookkeepingTypeEnum;
......@@ -24,7 +24,12 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
......@@ -75,28 +80,30 @@ public class TotalPerformanceStatementController extends CommonBaseController {
}
@PostMapping("/excel")
public ObjectRestResponse statisticalDownload(@RequestBody QueryCriteria queryCriteria) throws Exception {
public void exportTotalPerformance(@RequestBody QueryCriteria queryCriteria, HttpServletResponse response) throws Exception {
UserDTO userDTO = userFeign.userinfoByToken(userAuthConfig.getToken(request)).getData();
//获取用户权限
List<Integer> Jurisdiction = null;
//是否有查询所有数据的权限
if (!HIGHEST_AUTHORITY.equals(userDTO.getDataAll())) {
List<BranchCompany> branchCompanies = vehicleFeign.companyAll(userDTO.getDataAll(), userDTO.getDataCompany(), userDTO.getDataZone());
Jurisdiction = branchCompanies.parallelStream().map(BranchCompany::getId).collect(Collectors.toList());
}
queryCriteria.setJurisdiction(Jurisdiction);
try {
String name = DateTimeFormatter.ofPattern("YYYYMMddHHmmss").format(LocalDateTime.now());
response.setContentType("application/vnd.ms-excel;charset=utf-8");
if (BookkeepingTypeEnum.ENTER.getCode().equals(queryCriteria.getType())) {
TotalOrderRevenue totalOrderRevenue = totalPerformanceBiz.entryStatisticalData(queryCriteria);
return ObjectRestResponse.succ(totalOrderRevenue);
String filename = String.format("%s-总业绩-入账表.xlsx",name);
response.setHeader("Content-Disposition","attachment;filename="+ new String(filename.getBytes(), "iso8859-1"));
ServletOutputStream outputStream = response.getOutputStream();
totalPerformanceBiz.exportEntry(queryCriteria, name, outputStream);
}else if (BookkeepingTypeEnum.OUT.getCode().equals(queryCriteria.getType())){
List<ReturnOrderAmount> returnOrderAmounts = totalPerformanceBiz.outStatisticalData(queryCriteria);
return ObjectRestResponse.succ(PageResult.nowPageResult(queryCriteria.getPage(),queryCriteria.getLimit(),returnOrderAmounts));
String filename = String.format("%s-总业绩-出账表.xlsx",name);
response.setHeader("Content-Disposition","attachment;filename="+ new String(filename.getBytes(), "iso8859-1"));
ServletOutputStream outputStream = response.getOutputStream();
totalPerformanceBiz.exportAccount(queryCriteria, name, outputStream);
}else {
throw new BaseException("无相关数据");
}
return ObjectRestResponse.succ();
response.setCharacterEncoding("UTF-8");
} catch (IOException e) {
throw new BaseException("导入数据失败");
}
}
}
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