package com.doumee.service.business.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.config.rocketmq5.NormalMsgProducer; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; import com.doumee.dao.business.*; import com.doumee.dao.business.model.*; import com.doumee.dao.system.SystemUserMapper; import com.doumee.dao.system.dto.CountDataDTO; import com.doumee.dao.system.model.SystemUser; import com.doumee.dao.system.vo.BusinessDataCountVO; import com.doumee.dao.system.vo.CountDataVO; import com.doumee.dao.web.dto.CollectDTO; import com.doumee.dao.web.dto.MemberDTO; import com.doumee.dao.web.dto.MultiFileDTO; import com.doumee.dao.web.dto.OrgDTO; import com.doumee.dao.web.dto.activity.*; import com.doumee.dao.web.dto.shop.ShopSimpleDTO; import com.doumee.dao.web.request.ActivityPageListRequest; import com.doumee.service.business.*; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.checkerframework.checker.units.qual.C; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; import java.util.stream.Collectors; /** * 活动、资讯、探店信息表Service实现 * * @author 江蹄蹄 * @date 2023/03/21 15:48 */ @Service public class WorkbenchServiceImpl implements WorkbenchService { @Autowired private GoodsorderMapper goodsorderMapper; @Autowired private GoodsorderDetailMapper goodsorderDetailMapper; @Override public BusinessDataCountVO businessData(CountDataDTO param) { BusinessDataCountVO data = new BusinessDataCountVO(); int dataType = param.getDateType();//0今日 1近七日 2近30日 3近1年 String name = "HOUR(CREATE_DATE)"; List dateList = new ArrayList<>(); Date date = Utils.Date.getEnd(new Date());//今日 23:59:59 Date startDate = DateUtil.addDaysToDate(date,-1); switch (dataType) { case 1: { name = "DATE_FORMAT(t.CREATE_DATE, '%Y-%m-%d')"; for(int i=1;i<=7;i++){ dateList.add(DateUtil.getPlusTime2(DateUtil.addDaysToDate(date,7-i))); } startDate = DateUtil.addDaysToDate(date,7); break; } case 2: { name = "DATE_FORMAT(GoodsCREATE_DATE, '%Y-%m-%d')"; for(int i=1;i<=30;i++){ dateList.add(DateUtil.getPlusTime2(DateUtil.addDaysToDate(date,30-i))); } startDate = DateUtil.addDaysToDate(date,30); break; } case 3: { startDate = DateUtil.increaseMonth(date,-12); name = "DATE_FORMAT(GoodsCREATE_DATE, '%Y-%m')"; for(int i=1;i<=12;i++){ dateList.add(DateUtil.getPlusTime2(DateUtil.increaseMonth(date,12-i))); } break; } default:{ for(int i=0;i<=23;i++){ dateList.add(i+""); } break; } } //订单销量 CountDataVO r = goodsorderMapper.selectJoinOne(CountDataVO.class,new MPJLambdaWrapper() .select("(select count(t.id) )",CountDataVO::getNum) .select("(select sum(t.totalPrice) )",CountDataVO::getPrice) .ge(Goodsorder::getCreateDate,startDate) .eq(Goodsorder::getIsdeleted,Constants.ZERO) .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey()) ); if (r != null) { data.setNum(Constants.formatLongNum(r.getNum()));//订单量 data.setPrice(Constants.formatBigdecimal(r.getPrice()));//订单金额 } //退款统计 CountDataVO r1 = goodsorderMapper.selectJoinOne(CountDataVO.class,new MPJLambdaWrapper() .select("(select count(t.id) )",CountDataVO::getNum) .select("(select sum(t.reundMoney) )",CountDataVO::getPrice) .ge(Goodsorder::getRefundTime,startDate) .eq(Goodsorder::getIsdeleted,Constants.ZERO) .in(Goodsorder::getStatus,Constants.OrderStatus.REFUND.getKey()) ); if (r1 != null) { data.setNum1(Constants.formatLongNum(r1.getNum()));//退款单量 data.setPrice1(Constants.formatBigdecimal(r1.getPrice()));//退款金额 } //统计订单销量和销售额集合 List list1 = goodsorderMapper.selectJoinList(CountDataVO.class,new MPJLambdaWrapper() .select("(select "+name+")",CountDataVO::getDateStr) .select("(select count(t.id) )",CountDataVO::getNum) .select("(select sum(t.totalPrice) )",CountDataVO::getPrice) .ge(Goodsorder::getRefundTime,startDate) .eq(Goodsorder::getIsdeleted,Constants.ZERO) .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey()) .groupBy(name) ); List datalist1 = new ArrayList<>(); for(String str : dateList){ CountDataVO tmp = new CountDataVO(); tmp.setDateStr(str); tmp.setNum(0l); tmp.setPrice(new BigDecimal(0)); if(list1!=null){ for(CountDataVO p : list1){ if(StringUtils.equals(p.getDateStr(),str)){ tmp.setNum(Constants.formatLongNum(p.getNum())); tmp.setPrice(Constants.formatBigdecimal(p.getPrice())); } } } datalist1.add(tmp); } data.setDataList(datalist1 ); //统计各类商品数据集合 List list2 = goodsorderDetailMapper.selectJoinList(CountDataVO.class,new MPJLambdaWrapper() .select("(select "+name+")",CountDataVO::getDateStr) .selectAs(Labels::getName,CountDataVO::getName) .select("(select sum(t.totalPrice) )",CountDataVO::getPrice) .leftJoin(Goods.class,Goods::getId,GoodsorderDetail::getGoodsId) .leftJoin(Labels.class,Labels::getId,Goods::getCategoryId) .leftJoin(Goodsorder.class,Goodsorder::getId,GoodsorderDetail::getOrderId) .ge(Goodsorder::getRefundTime,startDate) .eq(Goodsorder::getIsdeleted,Constants.ZERO) .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey()) .groupBy(name +",t2.category_id")); List datalist2 = new ArrayList<>(); List cateList = getCateListFromDataList(list2); if(list2!=null &&list2.size()>0 && cateList!=null && cateList.size()>0){ BigDecimal[] temp = new BigDecimal[dateList.size()]; for(String cate : cateList){ for(int i=0;i getCateListFromDataList(List list2) { List list = new ArrayList<>(); for(CountDataVO model :list2){ boolean isnew = true; for(String str :list){ if(StringUtils.equals(str,model.getName())){ isnew = false; } } if(isnew ){ list.add(model.getName()); } } return list; } }