Commit f0034da0 authored by jiaorz's avatar jiaorz

Merge remote-tracking branch 'origin/dev' into dev

parents ef1328c8 a9a58107
package com.github.wxiaoqi.security.common.enumconstant;
import org.assertj.core.util.Lists;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
......@@ -15,9 +15,9 @@ import java.util.stream.Collectors;
* @data 2019/11/13 17:23
*/
public enum LevelEnum {
DIAMOND(3,"钻石"),
GOLD(2,"黄金"),
GENERAL(1,"普通");
DIAMOND(3, "钻石"),
GOLD(2, "黄金"),
GENERAL(1, "普通");
LevelEnum(Integer level, String desc) {
this.level = level;
......@@ -25,18 +25,18 @@ public enum LevelEnum {
}
public static LevelEnum getLevelEnumByLevel(Integer level){
public static LevelEnum getLevelEnumByLevel(Integer level) {
return levelMap.get(level);
}
private Integer level;
private String desc;
private static Map<Integer, LevelEnum> levelMap;
private static Map<Integer, LevelEnum> levelMap;
public static List<Integer> levels;
static {
levelMap = EnumSet.allOf(LevelEnum.class).stream().collect(Collectors.toMap(LevelEnum::getLevel, Function.identity()));
levels = Lists.newArrayList(levelMap.keySet());
levels = new ArrayList<>(levelMap.keySet());
}
public Integer getLevel() {
......@@ -55,4 +55,3 @@ public enum LevelEnum {
this.desc = desc;
}
}
package com.github.wxiaoqi.security.admin.bo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/26 17:09
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StaffStatisticsBo {
private static final long serialVersionUID = 1L;
private String name ;
private Integer userId;
private List<String> companyNames;
private List<Integer> compnayIds;
private List<String> postionNames;
private List<Integer> postionIds;
private String phone;
private BigDecimal sellAmount = BigDecimal.ZERO;
private BigDecimal royaltyAmount = BigDecimal.ZERO;
private Integer memberOrderNum = 0;
private BigDecimal memberAmount = BigDecimal.ZERO;
private Integer rentVehicleOrderNum = 0;
private BigDecimal rentVehicleAmount = BigDecimal.ZERO;
private Integer travelOrderNum = 0;
private BigDecimal travelAmount = BigDecimal.ZERO;
public List<String> getCompanyNames() {
return CollectionUtils.isEmpty(companyNames)? new ArrayList<>():companyNames;
}
public List<Integer> getCompnayIds() {
return CollectionUtils.isEmpty(compnayIds)?new ArrayList<>():compnayIds;
}
public List<String> getPostionNames() {
return CollectionUtils.isEmpty(postionNames)?new ArrayList<>() :postionNames;
}
public List<Integer> getPostionIds() {
return CollectionUtils.isEmpty(postionIds)?new ArrayList<>():postionIds;
}
public BigDecimal getSellAmount() {
return rentVehicleAmount.add(travelAmount).add(memberAmount);
}
}
package com.github.wxiaoqi.security.admin.bo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/26 17:09
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class StaffStatisticsTotalBo {
private Integer staffNum;
private BigDecimal totalSellAmount;
private BigDecimal totalRoyaltyAmount;
public Integer getStaffNum() {
return this.staffNum==null?0:staffNum;
}
public BigDecimal getTotalSellAmount() {
return this.totalSellAmount==null?BigDecimal.ZERO:totalSellAmount;
}
public BigDecimal getTotalRoyaltyAmount() {
return this.totalRoyaltyAmount==null?BigDecimal.ZERO:totalRoyaltyAmount;
}
}
......@@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
......@@ -13,10 +16,18 @@ import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDetailBo {
private Integer userId;
private String userName;
private String phone;
private Integer postionId;
private String postionName;
public class UserStaffBo implements Serializable {
private static final long serialVersionUID = 1L;
private Integer userId;
private String realName;
private String nickName;
private String phone;
private Integer postionId;
private String postionName;
private Integer companyId;
private String companyName;
/**
* 佣金
*/
private BigDecimal commission;
}
......@@ -3,6 +3,9 @@ package com.github.wxiaoqi.security.admin.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author libin
* @version 1.0
......@@ -10,7 +13,8 @@ import lombok.Data;
* @data 2019/7/11 15:14
*/
@Data
public class AppUserSellingWaterDTO {
public class AppUserSellingWaterDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 用户id
*/
......@@ -35,6 +39,8 @@ public class AppUserSellingWaterDTO {
@ApiModelProperty(value = "订单id")
private Integer orderId;
private Integer orderType;
/**
* 商品id
*/
......@@ -75,7 +81,7 @@ public class AppUserSellingWaterDTO {
* 售价
*/
@ApiModelProperty(value = "售价")
private Long price;
private BigDecimal price;
/**
* 提成百分比
......@@ -89,4 +95,12 @@ public class AppUserSellingWaterDTO {
@ApiModelProperty(value = "是否入账:0-未入账;1-已入账")
private Integer waiting;
private BigDecimal commission;
private Integer companyId;
private String companyName;
private String stateGroup;
}
package com.github.wxiaoqi.security.admin.dto;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/26 17:04
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StaffStatisticsFindDTO extends PageParam {
private Date startDate;
private Date endDate;
private String companyName;
private Integer userPostionId;
private Integer companyId;
private List<Integer> userIds;
private Boolean isExport;
}
package com.github.wxiaoqi.security.admin.feign;
import com.github.wxiaoqi.security.admin.bo.UserBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.dto.UserMemberDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserLogin;
import com.github.wxiaoqi.security.admin.entity.AppUserPosition;
import com.github.wxiaoqi.security.admin.entity.BaseUserMember;
import com.github.wxiaoqi.security.admin.entity.BaseUserMemberLevel;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
import com.github.wxiaoqi.security.admin.feign.dto.UserDTO;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.admin.vo.ImiVo;
import com.github.wxiaoqi.security.admin.vo.WalletPostionVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -163,4 +168,17 @@ public interface UserFeign {
boolean isCollectionByTypeAndTypeId(@RequestParam("userId") Integer userId,
@RequestParam(value = "type") int type,
@RequestParam("id") Integer typId);
@GetMapping("/app/user/list_staff")
List<UserStaffBo> findAllStaffs();
@GetMapping("/sellingwater/list_staff_sellerwater")
List<AppUserSellingWaterDTO> findStaffSellerWater(@RequestParam(value = "userIds",required = false) List<Integer> userIds,
@RequestParam(value = "startDate") Date startDate,
@RequestParam(value = "endDate") Date endDate);
@GetMapping("/postion/admin/postions")
ObjectRestResponse<List<WalletPostionVo>> findAllPostions();
@GetMapping("/public/getUsersByUserIdList")
ObjectRestResponse<List<AppUserVo>> getByUserIdList(@RequestParam("userIds") List<Integer> userIds);
}
......@@ -3,6 +3,8 @@ package com.github.wxiaoqi.security.admin.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* @author libin
* @version 1.0
......@@ -10,8 +12,8 @@ import lombok.Data;
* @data 2019/7/17 16:17
*/
@Data
public class WalletPostionVo {
public class WalletPostionVo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("主键id")
private Integer id;
......
......@@ -2,13 +2,16 @@ package com.github.wxiaoqi.security.admin.biz;
import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AccountBindDTO;
import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.mapper.AppUserDetailMapper;
import com.github.wxiaoqi.security.admin.rpc.service.AppPermissionService;
import com.github.wxiaoqi.security.admin.vo.AppUserInfoVo;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
......@@ -17,10 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.time.Instant;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -173,4 +173,18 @@ public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail
public List<AppUserVo> getUserByUserIds(List<Integer> ids) {
return mapper.getUserVo(ids);
}
public List<UserStaffBo> findAllStaffs() {
List<UserStaffBo> userStaffBos = mapper.selectAllStaffs();
return CollectionUtils.isEmpty(userStaffBos)? Collections.EMPTY_LIST:userStaffBos;
}
public List<AppUserVo> getUserByUserIdList(List<Integer> userIds) {
List<AppUserVo> appUserVos = mapper.getUserByUserIdList(userIds);
return CollectionUtils.isEmpty(appUserVos)?Collections.EMPTY_LIST:appUserVos;
}
public PageDataVO<UserStaffBo> findAllStaffsByCompanyIdAndPostionIdWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) {
return PageDataVO.pageInfo(staffStatisticsFindDTO.getPage(),staffStatisticsFindDTO.getLimit(),()->mapper.findAllStaffsByCompanyIdAndPostionIdWithPage(staffStatisticsFindDTO));
}
}
package com.github.wxiaoqi.security.admin.biz;
import com.github.wxiaoqi.security.admin.bo.UserIncomeBo;
import com.github.wxiaoqi.security.admin.dto.OrderGoodsDTO;
import com.github.wxiaoqi.security.admin.dto.OrderWaterDTO;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterAdminDTO;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterFindDTO;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.*;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.admin.entity.AppUserRelation;
import com.github.wxiaoqi.security.admin.vo.SellingWalletVo;
......@@ -20,6 +18,7 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Supplier;
......@@ -199,12 +198,12 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
amount = amount.add(commission);
}
BigDecimal unbooked=amount;
log.info("订单完成计算用户拥金----finishOrderWater----orderId====" + orderId + "---amount==" + amount+"---unbooked=="+unbooked);
if(orderType==1){
List<OrderGoodsDTO> goodsDTOList =orderWaterDTO.getGoodsDTOList();
log.info("租车订单完成-----goodsDTOList==="+goodsDTOList);
if (CollectionUtils.isNotEmpty(goodsDTOList)){
BigDecimal unbooked = amount;
log.info("订单完成计算用户拥金----finishOrderWater----orderId====" + orderId + "---amount==" + amount + "---unbooked==" + unbooked);
if (orderType == 1) {
List<OrderGoodsDTO> goodsDTOList = orderWaterDTO.getGoodsDTOList();
log.info("租车订单完成-----goodsDTOList===" + goodsDTOList);
if (CollectionUtils.isNotEmpty(goodsDTOList)) {
for (OrderGoodsDTO goodsDto : goodsDTOList) {
//商品id
Integer goodId = goodsDto.getGoodId();
......@@ -214,17 +213,17 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
sellingWater.setOrderId(orderId);
sellingWater.setGoodId(goodId);
sellingWater = selectOne(sellingWater);
if (sellingWater == null||sellingWater.getExtract()==null||sellingWater.getExtract()==0) {
if (sellingWater == null || sellingWater.getExtract() == null || sellingWater.getExtract() == 0) {
log.info("租车订单完成-----sellingWater---不存在或extract---为空");
continue;
}
if (price.compareTo(sellingWater.getPrice())>=0){
if (price.compareTo(sellingWater.getPrice()) >= 0) {
log.info("租车订单完成-----完成价格大于支付价格");
continue;
}
price=sellingWater.getPrice().subtract(price);
Integer extract=sellingWater.getExtract();
log.info("租车订单完成-----price====="+price+"---extract===="+extract);
price = sellingWater.getPrice().subtract(price);
Integer extract = sellingWater.getExtract();
log.info("租车订单完成-----price=====" + price + "---extract====" + extract);
BigDecimal commission = price.multiply(new BigDecimal(extract + "")).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
log.info("租车订单完成--------userId===" + userId + "---commission===" + commission);
sellingWater.setWaiting(1);
......@@ -234,8 +233,8 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
insertSelective(sellingWater);
log.info("租车订单完成计算用户拥成功----payOrderWater--------userId===" + userId);
amount = amount.subtract(commission);
}
}
}
}
log.info("订单完成计算用户拥金----finishOrderWater--------orderId===" + orderId + "----amount====" + amount + "--orderType===" + orderType);
int r = amount.compareTo(BigDecimal.ZERO);
......@@ -249,7 +248,7 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
detail.setSource(1);
myWaterBiz.updMyWater(detail);
}
if ((orderType == 1 || orderType == 2)&&unbooked.compareTo(BigDecimal.ZERO)==1 ){
if ((orderType == 1 || orderType == 2) && unbooked.compareTo(BigDecimal.ZERO) == 1) {
myWaterBiz.updMyWalletUnbooked(userId, unbooked, 2);
}
}
......@@ -449,7 +448,7 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
criteria.andEqualTo("userId", leaderId);
criteria.andEqualTo("orderType", orderType);
List<AppUserSellingWater> appUserSellingWaters = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(appUserSellingWaters)){
if (CollectionUtils.isEmpty(appUserSellingWaters)) {
return Collections.EMPTY_LIST;
}
return appUserSellingWaters.stream().map(AppUserSellingWater::getSourceId).collect(Collectors.toList());
......@@ -462,6 +461,37 @@ public class AppUserSellingWaterBiz extends BaseBiz<AppUserSellingWaterMapper, A
return pageDataVO;
}
public List<AppUserSellingWaterDTO> findStatffSellerWaterByUserIdsAndTime(List<Integer> userIds, Date startDate, Date endDate) {
/* List<UserStaffBo> userStaffBos = mapper.statisticsStatffSellerWaterByUserIdsAndTime(userIds,startDate.getTime(),endDate.getTime());
return CollectionUtils.isEmpty(userStaffBos)?Collections.EMPTY_LIST:userStaffBos;*/
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = new ArrayList<>();
Example example = new Example(AppUserSellingWater.class);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("userId", userIds);
if(startDate!=null && endDate!=null){
criteria.andBetween("crtTime", startDate.getTime(), endDate.getTime());
}
if (startDate!=null && endDate==null){
criteria.andGreaterThanOrEqualTo("crtTime",startDate.getTime());
}
if(startDate==null && endDate!=null){
criteria.andLessThanOrEqualTo("crtTime",endDate.getTime());
}
criteria.andNotEqualTo("positionId", 6);
List<AppUserSellingWater> appUserSellingWaters = mapper.selectByExample(example);
if (CollectionUtils.isEmpty(appUserSellingWaters)) {
return appUserSellingWaterDTOS;
}
AppUserSellingWaterDTO appUserSellingWaterDTO = null;
for (AppUserSellingWater appUserSellingWater : appUserSellingWaters) {
appUserSellingWaterDTO = new AppUserSellingWaterDTO();
BeanUtils.copyProperties(appUserSellingWater, appUserSellingWaterDTO);
appUserSellingWaterDTOS.add(appUserSellingWaterDTO);
}
return appUserSellingWaterDTOS;
}
private enum SellerWallterStatus {
CANCEL(2, "取消订单"),
POST(1, "已入账"),
......
package com.github.wxiaoqi.security.admin.biz;
import cn.hutool.core.collection.CollUtil;
import com.github.wxiaoqi.security.admin.bo.StaffStatisticsBo;
import com.github.wxiaoqi.security.admin.bo.StaffStatisticsTotalBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO;
import com.github.wxiaoqi.security.admin.vo.WalletPostionVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum;
import com.xxfc.platform.order.feign.OrderFeign;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/26 17:01
*/
@Transactional(rollbackFor = Exception.class)
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StaffStatisticsBiz {
private static final String TOTAL_VAL = "total";
private static final String PAGE_VAL = "page";
private static final String TOTAL_AMOUNT_VAL = "totalAmount";
private static final String TOTAL_NUM_VAL = "totalNum";
private static final String TOTAL_COMMISSION_VAL = "totalCommission";
private static final Integer NO_COMPANY_STATE = 0;
private final AppUserDetailBiz appUserDetailBiz;
private final AppUserSellingWaterBiz appUserSellingWaterBiz;
private final OrderFeign orderFeign;
private final VehicleFeign vehicleFeign;
private final AppUserPositionBiz appUserPositionBiz;
public Map<String, Object> listStaffStatisticsWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) {
Map<String, Object> result = new HashMap<>(2);
PageDataVO<StaffStatisticsBo> pageDataVO = new PageDataVO<>();
List<StaffStatisticsBo> staffStatisticsBos = new ArrayList<>();
//1.分页查询全部员工
PageDataVO<UserStaffBo> staffPage = appUserDetailBiz.findAllStaffsByCompanyIdAndPostionIdWithPage(staffStatisticsFindDTO);
List<UserStaffBo> allStaffs = staffPage.getData();
if (CollectionUtils.isEmpty(allStaffs)) {
result.put(TOTAL_VAL, new StaffStatisticsTotalBo());
pageDataVO.setData(Collections.EMPTY_LIST);
pageDataVO.setPageSize(staffStatisticsFindDTO.getLimit());
pageDataVO.setPageNum(staffStatisticsFindDTO.getPage());
pageDataVO.setTotalPage(0);
pageDataVO.setTotalCount(0L);
result.put(PAGE_VAL, pageDataVO);
return result;
}
//2.根据员工id范围和其他条件分页查询
List<Integer> userIds = allStaffs.stream().map(UserStaffBo::getUserId).collect(Collectors.toList());
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds, staffStatisticsFindDTO.getStartDate(), staffStatisticsFindDTO.getEndDate());
Map<Integer, Map<String, Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>>>> sellingWaterMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)) {
//3.根据订单id查询订单相关信息
List<Integer> orderIds = appUserSellingWaterDTOS.stream().map(AppUserSellingWaterDTO::getOrderId).collect(Collectors.toList());
ObjectRestResponse<List<OrderDTO>> response =orderFeign.findOrdersByorderId(orderIds);
List<OrderDTO> orders =response.getData();
Map<Integer, Integer> ordersMap = orders.stream().collect(Collectors.toMap(OrderDTO::getId, OrderDTO::getCompanyId));
for (AppUserSellingWaterDTO appUserSellingWaterDTO : appUserSellingWaterDTOS) {
appUserSellingWaterDTO.setCompanyId(ordersMap.get(appUserSellingWaterDTO.getOrderId()) == null ? NO_COMPANY_STATE : ordersMap.get(appUserSellingWaterDTO.getOrderId()));
appUserSellingWaterDTO.setStateGroup(String.format("%d-%d-%d", appUserSellingWaterDTO.getUserId(), appUserSellingWaterDTO.getPositionId(), appUserSellingWaterDTO.getCompanyId()));
}
sellingWaterMap = appUserSellingWaterDTOS.stream().collect(Collectors.groupingBy(AppUserSellingWaterDTO::getUserId,
Collectors.groupingBy(AppUserSellingWaterDTO::getStateGroup, Collectors.groupingBy(AppUserSellingWaterDTO::getOrderType, Collectors.groupingBy(AppUserSellingWaterDTO::getStatus, Collectors.toList())))));
}
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
List<WalletPostionVo> allPostions = appUserPositionBiz.findAllPostions();
Map<Integer, String> postionMap = allPostions.stream().collect(Collectors.toMap(WalletPostionVo::getId, WalletPostionVo::getName));
for (UserStaffBo userStaffBo : allStaffs) {
String stateGroup = String.format("%d-%d-%d", userStaffBo.getUserId(), userStaffBo.getPostionId(), userStaffBo.getCompanyId() == null ? NO_COMPANY_STATE : userStaffBo.getCompanyId());
StaffStatisticsBo staffStatisticsBo = creatDefaultStaffStatistics(userStaffBo);
if (!sellingWaterMap.isEmpty()) {
Map<String, Map<Integer, Map<Integer, List<AppUserSellingWaterDTO>>>> userSellingWaterMap = sellingWaterMap.get(userStaffBo.getUserId());
if (userSellingWaterMap != null && !userSellingWaterMap.isEmpty()) {
AtomicReference<BigDecimal> royaltyAmountAtomicReference = new AtomicReference<>(BigDecimal.ZERO);
userSellingWaterMap.forEach((K, V) -> {
if (!K.equals(stateGroup)) {
String[] sates = K.split("-");
String postionIdStr = sates[1];
postionMap.get(Integer.valueOf(postionIdStr));
String companyIdStr = sates[2];
List<String> postionNames = staffStatisticsBo.getPostionNames();
List<Integer> postionIds = staffStatisticsBo.getPostionIds();
List<String> companyNames = staffStatisticsBo.getCompanyNames();
List<Integer> compnayIds = staffStatisticsBo.getCompnayIds();
if (!postionIds.contains(Integer.valueOf(postionIdStr))) {
postionNames.add(postionMap.get(Integer.valueOf(postionIdStr)));
postionIds.add(Integer.valueOf(postionIdStr));
}
if (!compnayIds.contains(Integer.valueOf(companyIdStr))) {
String companyName = companyMap.get(Integer.valueOf(companyIdStr));
if (StringUtils.hasText(companyName)){
companyNames.add(companyName);
compnayIds.add(Integer.valueOf(companyIdStr));
}
}
staffStatisticsBo.setPostionIds(postionIds);
staffStatisticsBo.setPostionNames(postionNames);
staffStatisticsBo.setCompnayIds(compnayIds);
staffStatisticsBo.setCompanyNames(companyNames);
}
wrapStaffStatistics(V, royaltyAmountAtomicReference, staffStatisticsBo);
});
staffStatisticsBo.setRoyaltyAmount(royaltyAmountAtomicReference.get());
}
}
staffStatisticsBos.add(staffStatisticsBo);
}
if (staffStatisticsFindDTO.getPage() == 1) {
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) {
waterDTOSMap.forEach((K, V) -> {
Map<String, Object> orderRentResultMap = wrapStaffStatisticsMap(V);
BigDecimal royaltyAmount = royaltyAmountAtomicReference.get();
royaltyAmount = royaltyAmount.add((BigDecimal) orderRentResultMap.get(TOTAL_COMMISSION_VAL));
royaltyAmountAtomicReference.set(royaltyAmount);
switch (K) {
case StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE:
staffStatisticsBo.setRentVehicleOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getRentVehicleOrderNum());
staffStatisticsBo.setRentVehicleAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getRentVehicleAmount()));
break;
case StatisticsStatusEnum.ORDER_TOUR_TYPE:
staffStatisticsBo.setTravelOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getTravelOrderNum());
staffStatisticsBo.setTravelAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getTravelAmount()));
break;
case StatisticsStatusEnum.ORDER_MEMBER_TYPE:
staffStatisticsBo.setMemberOrderNum(((Integer) orderRentResultMap.get(TOTAL_NUM_VAL))+staffStatisticsBo.getMemberOrderNum());
staffStatisticsBo.setMemberAmount(((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL)).add(staffStatisticsBo.getMemberAmount()));
break;
default:
break;
}
});
return staffStatisticsBo;
}
private Map<String, Object> wrapStaffStatisticsMap(Map<Integer, List<AppUserSellingWaterDTO>> sellingWaters) {
Map<String, Object> staffStatisticsResultMap = new HashMap<>(2);
AtomicInteger orderCounter = new AtomicInteger(0);
if (sellingWaters == null || sellingWaters.isEmpty()) {
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, BigDecimal.ZERO);
staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get());
}
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal royaltyAmount = BigDecimal.ZERO;
Set<Map.Entry<Integer, List<AppUserSellingWaterDTO>>> sellingWaterSet = sellingWaters.entrySet();
for (Map.Entry<Integer, List<AppUserSellingWaterDTO>> sellingWaterEntry : sellingWaterSet) {
List<AppUserSellingWaterDTO> waterDTOS = sellingWaterEntry.getValue();
for (AppUserSellingWaterDTO waterDTO : waterDTOS) {
if (sellingWaterEntry.getKey() == 0) {
royaltyAmount = royaltyAmount.add(waterDTO.getCommission());
totalAmount = totalAmount.add(waterDTO.getPrice());
orderCounter.incrementAndGet();
}
if (sellingWaterEntry.getKey() == 1) {
royaltyAmount = royaltyAmount.subtract(waterDTO.getCommission());
totalAmount = totalAmount.subtract(waterDTO.getPrice());
}
}
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL, totalAmount);
staffStatisticsResultMap.put(TOTAL_NUM_VAL, orderCounter.get());
staffStatisticsResultMap.put(TOTAL_COMMISSION_VAL, royaltyAmount);
}
return staffStatisticsResultMap;
}
private StaffStatisticsBo creatDefaultStaffStatistics(UserStaffBo userStaffBo) {
StaffStatisticsBo staffStatisticsBo = new StaffStatisticsBo();
if (userStaffBo.getCompanyId() != null) {
staffStatisticsBo.setCompanyNames(Arrays.asList(userStaffBo.getCompanyName()));
staffStatisticsBo.setCompnayIds(Arrays.asList(userStaffBo.getCompanyId()));
}
if (userStaffBo.getPostionId() != null) {
staffStatisticsBo.setPostionNames(Arrays.asList(userStaffBo.getPostionName()));
staffStatisticsBo.setPostionIds(Arrays.asList(userStaffBo.getPostionId()));
}
staffStatisticsBo.setUserId(userStaffBo.getUserId());
staffStatisticsBo.setName(StringUtils.hasText(userStaffBo.getRealName())?userStaffBo.getRealName():userStaffBo.getNickName());
staffStatisticsBo.setPhone(userStaffBo.getPhone());
staffStatisticsBo.setMemberAmount(BigDecimal.ZERO);
staffStatisticsBo.setMemberOrderNum(0);
staffStatisticsBo.setTravelAmount(BigDecimal.ZERO);
staffStatisticsBo.setTravelOrderNum(0);
staffStatisticsBo.setRentVehicleAmount(BigDecimal.ZERO);
staffStatisticsBo.setRentVehicleOrderNum(0);
staffStatisticsBo.setSellAmount(BigDecimal.ZERO);
staffStatisticsBo.setRoyaltyAmount(BigDecimal.ZERO);
return staffStatisticsBo;
}
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserManageDTO;
import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.vo.AppUserManageVo;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
......@@ -25,4 +27,10 @@ public interface AppUserDetailMapper extends Mapper<AppUserDetail> {
List<AppUserVo> getUserVo(@Param("list") List<Integer> ids);
List<AppUserManageVo> selectAppUser(AppUserManageDTO appUserManageDTO);
List<UserStaffBo> selectAllStaffs();
List<AppUserVo> getUserByUserIdList(@Param("userIds") List<Integer> userIds);
List<UserStaffBo> findAllStaffsByCompanyIdAndPostionIdWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO);
}
\ No newline at end of file
package com.github.wxiaoqi.security.admin.mapper;
import com.github.wxiaoqi.security.admin.bo.UserIncomeBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterAdminDTO;
import com.github.wxiaoqi.security.admin.dto.UserSellingWaterFindDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserSellingWater;
......@@ -27,4 +29,8 @@ public interface AppUserSellingWaterMapper extends Mapper<AppUserSellingWater> {
List<SellingWalletVo> selectSellerWalterByUserIdAndWating(@Param("userId") Integer userId, @Param("wating") Integer wating);
List<UserSellingWaterAdminDTO> selectSellingWaterPage(UserSellingWaterFindDTO userSellingWaterFindDTO);
List<AppUserSellingWaterDTO> statisticsStatffSellerWaterByUserIdsAndTime(@Param("userIds") List<Integer> userIds,
@Param("startTime") Long startTime,
@Param("endTime") Long endTime);
}
......@@ -2,6 +2,7 @@ package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.*;
import com.github.wxiaoqi.security.admin.bo.UserBo;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AccountBindDTO;
import com.github.wxiaoqi.security.admin.entity.*;
import com.github.wxiaoqi.security.admin.feign.dto.AppUserDTO;
......@@ -366,4 +367,9 @@ public class AppUserController extends CommonBaseController{
return appUserLoginBiz.findUserDetailInfo(userBos);
}
@ApiOperation("查询全部员工")
@GetMapping("/list_staff")
public List<UserStaffBo> findAllStaffs(){
return userDetailBiz.findAllStaffs();
}
}
......@@ -105,7 +105,7 @@ public class PublicController {
//获取用户基础信息
AppUserVo userVo = detailBiz.getUserInfoById(userid);
if (userVo == null) {
return null;
return null;
}
Integer id= userVo.getId();
Integer positionId=userVo.getPositionId();
......@@ -169,5 +169,9 @@ public class PublicController {
return ObjectRestResponse.succ(appUserVos);
}
@GetMapping("/getUsersByUserIdList")
ObjectRestResponse<List<AppUserVo>> getByUserIdList(@RequestParam("userIds") List<Integer> userIds){
List<AppUserVo> appUserVos = detailBiz.getUserByUserIdList(userIds);
return ObjectRestResponse.succ(appUserVos);
}
}
package com.github.wxiaoqi.security.admin.rest;
import com.github.wxiaoqi.security.admin.biz.AppUserSellingWaterBiz;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.dto.OrderWaterDTO;
import com.github.wxiaoqi.security.admin.vo.SellingWalletPagVo;
import com.github.wxiaoqi.security.auth.client.config.UserAuthConfig;
......@@ -8,10 +10,13 @@ import com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil;
import com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
/**
* @author libin
......@@ -72,4 +77,13 @@ public class UserSellingWaterController {
throw new BaseException(e);
}
}
@ApiOperation("员工佣金")
@GetMapping("/list_staff_sellerwater")
public List<AppUserSellingWaterDTO> findStaffSellerWater(@RequestParam(value = "userIds",required = false) List<Integer> userIds,
@RequestParam(value = "startDate") Date startDate,
@RequestParam(value = "endDate") Date endDate){
return appUserSellingWaterBiz.findStatffSellerWaterByUserIdsAndTime(userIds,startDate,endDate);
}
}
package com.github.wxiaoqi.security.admin.rest.admin;
import com.github.wxiaoqi.security.admin.biz.StaffStatisticsBiz;
import com.github.wxiaoqi.security.admin.dto.StaffStatisticsFindDTO;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/11/26 16:59
*/
@RestController
@RequestMapping("/staff_statistics")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StaffStatisticsAdminController {
private final StaffStatisticsBiz staffStatisticsBiz;
@PostMapping("/page")
public ObjectRestResponse<Map<String,Object>> lisetStaffStatisticsWithPage(@RequestBody StaffStatisticsFindDTO staffStatisticsFindDTO){
Map<String,Object> result = staffStatisticsBiz.listStaffStatisticsWithPage(staffStatisticsFindDTO);
return ObjectRestResponse.succ(result);
}
}
......@@ -66,7 +66,7 @@
#{userId}
</foreach>
</select>
</select>
<select id="getUserIdByUsername" resultType="java.lang.Integer" parameterType="java.lang.String">
......@@ -200,7 +200,6 @@
<if test="memberLevel == -1">
and m.member_level in (select level from base_user_member_level)
</if>
<if test="registrationTimeBegin !=null ">
and l.createtime &gt;= #{registrationTimeBegin}
</if>
......@@ -235,4 +234,47 @@
order by l.id ASC
</select>
<!--查询非普通用户-->
<select id="selectAllStaffs" 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`
from `app_user_detail` as `aud` left join `app_user_login` as `aul` on aul.id=aud.userid
left join `app_user_position_temp` as `aupt` on aupt.user_id=aul.id
left join `app_user_position` as `aup` on aup.id=aud.position_id
where <![CDATA[aud.position_id<>6]]> and aud.isdel=0
</select>
<select id="getUserByUserIdList" resultMap="AppUserVoMap">
select
l.im_userid,l.username,l.wx_openid,l.unionid,l.openid,l.status,l.id_number,l.certification_status,d.*,p.name as
jobTitle,buml.name as memberName from app_user_login l
left join app_user_detail d
on d.userid = l.id
left join base_user_member bum
on bum.user_id=l.id
left join (select level, name from base_user_member_level level where isdel = 0) buml
on bum.member_level = buml.level
left join (select id, name from app_user_position where is_del=0) p
on d.position_id=p.id
where l.isdel=0 and
d.userid in
<foreach collection="userIds" item="userId" index="index" open="(" separator="," close=")">
#{userId}
</foreach>
</select>
<select id="findAllStaffsByCompanyIdAndPostionIdWithPage"
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`
from `app_user_detail` as `aud` left join `app_user_login` as `aul` on aul.id=aud.userid
left join `app_user_position_temp` as `aupt` on aupt.user_id=aul.id
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">
and aud.`position_id`=#{userPostionId}
</if>
<if test="companyId!=null">
and aupt.`company_id`=#{companyId}
</if>
</select>
</mapper>
\ No newline at end of file
......@@ -26,10 +26,10 @@ FROM
<select id="selectTotalIncomeByUserId" resultType="java.math.BigDecimal">
SELECT
( auswu.upIncome - auswd.dowIncome ) AS `income`
( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `income`
FROM
( SELECT IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` WHERE STATUS = 0 AND `user_id` = #{userId} ) AS `auswu`,
( SELECT IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` WHERE STATUS = 1 AND `user_id` = #{userId} ) AS `auswd`;
( SELECT IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` WHERE STATUS = 0 AND waiting=1 AND `user_id` = #{userId} ) AS `auswu`,
( SELECT IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` WHERE STATUS = 1 AND waiting=1 AND `user_id` = #{userId} ) AS `auswd`;
</select>
<select id="selectSellerWalterByUserIdAndWating" resultType="com.github.wxiaoqi.security.admin.vo.SellingWalletVo">
......@@ -151,4 +151,27 @@ FROM
</if>) AS audd ON audd.userid = ausw.user_id
ORDER BY ausw.crt_time DESC
</select>
<select id="statisticsStatffSellerWaterByUserIdsAndTime"
resultType="com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO">
SELECT
`auswu`.user_id, ( IFNULL(auswu.upIncome,0) - IFNULL(auswd.dowIncome,0) ) AS `commission`
FROM
( SELECT `user_id` as `userId`, IFNULL(SUM( commission ),0) AS upIncome FROM `app_user_selling_water` where STATUS = 0 and waiting=1
AND `crt_time` between #{startTime} and #{endTime}
<if test="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if> group by user_id) AS `auswu`
left join
( SELECT `user_id`,IFNULL(SUM( commission ),0) AS `dowIncome` FROM `app_user_selling_water` where STATUS = 1 and waiting=1
and `crt_time` between #{startTime} and #{endTime}
<if test="userIds!=null and userIds.size!=0">
AND `user_id` IN <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
#{userId}
</foreach>
</if> group by user_id) AS `auswd`
on auswd.user_id=auswu.user_id
</select>
</mapper>
\ No newline at end of file
......@@ -46,7 +46,7 @@ public class StaffStatistics implements Serializable {
protected String weekOfYear;
@ApiModelProperty("员工所属公司id")
@Column(name = "compnay_id")
@Column(name = "company_id")
private Integer companyId;
@ApiModelProperty("公司名称")
......@@ -96,4 +96,8 @@ public class StaffStatistics implements Serializable {
@ApiModelProperty("提成")
@Column(name = "royalty_amount")
private BigDecimal royaltyAmount;
@ApiModelProperty("创建时间")
@Column(name = "crt_time")
private Date crtTime;
}
package com.xxfc.platform.order.feign;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.GoodDataVO;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import com.xxfc.platform.vehicle.common.RestResponse;
import com.xxfc.platform.vehicle.entity.*;
import com.xxfc.platform.vehicle.pojo.*;
import com.xxfc.platform.vehicle.pojo.vo.AccompanyingItemVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by ace on 2017/9/15.
......@@ -25,4 +23,8 @@ public interface OrderFeign {
@GetMapping("/count/list")
public ObjectRestResponse<List<OrderPageVO>> getOrderList(@RequestParam("dateTime")Long dateTime, @RequestParam("type")Integer type, @RequestParam("status")Integer status);
@GetMapping(value = "/count/basebase/findByOrderIds")
public ObjectRestResponse<List<OrderDTO>> findOrdersByorderId(@RequestParam(value = "orderIds") List<Integer> orderIds);
}
......@@ -35,6 +35,9 @@ public class OrderDTO {
private JSONObject data;
private Integer damageSafe;
private BigDecimal deposit;
private Integer userId;
private Integer postionId;
/**
* 费用其他明细 租车使用
*/
......
......@@ -23,5 +23,5 @@ public class StaffStatisticsFindDTO extends PageParam {
private Date endDate;
private String companyName;
private Integer userPostionId;
private List<String> companyIds;
private List<Integer> companyIds;
}
......@@ -135,8 +135,8 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements
}
public List<OrderListVo> listOrder(Map<String, Object> paramMap) {
return mapper.listOrder(paramMap);
List<OrderListVo> orderListVos = mapper.listOrder(paramMap);
return orderListVos;
}
public List<OrderPageVO> getRentVehicle(Map<String, Object> paramMap) {
......@@ -854,11 +854,9 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements
switch (sign) {
case 2:
sendMsgDTO.setRoutKey(KEY_ORDER_CANCEL);
// mqSenderFeign.sendMessage(ORDER_TOPIC, KEY_ORDER_CANCEL, JSONUtil.toJsonStr(orderMQDTO));
break;
case 4:
sendMsgDTO.setRoutKey(KEY_ORDER_PAY);
// mqSenderFeign.sendMessage(ORDER_TOPIC, KEY_ORDER_PAY, JSONUtil.toJsonStr(orderMQDTO));
break;
case 6:
sendMsgDTO.setRoutKey(KEY_ORDER_FINLISH);
......@@ -890,6 +888,7 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements
public UserFeign getUserFeign() {
return userFeign;
}
/**
* 订单查询类
*/
......@@ -912,11 +911,16 @@ public class BaseOrderBiz extends BaseBiz<BaseOrderMapper, BaseOrder> implements
return Lists.newArrayList();
}
public List<OrderDTO> selectOrdersByTypeAndTime(List<Integer> types, Date startDate, Date endDate) {
List<OrderDTO> orderDTOS = mapper.selectOrdersByTypeAndTime(types,startDate,endDate);
public List<OrderDTO> selectOrdersByTypeAndTime(List<Integer> types,Integer hasPay, Date startDate, Date endDate) {
List<OrderDTO> orderDTOS = mapper.selectOrdersByTypeAndTime(types,hasPay,startDate,endDate);
return CollectionUtils.isEmpty(orderDTOS)?Collections.EMPTY_LIST:orderDTOS;
}
public List<OrderDTO> selectBaeOrderByOrderIds(List<Integer> orderIds) {
List<OrderDTO> orderDTOList = mapper.selectBaeOrderByOrderIds(orderIds);
return CollectionUtils.isNotEmpty(orderDTOList)?Collections.EMPTY_LIST:orderDTOList;
}
public List<OrderPageVO> selectAllRentVehicleOrder(Map<String, Object> paramMap) {
return mapper.selectAllRentVehicleOrder(paramMap);
}
......
......@@ -655,8 +655,20 @@ public class OrderAccountBiz extends BaseBiz<OrderAccountMapper,OrderAccount> {
* @param endDate
* @return
*/
public List<OrderAccountBo> selectByTypeAndDate(Integer orderType,Date startDate, Date endDate) {
public List<OrderAccountBo> selectByTypeAndDate(Integer orderType, Date startDate, Date endDate) {
List<OrderAccountBo> accountBos = mapper.selectOrderAccountByOrderTypeAndStartTimeAndEndTime(orderType,startDate.getTime(),endDate.getTime());
return CollectionUtils.isEmpty(accountBos)? Collections.EMPTY_LIST:accountBos;
}
/**
* 根据创建时间与员工id查询
* @param startDate
* @param endDate
* @param staffUserIds
* @return
*/
public List<OrderAccountBo> selectByDateAndStatffIds(Date startDate, Date endDate, List<Integer> staffUserIds) {
List<OrderAccountBo> orderAccountBos = mapper.selectByDateAndStatffIds(startDate,endDate,staffUserIds);
return CollectionUtils.isNotEmpty(orderAccountBos)?Collections.EMPTY_LIST:orderAccountBos;
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ public class OrderMemberReceivedStatisticsBiz extends BaseBiz<OrderMemberReceive
List<String> stisticsActiveState = new ArrayList<>();
//根据时间范围查询出会员单
List<OrderDTO> orders = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_MEMBER_TYPE), startDate, endDate);
List<OrderDTO> orders = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_MEMBER_TYPE), null,startDate, endDate);
//数据处理 状态组合 按支付状态分组 而后按组合状态
Map<Boolean, Map<String, Map<LevelEnum, List<OrderDTO>>>> stateGroupMap = orders.stream().peek(x -> {
......
......@@ -60,7 +60,7 @@ public class OrderRentVehicleReceivedStatisticsBiz extends BaseBiz<OrderRentVehi
List<OrderRentVehicleReceivedStatistics> orderRentVehicleReceivedStatisticsList = new ArrayList<>();
List<String> stisticsActiveState = new ArrayList<>();
//根据租车订单类型 时间查询
List<OrderDTO> orderDTOS = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE), startDate, endDate);
List<OrderDTO> orderDTOS = baseOrderBiz.selectOrdersByTypeAndTime(Arrays.asList(StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE),null, startDate, endDate);
//数据处理 状态组合 按支付状态分组 而后按组合状态
Map<Boolean, Map<String, List<OrderDTO>>> stateGroupMap = orderDTOS.stream().peek(x -> {
......
package com.xxfc.platform.order.biz;
import cn.hutool.core.util.ObjectUtil;
import com.github.wxiaoqi.security.admin.bo.UserDetailBo;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.admin.bo.UserStaffBo;
import com.github.wxiaoqi.security.admin.dto.AppUserSellingWaterDTO;
import com.github.wxiaoqi.security.admin.entity.AppUserSellingWater;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.vo.AppUserVo;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.google.common.collect.Lists;
import com.xxfc.platform.order.contant.enumerate.AccountTypeEnum;
import com.xxfc.platform.order.contant.enumerate.DeductionTypeEnum;
import com.xxfc.platform.order.contant.enumerate.StatisticsStatusEnum;
import com.xxfc.platform.order.entity.BaseOrder;
import com.xxfc.platform.order.entity.StaffStatistics;
import com.xxfc.platform.order.mapper.StaffStatisticsMapper;
import com.xxfc.platform.order.pojo.dto.StaffStatisticsFindDTO;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
import com.xxfc.platform.order.pojo.bo.StaffStatisticsTotalBo;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.dto.StaffStatisticsFindDTO;
import com.xxfc.platform.order.pojo.vo.StaffStatisticsVo;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -21,7 +32,12 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -33,38 +49,45 @@ import java.util.stream.Collectors;
*/
@Transactional(rollbackFor = Exception.class)
@Service
@RequiredArgsConstructor(onConstructor =@__(@Autowired))
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StaffStatisticsBiz extends BaseBiz<StaffStatisticsMapper, StaffStatistics> {
private final UserFeign userFeign;
private static final String TOTAL_AMOUNT_VAL="totalAmount";
private static final String TOTAL_NUM_VAL="totalNum";
private static final String TOTAL_COMMISSION_VAL="totalCommission";
private static final Integer NO_COMPANY_STATE=0;
private final UserFeign userFeign;
private final BaseOrderBiz baseOrderBiz;
public StaffStatisticsTotalBo staffStatisticsWithTotal(StaffStatisticsFindDTO staffStatisticsFindDTO) {
return mapper.statistics(staffStatisticsFindDTO);
}
public PageDataVO<StaffStatisticsVo> staffStatisticsWithPage(StaffStatisticsFindDTO staffStatisticsFindDTO) {
PageDataVO<StaffStatisticsVo> pageDataVO = new PageDataVO<>();
PageDataVO<StaffStatistics> statisticsVoPageDataVO = PageDataVO.pageInfo(staffStatisticsFindDTO.getPage(),staffStatisticsFindDTO.getLimit(),()->mapper.selectStaffStatistics(staffStatisticsFindDTO));
List<StaffStatistics> data = statisticsVoPageDataVO.getData();
if (CollectionUtils.isEmpty(data)){
pageDataVO.setTotalCount(0L);
pageDataVO.setTotalPage(0);
pageDataVO.setPageNum(staffStatisticsFindDTO.getPage());
pageDataVO.setPageSize(staffStatisticsFindDTO.getLimit());
pageDataVO.setData(Collections.EMPTY_LIST);
return pageDataVO;
}
PageDataVO<StaffStatisticsVo> pageDataVO = new PageDataVO<>();
PageDataVO<StaffStatistics> statisticsVoPageDataVO = PageDataVO.pageInfo(staffStatisticsFindDTO.getPage(), staffStatisticsFindDTO.getLimit(), () -> mapper.selectStaffStatistics(staffStatisticsFindDTO));
List<StaffStatistics> data = statisticsVoPageDataVO.getData();
if (CollectionUtils.isEmpty(data)) {
pageDataVO.setTotalCount(0L);
pageDataVO.setTotalPage(0);
pageDataVO.setPageNum(staffStatisticsFindDTO.getPage());
pageDataVO.setPageSize(staffStatisticsFindDTO.getLimit());
pageDataVO.setData(Collections.EMPTY_LIST);
return pageDataVO;
}
List<Integer> userIds = data.stream().map(StaffStatistics::getUserId).collect(Collectors.toList());
ObjectRestResponse<List<AppUserVo>> result = userFeign.getByUserIds(userIds);
//根据员工id查询员工信息
ObjectRestResponse<List<AppUserVo>> result = userFeign.getByUserIdList(userIds);
List<AppUserVo> users = result.getData();
Map<Integer,AppUserVo> userVoMap = CollectionUtils.isEmpty(users) ? Collections.EMPTY_MAP : users.stream().filter(x->Objects.nonNull(x.getUserid())).collect(Collectors.toMap(AppUserVo::getUserid, Function.identity()));
Map<Integer, AppUserVo> userVoMap = CollectionUtils.isEmpty(users) ? Collections.EMPTY_MAP : users.stream().filter(x -> Objects.nonNull(x.getUserid())).collect(Collectors.toMap(AppUserVo::getUserid, Function.identity()));
Map<Integer, List<StaffStatistics>> statisticsMap = data.stream().collect(Collectors.groupingBy(StaffStatistics::getUserId, Collectors.toList()));
List<StaffStatisticsVo> staffStatisticsVos = new ArrayList<>(data.size());
StaffStatisticsVo staffStatisticsVo = new StaffStatisticsVo();
statisticsMap.forEach((K,V)->{
statisticsMap.forEach((K, V) -> {
List<String> compnayNames = new ArrayList<>(V.size());
List<String> postionNames = new ArrayList<>(V.size());
StaffStatisticsVo staffStatisticsClone = ObjectUtil.cloneByStream(staffStatisticsVo);
......@@ -72,16 +95,16 @@ public class StaffStatisticsBiz extends BaseBiz<StaffStatisticsMapper, StaffStat
staffStatisticsClone.setSellAmount(staffStatistics.getSellAmount().add(staffStatisticsClone.getSellAmount()));
staffStatisticsClone.setRoyaltyAmount(staffStatistics.getRoyaltyAmount().add(staffStatisticsClone.getRoyaltyAmount()));
staffStatisticsClone.setRentVehicleAmount(staffStatistics.getRentVehicleAmount().add(staffStatisticsClone.getRentVehicleAmount()));
staffStatisticsClone.setRentVehicleOrderNum(staffStatistics.getRentVehicleOrderNum()+staffStatisticsClone.getRentVehicleOrderNum());
staffStatisticsClone.setRentVehicleOrderNum(staffStatistics.getRentVehicleOrderNum() + staffStatisticsClone.getRentVehicleOrderNum());
staffStatisticsClone.setTravelAmount(staffStatistics.getTravelAmount().add(staffStatisticsClone.getTravelAmount()));
staffStatisticsClone.setTravelOrderNum(staffStatistics.getTravelOrderNum()+staffStatisticsClone.getTravelOrderNum());
staffStatisticsClone.setTravelOrderNum(staffStatistics.getTravelOrderNum() + staffStatisticsClone.getTravelOrderNum());
staffStatisticsClone.setMemberAmount(staffStatistics.getMemberAmount().add(staffStatisticsClone.getMemberAmount()));
staffStatisticsClone.setMemberOrderNum(staffStatistics.getMemberOrderNum()+staffStatisticsClone.getMemberOrderNum());
staffStatisticsClone.setMemberOrderNum(staffStatistics.getMemberOrderNum() + staffStatisticsClone.getMemberOrderNum());
compnayNames.add(staffStatistics.getCompanyName());
postionNames.add(staffStatistics.getPostionName());
}
AppUserVo appUserVo = userVoMap ==null?new AppUserVo():userVoMap.get(K)==null?new AppUserVo():userVoMap.get(K);
String name = StringUtils.hasText(appUserVo.getRealname())?appUserVo.getRealname():StringUtils.hasText(appUserVo.getNickname())?appUserVo.getNickname():"";
AppUserVo appUserVo = userVoMap == null ? new AppUserVo() : userVoMap.get(K) == null ? new AppUserVo() : userVoMap.get(K);
String name = StringUtils.hasText(appUserVo.getRealname()) ? appUserVo.getRealname() : StringUtils.hasText(appUserVo.getNickname()) ? appUserVo.getNickname() : "";
staffStatisticsClone.setName(name);
staffStatisticsClone.setPhone(appUserVo.getUsername());
staffStatisticsClone.setCompanyNames(compnayNames);
......@@ -97,4 +120,157 @@ public class StaffStatisticsBiz extends BaseBiz<StaffStatisticsMapper, StaffStat
pageDataVO.setTotalCount(statisticsVoPageDataVO.getTotalCount());
return pageDataVO;
}
public void staffStatisticsJob(Date startDate, Date endDate, Map<Integer, String> companyMap,Map<Integer,String> postionMap) {
List<StaffStatistics> staffStatisticsList = new ArrayList<>();
//1.查询全部员工信息
List<UserStaffBo> userStaffBos = userFeign.findAllStaffs();
//2.根据员工id调用用户服务查询员工的佣金
if (CollectionUtils.isEmpty(userStaffBos)) {
return;
}
Map<Integer, UserStaffBo> staffMap = userStaffBos.stream().collect(Collectors.toMap(UserStaffBo::getUserId, Function.identity()));
List<AppUserSellingWaterDTO> appUserSellingWaterDTOS = userFeign.findStaffSellerWater(Lists.newArrayList(staffMap.keySet()),startDate,endDate);
Map<Integer, Map<String, Map<Integer,Map<Integer,List<AppUserSellingWaterDTO>>>>> sellingWaterMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(appUserSellingWaterDTOS)){
List<Integer> orderIds = appUserSellingWaterDTOS.stream().map(AppUserSellingWaterDTO::getOrderId).collect(Collectors.toList());
List<OrderDTO> orders = baseOrderBiz.selectBaeOrderByOrderIds(orderIds);
Map<Integer, Integer> ordersMap = orders.stream().collect(Collectors.toMap(OrderDTO::getId,OrderDTO::getCompanyId));
for (AppUserSellingWaterDTO appUserSellingWaterDTO : appUserSellingWaterDTOS) {
appUserSellingWaterDTO.setCompanyId(ordersMap.get(appUserSellingWaterDTO.getOrderId())==null?NO_COMPANY_STATE:ordersMap.get(appUserSellingWaterDTO.getOrderId()));
appUserSellingWaterDTO.setStateGroup(String.format("%d-%d-%d",appUserSellingWaterDTO.getUserId(),appUserSellingWaterDTO.getPositionId(),appUserSellingWaterDTO.getCompanyId()));
}
sellingWaterMap = appUserSellingWaterDTOS.stream().collect(Collectors.groupingBy(AppUserSellingWaterDTO::getUserId,
Collectors.groupingBy(AppUserSellingWaterDTO::getStateGroup,Collectors.groupingBy(AppUserSellingWaterDTO::getOrderType,Collectors.groupingBy(AppUserSellingWaterDTO::getStatus,Collectors.toList())))));
}
for (UserStaffBo userStaffBo : userStaffBos) {
String stateGroup = String.format("%d-%d-%d",userStaffBo.getUserId(),userStaffBo.getPostionId(),userStaffBo.getCompanyId()==null?NO_COMPANY_STATE:userStaffBo.getCompanyId());
StaffStatistics staffStatistics = creatDefaultStaffStatistics(startDate, userStaffBo);
if (!sellingWaterMap.isEmpty()){
Map<String, Map<Integer,Map<Integer,List<AppUserSellingWaterDTO>>>> userSellingWaterMap = sellingWaterMap.get(userStaffBo.getUserId());
if (userSellingWaterMap!=null && !userSellingWaterMap.isEmpty()){
Map<Integer,Map<Integer,List<AppUserSellingWaterDTO>>> waterDTOSMap = userSellingWaterMap.get(stateGroup);
AtomicReference<BigDecimal> royaltyAmountAtomicReference = new AtomicReference<>(BigDecimal.ZERO);
if (waterDTOSMap!=null && !waterDTOSMap.isEmpty()) {
wrapStaffStatistics(waterDTOSMap,royaltyAmountAtomicReference,staffStatistics);
}
userSellingWaterMap.remove(stateGroup);
if (!userSellingWaterMap.isEmpty()){
userSellingWaterMap.forEach((K,V)->{
String[] sates = K.split("-");
StaffStatistics staffStatisticsTo = creatDefaultStaffStatistics(startDate, userStaffBo);
staffStatisticsTo.setUserPostionId(Integer.valueOf(sates[1]));
staffStatisticsTo.setCompanyId(Integer.valueOf(sates[2]));
staffStatisticsTo.setCompanyName(companyMap.get(staffStatisticsTo.getCompanyId()));
staffStatisticsTo.setPostionName(postionMap.get(staffStatisticsTo.getUserPostionId()));
AtomicReference<BigDecimal> royaltyference = new AtomicReference(BigDecimal.ZERO);
wrapStaffStatistics(V,royaltyference,staffStatisticsTo);
staffStatisticsTo.setRoyaltyAmount(royaltyference.get());
staffStatisticsList.add(staffStatisticsTo);
});
}
}
}
staffStatisticsList.add(staffStatistics);
}
//批量插入
inserBatchStaffStatistics(staffStatisticsList);
}
public void inserBatchStaffStatistics(List<StaffStatistics> staffStatistics){
mapper.insertList(staffStatistics);
}
private StaffStatistics wrapStaffStatistics(Map<Integer,Map<Integer,List<AppUserSellingWaterDTO>>> waterDTOSMap,AtomicReference<BigDecimal> royaltyAmountAtomicReference,StaffStatistics staffStatistics){
waterDTOSMap.forEach((K,V)->{
Map<String, Object> orderRentResultMap = wrapStaffStatisticsMap(V);
BigDecimal royaltyAmount = royaltyAmountAtomicReference.get();
royaltyAmount = royaltyAmount.add((BigDecimal) orderRentResultMap.get(TOTAL_COMMISSION_VAL));
royaltyAmountAtomicReference.set(royaltyAmount);
switch (K){
case StatisticsStatusEnum.ORDER_RENT_VEHICLE_TYPE:
staffStatistics.setRentVehicleOrderNum((Integer) orderRentResultMap.get(TOTAL_NUM_VAL));
staffStatistics.setRentVehicleAmount((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL));
break;
case StatisticsStatusEnum.ORDER_TOUR_TYPE:
staffStatistics.setTravelOrderNum((Integer) orderRentResultMap.get(TOTAL_NUM_VAL));
staffStatistics.setTravelAmount((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL));
break;
case StatisticsStatusEnum.ORDER_MEMBER_TYPE:
staffStatistics.setMemberOrderNum((Integer) orderRentResultMap.get(TOTAL_NUM_VAL));
staffStatistics.setMemberAmount((BigDecimal) orderRentResultMap.get(TOTAL_AMOUNT_VAL));
break;
default:
break;
}
});
return staffStatistics;
}
private Map<String,Object> wrapStaffStatisticsMap(Map<Integer,List<AppUserSellingWaterDTO>> sellingWaters){
Map<String,Object> staffStatisticsResultMap = new HashMap<>(2);
AtomicInteger orderCounter = new AtomicInteger(0);
if (sellingWaters==null || sellingWaters.isEmpty()){
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL,BigDecimal.ZERO);
staffStatisticsResultMap.put(TOTAL_NUM_VAL,orderCounter.get());
}
BigDecimal totalAmount = BigDecimal.ZERO;
BigDecimal royaltyAmount = BigDecimal.ZERO;
Set<Map.Entry<Integer, List<AppUserSellingWaterDTO>>> sellingWaterSet = sellingWaters.entrySet();
for (Map.Entry<Integer, List<AppUserSellingWaterDTO>> sellingWaterEntry : sellingWaterSet) {
List<AppUserSellingWaterDTO> waterDTOS = sellingWaterEntry.getValue();
for (AppUserSellingWaterDTO waterDTO : waterDTOS) {
if (sellingWaterEntry.getKey() == 0){
royaltyAmount = royaltyAmount.add(waterDTO.getCommission());
totalAmount = totalAmount.add(waterDTO.getPrice());
orderCounter.incrementAndGet();
}
if (sellingWaterEntry.getKey()==1){
royaltyAmount = royaltyAmount.subtract(waterDTO.getCommission());
totalAmount = totalAmount.subtract(waterDTO.getPrice());
}
}
staffStatisticsResultMap.put(TOTAL_AMOUNT_VAL,totalAmount);
staffStatisticsResultMap.put(TOTAL_NUM_VAL,orderCounter.get());
staffStatisticsResultMap.put(TOTAL_COMMISSION_VAL,royaltyAmount);
}
return staffStatisticsResultMap;
}
private StaffStatistics creatDefaultStaffStatistics(Date startDate, UserStaffBo userStaffBo) {
StaffStatistics staffStatistics = new StaffStatistics();
LocalDate localDate = LocalDate.from(new Date().toInstant().atZone(ZoneId.systemDefault()));
String year = String.valueOf(localDate.getYear());
String month = String.format("%s%d", year, localDate.getMonthValue());
String weekOfYear = String.format("%s%d", year, localDate.get(WeekFields.of(Locale.CHINESE).weekOfYear()));
staffStatistics.setUserId(userStaffBo.getUserId());
staffStatistics.setCompanyId(userStaffBo.getCompanyId()==null?NO_COMPANY_STATE:userStaffBo.getCompanyId());
staffStatistics.setCompanyName(userStaffBo.getCompanyName());
staffStatistics.setUserPostionId(userStaffBo.getPostionId());
staffStatistics.setPostionName(userStaffBo.getPostionName());
staffStatistics.setMemberAmount(BigDecimal.ZERO);
staffStatistics.setMemberOrderNum(0);
staffStatistics.setTravelAmount(BigDecimal.ZERO);
staffStatistics.setTravelOrderNum(0);
staffStatistics.setRentVehicleAmount(BigDecimal.ZERO);
staffStatistics.setRentVehicleOrderNum(0);
staffStatistics.setSellAmount(BigDecimal.ZERO);
staffStatistics.setRoyaltyAmount(BigDecimal.ZERO);
staffStatistics.setDate(startDate);
staffStatistics.setYear(year);
staffStatistics.setMonth(month);
staffStatistics.setWeekOfYear(weekOfYear);
staffStatistics.setCrtTime(new Date());
return staffStatistics;
}
}
......@@ -22,7 +22,7 @@ import java.util.Enumeration;
* @see FeignHeadConfiguration
* @since JDK1.8
*/
@Configuration
//@Configuration
@Slf4j
public class FeignHeadConfiguration {
......
package com.xxfc.platform.order.jobhandler;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.wxiaoqi.security.admin.entity.AppUserPosition;
import com.github.wxiaoqi.security.admin.feign.UserFeign;
import com.github.wxiaoqi.security.admin.vo.WalletPostionVo;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.order.biz.StaffStatisticsBiz;
import com.xxfc.platform.vehicle.feign.VehicleFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author libin
* @version 1.0
* @description 员工业绩统计job
* @data 2019/11/26 10:12
*/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class SaffStatisticsJobHandler extends IJobHandler {
private final StaffStatisticsBiz staffStatisticsBiz;
private final VehicleFeign vehicleFeign;
private final UserFeign userFeign;
@Override
public ReturnT<String> execute(String arg) throws Exception {
//1.查询公司
Map<Integer, String> companyMap = vehicleFeign.findCompanyMap();
Date date= null;
if (StringUtils.hasText(arg)){
date = DateUtil.parse(arg,"yyyy-MM-dd");
}else {
date = DateUtil.yesterday().toJdkDate();
}
Date startDate = DateUtil.beginOfDay(date).toJdkDate();
Date endDate = DateUtil.endOfDay(date).toJdkDate();
ObjectRestResponse<List<WalletPostionVo>> response = userFeign.findAllPostions();
Map<Integer, String> postionMap = response.getData().stream().collect(Collectors.toMap(WalletPostionVo::getId, WalletPostionVo::getName));
staffStatisticsBiz.staffStatisticsJob(startDate,endDate,companyMap,postionMap);
return ReturnT.SUCCESS;
}
}
......@@ -7,7 +7,7 @@ import com.xxfc.platform.order.pojo.dto.MemberOrderFindDTO;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.order.OrderListVo;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import org.springframework.data.repository.query.Param;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.Date;
......@@ -39,10 +39,12 @@ public interface BaseOrderMapper extends Mapper<BaseOrder> {
List<MemberOrderBo> findMemberOrders(MemberOrderFindDTO memberOrderFindDTO);
public List<BgOrderListVo> getAllOrderList(Map<String, Object> paramMap);
List<OrderDTO> selectOrdersByTypeAndTime(@Param("types") List<Integer> types,
@Param("hasPay") Integer hasPay,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate);
public List<BgOrderListVo> getAllOrderList(Map<String, Object> paramMap);
List<OrderDTO> selectBaeOrderByOrderIds(@Param("orderIds") List<Integer> orderIds);
}
package com.xxfc.platform.order.mapper;
import com.xxfc.platform.order.entity.OrderAccount;
import com.xxfc.platform.order.pojo.Term;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDTO;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import com.xxfc.platform.order.entity.OrderAccount;
import com.xxfc.platform.order.pojo.Term;
import com.xxfc.platform.order.pojo.account.OrderAccountBo;
import com.xxfc.platform.order.pojo.account.OrderAccountDTO;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
import java.util.Date;
import java.util.List;
/**
* 订单帐目
*
*
* @author zhoujw
* @email 18178966185@163.com
* @date 2019-09-09 15:51:16
......@@ -24,4 +25,8 @@ public interface OrderAccountMapper extends Mapper<OrderAccount> {
List<OrderAccountBo> selectOrderAccountByOrderTypeAndStartTimeAndEndTime(@Param("orderType") Integer orderType,
@Param("startTime") long startTime,
@Param("endTime") long endTime);
List<OrderAccountBo> selectByDateAndStatffIds(@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
@Param("staffUserIds") List<Integer> staffUserIds);
}
......@@ -24,6 +24,7 @@ import com.xxfc.platform.order.entity.*;
import com.xxfc.platform.order.mqhandler.RabbitProduct;
import com.xxfc.platform.order.pojo.account.OrderAccountDeduction;
import com.xxfc.platform.order.pojo.account.OrderAccountDetail;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.mq.OrderMQDTO;
import com.xxfc.platform.order.pojo.order.CancelOrderDTO;
import com.xxfc.platform.order.pojo.order.OrderAboutParamDTO;
......@@ -473,4 +474,12 @@ public class BaseOrderController extends CommonBaseController implements UserRes
return ObjectRestResponse.succ();
}
@RequestMapping(value = "/basebase/aaa", method = RequestMethod.GET)
@IgnoreClientToken
@IgnoreUserToken
public ObjectRestResponse<List<OrderDTO>> findOrdersByorderId(@RequestParam(value = "orderIds") String orderIds){
return ObjectRestResponse.succ();
//ObjectRestResponse.succ(baseOrderBiz.selectBaeOrderByOrderIds(orderIds));
}
}
package com.xxfc.platform.order.rest.background;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreClientToken;
import com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.order.biz.BaseOrderBiz;
import com.xxfc.platform.order.biz.rpc.OrderListBiz;
import com.xxfc.platform.order.pojo.dto.OrderDTO;
import com.xxfc.platform.order.pojo.order.OrderPageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -18,9 +19,18 @@ public class OrderListController {
@Autowired
OrderListBiz orderListBiz;
@Autowired
private BaseOrderBiz baseOrderBiz;
@GetMapping("/list")
public ObjectRestResponse<List<OrderPageVO>> getOrderList(@RequestParam("dateTime")Long dateTime, @RequestParam("type")Integer type, @RequestParam("status")Integer status) {
return orderListBiz.getOrderList(dateTime, type, status);
}
@GetMapping(value = "/basebase/findByOrderIds")
@IgnoreClientToken
@IgnoreUserToken
public ObjectRestResponse<List<OrderDTO>> findOrdersByorderId(@RequestParam(value = "orderIds") List<Integer> orderIds){
return ObjectRestResponse.succ(baseOrderBiz.selectBaeOrderByOrderIds(orderIds));
}
}
......@@ -116,14 +116,14 @@
<select id="listOrder" parameterType="Map" resultMap="orderListMap">
select b.*
<if test="type==1">
,i.detail as carArticlesJson
,i.detail as carArticlesJson
</if>
from base_order b
LEFT JOIN order_rent_vehicle_detail r on r.order_id = b.id
LEFT JOIN order_tour_detail t on t.order_id = b.id
LEFT JOIN order_member_detail m on m.order_id = b.id
<if test="type==1">
LEFT JOIN (select * from order_item where type = 104) i on b.id = i.order_id
LEFT JOIN (select * from order_item where type = 104) i on b.id = i.order_id
</if>
<where>
<if test="crtUser != null">
......@@ -329,12 +329,12 @@
select b.*
from base_order b
LEFT JOIN order_rent_vehicle_detail r on r.order_id = b.id
where b.type = 1 and b.status &gt;= 4
where b.type = 2 and b.status &gt;= 4
<if test="startTime != null and status == 1">
and r.start_time between #{startTime} and #{endTime}
</if>
<if test="startTime != null and status == 2">
and r.end_time between #{startTime} and #{endTime}
and r.start_time between #{startTime} and #{endTime}
</if>
</select>
......@@ -349,7 +349,7 @@
</select>
<select id="findMemberOrders" resultType="com.xxfc.platform.order.pojo.dto.MemberOrderBo">
select bo.*,omd.member_level AS `memberLevel` from (
select bo.*,omd.member_level AS `memberLevel` from (
SELECT
`id`,
`no` AS `orderNo`,
......@@ -403,19 +403,24 @@
</foreach>
</if>
) AS `bo`
INNER JOIN (select * from `order_member_detail` where 1=1
INNER JOIN (select * from `order_member_detail` where 1=1
<if test="level!=null">
and `member_level`=#{level}
and `member_level`=#{level}
</if>
) AS `omd` ON omd.order_id=bo.id
ORDER BY bo.`creatTime` DESC
</select>
<select id="selectOrdersByTypeAndTime" resultType="com.xxfc.platform.order.pojo.dto.OrderDTO">
select bo.*,omd.memberLevel,IFNULL(IFNULL(orvd.start_company_id,otd.start_company_id),`parent_user_company_id`) AS `companyId`,orvd.deposit,orvd.cost_detail_extend AS `costDetailExtend` from (select `id`,`type`,`status`,`order_amount` AS `orderAmount`, `real_amount`AS
select bo.id,bo.type,bo.status,bo.order_amount,bo.real_amount,bo.order_origin,bo.parent_user_id as `userId`,bo.parent_postion_id as `postionId`,
bo.has_pay,bo.pay_way,omd.memberLevel,IFNULL(IFNULL(orvd.start_company_id,otd.start_company_id),`parent_user_company_id`) AS `companyId`,orvd.deposit,orvd.cost_detail_extend AS `costDetailExtend` from (select `id`,`type`,`status`,`order_amount` AS `orderAmount`, `real_amount`AS
`realAmount`,`order_origin` AS `orderOrigin`, `has_pay` AS `hasPay`,
`pay_way` AS `payWay`
from `base_order` where (`crt_time` between #{startDate} and #{endDate} or `pay_time` between #{startDate} and #{endDate} ) and `type` IN <foreach collection="types"
from `base_order` where 1=1
<if test="hasPay!=null">
and `has_pay`=#{hasPay}
</if>
and (`crt_time` between #{startDate} and #{endDate} or `pay_time` between #{startDate} and #{endDate} ) and `type` IN <foreach collection="types"
item="type"
open="(" close=")"
separator=",">
......@@ -427,4 +432,11 @@
LEFT JOIN (select `order_id`,`member_level` AS `memberLevel` from `order_member_detail`) AS `omd` ON
omd.order_id=bo.id;
</select>
<select id="selectBaeOrderByOrderIds" resultType="com.xxfc.platform.order.pojo.dto.OrderDTO">
select `id`,`parent_user_company_id` as `companyId` from `base_order` where id in
<foreach collection="orderIds" item="orderId" open="(" close=")" separator=",">
#{orderId}
</foreach>
</select>
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxfc.platform.order.mapper.OrderAccountMapper">
<select id="getOrderAccountByOrderType" parameterType="com.xxfc.platform.order.pojo.Term"
resultType="com.xxfc.platform.order.pojo.account.OrderAccountDTO">
<select id="getOrderAccountByOrderType" parameterType="com.xxfc.platform.order.pojo.Term" resultType="com.xxfc.platform.order.pojo.account.OrderAccountDTO">
SELECT
<if test="subdivide !=null and subdivide ==1">
date( FROM_UNIXTIME( a.crt_time / 1000 ) ) as oneDay,
......@@ -28,7 +27,7 @@
AND
b.type = #{orderType}
<if test="startTime != null">
AND a.crt_time <![CDATA[>= ]]> #{startTime}
AND a.crt_time <![CDATA[>= ]]> #{startTime}
</if>
<if test="endTime != null">
AND a.crt_time &gt; endTime
......@@ -62,7 +61,7 @@
bo.order_origin,
bo.pay_way,
bo.has_pay,
brvd.start_company_id AS `companyId`,
IFNULL(brvd.start_company_id,IFNULL(otd.start_company_id,bo.parent_user_company_id)) AS `companyId`,
brvd.cost_detail_extend AS `costDetailExtend`,
brvd.damage_safe AS `damageSafe`,
omd.member_level AS `memberLevel`
......@@ -71,7 +70,38 @@
`order_account` AS `oa`
LEFT JOIN `base_order` AS `bo` ON bo.id = oa.order_id
LEFT JOIN `order_rent_vehicle_detail` AS `brvd` ON brvd.order_id=oa.order_id
LEFT JOIN `order_tour_detail` as `otd` ON otd.order_id=oa.order_id
LEFT JOIN `order_member_detail` AS `omd` ON omd.order_id=oa.order_id
WHERE bo.type=#{orderType} AND `oa`.account_status=1 AND oa.`crt_time` BETWEEN #{startTime} AND #{endTime}
</select>
<select id="selectByDateAndStatffIds" resultType="com.xxfc.platform.order.pojo.account.OrderAccountBo">
oa.*,
bo.id,
bo.`status`,
bo.order_origin,
bo.pay_way,
bo.has_pay,
bo.parent_user_id as `userId`,
bo.parent_position_id as `postionId`,
IFNULL(brvd.start_company_id,IFNULL(otd.start_company_id,bo.parent_user_company_id)) AS `companyId`,
brvd.cost_detail_extend AS `costDetailExtend`,
brvd.damage_safe AS `damageSafe`,
omd.member_level AS `memberLevel`
FROM
`order_account` AS `oa`
LEFT JOIN `base_order` AS `bo` ON bo.id = oa.order_id
LEFT JOIN `order_rent_vehicle_detail` AS `brvd` ON brvd.order_id=oa.order_id
LEFT JOIN `order_tour_detail` as `otd` ON otd.order_id=oa.order_id
LEFT JOIN `order_member_detail` AS `omd` ON omd.order_id=oa.order_id
WHERE `oa`.account_status=1
AND oa.`crt_time` BETWEEN #{startDate} AND #{endDate}
<if test="staffUserIds!=null and staffUserIds.size>0">
and bo.id IN <foreach collection="staffUserIds" item="staffId" open="(" close=")" separator=",">
#{staffId}
</foreach>
</if>
</select>
</mapper>
\ No newline at end of file
......@@ -2,7 +2,9 @@ import com.xxfc.platform.order.OrderApplication;
import com.xxfc.platform.order.biz.DailyOrderStatisticsBiz;
import com.xxfc.platform.order.biz.OrderStatisticsBiz;
import com.xxfc.platform.order.jobhandler.BaseOrderStatisticsJobHandler;
import com.xxfc.platform.order.jobhandler.SaffStatisticsJobHandler;
import com.xxfc.platform.order.pojo.HomePageOrderData;
import lombok.SneakyThrows;
import org.joda.time.DateTime;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -33,6 +35,9 @@ public class ServiceTest {
@Autowired
private BaseOrderStatisticsJobHandler handler;
@Autowired
private SaffStatisticsJobHandler statisticsJobHandler;
@Test
public void testSchedu(){
......@@ -77,5 +82,10 @@ public class ServiceTest {
handler.execute("2019-09-29");
}
@Test
@SneakyThrows
public void testStaffStatisticsJob(){
statisticsJobHandler.execute("");
}
}
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