| @@ -2,6 +2,7 @@ package com.simple.controller; | |||||
| import java.text.NumberFormat; | import java.text.NumberFormat; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Calendar; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -28,6 +29,7 @@ import com.simple.domain.po.WxCoupon; | |||||
| import com.simple.domain.po.WxCouponOrder; | import com.simple.domain.po.WxCouponOrder; | ||||
| import com.simple.domain.po.WxTags; | import com.simple.domain.po.WxTags; | ||||
| import com.simple.domain.vo.UserStructureVo; | import com.simple.domain.vo.UserStructureVo; | ||||
| import com.simple.enums.EnumAgeInfo; | |||||
| import com.simple.service.WxCUserBasicInfoService; | import com.simple.service.WxCUserBasicInfoService; | ||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| import com.simple.service.WxCUserTagsService; | import com.simple.service.WxCUserTagsService; | ||||
| @@ -206,30 +208,61 @@ public class WxCUserBasicInfoController extends BaseController | |||||
| WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto(); | WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto(); | ||||
| dto.setStartTime(startTime); | dto.setStartTime(startTime); | ||||
| dto.setEndTime(endTime); | dto.setEndTime(endTime); | ||||
| dto.setSex(0); | |||||
| //保密 | //保密 | ||||
| long secrecy = wxCUserBasicInfoService.findCountBySex(dto); | |||||
| dto.setSex(0); | |||||
| long secrecy = getCount(dto); | |||||
| dto.setSex(1); | dto.setSex(1); | ||||
| long boy = wxCUserBasicInfoService.findCountBySex(dto); | |||||
| long boy = getCount(dto); | |||||
| dto.setSex(2); | dto.setSex(2); | ||||
| long girl=wxCUserBasicInfoService.findCountBySex(dto); | |||||
| long girl=getCount(dto); | |||||
| Long all =secrecy+boy+girl; | Long all =secrecy+boy+girl; | ||||
| List<UserStructureVo> vos = new ArrayList<>(); | List<UserStructureVo> vos = new ArrayList<>(); | ||||
| vos.add(getVo(secrecy, all, "保密")); | |||||
| vos.add(getVo(boy, all, "男")); | vos.add(getVo(boy, all, "男")); | ||||
| vos.add(getVo(girl, all, "女")); | vos.add(getVo(girl, all, "女")); | ||||
| vos.add(getVo(secrecy, all, "保密")); | |||||
| return new ResultData(vos); | return new ResultData(vos); | ||||
| } | } | ||||
| @ApiOperation("查询会员年龄结构") | @ApiOperation("查询会员年龄结构") | ||||
| @GetMapping("/findUserAgeStructure") | @GetMapping("/findUserAgeStructure") | ||||
| public ResultData findUserAgeStructure() { | public ResultData findUserAgeStructure() { | ||||
| Calendar c = Calendar.getInstance(); | |||||
| for(EnumAgeInfo a:EnumAgeInfo.values()) { | |||||
| c.clear(); | |||||
| c.setTime(new Date()); | |||||
| c.set(Calendar.HOUR_OF_DAY, 0); | |||||
| c.set(Calendar.MINUTE,0); | |||||
| c.set(Calendar.SECOND,0); | |||||
| long count = getCountByAge(a, c); | |||||
| } | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| private long getCountByAge(EnumAgeInfo a,Calendar c) { | |||||
| WxCuerBasicInfoDto dto =new WxCuerBasicInfoDto(); | |||||
| c.add(Calendar.YEAR, -a.getEnd()); | |||||
| Date startTime = c.getTime(); | |||||
| c.clear(); | |||||
| c.setTime(startTime); | |||||
| c.add(Calendar.YEAR,a.getEnd()-a.getStart()); | |||||
| Date endTime = c.getTime(); | |||||
| dto.setStartTime(startTime); | |||||
| dto.setEndTime(endTime); | |||||
| return wxCUserBasicInfoService.findCountByAge(dto); | |||||
| } | |||||
| //通过性别获取数量 | |||||
| private long getCount(WxCuerBasicInfoDto dto) { | |||||
| //TODO 考虑性能问题,暂不处理少量重复问题,后续可考虑大数据处理 | |||||
| return wxCUserBasicInfoService.findCountBySex(dto)+ | |||||
| wxCUserService.findCountBySex(dto); | |||||
| } | |||||
| private UserStructureVo getVo(long count,long all,String name) { | private UserStructureVo getVo(long count,long all,String name) { | ||||
| UserStructureVo vo = new UserStructureVo(); | UserStructureVo vo = new UserStructureVo(); | ||||
| vo.setName(name); | vo.setName(name); | ||||
| @@ -72,10 +72,10 @@ public class WxLevelConfigController extends BaseController | |||||
| // } | // } | ||||
| @ApiOperation("根据id删除接口") | @ApiOperation("根据id删除接口") | ||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxLevelConfigService.deleteById(id); | |||||
| @PostMapping("/del") | |||||
| // @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(@RequestBody WxLevelConfig wxLevelConfig) { | |||||
| wxLevelConfigService.deleteById(wxLevelConfig.getId()); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | return new ResultData(Result.SUCCESS, "删除成功", null); | ||||
| } | } | ||||
| @@ -3,11 +3,11 @@ package com.simple.enums; | |||||
| public enum EnumAgeInfo { | public enum EnumAgeInfo { | ||||
| FIRST_SLOT(1,0,18,"18岁以下"), | FIRST_SLOT(1,0,18,"18岁以下"), | ||||
| SECOND_SLOT(2,18,24,"18岁-24岁"), | SECOND_SLOT(2,18,24,"18岁-24岁"), | ||||
| THIRD_SLOT(3,18,24,"18岁-24岁"), | |||||
| FOURTH_SLOT(4,18,24,"18岁-24岁"), | |||||
| FIFTH_SLOT(5,18,24,"18岁-24岁"), | |||||
| SIXTH_SLOT(6,18,24,"18岁-24岁"), | |||||
| SEVENTH_SLOT(7,18,24,"18岁-24岁") | |||||
| THIRD_SLOT(3,18,24,"25岁-34岁"), | |||||
| FOURTH_SLOT(4,18,24,"35岁-44岁"), | |||||
| FIFTH_SLOT(5,18,24,"45岁-54岁"), | |||||
| SIXTH_SLOT(6,18,24,"55岁-60岁"), | |||||
| SEVENTH_SLOT(7,18,24,"60岁以上") | |||||
| ; | ; | ||||
| private EnumAgeInfo(Integer sortNum,Integer start,Integer end,String desc) { | private EnumAgeInfo(Integer sortNum,Integer start,Integer end,String desc) { | ||||
| @@ -1,8 +1,9 @@ | |||||
| package com.simple.mapper; | package com.simple.mapper; | ||||
| import java.util.*; | |||||
| import java.util.List; | |||||
| import com.simple.common.CommonMapper; | import com.simple.common.CommonMapper; | ||||
| import org.apache.ibatis.annotations.Param; | |||||
| import com.simple.domain.dto.WxCuerBasicInfoDto; | |||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| public interface WxCUserMapper extends CommonMapper<WxCUser, Long> { | public interface WxCUserMapper extends CommonMapper<WxCUser, Long> { | ||||
| @@ -13,4 +14,6 @@ public interface WxCUserMapper extends CommonMapper<WxCUser, Long> { | |||||
| WxCUser findByOpenId(WxCUser record); | WxCUser findByOpenId(WxCUser record); | ||||
| WxCUser findByToken(String token); | WxCUser findByToken(String token); | ||||
| long findCountBySex(WxCuerBasicInfoDto dto); | |||||
| } | } | ||||
| @@ -1,8 +1,7 @@ | |||||
| package com.simple.service; | package com.simple.service; | ||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.dto.WxCuerBasicInfoDto; | |||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| public interface WxCUserService { | public interface WxCUserService { | ||||
| @@ -55,5 +54,10 @@ public interface WxCUserService { | |||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | |||||
| * 根据性别统计数量 | |||||
| * @param dto | |||||
| * @return | |||||
| */ | |||||
| long findCountBySex(WxCuerBasicInfoDto dto); | |||||
| } | } | ||||
| @@ -1,15 +1,15 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.util.*; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.IdWorker; | |||||
| import com.simple.domain.dto.WxCuerBasicInfoDto; | import com.simple.domain.dto.WxCuerBasicInfoDto; | ||||
| import com.simple.domain.po.WxCUserBasicInfo; | import com.simple.domain.po.WxCUserBasicInfo; | ||||
| import com.simple.mapper.WxCUserBasicInfoMapper; | import com.simple.mapper.WxCUserBasicInfoMapper; | ||||
| import com.simple.service.WxCUserBasicInfoService; | import com.simple.service.WxCUserBasicInfoService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import com.simple.common.IdWorker; | |||||
| @Service | @Service | ||||
| public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | ||||
| @@ -72,8 +72,8 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||||
| @Override | @Override | ||||
| public long findCountByAge(WxCuerBasicInfoDto dto) { | public long findCountByAge(WxCuerBasicInfoDto dto) { | ||||
| // TODO Auto-generated method stub | |||||
| return 0; | |||||
| return wxCUserBasicInfoMapper.findCountByAge(dto); | |||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package com.simple.service.impl; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.dto.WxCuerBasicInfoDto; | |||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.mapper.WxCUserMapper; | import com.simple.mapper.WxCUserMapper; | ||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| @@ -60,6 +61,12 @@ public class WxCUserServiceImpl implements WxCUserService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxCUserMapper.deleteByPrimaryKey(id); | wxCUserMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public long findCountBySex(WxCuerBasicInfoDto dto) { | |||||
| return wxCUserMapper.findCountBySex(dto); | |||||
| } | |||||
| } | } | ||||
| @@ -141,7 +141,7 @@ | |||||
| </update> | </update> | ||||
| <select id="findCountBySex" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto"> | |||||
| <select id="findCountBySex" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto" resultType="java.lang.Long"> | |||||
| select count(id) from wx_c_user_basic_info where sex =#{sex} | select count(id) from wx_c_user_basic_info where sex =#{sex} | ||||
| <if test=" null != startTime "> | <if test=" null != startTime "> | ||||
| and create_date >= #{startTime} | and create_date >= #{startTime} | ||||
| @@ -152,10 +152,14 @@ | |||||
| </select> | </select> | ||||
| <select id="findCountByAge" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto"> | |||||
| select count(id) from wx_c_user_basic_info where | |||||
| create_date >= #{startTime} | |||||
| and create_date <= #{endTime} | |||||
| <select id="findCountByAge" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto" resultType="java.lang.Long"> | |||||
| select count(id) from wx_c_user_basic_info where 1=1 | |||||
| <if test=" null != startTime "> | |||||
| and birthdate >= #{startTime} | |||||
| </if> | |||||
| <if test=" null != endTime"> | |||||
| and birthdate <= #{endTime} | |||||
| </if> | |||||
| </select> | </select> | ||||
| </mapper> | </mapper> | ||||
| @@ -183,4 +183,14 @@ | |||||
| select * from wx_c_user | select * from wx_c_user | ||||
| where `token` = #{token} | where `token` = #{token} | ||||
| </select> | </select> | ||||
| <select id="findCountBySex" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto" resultType="java.lang.Long"> | |||||
| select count(id) from wx_c_user where gender =#{sex} | |||||
| <if test=" null != startTime "> | |||||
| and create_date >= #{startTime} | |||||
| </if> | |||||
| <if test=" null != endTime"> | |||||
| and create_date <= #{endTime} | |||||
| </if> | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||