| @@ -0,0 +1,29 @@ | |||
| package com.simple.controller; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.service.MarkingDataReportService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiOperation; | |||
| 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.RestController; | |||
| /** | |||
| * Created by syf on 2018/8/29. | |||
| */ | |||
| @RestController | |||
| @RequestMapping("markingDataReport") | |||
| @Api(description="营销报表接口") | |||
| public class MarkingDataReportController extends BaseController { | |||
| @Autowired | |||
| private MarkingDataReportService markingDataReportService; | |||
| @ApiOperation("根据id查询接口") | |||
| @GetMapping("/couponData") | |||
| public ResultData findCouponData() { | |||
| return new ResultData(markingDataReportService.getCouponDate(getTenantId())); | |||
| } | |||
| } | |||
| @@ -43,6 +43,7 @@ public class WxCouponChannelController extends BaseController | |||
| wxCouponChannel.setStatus(null); | |||
| } | |||
| wxCouponChannel.setTenantId(getUser().getTenantId()); | |||
| wxCouponChannel.setSortColumns(WxCouponChannel.Field.CreateDate_DESC); | |||
| final PageInfo<WxCouponChannelVo> page = wxCouponChannelService.listPageCAPI(wxCouponChannel, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @@ -0,0 +1,62 @@ | |||
| package com.simple.domain.vo; | |||
| /** | |||
| * Created by syf on 2018/8/28. | |||
| */ | |||
| public class MarkingCouponDataReportVo { | |||
| //券领取张数 couponCount | |||
| //券领取人数 couponUserCount | |||
| //券核销张数 verifyCount | |||
| //券核销人数 verifyUserCount | |||
| private String createTime; | |||
| public String getCreateTime() { | |||
| return createTime; | |||
| } | |||
| public void setCreateTime(String createTime) { | |||
| this.createTime = createTime; | |||
| } | |||
| public int getCouponCount() { | |||
| return couponCount; | |||
| } | |||
| public void setCouponCount(int couponCount) { | |||
| this.couponCount = couponCount; | |||
| } | |||
| public int getCouponUserCount() { | |||
| return couponUserCount; | |||
| } | |||
| public void setCouponUserCount(int couponUserCount) { | |||
| this.couponUserCount = couponUserCount; | |||
| } | |||
| public int getVerifyCount() { | |||
| return verifyCount; | |||
| } | |||
| public void setVerifyCount(int verifyCount) { | |||
| this.verifyCount = verifyCount; | |||
| } | |||
| public int getVerifyUserCount() { | |||
| return verifyUserCount; | |||
| } | |||
| public void setVerifyUserCount(int verifyUserCount) { | |||
| this.verifyUserCount = verifyUserCount; | |||
| } | |||
| private int couponCount; | |||
| private int couponUserCount; | |||
| private int verifyCount; | |||
| private int verifyUserCount; | |||
| } | |||
| @@ -2,6 +2,7 @@ package com.simple.mapper; | |||
| import java.util.*; | |||
| import com.simple.common.CommonMapper; | |||
| import com.simple.domain.vo.MarkingCouponDataReportVo; | |||
| import com.simple.domain.vo.WxCouponOrderBVo; | |||
| import com.simple.domain.vo.WxCouponOrderCVo; | |||
| import org.apache.ibatis.annotations.Param; | |||
| @@ -22,4 +23,16 @@ public interface WxCouponOrderMapper extends CommonMapper<WxCouponOrder, Long> { | |||
| List<WxCouponOrderCVo> findListOfCUser(WxCouponOrder wxCouponOrder); | |||
| List<WxCouponOrderCVo> findListOfAdmin(WxCouponOrder wxCouponOrder); | |||
| List<MarkingCouponDataReportVo> couponDataMap(HashMap<String,Object> params); | |||
| /** | |||
| * 查询商场领券数 | |||
| * @param tenantId | |||
| * @param startTime | |||
| * @param endTime | |||
| * @return | |||
| */ | |||
| int findCountByDateLimit(@Param("tenantId")String tenantId,@Param("startTime") Date startTime,@Param("endTime")Date endTime); | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| package com.simple.service; | |||
| import java.util.Map; | |||
| /** | |||
| * Created by syf on 2018/8/28. | |||
| */ | |||
| public interface MarkingDataReportService { | |||
| Map<String,Object> getCouponDate(String tenantId); | |||
| } | |||
| @@ -0,0 +1,83 @@ | |||
| package com.simple.service.impl; | |||
| import com.simple.domain.vo.MarkingCouponDataReportVo; | |||
| import com.simple.mapper.WxCouponOrderMapper; | |||
| import com.simple.service.MarkingDataReportService; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.text.NumberFormat; | |||
| import java.util.*; | |||
| /** | |||
| * Created by syf on 2018/8/28. | |||
| */ | |||
| @Service | |||
| public class MarkingDataReportServiceImpl implements MarkingDataReportService { | |||
| @Autowired | |||
| private WxCouponOrderMapper wxCouponOrderMapper; | |||
| //取本月第一天 | |||
| private Date getFirstDayOfMonth(){ | |||
| Calendar c = Calendar.getInstance(); | |||
| c.set(Calendar.DAY_OF_MONTH, 0);//设置为1号,当前日期既为本月第一天 | |||
| c.set(Calendar.HOUR_OF_DAY, 0); | |||
| c.set(Calendar.MINUTE, 0); | |||
| c.set(Calendar.SECOND, 0); | |||
| c.set(Calendar.MILLISECOND, 0); | |||
| Date thisMonth = c.getTime(); | |||
| return thisMonth; | |||
| } | |||
| private Date addDay(int addDayAmount){ | |||
| Calendar c = Calendar.getInstance(); | |||
| c.add(Calendar.DATE, addDayAmount); | |||
| c.set(Calendar.HOUR_OF_DAY, 0); | |||
| c.set(Calendar.MINUTE, 0); | |||
| c.set(Calendar.SECOND, 0); | |||
| c.set(Calendar.MILLISECOND, 0); | |||
| Date date = c.getTime(); | |||
| return date; | |||
| } | |||
| //取的当月券数据 | |||
| public Map<String,Object> getCouponDate(String tenantId){ | |||
| //今日领取券数 | |||
| //查询coupon order表 | |||
| int todayCouponCount = wxCouponOrderMapper.findCountByDateLimit(tenantId,addDay(0),addDay(1)); | |||
| int yesterdayCount = wxCouponOrderMapper.findCountByDateLimit(tenantId,addDay(-1),addDay(0)); | |||
| int lastWeekCount = wxCouponOrderMapper.findCountByDateLimit(tenantId,addDay(-7),addDay(-6)); | |||
| NumberFormat nf = NumberFormat.getPercentInstance(); | |||
| nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 | |||
| String couponUpDay =""; | |||
| if(yesterdayCount!=0) { | |||
| couponUpDay = nf.format((todayCouponCount - yesterdayCount) / (float) yesterdayCount); | |||
| }else{ | |||
| couponUpDay = nf.format(todayCouponCount); | |||
| } | |||
| String couponUpWeek =""; | |||
| if(lastWeekCount!=0) { | |||
| couponUpWeek = nf.format((todayCouponCount - lastWeekCount) / (float) lastWeekCount); | |||
| }else{ | |||
| couponUpWeek = nf.format(todayCouponCount); | |||
| } | |||
| //couponData | |||
| HashMap<String, Object> params = new HashMap<>(); | |||
| params.put("tenantId",tenantId); | |||
| params.put("startTime",getFirstDayOfMonth()); | |||
| params.put("endTime",addDay(1)); | |||
| List<MarkingCouponDataReportVo> couponDataMap=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); | |||
| return returnMap; | |||
| } | |||
| } | |||
| @@ -371,7 +371,26 @@ | |||
| </select> | |||
| <select id="findCountByDateLimit" resultType="java.lang.Integer"> | |||
| 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 | |||
| ,(select Count(*) from wx_coupon_order c where coupon_order_status=1 AND DATE_FORMAT(create_date,'%m/%d')=createTime and tenant_id=#{tenantId} AND c.update_date >= #{startTime} and c.update_date <= #{endTime}) as verifyCount | |||
| ,(select Count(DISTINCT c_user_id) from wx_coupon_order d where coupon_order_status=1 AND DATE_FORMAT(create_date,'%m/%d')=createTime and tenant_id=#{tenantId} AND d.update_date >= #{startTime} and d.update_date <= #{endTime}) as verifyUserCount | |||
| from wx_coupon_order where tenant_id=#{tenantId} AND create_date >= #{startTime} and create_date <= #{endTime} GROUP BY createTime | |||
| </select> | |||
| </mapper> | |||