From fe821c9d7fa91deefcf0388b030fac537a591445 Mon Sep 17 00:00:00 2001 From: "jinguo24@163.com" Date: Sun, 26 Aug 2018 14:33:39 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=9A=E5=91=98=E7=BB=93=E6=9E=84][?= =?UTF-8?q?=E6=96=B0=E5=A2=9E]=E6=A0=B9=E6=8D=AE=E5=B9=B4=E9=BE=84?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WxCUserBasicInfoController.java | 43 ++++++++++++++++--- .../controller/WxLevelConfigController.java | 8 ++-- .../java/com/simple/enums/EnumAgeInfo.java | 10 ++--- .../java/com/simple/mapper/WxCUserMapper.java | 7 ++- .../com/simple/service/WxCUserService.java | 10 +++-- .../impl/WxCUserBasicInfoServiceImpl.java | 12 +++--- .../service/impl/WxCUserServiceImpl.java | 7 +++ .../mapper/WxCUserBasicInfoMapper.xml | 14 +++--- .../main/resources/mapper/WxCUserMapper.xml | 10 +++++ 9 files changed, 91 insertions(+), 30 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/simple/controller/WxCUserBasicInfoController.java b/mallinkAdmin/src/main/java/com/simple/controller/WxCUserBasicInfoController.java index bc6ea276b..645ad14e3 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/WxCUserBasicInfoController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/WxCUserBasicInfoController.java @@ -2,6 +2,7 @@ package com.simple.controller; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; 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.WxTags; import com.simple.domain.vo.UserStructureVo; +import com.simple.enums.EnumAgeInfo; import com.simple.service.WxCUserBasicInfoService; import com.simple.service.WxCUserService; import com.simple.service.WxCUserTagsService; @@ -206,30 +208,61 @@ public class WxCUserBasicInfoController extends BaseController WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto(); dto.setStartTime(startTime); dto.setEndTime(endTime); - dto.setSex(0); //保密 - long secrecy = wxCUserBasicInfoService.findCountBySex(dto); + dto.setSex(0); + long secrecy = getCount(dto); dto.setSex(1); - long boy = wxCUserBasicInfoService.findCountBySex(dto); + long boy = getCount(dto); dto.setSex(2); - long girl=wxCUserBasicInfoService.findCountBySex(dto); + long girl=getCount(dto); Long all =secrecy+boy+girl; List vos = new ArrayList<>(); - vos.add(getVo(secrecy, all, "保密")); vos.add(getVo(boy, all, "男")); vos.add(getVo(girl, all, "女")); + vos.add(getVo(secrecy, all, "保密")); return new ResultData(vos); } @ApiOperation("查询会员年龄结构") @GetMapping("/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(); } + 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) { UserStructureVo vo = new UserStructureVo(); vo.setName(name); diff --git a/mallinkAdmin/src/main/java/com/simple/controller/WxLevelConfigController.java b/mallinkAdmin/src/main/java/com/simple/controller/WxLevelConfigController.java index 72fc73465..343467087 100644 --- a/mallinkAdmin/src/main/java/com/simple/controller/WxLevelConfigController.java +++ b/mallinkAdmin/src/main/java/com/simple/controller/WxLevelConfigController.java @@ -72,10 +72,10 @@ public class WxLevelConfigController extends BaseController // } @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); } diff --git a/mallinkService/src/main/java/com/simple/enums/EnumAgeInfo.java b/mallinkService/src/main/java/com/simple/enums/EnumAgeInfo.java index 515b7292c..15e14a346 100644 --- a/mallinkService/src/main/java/com/simple/enums/EnumAgeInfo.java +++ b/mallinkService/src/main/java/com/simple/enums/EnumAgeInfo.java @@ -3,11 +3,11 @@ package com.simple.enums; public enum EnumAgeInfo { FIRST_SLOT(1,0,18,"18岁以下"), 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) { diff --git a/mallinkService/src/main/java/com/simple/mapper/WxCUserMapper.java b/mallinkService/src/main/java/com/simple/mapper/WxCUserMapper.java index f370d5697..222053d6e 100644 --- a/mallinkService/src/main/java/com/simple/mapper/WxCUserMapper.java +++ b/mallinkService/src/main/java/com/simple/mapper/WxCUserMapper.java @@ -1,8 +1,9 @@ package com.simple.mapper; -import java.util.*; +import java.util.List; + import com.simple.common.CommonMapper; -import org.apache.ibatis.annotations.Param; +import com.simple.domain.dto.WxCuerBasicInfoDto; import com.simple.domain.po.WxCUser; public interface WxCUserMapper extends CommonMapper { @@ -13,4 +14,6 @@ public interface WxCUserMapper extends CommonMapper { WxCUser findByOpenId(WxCUser record); WxCUser findByToken(String token); + + long findCountBySex(WxCuerBasicInfoDto dto); } diff --git a/mallinkService/src/main/java/com/simple/service/WxCUserService.java b/mallinkService/src/main/java/com/simple/service/WxCUserService.java index dcb7a6d11..1dcb1e883 100644 --- a/mallinkService/src/main/java/com/simple/service/WxCUserService.java +++ b/mallinkService/src/main/java/com/simple/service/WxCUserService.java @@ -1,8 +1,7 @@ package com.simple.service; -import java.util.*; - import com.github.pagehelper.PageInfo; +import com.simple.domain.dto.WxCuerBasicInfoDto; import com.simple.domain.po.WxCUser; public interface WxCUserService { @@ -55,5 +54,10 @@ public interface WxCUserService { */ void deleteById(Long id); - + /** + * 根据性别统计数量 + * @param dto + * @return + */ + long findCountBySex(WxCuerBasicInfoDto dto); } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java index 2f8936f2c..6dac1344d 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCUserBasicInfoServiceImpl.java @@ -1,15 +1,15 @@ 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.PageInfo; +import com.simple.common.IdWorker; import com.simple.domain.dto.WxCuerBasicInfoDto; import com.simple.domain.po.WxCUserBasicInfo; import com.simple.mapper.WxCUserBasicInfoMapper; import com.simple.service.WxCUserBasicInfoService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.simple.common.IdWorker; @Service public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { @@ -72,8 +72,8 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { @Override public long findCountByAge(WxCuerBasicInfoDto dto) { - // TODO Auto-generated method stub - return 0; + + return wxCUserBasicInfoMapper.findCountByAge(dto); } diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java index 6ada899ac..e1dbc5676 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java +++ b/mallinkService/src/main/java/com/simple/service/impl/WxCUserServiceImpl.java @@ -3,6 +3,7 @@ package com.simple.service.impl; import java.util.*; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.simple.domain.dto.WxCuerBasicInfoDto; import com.simple.domain.po.WxCUser; import com.simple.mapper.WxCUserMapper; import com.simple.service.WxCUserService; @@ -60,6 +61,12 @@ public class WxCUserServiceImpl implements WxCUserService { public void deleteById(Long id) { wxCUserMapper.deleteByPrimaryKey(id); } + + @Override + public long findCountBySex(WxCuerBasicInfoDto dto) { + + return wxCUserMapper.findCountBySex(dto); + } } diff --git a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml index 67c17a31e..f127b6edf 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserBasicInfoMapper.xml @@ -141,7 +141,7 @@ - select count(id) from wx_c_user_basic_info where sex =#{sex} and create_date >= #{startTime} @@ -152,10 +152,14 @@ - + select count(id) from wx_c_user_basic_info where 1=1 + + and birthdate >= #{startTime} + + + and birthdate <= #{endTime} + diff --git a/mallinkService/src/main/resources/mapper/WxCUserMapper.xml b/mallinkService/src/main/resources/mapper/WxCUserMapper.xml index 9d9ae3fc5..c247c6fe4 100644 --- a/mallinkService/src/main/resources/mapper/WxCUserMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCUserMapper.xml @@ -183,4 +183,14 @@ select * from wx_c_user where `token` = #{token} + +