| @@ -21,9 +21,16 @@ public class MarkingDataReportController extends BaseController { | |||
| @Autowired | |||
| private MarkingDataReportService markingDataReportService; | |||
| @ApiOperation("根据id查询接口") | |||
| @ApiOperation("查询券数据") | |||
| @GetMapping("/couponData") | |||
| public ResultData findCouponData() { | |||
| return new ResultData(markingDataReportService.getCouponDate(getTenantId())); | |||
| } | |||
| @ApiOperation("查询场景投放券数据") | |||
| @GetMapping("/sceneData") | |||
| public ResultData findSceneData() { | |||
| return new ResultData(markingDataReportService.getSceneData(getTenantId())); | |||
| } | |||
| } | |||
| @@ -0,0 +1,62 @@ | |||
| package com.simple.domain.vo; | |||
| /** | |||
| * Created by syf on 2018/8/29. | |||
| */ | |||
| public class MarkingSceneDataReportVo { | |||
| private String xTime; | |||
| private int parkSendCount; | |||
| private int verifySendCount; | |||
| private int parkCount; | |||
| private int verifyCount; | |||
| private int tempCount; | |||
| public int getTempCount() { | |||
| return tempCount; | |||
| } | |||
| public void setTempCount(int tempCount) { | |||
| this.tempCount = tempCount; | |||
| } | |||
| public String getxTime() { | |||
| return xTime; | |||
| } | |||
| public void setxTime(String xTime) { | |||
| this.xTime = xTime; | |||
| } | |||
| public int getParkSendCount() { | |||
| return parkSendCount; | |||
| } | |||
| public void setParkSendCount(int parkSendCount) { | |||
| this.parkSendCount = parkSendCount; | |||
| } | |||
| public int getVerifySendCount() { | |||
| return verifySendCount; | |||
| } | |||
| public void setVerifySendCount(int verifySendCount) { | |||
| this.verifySendCount = verifySendCount; | |||
| } | |||
| public int getParkCount() { | |||
| return parkCount; | |||
| } | |||
| public void setParkCount(int parkCount) { | |||
| this.parkCount = parkCount; | |||
| } | |||
| public int getVerifyCount() { | |||
| return verifyCount; | |||
| } | |||
| public void setVerifyCount(int verifyCount) { | |||
| this.verifyCount = verifyCount; | |||
| } | |||
| } | |||
| @@ -2,12 +2,24 @@ package com.simple.mapper; | |||
| import java.util.*; | |||
| import com.simple.common.CommonMapper; | |||
| import com.simple.domain.vo.MarkingSceneDataReportVo; | |||
| import org.apache.ibatis.annotations.Param; | |||
| import com.simple.domain.po.WxCouponActionLog; | |||
| public interface WxCouponActionLogMapper extends CommonMapper<WxCouponActionLog, String> { | |||
| List<WxCouponActionLog> findList(WxCouponActionLog wxCouponActionLog); | |||
| /** | |||
| * 查询场景投放发券数 | |||
| * @param tenantId | |||
| * @param startTime | |||
| * @param endTime | |||
| * @return | |||
| */ | |||
| int findCountByDateLimit(@Param("tenantId")String tenantId,@Param("startTime") Date startTime,@Param("endTime")Date endTime); | |||
| List<MarkingSceneDataReportVo> sceneDataMap(HashMap<String,Object> params); | |||
| List<MarkingSceneDataReportVo> sceneDataMapJoinCouponOrder(HashMap<String,Object> params); | |||
| @@ -7,4 +7,6 @@ import java.util.Map; | |||
| */ | |||
| public interface MarkingDataReportService { | |||
| Map<String,Object> getCouponDate(String tenantId); | |||
| Map<String,Object> getSceneData(String tenantId); | |||
| } | |||
| @@ -1,6 +1,8 @@ | |||
| package com.simple.service.impl; | |||
| import com.simple.domain.vo.MarkingCouponDataReportVo; | |||
| import com.simple.domain.vo.MarkingSceneDataReportVo; | |||
| import com.simple.mapper.WxCouponActionLogMapper; | |||
| import com.simple.mapper.WxCouponOrderMapper; | |||
| import com.simple.service.MarkingDataReportService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -8,6 +10,7 @@ import org.springframework.stereotype.Service; | |||
| import java.text.NumberFormat; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| * Created by syf on 2018/8/28. | |||
| @@ -18,6 +21,8 @@ public class MarkingDataReportServiceImpl implements MarkingDataReportService { | |||
| @Autowired | |||
| private WxCouponOrderMapper wxCouponOrderMapper; | |||
| @Autowired | |||
| private WxCouponActionLogMapper wxCouponActionLogMapper; | |||
| //取本月第一天 | |||
| private Date getFirstDayOfMonth(){ | |||
| @@ -41,6 +46,7 @@ public class MarkingDataReportServiceImpl implements MarkingDataReportService { | |||
| return date; | |||
| } | |||
| //取的当月券数据 | |||
| @Override | |||
| public Map<String,Object> getCouponDate(String tenantId){ | |||
| //今日领取券数 | |||
| //查询coupon order表 | |||
| @@ -68,16 +74,78 @@ public class MarkingDataReportServiceImpl implements MarkingDataReportService { | |||
| params.put("tenantId",tenantId); | |||
| params.put("startTime",getFirstDayOfMonth()); | |||
| params.put("endTime",addDay(1)); | |||
| List<MarkingCouponDataReportVo> couponDataMap=wxCouponOrderMapper.couponDataMap(params); | |||
| List<MarkingCouponDataReportVo> couponDatalist=wxCouponOrderMapper.couponDataMap(params); | |||
| //查询券领取人数 | |||
| HashMap<String,Object> returnMap = new HashMap<>(); | |||
| returnMap.put("couponUpDay",couponUpDay);//比昨日提升 | |||
| returnMap.put("couponUpWeek",couponUpWeek);//比上周提升 | |||
| returnMap.put("todayCouponCount",todayCouponCount);//今日领取数 | |||
| returnMap.put("couponDataMap",couponDataMap); | |||
| returnMap.put("couponDataMap",couponDatalist); | |||
| return returnMap; | |||
| } | |||
| @Override | |||
| public Map<String,Object> getSceneData(String tenantId){ | |||
| //今日营销投放券数 | |||
| int todaySceneCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId,addDay(0),addDay(1)); | |||
| int yesterdayCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId,addDay(-1),addDay(0)); | |||
| int lastWeekCount = wxCouponActionLogMapper.findCountByDateLimit(tenantId,addDay(-7),addDay(-6)); | |||
| NumberFormat nf = NumberFormat.getPercentInstance(); | |||
| nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 | |||
| String sceneDownDay =""; | |||
| if(yesterdayCount!=0) { | |||
| sceneDownDay = nf.format((yesterdayCount-todaySceneCount) / (float) yesterdayCount); | |||
| }else{ | |||
| sceneDownDay = nf.format(0-todaySceneCount); | |||
| } | |||
| String sceneUpWeek =""; | |||
| if(lastWeekCount!=0) { | |||
| sceneUpWeek = nf.format((todaySceneCount - lastWeekCount) / (float) lastWeekCount); | |||
| }else{ | |||
| sceneUpWeek = nf.format(todaySceneCount); | |||
| } | |||
| HashMap<String, Object> params = new HashMap<>(); | |||
| params.put("tenantId",tenantId); | |||
| params.put("startTime",getFirstDayOfMonth()); | |||
| params.put("endTime",addDay(1)); | |||
| //停车发券数 停车发券被核销数 核销发券数 核销发券被核销数 | |||
| List<MarkingSceneDataReportVo> list = wxCouponActionLogMapper.sceneDataMap(params); | |||
| //停车发券被核销数 | |||
| HashMap<String, Object> params1 = new HashMap<>(); | |||
| params1.put("tenantId",tenantId); | |||
| params1.put("startTime",getFirstDayOfMonth()); | |||
| params1.put("endTime",addDay(1)); | |||
| params1.put("channelType",3);//停车 | |||
| List<MarkingSceneDataReportVo> list1 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params1); | |||
| Map<String,Integer> parkCountMap = list1.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getxTime, p->p.getTempCount())); | |||
| //核销发券被核销数 | |||
| HashMap<String, Object> params2 = new HashMap<>(); | |||
| params2.put("tenantId",tenantId); | |||
| params2.put("startTime",getFirstDayOfMonth()); | |||
| params2.put("endTime",addDay(1)); | |||
| params2.put("channelType",4);//核销 | |||
| List<MarkingSceneDataReportVo> list2 = wxCouponActionLogMapper.sceneDataMapJoinCouponOrder(params2); | |||
| Map<String,Integer> verifyCountMap = list2.stream().collect(Collectors.toMap(MarkingSceneDataReportVo::getxTime, p->p.getTempCount())); | |||
| for (MarkingSceneDataReportVo vo:list) { | |||
| vo.setParkCount(parkCountMap.get(vo.getxTime()) == null ? 0 : parkCountMap.get(vo.getxTime())); | |||
| vo.setVerifyCount(verifyCountMap.get(vo.getxTime()) == null ? 0 : verifyCountMap.get(vo.getxTime())); | |||
| } | |||
| HashMap<String,Object> returnMap = new HashMap<>(); | |||
| returnMap.put("sceneDownDay",sceneDownDay);//比昨日下降 | |||
| returnMap.put("sceneUpWeek",sceneUpWeek);//比上周提升 | |||
| returnMap.put("todaySceneCount",todaySceneCount);//今日领取数 | |||
| returnMap.put("sceneDataMap",list); | |||
| return returnMap; | |||
| } | |||
| } | |||
| @@ -71,7 +71,23 @@ | |||
| select <include refid="allColumns" /> from wx_coupon_action_log | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| <select id="findCountByDateLimit" resultType="java.lang.Integer"> | |||
| select COUNT(*) FROM wx_coupon_action_log where tenant_id = #{tenantId} and `createtime` >= #{startTime} and `createtime` <= #{endTime} | |||
| </select> | |||
| <select id="sceneDataMap" resultType="com.simple.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap"> | |||
| select DATE_FORMAT(createtime,'%m/%d') as xTime, (select Count(*) from wx_coupon_action_log c where DATE_FORMAT(createtime,'%m/%d')=xTime and c.channel_type=3 and tenant_id=#{tenantId} ) as parkSendCount,(select Count(*) from wx_coupon_action_log c where DATE_FORMAT(createtime,'%m/%d')=xTime and c.channel_type=4 and tenant_id=#{tenantId}) as verifySendCount | |||
| from wx_coupon_action_log where tenant_id=#{tenantId} and createtime >= #{startTime} and createtime <= #{endTime} group by xTime | |||
| </select> | |||
| <select id="sceneDataMapJoinCouponOrder" resultType="com.simple.domain.vo.MarkingSceneDataReportVo" parameterType="hashmap"> | |||
| select DATE_FORMAT(create_date,'%m/%d') AS xTime,COUNT(wx_coupon_order.id) as tempCount from wx_coupon_action_log left join wx_coupon_order on wx_coupon_action_log.coupon_order_id=wx_coupon_order.id where wx_coupon_action_log.tenant_id=#{tenantId} | |||
| AND wx_coupon_order.coupon_order_status = 1 and wx_coupon_action_log.createtime >= #{startTime} and wx_coupon_action_log.createtime <= #{endTime} | |||
| AND wx_coupon_action_log.channel_type = #{channelType} group by xTime | |||
| </select> | |||
| @@ -374,15 +374,6 @@ | |||
| select COUNT(*) FROM wx_coupon_order where tenant_id = #{tenantId} and create_date >= #{startTime} and create_date <= #{endTime} | |||
| </select> | |||
| <select id="sceneMarkingMap" resultType="hashmap" parameterType="hashmap"> | |||
| select count(c.id) carcount,c.create_date from ( | |||
| select id,DATE_FORMAT(create_date,'%Y-%m-%d') create_date | |||
| from wx_car_cmd_log where tenant_id = #{tenantId} and cmd_type=#{cmdType} | |||
| and create_date BETWEEN #{startdate} and #{enddate} | |||
| ) c | |||
| group by c.create_date | |||
| </select> | |||
| <select id="couponDataMap" resultType="com.simple.domain.vo.MarkingCouponDataReportVo" parameterType="hashmap"> | |||
| SELECT DATE_FORMAT(create_date,'%m/%d') as createTime | |||
| ,COUNT(DISTINCT c_user_id) as couponUserCount,count(*) as couponCount | |||