Commit df7ca4d5 authored by libin's avatar libin

员工统计

parent 3e08c06f
...@@ -21,8 +21,8 @@ public class StaffStatisticsFindDTO extends PageParam { ...@@ -21,8 +21,8 @@ public class StaffStatisticsFindDTO extends PageParam {
private Date startDate; private Date startDate;
private Date endDate; private Date endDate;
private String companyName; private String companyName;
private String postionName;
private Integer userPostionId; private Integer userPostionId;
private Integer companyId; private Integer companyId;
private List<Integer> userIds; private List<Integer> userIds;
private Boolean isExport;
} }
...@@ -185,6 +185,11 @@ public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail ...@@ -185,6 +185,11 @@ public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail
} }
public PageDataVO<UserStaffBo> findAllStaffsByCompanyIdAndPostionIdWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) { public PageDataVO<UserStaffBo> findAllStaffsByCompanyIdAndPostionIdWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) {
return PageDataVO.pageInfo(staffStatisticsFindDTO.getPage(),staffStatisticsFindDTO.getLimit(),()->mapper.findAllStaffsByCompanyIdAndPostionIdWithPage(staffStatisticsFindDTO)); return PageDataVO.pageInfo(staffStatisticsFindDTO.getPage(),staffStatisticsFindDTO.getLimit(),()->mapper.findAllStaffsByCompanyIdAndPostionId(staffStatisticsFindDTO));
}
public List<UserStaffBo> findStaffsByIdsAndCompanyAndPostion(StaffStatisticsFindDTO staffStatisticsFindDTO) {
List<UserStaffBo> staffBos = mapper.findAllStaffsByCompanyIdAndPostionId(staffStatisticsFindDTO);
return CollectionUtils.isEmpty(staffBos)?Collections.EMPTY_LIST:staffBos;
} }
} }
package com.github.wxiaoqi.security.admin.biz; package com.github.wxiaoqi.security.admin.biz;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import com.github.wxiaoqi.security.admin.bo.StaffStatisticsBo; import com.github.wxiaoqi.security.admin.bo.StaffStatisticsBo;
import com.github.wxiaoqi.security.admin.bo.StaffStatisticsTotalBo; import com.github.wxiaoqi.security.admin.bo.StaffStatisticsTotalBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo; import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
...@@ -15,11 +16,18 @@ import com.xxfc.platform.order.pojo.dto.OrderDTO; ...@@ -15,11 +16,18 @@ import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.vehicle.feign.VehicleFeign; import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.servlet.ServletOutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -51,10 +59,154 @@ public class StaffStatisticsBiz { ...@@ -51,10 +59,154 @@ public class StaffStatisticsBiz {
private final VehicleFeign vehicleFeign; private final VehicleFeign vehicleFeign;
private final AppUserPositionBiz appUserPositionBiz; private final AppUserPositionBiz appUserPositionBiz;
/**
* 导出数据
*
* @param staffStatisticsFindDTO
* @param outputStream
*/
public void exportStaffStistics(StaffStatisticsFindDTO staffStatisticsFindDTO, ServletOutputStream outputStream) throws Exception {
//1.查询根据员工查询
List<UserStaffBo> userStaffBos = appUserDetailBiz.findStaffsByIdsAndCompanyAndPostion(staffStatisticsFindDTO);
//2.计算员工的业绩
List<StaffStatisticsBo> staffStatisticsBos = processStaffStatistics(userStaffBos, staffStatisticsFindDTO);
//3.计算总业绩
StaffStatisticsTotalBo staffStatisticsTotalBo = getStaffStatisticsTotalBo(userStaffBos.size(), staffStatisticsBos);
//excel相关
XSSFWorkbook hssfWorkbook = new XSSFWorkbook();
XSSFSheet sheet = hssfWorkbook.createSheet("员工业绩统计报表");
Row titleRow = sheet.createRow(0);
CellStyle headerCellStyle = createHeaderCellStyle(hssfWorkbook);
Cell titleCell = titleRow.createCell(0);
titleCell.setCellValue("员工业绩统计报表");
titleCell.setCellStyle(headerCellStyle);
CellRangeAddress titleCellRangeAddress = new CellRangeAddress(0, 0, 0, 10);
sheet.addMergedRegion(titleCellRangeAddress);
Row ctpRow = sheet.createRow(1);
Cell ctpCell = ctpRow.createCell(0);
//缺少判断 公司 身份 时间
String companyName = StringUtils.hasText(staffStatisticsFindDTO.getCompanyName()) ? staffStatisticsFindDTO.getCompanyName() : "全集团";
String postionName = StringUtils.hasText(staffStatisticsFindDTO.getPostionName()) ? staffStatisticsFindDTO.getPostionName() : "全部员工";
String startTimeStr = staffStatisticsFindDTO.getStartDate()==null?"":DateUtil.format(staffStatisticsFindDTO.getStartDate(), "yyyy-MM-dd HH:mm:ss");
String endTimeStr = staffStatisticsFindDTO.getEndDate()==null?staffStatisticsFindDTO.getStartDate()==null?"":
DateUtil.format(DateUtil.endOfDay(new Date()),"yyyy-MM-dd HH:mm:ss"):DateUtil.format(staffStatisticsFindDTO.getEndDate(), "yyyy-MM-dd HH:mm:ss");
String ctpValue = String.format("时间:%s~%s 公司:%s 身份:%s", startTimeStr,endTimeStr,
companyName, postionName);
ctpCell.setCellValue(ctpValue);
CellRangeAddress ctpCellRangeAddress = new CellRangeAddress(1, 1, 0, 10);
sheet.addMergedRegion(ctpCellRangeAddress);
Row totalStatisticsRow = sheet.createRow(2);
Cell totalStatisticsRowCell = totalStatisticsRow.createCell(0);
String totalStatisticsRowCellValue = String.format("合计 员工人数:%s 员工销售额:%s 员工App提成总额:%s", staffStatisticsTotalBo.getStaffNum(),
staffStatisticsTotalBo.getTotalSellAmount(),
staffStatisticsTotalBo.getTotalRoyaltyAmount());
totalStatisticsRowCell.setCellValue(totalStatisticsRowCellValue);
CellRangeAddress totalStatisticsRowCellRangeAddress = new CellRangeAddress(2, 2, 0, 10);
sheet.addMergedRegion(totalStatisticsRowCellRangeAddress);
//分割行
CellRangeAddress lineCellRangeAddress = new CellRangeAddress(3, 3, 0, 10);
sheet.addMergedRegion(lineCellRangeAddress);
Row staffHeaderRow = sheet.createRow(4);
String[] staffHeaderValue = {"序号", "员工姓名", "所属公司", "身份", "电话", "销售额(元)", "APP提成", "会员订单数/合计金额", "租车订单数/合计金额", "旅游订单数/合计金额"};
createHeader(staffHeaderRow, 0, staffHeaderValue, headerCellStyle);
for (int i = 0; i < staffHeaderValue.length; i++) {
sheet.setColumnWidth(i,24*256);
}
//设置数据
CellStyle generalCellStyle = createGeneralCellStyle(hssfWorkbook);
List<String[]> staffStatisticsData = getStaffStatisticsData(staffStatisticsBos);
createStaffStatisticsCellData(sheet, 5, generalCellStyle, staffStatisticsData);
hssfWorkbook.write(outputStream);
hssfWorkbook.close();
}
private void createStaffStatisticsCellData(Sheet sheet, int startRowIndex, CellStyle cellStyle, List<String[]> staffStatisticsData) {
for (String[] data : staffStatisticsData) {
Row row = sheet.createRow(startRowIndex++);
createCellCount(row, 0, data, cellStyle);
}
}
private void createCellCount(Row row, int CellStartIndex, String[] data, CellStyle cellStyle) {
for (int i = CellStartIndex, y = 0; y < data.length; i++, y++) {
Cell cell = row.createCell(i);
cell.setCellStyle(cellStyle);
cell.setCellValue(data[y]);
}
}
private List<String[]> getStaffStatisticsData(List<StaffStatisticsBo> staffStatisticsBos) {
List<String[]> data = new ArrayList<>(staffStatisticsBos.size());
for (int i = 0; i < staffStatisticsBos.size(); i++) {
String[] staffData = getData(i + 1, staffStatisticsBos.get(i));
data.add(staffData);
}
return data;
}
private String[] getData(int index, StaffStatisticsBo staffStatisticsBo) {
String companyNames = ArrayUtil.join(staffStatisticsBo.getCompanyNames().toArray(), ",");
String postinNames = ArrayUtil.join(staffStatisticsBo.getPostionNames().toArray(), ",");
String sellAmount = staffStatisticsBo.getSellAmount().toString();
String royaltyAmount = staffStatisticsBo.getRoyaltyAmount().toString();
String member = String.format("%s/%s", staffStatisticsBo.getMemberOrderNum(), staffStatisticsBo.getMemberAmount());
String rentVehicle = String.format("%s/%s", staffStatisticsBo.getRentVehicleOrderNum(), staffStatisticsBo.getRentVehicleAmount());
String travel = String.format("%s/%s", staffStatisticsBo.getTravelOrderNum(), staffStatisticsBo.getTravelAmount());
return new String[]{String.valueOf(index), staffStatisticsBo.getName(), companyNames, postinNames, staffStatisticsBo.getPhone(),sellAmount, royaltyAmount, member, rentVehicle, travel};
}
private void createHeader(Row row, int cellStartIndex, String[] header, CellStyle cellStyle) {
for (int i = 0; i < header.length; i++) {
Cell cell = row.createCell(cellStartIndex);
cell.setCellValue(header[i]);
cell.setCellStyle(cellStyle);
cellStartIndex += 1;
}
}
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 CellStyle createHeaderCellStyle(XSSFWorkbook hssfWorkbook) {
XSSFCellStyle cellStyleHeader = hssfWorkbook.createCellStyle();
cellStyleHeader.setAlignment(HorizontalAlignment.CENTER);
cellStyleHeader.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyleHeader.setLocked(false);
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;
}
/**
* 员工业绩统计
*
* @param staffStatisticsFindDTO
* @return
*/
public Map<String, Object> listStaffStatisticsWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) { public Map<String, Object> listStaffStatisticsWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) {
Map<String, Object> result = new HashMap<>(2); Map<String, Object> result = new HashMap<>(2);
PageDataVO<StaffStatisticsBo> pageDataVO = new PageDataVO<>(); PageDataVO<StaffStatisticsBo> pageDataVO = new PageDataVO<>();
List<StaffStatisticsBo> staffStatisticsBos = new ArrayList<>();
//1.分页查询全部员工 //1.分页查询全部员工
PageDataVO<UserStaffBo> staffPage = appUserDetailBiz.findAllStaffsByCompanyIdAndPostionIdWithPage(staffStatisticsFindDTO); PageDataVO<UserStaffBo> staffPage = appUserDetailBiz.findAllStaffsByCompanyIdAndPostionIdWithPage(staffStatisticsFindDTO);
List<UserStaffBo> allStaffs = staffPage.getData(); List<UserStaffBo> allStaffs = staffPage.getData();
...@@ -68,6 +220,33 @@ public class StaffStatisticsBiz { ...@@ -68,6 +220,33 @@ public class StaffStatisticsBiz {
result.put(PAGE_VAL, pageDataVO); result.put(PAGE_VAL, pageDataVO);
return result; return result;
} }
List<StaffStatisticsBo> staffStatisticsBos = processStaffStatistics(allStaffs, staffStatisticsFindDTO);
if (staffStatisticsFindDTO.getPage() == 1) {
StaffStatisticsTotalBo staffStatisticsTotalBo = getStaffStatisticsTotalBo(allStaffs.size(), staffStatisticsBos);
result.put(TOTAL_VAL, staffStatisticsTotalBo);
}
pageDataVO.setData(staffStatisticsBos);
pageDataVO.setPageNum(staffPage.getPageNum());
pageDataVO.setPageSize(staffPage.getPageSize());
pageDataVO.setTotalCount(staffPage.getTotalCount());
pageDataVO.setTotalPage(staffPage.getTotalPage());
result.put(PAGE_VAL, pageDataVO);
return result;
}
private StaffStatisticsTotalBo getStaffStatisticsTotalBo(Integer size, List<StaffStatisticsBo> staffStatisticsBos) {
StaffStatisticsTotalBo staffStatisticsTotalBo = new StaffStatisticsTotalBo();
Supplier<Stream<StaffStatisticsBo>> streamSupplier = () -> staffStatisticsBos.stream();
BigDecimal royaltyAmount = streamSupplier.get().map(StaffStatisticsBo::getRoyaltyAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal sellAmount = streamSupplier.get().map(StaffStatisticsBo::getSellAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
staffStatisticsTotalBo.setTotalRoyaltyAmount(royaltyAmount);
staffStatisticsTotalBo.setTotalSellAmount(sellAmount);
staffStatisticsTotalBo.setStaffNum(size);
return staffStatisticsTotalBo;
}
private List<StaffStatisticsBo> processStaffStatistics(List<UserStaffBo> allStaffs, StaffStatisticsFindDTO staffStatisticsFindDTO) {
List<StaffStatisticsBo> staffStatisticsBos = new ArrayList<>();
//2.根据员工id范围和其他条件分页查询 //2.根据员工id范围和其他条件分页查询
List<Integer> userIds = allStaffs.stream().map(UserStaffBo::getUserId).collect(Collectors.toList()); List<Integer> userIds = allStaffs.stream().map(UserStaffBo::getUserId).collect(Collectors.toList());
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds, staffStatisticsFindDTO.getStartDate(), staffStatisticsFindDTO.getEndDate()); List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds, staffStatisticsFindDTO.getStartDate(), staffStatisticsFindDTO.getEndDate());
...@@ -76,8 +255,8 @@ public class StaffStatisticsBiz { ...@@ -76,8 +255,8 @@ public class StaffStatisticsBiz {
if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)) { if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)) {
//3.根据订单id查询订单相关信息 //3.根据订单id查询订单相关信息
List<Integer> orderIds = appUserSellingWaterDTOS.stream().map(AppUserSellingWaterDTO::getOrderId).collect(Collectors.toList()); List<Integer> orderIds = appUserSellingWaterDTOS.stream().map(AppUserSellingWaterDTO::getOrderId).collect(Collectors.toList());
ObjectRestResponse<List<OrderDTO>> response =orderFeign.findOrdersByorderId(orderIds); ObjectRestResponse<List<OrderDTO>> response = orderFeign.findOrdersByorderId(orderIds);
List<OrderDTO> orders =response.getData(); List<OrderDTO> orders = response.getData();
Map<Integer, Integer> ordersMap = orders.stream().collect(Collectors.toMap(OrderDTO::getId, OrderDTO::getCompanyId)); Map<Integer, Integer> ordersMap = orders.stream().collect(Collectors.toMap(OrderDTO::getId, OrderDTO::getCompanyId));
for (AppUserSellingWaterDTO appUserSellingWaterDTO : appUserSellingWaterDTOS) { for (AppUserSellingWaterDTO appUserSellingWaterDTO : appUserSellingWaterDTOS) {
appUserSellingWaterDTO.setCompanyId(ordersMap.get(appUserSellingWaterDTO.getOrderId()) == null ? NO_COMPANY_STATE : ordersMap.get(appUserSellingWaterDTO.getOrderId())); appUserSellingWaterDTO.setCompanyId(ordersMap.get(appUserSellingWaterDTO.getOrderId()) == null ? NO_COMPANY_STATE : ordersMap.get(appUserSellingWaterDTO.getOrderId()));
...@@ -116,7 +295,7 @@ public class StaffStatisticsBiz { ...@@ -116,7 +295,7 @@ public class StaffStatisticsBiz {
if (!compnayIds.contains(Integer.valueOf(companyIdStr))) { if (!compnayIds.contains(Integer.valueOf(companyIdStr))) {
String companyName = companyMap.get(Integer.valueOf(companyIdStr)); String companyName = companyMap.get(Integer.valueOf(companyIdStr));
if (StringUtils.hasText(companyName)){ if (StringUtils.hasText(companyName)) {
companyNames.add(companyName); companyNames.add(companyName);
compnayIds.add(Integer.valueOf(companyIdStr)); compnayIds.add(Integer.valueOf(companyIdStr));
} }
...@@ -129,31 +308,15 @@ public class StaffStatisticsBiz { ...@@ -129,31 +308,15 @@ public class StaffStatisticsBiz {
wrapStaffStatistics(V, royaltyAmountAtomicReference, staffStatisticsBo); wrapStaffStatistics(V, royaltyAmountAtomicReference, staffStatisticsBo);
}); });
staffStatisticsBo.setCompnayIds(compnayIds); staffStatisticsBo.setCompnayIds(compnayIds);
staffStatisticsBo.setCompanyNames(companyNames.stream().distinct().collect(Collectors.toList())); staffStatisticsBo.setCompanyNames(companyNames);
staffStatisticsBo.setPostionIds(postionIds); staffStatisticsBo.setPostionIds(postionIds);
staffStatisticsBo.setPostionNames(postionNames.stream().distinct().collect(Collectors.toList())); staffStatisticsBo.setPostionNames(postionNames);
staffStatisticsBo.setRoyaltyAmount(royaltyAmountAtomicReference.get()); staffStatisticsBo.setRoyaltyAmount(royaltyAmountAtomicReference.get());
} }
} }
staffStatisticsBos.add(staffStatisticsBo); staffStatisticsBos.add(staffStatisticsBo);
} }
if (staffStatisticsFindDTO.getPage() == 1) { return staffStatisticsBos;
StaffStatisticsTotalBo staffStatisticsTotalBo = new StaffStatisticsTotalBo();
Supplier<Stream<StaffStatisticsBo>> streamSupplier = () -> staffStatisticsBos.stream();
BigDecimal royaltyAmount = streamSupplier.get().map(StaffStatisticsBo::getRoyaltyAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal sellAmount = streamSupplier.get().map(StaffStatisticsBo::getSellAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
staffStatisticsTotalBo.setTotalRoyaltyAmount(royaltyAmount);
staffStatisticsTotalBo.setTotalSellAmount(sellAmount);
staffStatisticsTotalBo.setStaffNum(allStaffs.size());
result.put(TOTAL_VAL, staffStatisticsTotalBo);
}
pageDataVO.setData(staffStatisticsBos);
pageDataVO.setPageNum(staffPage.getPageNum());
pageDataVO.setPageSize(staffPage.getPageSize());
pageDataVO.setTotalCount(staffPage.getTotalCount());
pageDataVO.setTotalPage(staffPage.getTotalPage());
result.put(PAGE_VAL, pageDataVO);
return result;
} }
private StaffStatisticsBo wrapStaffStatistics(Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>> waterDTOSMap, AtomicReference<BigDecimal> royaltyAmountAtomicReference, StaffStatisticsBo staffStatisticsBo) { private StaffStatisticsBo wrapStaffStatistics(Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>> waterDTOSMap, AtomicReference<BigDecimal> royaltyAmountAtomicReference, StaffStatisticsBo staffStatisticsBo) {
...@@ -164,15 +327,15 @@ public class StaffStatisticsBiz { ...@@ -164,15 +327,15 @@ public class StaffStatisticsBiz {
royaltyAmountAtomicReference.set(royaltyAmount); royaltyAmountAtomicReference.set(royaltyAmount);
switch (K) { switch (K) {
case StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE: case StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE:
staffStatisticsBo.setRentVehicleOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getRentVehicleOrderNum()); staffStatisticsBo.setRentVehicleOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL)) + staffStatisticsBo.getRentVehicleOrderNum());
staffStatisticsBo.setRentVehicleAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getRentVehicleAmount())); staffStatisticsBo.setRentVehicleAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getRentVehicleAmount()));
break; break;
case StatisticsStatusEnum.ORDER_TOUR_TYPE: case StatisticsStatusEnum.ORDER_TOUR_TYPE:
staffStatisticsBo.setTravelOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getTravelOrderNum()); staffStatisticsBo.setTravelOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL)) + staffStatisticsBo.getTravelOrderNum());
staffStatisticsBo.setTravelAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getTravelAmount())); staffStatisticsBo.setTravelAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getTravelAmount()));
break; break;
case StatisticsStatusEnum.ORDER_MEMBER_TYPE: case StatisticsStatusEnum.ORDER_MEMBER_TYPE:
staffStatisticsBo.setMemberOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getMemberOrderNum()); staffStatisticsBo.setMemberOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL)) + staffStatisticsBo.getMemberOrderNum());
staffStatisticsBo.setMemberAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getMemberAmount())); staffStatisticsBo.setMemberAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getMemberAmount()));
break; break;
default: default:
...@@ -224,7 +387,7 @@ public class StaffStatisticsBiz { ...@@ -224,7 +387,7 @@ public class StaffStatisticsBiz {
staffStatisticsBo.setPostionIds(Arrays.asList(userStaffBo.getPostionId())); staffStatisticsBo.setPostionIds(Arrays.asList(userStaffBo.getPostionId()));
} }
staffStatisticsBo.setUserId(userStaffBo.getUserId()); staffStatisticsBo.setUserId(userStaffBo.getUserId());
staffStatisticsBo.setName(StringUtils.hasText(userStaffBo.getRealName())?userStaffBo.getRealName():userStaffBo.getNickName()); staffStatisticsBo.setName(StringUtils.hasText(userStaffBo.getRealName()) ? userStaffBo.getRealName() : userStaffBo.getNickName());
staffStatisticsBo.setPhone(userStaffBo.getPhone()); staffStatisticsBo.setPhone(userStaffBo.getPhone());
staffStatisticsBo.setMemberAmount(BigDecimal.ZERO); staffStatisticsBo.setMemberAmount(BigDecimal.ZERO);
staffStatisticsBo.setMemberOrderNum(0); staffStatisticsBo.setMemberOrderNum(0);
...@@ -237,5 +400,4 @@ public class StaffStatisticsBiz { ...@@ -237,5 +400,4 @@ public class StaffStatisticsBiz {
return staffStatisticsBo; return staffStatisticsBo;
} }
} }
\ No newline at end of file
...@@ -32,5 +32,5 @@ public interface AppUserDetailMapper extends Mapper<AppUserDetail> { ...@@ -32,5 +32,5 @@ public interface AppUserDetailMapper extends Mapper<AppUserDetail> {
List<AppUserVo> getUserByUserIdList(@Param("userIds") List<Integer> userIds); List<AppUserVo> getUserByUserIdList(@Param("userIds") List<Integer> userIds);
List<UserStaffBo> findAllStaffsByCompanyIdAndPostionIdWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO); List<UserStaffBo> findAllStaffsByCompanyIdAndPostionId(StaffStatisticsFindDTO staffStatisticsFindDTO);
} }
\ No newline at end of file
...@@ -9,7 +9,11 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -9,7 +9,11 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.github.wxiaoqi.security.common.exception.BaseException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map; import java.util.Map;
/** /**
...@@ -30,4 +34,19 @@ public class StaffStatisticsAdminController { ...@@ -30,4 +34,19 @@ public class StaffStatisticsAdminController {
Map<String,Object> result = staffStatisticsBiz.listStaffStatisticsWithPage(staffStatisticsFindDTO); Map<String,Object> result = staffStatisticsBiz.listStaffStatisticsWithPage(staffStatisticsFindDTO);
return ObjectRestResponse.succ(result); return ObjectRestResponse.succ(result);
} }
@PostMapping("/export")
public void exportStaffStatistics(@RequestBody StaffStatisticsFindDTO staffStatisticsFindDTO, HttpServletResponse response){
try {
String name = DateTimeFormatter.ofPattern("YYYYMMddHHmmss").format(LocalDateTime.now());
response.setContentType("application/vnd.ms-excel;charset=utf-8");
String filename = String.format("%s-staff-statistics.xlsx",name);
response.setHeader("Content-Disposition","attachment;filename="+ new String(filename.getBytes(), "iso8859-1"));
ServletOutputStream outputStream = response.getOutputStream();
staffStatisticsBiz.exportStaffStistics(staffStatisticsFindDTO, outputStream);
response.setCharacterEncoding("UTF-8");
}catch (Exception ex){
throw new BaseException("导出数据失败");
}
}
} }
...@@ -261,19 +261,53 @@ from `app_user_detail` as `aud` left join `app_user_login` as `aul` on aul.id= ...@@ -261,19 +261,53 @@ from `app_user_detail` as `aud` left join `app_user_login` as `aul` on aul.id=
</foreach> </foreach>
</select> </select>
<select id="findAllStaffsByCompanyIdAndPostionIdWithPage" <select id="findAllStaffsByCompanyIdAndPostionId"
resultType="com.github.wxiaoqi.security.admin.bo.UserStaffBo"> resultType="com.github.wxiaoqi.security.admin.bo.UserStaffBo">
select aud.userid as `userId`,aud.realname as `realName`,aud.nickname as `nickName`,aul.username as `phone`,aud.position_id as `postionId`,aup.name as `postionName`,aupt.company_id as `companyId`,aupt.company_name as `companyName` select * from (select aud.userid as `userId`,aud.realname as `realName`,aud.nickname as `nickName`,aul.username as `phone`,aud.position_id
from `app_user_detail` as `aud` left join `app_user_login` as `aul` on aul.id=aud.userid as `postionId`,aup.name as `postionName`,aupt.company_id as `companyId`,aupt.company_name as `companyName` from `app_user_detail` as `aud`
left join `app_user_position_temp` as `aupt` on aupt.user_id=aul.id left join `app_user_login` as `aul` on aul.id=aud.userid
left join `app_user_position` as `aup` on aup.id=aud.position_id left join (select * from `app_user_position_temp` where is_del=0) as `aupt` on aupt.user_id=aul.id
where <![CDATA[aud.position_id<>6]]> and aud.isdel=0 left join `app_user_position` as `aup` on aup.id=aud.position_id where <![CDATA[aud.position_id<>6]]> and aud.isdel=0
<if test="userPostionId!=null"> <if test="userPostionId!=null">
and aud.`position_id`=#{userPostionId} and aud.`position_id`=#{userPostionId}
</if> </if>
<if test="companyId!=null"> <if test="companyId!=null">
and aupt.`company_id`=#{companyId} and aupt.`company_id`=#{companyId}
</if>
<if test="userIds!=null and userIds.size>0">
and aud.userid in
<foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if>) as `saff`
left join (
select auswp.user_id, IFNULL(auswp.upIncome, 0) - IFNULL(auswd.dowIncome, 0) as `sellAmount`
from (select `user_id`, sum(price) as `upIncome`
from `app_user_selling_water`
where <![CDATA[position_id<>6]]>
and status = 0
<if test="startDate!=null and endDate!=null">
and `crt_time` between #{startDate} and #{endDate}
</if>
<if test="startDate!=null and endDate==null">
and <![CDATA[
`crt_time` >=#{startDate}
]]>
</if>
<if test="startDate==null and endDate!=null">
and <![CDATA[
`crt_time` <=#{endDate}
]]>
</if> </if>
group by user_id) as auswp
left join (select `user_id`, sum(price) as `dowIncome`
from `app_user_selling_water`
where <![CDATA[position_id<>6]]>
and status = 1
group by user_id) as auswd
on auswd.user_id = auswp.user_id
) as `sell` on sell.user_id=saff.userId
order by sell.sellAmount desc
</select> </select>
......
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