| @@ -1,9 +1,13 @@ | |||||
| package com.iformall.controller.datatower; | package com.iformall.controller.datatower; | ||||
| import com.iformall.annotation.SystemControllerLog; | import com.iformall.annotation.SystemControllerLog; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.controller.base.BaseController; | import com.iformall.controller.base.BaseController; | ||||
| import com.iformall.domain.dto.WxCUserBasicInfoDto; | |||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.enums.EnumAppPlat; | |||||
| import com.iformall.enums.EnumChartType; | |||||
| import com.iformall.service.WxChartDataService; | import com.iformall.service.WxChartDataService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -15,6 +19,8 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.util.Calendar; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @Api(description = "图表") | @Api(description = "图表") | ||||
| @@ -79,4 +85,28 @@ public class WxChartDataController extends BaseController { | |||||
| return data; | return data; | ||||
| } | } | ||||
| @GetMapping("queryWeekCount") | |||||
| @ApiOperation("查询用户增长 总数,今日,近一周") | |||||
| @SystemControllerLog(description = "会员首页-报表数据-查询用户增长") | |||||
| public ResultData queryWeekCount(Integer chartType) { | |||||
| logger.info("[" + getIpAddr() + "] WxChartDataController::queryWeekCount chartType: " + chartType); | |||||
| EnumChartType enumChartType = EnumChartType.getEnum(chartType); | |||||
| if(enumChartType == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"url不能为空"); | |||||
| } | |||||
| return wxChartDataService.queryWeekCount(enumChartType,getTenantInfo()); | |||||
| } | |||||
| @GetMapping("queryMonthVos") | |||||
| @ApiOperation("查询用户增长 总数,今日,近一周") | |||||
| @SystemControllerLog(description = "会员首页-报表数据-查询用户增长") | |||||
| public ResultData queryMonthVos(Integer chartType) { | |||||
| logger.info("[" + getIpAddr() + "] WxChartDataController::queryMonthVos chartType: " + chartType); | |||||
| EnumChartType enumChartType = EnumChartType.getEnum(chartType); | |||||
| if(enumChartType == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"url不能为空"); | |||||
| } | |||||
| return wxChartDataService.queryMonthVos(enumChartType,getTenantInfo()); | |||||
| } | |||||
| } | } | ||||
| @@ -238,6 +238,8 @@ public class WxCUserBasicInfo extends TenantEntityWithoutFinalTenantId { | |||||
| } | } | ||||
| public void undateFinalTenantId(TenantEntity tenantEntity){ | public void undateFinalTenantId(TenantEntity tenantEntity){ | ||||
| setTenantId(tenantEntity.getTenantId()); | |||||
| setParentTenantId(tenantEntity.getParentTenantId()); | |||||
| setFinalTenantId(tenantEntity.getTenantId()); | setFinalTenantId(tenantEntity.getTenantId()); | ||||
| if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){ | if(StringUtils.isNotBlank(tenantEntity.getParentTenantId())){ | ||||
| setFinalTenantId(tenantEntity.getParentTenantId()); | setFinalTenantId(tenantEntity.getParentTenantId()); | ||||
| @@ -9,4 +9,7 @@ public interface WxChartDataMapper extends CommonMapper<WxChartDataEntity, Long> | |||||
| List<WxChartDataEntity> findList(WxChartDataEntity chartData); | List<WxChartDataEntity> findList(WxChartDataEntity chartData); | ||||
| Long findSumResult(WxChartDataEntity chartData); | |||||
| } | } | ||||
| @@ -1,11 +1,30 @@ | |||||
| package com.iformall.service; | package com.iformall.service; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxChartDataEntity; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.enums.EnumChartType; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| public interface WxChartDataService { | public interface WxChartDataService { | ||||
| /** | |||||
| * 获取昨日, | |||||
| * 近一周 | |||||
| * @param | |||||
| * @return | |||||
| */ | |||||
| ResultData queryWeekCount(EnumChartType chartType, TenantEntity tenantEntity); | |||||
| /** | |||||
| * 获取周统计, | |||||
| * 月统计 | |||||
| * @param | |||||
| * @return | |||||
| */ | |||||
| ResultData queryMonthVos(EnumChartType chartType, TenantEntity tenantEntity); | |||||
| ResultData queryData(Map<String, String> params); | ResultData queryData(Map<String, String> params); | ||||
| } | } | ||||
| @@ -38,8 +38,102 @@ import java.util.stream.Collectors; | |||||
| @Service | @Service | ||||
| public class WxChartServiceImpl implements WxChartDataService { | public class WxChartServiceImpl implements WxChartDataService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | private final Logger logger = LoggerFactory.getLogger(this.getClass()); | ||||
| @Autowired | |||||
| WxChartDataMapper wxChartDataMapper; | |||||
| @Override | |||||
| public ResultData queryWeekCount(EnumChartType chartType, TenantEntity tenantEntity) { | |||||
| Date now = new Date(); | |||||
| String weekStartdate = DateUtils.getTimeBefore(7, now); | |||||
| String yesterdayDate = DateUtils.getTimeBefore(1, now); | |||||
| WxChartDataEntity ChartDataEntity = new WxChartDataEntity(); | |||||
| ChartDataEntity.updateTenantInfo(tenantEntity); | |||||
| ChartDataEntity.setType(chartType.getCode()); | |||||
| ChartDataEntity.setStartTime(DateUtils.stringToDate(yesterdayDate)); | |||||
| Long yesterdayCount = wxChartDataMapper.findSumResult(ChartDataEntity); | |||||
| ChartDataEntity.setStartTime(DateUtils.stringToDate(weekStartdate)); | |||||
| Long weekCount = wxChartDataMapper.findSumResult(ChartDataEntity); | |||||
| Map<String, Long> map = new HashMap<>(); | |||||
| map.put("yesterdayCount", yesterdayCount); | |||||
| map.put("weekCount", weekCount); | |||||
| return new ResultData(map); | |||||
| } | |||||
| @Override | |||||
| public ResultData queryMonthVos(EnumChartType chartType, TenantEntity tenantEntity) { | |||||
| Date now = new Date(); | |||||
| String monthStartdate = DateUtils.getTimeBefore(30, now); | |||||
| String yesyeweekDate = DateUtils.getTimeBefore(8, now);//计算周同比时间 | |||||
| String weekStartdate = DateUtils.getTimeBefore(7, now); | |||||
| String yesyesDate = DateUtils.getTimeBefore(2, now);//计算日同比时间 | |||||
| String yesterdayDate = DateUtils.getTimeBefore(1, now); | |||||
| List<String> tjTimeList = DateUtils.getTjTimeList(monthStartdate, yesterdayDate, "0"); | |||||
| WxChartDataEntity ChartDataEntity = new WxChartDataEntity(); | |||||
| ChartDataEntity.updateTenantInfo(tenantEntity); | |||||
| ChartDataEntity.setType(chartType.getCode()); | |||||
| ChartDataEntity.setStartTime(DateUtils.stringToDate(monthStartdate)); | |||||
| ChartDataEntity.setEndTime(DateUtils.stringToDate(yesterdayDate)); | |||||
| List<WxChartDataEntity> list = wxChartDataMapper.findList(ChartDataEntity); | |||||
| Map<String, String> collect = list.stream().collect(Collectors.toMap(m -> { | |||||
| return new SimpleDateFormat("yyyy-MM-dd").format(m.getQuerytime()); | |||||
| }, m -> { | |||||
| return m.getResult(); | |||||
| })); | |||||
| List<UserStructureVo> weekVos = new ArrayList<>(); | |||||
| List<UserStructureVo> monthVos = new ArrayList<>(); | |||||
| long yesterdayCount = 0l,yesyesCount = 0l,yesWeekCount = 0l; | |||||
| for (String date : tjTimeList) { | |||||
| UserStructureVo vo = new UserStructureVo(); | |||||
| vo.setName(date.substring(5).replace("-", "/")); | |||||
| String result = collect.get(date); | |||||
| if(StringUtils.isBlank(result)){ | |||||
| vo.setCount(0l); | |||||
| }else{ | |||||
| vo.setCount(Long.parseLong(result)); | |||||
| } | |||||
| if(weekStartdate.equals(date) || (DateUtils.stringToDate(weekStartdate).before(DateUtils.stringToDate(date)))){ | |||||
| weekVos.add(vo); | |||||
| } | |||||
| if(yesterdayDate.equals(date)){//昨日 | |||||
| yesterdayCount = vo.getCount(); | |||||
| } | |||||
| if(yesyesDate.equals(date)){//昨日的昨日(计算日环比) | |||||
| yesyesCount = vo.getCount(); | |||||
| } | |||||
| if(yesyeweekDate.equals(date)){//一周前的昨日(计算周同比) | |||||
| yesWeekCount = vo.getCount(); | |||||
| } | |||||
| monthVos.add(vo); | |||||
| } | |||||
| NumberFormat nf = NumberFormat.getPercentInstance(); | |||||
| nf.setMinimumFractionDigits(2); | |||||
| String dayPercentage = "--"; | |||||
| if (yesyesCount > 0) { | |||||
| Long count = yesterdayCount - yesyesCount; | |||||
| dayPercentage = nf.format(count.doubleValue() / new Double(yesyesCount).doubleValue()); | |||||
| } | |||||
| String weekPercentage = "--"; | |||||
| if (yesWeekCount > 0) { | |||||
| Long count = yesterdayCount - yesWeekCount; | |||||
| weekPercentage = nf.format(count.doubleValue() / new Double(yesWeekCount).doubleValue()); | |||||
| } | |||||
| Map<String, Object> map = new HashMap<>(); | |||||
| map.put("weekVos", weekVos); | |||||
| map.put("monthVos", monthVos); | |||||
| map.put("dayPercentage", dayPercentage);//日环比 | |||||
| map.put("weekPercentage", weekPercentage);//周同比 | |||||
| return new ResultData(map); | |||||
| } | |||||
| @Autowired | @Autowired | ||||
| private WxMallService wxMallService; | private WxMallService wxMallService; | ||||
| @Autowired | @Autowired | ||||
| @@ -93,8 +187,7 @@ public class WxChartServiceImpl implements WxChartDataService { | |||||
| WxBillOtherMapper wxBillOtherMapper; | WxBillOtherMapper wxBillOtherMapper; | ||||
| @Autowired | @Autowired | ||||
| WxBillAllMapper wxBillAllMapper; | WxBillAllMapper wxBillAllMapper; | ||||
| @Autowired | |||||
| WxChartDataMapper wxChartDataMapper; | |||||
| @Lazy | @Lazy | ||||
| @Autowired | @Autowired | ||||
| @@ -132,7 +225,8 @@ public class WxChartServiceImpl implements WxChartDataService { | |||||
| @Autowired | @Autowired | ||||
| private WxShopService wxShopService; | private WxShopService wxShopService; | ||||
| @Override | @Override | ||||
| public ResultData queryData(Map<String, String> paramsMap) { | public ResultData queryData(Map<String, String> paramsMap) { | ||||
| String tenantId = paramsMap.get("tenantId"); | String tenantId = paramsMap.get("tenantId"); | ||||
| @@ -33,6 +33,10 @@ | |||||
| and `type` = #{type} | and `type` = #{type} | ||||
| </if> | </if> | ||||
| <if test=" null != querytime "> | |||||
| and `querytime` = #{querytime} | |||||
| </if> | |||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and `querytime` >= #{startTime} | and `querytime` >= #{startTime} | ||||
| </if> | </if> | ||||
| @@ -51,4 +55,10 @@ | |||||
| <include refid="dynamicWhereConditions"/> | <include refid="dynamicWhereConditions"/> | ||||
| </select> | </select> | ||||
| <select id="findSumResult" parameterType="com.iformall.domain.po.WxChartDataEntity" resultType="long"> | |||||
| select IFNULL(sum(result),0) | |||||
| from wx_chart_data | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||