diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataSchedule.java index 979fec007..405f4d8c6 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataSchedule.java @@ -235,7 +235,6 @@ public class ChartDataSchedule { * 销售总交易额 */ public void createSaleData() { - HashMap params = new HashMap<>(); Date createtime = new Date(); String yesterday = DateUtils.getTimeBefore(1, createtime); String today = DateUtils.getSystemTime("yyyy-MM-dd"); @@ -248,10 +247,6 @@ public class ChartDataSchedule { List wxMalls = wxMallMapper.findList(null); for (WxMall wxMall : wxMalls) { TenantEntity tenantEntity = wxMall.getTenantInfo(); - params.put("tenantId", tenantEntity.getTenantId()); - if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { - params.put("parentTenantId", tenantEntity.getParentTenantId()); - } wxChartDataEntity.updateTenantInfo(tenantEntity); wxChartDataEntity.setType(EnumChartType.SALE_COUPON_PRICE.getCode()); int count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); @@ -271,7 +266,6 @@ public class ChartDataSchedule { * 解单金额 */ public void createMerchantTradeData() { - HashMap params = new HashMap<>(); Date createtime = new Date(); String yesterday = DateUtils.getTimeBefore(1, createtime); Date querytime = DateUtils.stringToDate(yesterday); @@ -282,10 +276,6 @@ public class ChartDataSchedule { List wxMalls = wxMallMapper.findList(null); for (WxMall wxMall : wxMalls) { TenantEntity tenantEntity = wxMall.getTenantInfo(); - params.put("tenantId", tenantEntity.getTenantId()); - if (StringUtils.isNotBlank(tenantEntity.getParentTenantId())) { - params.put("parentTenantId", tenantEntity.getParentTenantId()); - } wxChartDataEntity.updateTenantInfo(tenantEntity); wxChartDataEntity.setType(EnumChartType.MERCHANT_TRADE.getCode()); diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataScheduleTest.java b/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataScheduleTest.java new file mode 100644 index 000000000..c694889ed --- /dev/null +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/ChartDataScheduleTest.java @@ -0,0 +1,331 @@ +package com.iformall.schedule; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.iformall.common.IdWorker; +import com.iformall.domain.dto.WxCUserBasicInfoDto; +import com.iformall.domain.po.WxChartDataEntity; +import com.iformall.domain.po.WxCouponOrder; +import com.iformall.domain.po.WxMall; +import com.iformall.domain.po.WxMerchantTradeDaily; +import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumAppPlat; +import com.iformall.enums.EnumCarCmd; +import com.iformall.enums.EnumChartType; +import com.iformall.mapper.WxCUserCarMapper; +import com.iformall.mapper.WxChartDataMapper; +import com.iformall.mapper.WxMallMapper; +import com.iformall.service.*; +import com.iformall.service.cuser.CUserServiceFactory; +import com.iformall.utils.DateUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.HashMap; +import java.util.List; + +/** + * @author gongbiao + */ +@Component +public class ChartDataScheduleTest { + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Autowired + WxCarCmdLogService wxCarCmdLogService; + + @Autowired + WxMallMapper wxMallMapper; + + @Autowired + WxCUserCarMapper wxCUserCarMapper; + + @Autowired + WxChartDataMapper wxChartDataMapper; + + @Autowired + WxCouponOrderService wxCouponOrderService; + + @Autowired + WxMerchantTradeDailyService wxMerchantTradeDailyService; + + @Autowired + WxCUserCarService wxCUserCarService; + + @Autowired + private WxCUserBasicInfoService wxCUserBasicInfoService; + + @Autowired + private CUserServiceFactory cuserFactory; + + @Async + @Scheduled(cron = "0 0 11 10 3 ?") + public void testCreateData() { + createUserData(); + createCarData(); + createSaleData(); + createMerchantTradeData(); + } + + + /** + * 微信新增用户、抖音新增用户、ali新增用户,新增会员 + */ + public void createUserData() { + Date createtime = new Date(); + for (int i = 30;i > 0; i++){ + String yesterday = DateUtils.getTimeBefore(i, createtime); + Date date = DateUtils.stringToDate(yesterday); + String today = DateUtils.getTimeBefore(i-1, createtime); + Date endDate = DateUtils.stringToDate(today); + + logger.info("createUserData--date{}"+yesterday+"----- endDate{}"+today); + + WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); + wxChartDataEntity.setQuerytime(date); + WxCUserBasicInfoDto dto = new WxCUserBasicInfoDto(); + dto.setEndTime(endDate); + + List wxMalls = wxMallMapper.findList(null); + for (WxMall wxMall : wxMalls) { + TenantEntity tenantEntity = wxMall.getTenantInfo(); + dto.updateTenantInfo(tenantEntity); + wxChartDataEntity.updateTenantInfo(tenantEntity); + wxChartDataEntity.setType(EnumChartType.WX_USER.getCode()); + int count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("微信用户总数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long wxUserCount = cuserFactory.getCUserService(EnumAppPlat.WX).findCount(dto); + addChartData(tenantEntity, String.valueOf(wxUserCount), EnumChartType.WX_USER.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.TT_USER.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("抖音用户总数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long ttUserCount = cuserFactory.getCUserService(EnumAppPlat.TOUTIAO).findCount(dto); + addChartData(tenantEntity, String.valueOf(ttUserCount), EnumChartType.TT_USER.getCode(), date, createtime); + } +// wxChartDataEntity.setType(EnumChartType.ALI_USER.getCode()); +// count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); +// if (count == 0) { +// logger.info("支付宝用户总数>>>>>>>>>>>>>>>>>>>>>>>>>>"); +// } + wxChartDataEntity.setType(EnumChartType.BASIC_USER.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("会员总数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long basicUserCount = wxCUserBasicInfoService.findCount(dto); + addChartData(tenantEntity, String.valueOf(basicUserCount), EnumChartType.BASIC_USER.getCode(), date, createtime); + } + dto.setStartTime(date); + wxChartDataEntity.setType(EnumChartType.WX_USER_ADD.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("微信用户增加数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long wxUserCount = cuserFactory.getCUserService(EnumAppPlat.WX).findCount(dto); + addChartData(tenantEntity, String.valueOf(wxUserCount), EnumChartType.WX_USER_ADD.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.TT_USER_ADD.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("抖音用户增加数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long ttUserCount = cuserFactory.getCUserService(EnumAppPlat.TOUTIAO).findCount(dto); + addChartData(tenantEntity, String.valueOf(ttUserCount), EnumChartType.TT_USER_ADD.getCode(), date, createtime); + } +// wxChartDataEntity.setType(EnumChartType.ALI_USER_ADD.getCode()); +// count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); +// if (count == 0) { +// logger.info("支付宝用户增加数>>>>>>>>>>>>>>>>>>>>>>>>>>"); +// } + wxChartDataEntity.setType(EnumChartType.BASIC_USER_ADD.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("会员增加数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + long basicUserCount = wxCUserBasicInfoService.findCount(dto); + addChartData(tenantEntity, String.valueOf(basicUserCount), EnumChartType.BASIC_USER_ADD.getCode(), date, createtime); + } + + } + } + + } + + /** + * 出场车辆、缴费车辆、缴费金额、新增会员、新增停车会员、已绑车辆 + */ + public void createCarData() { + Date createtime = new Date(); + for (int i = 30;i > 0; i++) { + String yesterday = DateUtils.getTimeBefore(i, createtime); + Date date = DateUtils.stringToDate(yesterday); + String today = DateUtils.getTimeBefore(i - 1, createtime); + Date endDate = DateUtils.stringToDate(today); + + logger.info("createCarData--date{}" + yesterday + "----- endDate{}" + today); + + HashMap params = new HashMap<>(); + params.put("startdate", yesterday + " 00:00:00"); + params.put("enddate", today + " 00:00:00"); + + WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); + wxChartDataEntity.setQuerytime(date); + + List wxMalls = wxMallMapper.findList(null); + for (WxMall wxMall : wxMalls) { + TenantEntity tenantEntity = wxMall.getTenantInfo(); + params.put("tenantId", tenantEntity.getTenantId()); + params.put("parentTenantId", tenantEntity.getParentTenantId()); + wxChartDataEntity.updateTenantInfo(tenantEntity); + wxChartDataEntity.setType(EnumChartType.CAR_IN.getCode()); + int count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("入场车数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + params.put("cmdTypes",EnumCarCmd.getCarIn()); + Long carOutCount = wxCarCmdLogService.queryHistoryCount(params); + addChartData(tenantEntity, carOutCount.toString(), EnumChartType.CAR_IN.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.CAR_OUT.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("出场车数>>>>>>>>>>>>>>>>>>>>>>>>>>"); + params.put("cmdTypes",EnumCarCmd.getCarOut()); + Long carOutCount = wxCarCmdLogService.queryHistoryCount(params); + addChartData(tenantEntity, carOutCount.toString(), EnumChartType.CAR_OUT.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.CAR_PAID.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("缴费车辆>>>>>>>>>>>>>>>>>>>>>>>>>>"); + params.put("cmdTypes", EnumCarCmd.getCarPay()); + Long carPayFeeCount = wxCarCmdLogService.queryHistoryCount(params); + addChartData(tenantEntity, carPayFeeCount.toString(), EnumChartType.CAR_PAID.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.CAR_PAY_FEE.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("缴费金额>>>>>>>>>>>>>>>>>>>>>>>>>>"); + params.put("cmdTypes", EnumCarCmd.getCarPay()); + BigDecimal fee = wxCarCmdLogService.queryCarPay(params); + addChartData(tenantEntity, fee.toString(), EnumChartType.CAR_PAY_FEE.getCode(), date, createtime); + } +// wxChartDataEntity.setType(EnumChartType.CAR_MEMBER.getCode()); +// count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); +// if (count == 0) { +// logger.info("新增会员>>>>>>>>>>>>>>>>>>>>>>>>>>"); +// carMemberData(params, createtime, date, tenantEntity); +// } + wxChartDataEntity.setType(EnumChartType.CAR_NEW_MEMBER.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("新增停车会员>>>>>>>>>>>>>>>>>>>>>>>>>>"); + WxCUserBasicInfoDto wxCUserBasicInfoDto = new WxCUserBasicInfoDto(); + wxCUserBasicInfoDto.updateTenantInfo(tenantEntity); + wxCUserBasicInfoDto.setStartTime(date); + wxCUserBasicInfoDto.setEndTime(endDate); + Integer carUserCount = wxCUserCarService.countUser(wxCUserBasicInfoDto); + addChartData(tenantEntity, carUserCount.toString(), EnumChartType.CAR_NEW_MEMBER.getCode(), date, createtime); + } + wxChartDataEntity.setType(EnumChartType.CAR_BIND.getCode()); + count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("已绑车辆>>>>>>>>>>>>>>>>>>>>>>>>>>"); + Long todaybindcar = wxCUserCarService.queryCarCount(params); + addChartData(tenantEntity, todaybindcar.toString(), EnumChartType.CAR_BIND.getCode(), date, createtime); + } + } + } + + } + + /** + * 销售总交易额 + */ + public void createSaleData() { + Date createtime = new Date(); + for (int i = 30;i > 0; i++) { + String yesterday = DateUtils.getTimeBefore(i, createtime); + Date date = DateUtils.stringToDate(yesterday); + String today = DateUtils.getTimeBefore(i - 1, createtime); + Date endDate = DateUtils.stringToDate(today); + + logger.info("createSaleData--date{}" + yesterday + "----- endDate{}" + today); + + WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); + wxChartDataEntity.setQuerytime(date); + List wxMalls = wxMallMapper.findList(null); + for (WxMall wxMall : wxMalls) { + TenantEntity tenantEntity = wxMall.getTenantInfo(); + wxChartDataEntity.updateTenantInfo(tenantEntity); + wxChartDataEntity.setType(EnumChartType.SALE_COUPON_PRICE.getCode()); + int count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("销售总交易额>>>>>>>>>>>>>>>>>>>>>>>>>>"); + WxCouponOrder wxCouponOrder = new WxCouponOrder(); + wxCouponOrder.updateTenantInfo(tenantEntity); + wxCouponOrder.setStartTime(date); + wxCouponOrder.setEndTime(endDate); + Integer price = wxCouponOrderService.queryPriceTotal(wxCouponOrder); + addChartData(tenantEntity, price.toString(), EnumChartType.SALE_COUPON_PRICE.getCode(), date, createtime); + } + } + } + + } + + /** + * 解单金额 + */ + public void createMerchantTradeData() { + Date createtime = new Date(); + for (int i = 30;i > 0; i++) { + String yesterday = DateUtils.getTimeBefore(i, createtime); + Date date = DateUtils.stringToDate(yesterday); + String today = DateUtils.getTimeBefore(i - 1, createtime); + Date endDate = DateUtils.stringToDate(today); + + logger.info("createSaleData--date{}" + yesterday + "----- endDate{}" + today); + WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); + wxChartDataEntity.setQuerytime(date); + List wxMalls = wxMallMapper.findList(null); + for (WxMall wxMall : wxMalls) { + TenantEntity tenantEntity = wxMall.getTenantInfo(); + + wxChartDataEntity.updateTenantInfo(tenantEntity); + wxChartDataEntity.setType(EnumChartType.MERCHANT_TRADE.getCode()); + int count = wxChartDataMapper.selectCount(new QueryWrapper(wxChartDataEntity)); + if (count == 0) { + logger.info("解单金额>>>>>>>>>>>>>>>>>>>>>>>>>>"); + WxMerchantTradeDaily wxMerchantTradeDaily = new WxMerchantTradeDaily(); + wxMerchantTradeDaily.updateTenantInfo(tenantEntity); + wxMerchantTradeDaily.setReportDate(yesterday); + Integer price = wxMerchantTradeDailyService.findSumMoney(wxMerchantTradeDaily); + addChartData(tenantEntity, price.toString(), EnumChartType.MERCHANT_TRADE.getCode(), date, createtime); + } + } + } + + } + + private void addChartData(TenantEntity tenantEntity, String result, Integer type, Date querytime, Date createtime) { + logger.info("即将插入数据>>>>>>>>>>>>>>>>>>>>>>>"); + final IdWorker idWorker = IdWorker.get(); + long id = idWorker.nextId(); + WxChartDataEntity wxChartDataEntity = new WxChartDataEntity(); + wxChartDataEntity.setId(id); + wxChartDataEntity.updateTenantInfo(tenantEntity); + wxChartDataEntity.setResult(result); + wxChartDataEntity.setType(type); + wxChartDataEntity.setQuerytime(querytime); + wxChartDataEntity.setCreatetime(createtime); + logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>" + wxChartDataEntity.toString()); + wxChartDataMapper.insert(wxChartDataEntity); + } + +} \ No newline at end of file