| @@ -1,6 +1,8 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import java.text.NumberFormat; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| @@ -25,6 +27,7 @@ import com.simple.domain.po.WxCUserTags; | |||||
| import com.simple.domain.po.WxCoupon; | 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.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; | ||||
| @@ -194,4 +197,51 @@ public class WxCUserBasicInfoController extends BaseController | |||||
| } | } | ||||
| return new ResultData(Result.SUCCESS,"查询成功",page); | return new ResultData(Result.SUCCESS,"查询成功",page); | ||||
| } | } | ||||
| @ApiOperation("查询会员性别结构") | |||||
| @GetMapping("/findUserSexStructure") | |||||
| public ResultData findUserSexStructure( | |||||
| Date startTime,Date endTime | |||||
| ) { | |||||
| WxCuerBasicInfoDto dto = new WxCuerBasicInfoDto(); | |||||
| dto.setStartTime(startTime); | |||||
| dto.setEndTime(endTime); | |||||
| dto.setSex(0); | |||||
| //保密 | |||||
| long secrecy = wxCUserBasicInfoService.findCountBySex(dto); | |||||
| dto.setSex(1); | |||||
| long boy = wxCUserBasicInfoService.findCountBySex(dto); | |||||
| dto.setSex(2); | |||||
| long girl=wxCUserBasicInfoService.findCountBySex(dto); | |||||
| Long all =secrecy+boy+girl; | |||||
| List<UserStructureVo> vos = new ArrayList<>(); | |||||
| vos.add(getVo(secrecy, all, "保密")); | |||||
| vos.add(getVo(boy, all, "男")); | |||||
| vos.add(getVo(girl, all, "女")); | |||||
| return new ResultData(vos); | |||||
| } | |||||
| @ApiOperation("查询会员年龄结构") | |||||
| @GetMapping("/findUserSexStructure") | |||||
| public ResultData findUserAgeStructure() { | |||||
| return new ResultData(); | |||||
| } | |||||
| private UserStructureVo getVo(long count,long all,String name) { | |||||
| UserStructureVo vo = new UserStructureVo(); | |||||
| vo.setName(name); | |||||
| vo.setCount(count+""); | |||||
| NumberFormat nf = NumberFormat.getPercentInstance(); | |||||
| nf.setMinimumFractionDigits(2);//控制保留小数点后几位,2:表示保留2位小数点 | |||||
| if(all>0) { | |||||
| vo.setPercentage(nf.format(new Long(count).doubleValue()/new Long(all).doubleValue())); | |||||
| }else { | |||||
| vo.setPercentage("0.00%"); | |||||
| } | |||||
| return vo; | |||||
| } | |||||
| } | } | ||||
| @@ -32,10 +32,18 @@ public class WxCuerBasicInfoDto implements Serializable{ | |||||
| // @io.swagger.annotations.ApiModelProperty(value="租户id",name="tenantId") | // @io.swagger.annotations.ApiModelProperty(value="租户id",name="tenantId") | ||||
| @Transient | @Transient | ||||
| private String tenantId; | private String tenantId; | ||||
| @Transient | |||||
| private Integer sex; | |||||
| public Integer getSex() { | |||||
| return sex; | |||||
| } | |||||
| public void setSex(Integer sex) { | |||||
| this.sex = sex; | |||||
| } | |||||
| public String getName() { | public String getName() { | ||||
| return name; | return name; | ||||
| } | } | ||||
| @@ -0,0 +1,42 @@ | |||||
| package com.simple.domain.vo; | |||||
| import java.io.Serializable; | |||||
| /** | |||||
| * 会员结构vo | |||||
| * @author jinguo | |||||
| * | |||||
| */ | |||||
| public class UserStructureVo implements Serializable{ | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private static final long serialVersionUID = 6780570955120276660L; | |||||
| //名称 | |||||
| private String name; | |||||
| //数量 | |||||
| private String count; | |||||
| //百分比 | |||||
| private String percentage; | |||||
| public String getName() { | |||||
| return name; | |||||
| } | |||||
| public void setName(String name) { | |||||
| this.name = name; | |||||
| } | |||||
| public String getCount() { | |||||
| return count; | |||||
| } | |||||
| public void setCount(String count) { | |||||
| this.count = count; | |||||
| } | |||||
| public String getPercentage() { | |||||
| return percentage; | |||||
| } | |||||
| public void setPercentage(String percentage) { | |||||
| this.percentage = percentage; | |||||
| } | |||||
| } | |||||
| @@ -17,5 +17,7 @@ public interface WxCUserBasicInfoMapper extends CommonMapper<WxCUserBasicInfo, S | |||||
| void updateScore(WxCUserBasicInfo record); | void updateScore(WxCUserBasicInfo record); | ||||
| long findCountBySex(WxCuerBasicInfoDto dto); | |||||
| long findCountByAge(WxCuerBasicInfoDto dto); | |||||
| } | } | ||||
| @@ -48,10 +48,19 @@ public interface WxCUserBasicInfoService { | |||||
| */ | */ | ||||
| void updateScore(WxCUserBasicInfo record); | void updateScore(WxCUserBasicInfo record); | ||||
| /** | |||||
| * 根据性别查询数量 | |||||
| * @param sex | |||||
| * @return | |||||
| */ | |||||
| long findCountBySex(WxCuerBasicInfoDto dto); | |||||
| /** | |||||
| * 根据年龄查询数量 | |||||
| * @param dto | |||||
| * @return | |||||
| */ | |||||
| long findCountByAge(WxCuerBasicInfoDto dto); | |||||
| @@ -35,6 +35,7 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||||
| wxCUserBasicInfoMapper.updateScore(record); | wxCUserBasicInfoMapper.updateScore(record); | ||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -58,12 +59,22 @@ public class WxCUserBasicInfoServiceImpl implements WxCUserBasicInfoService { | |||||
| public void deleteById(Long id) { | public void deleteById(Long id) { | ||||
| wxCUserBasicInfoMapper.deleteByPrimaryKey(id); | wxCUserBasicInfoMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public long findCountBySex(WxCuerBasicInfoDto dto) { | |||||
| return wxCUserBasicInfoMapper.findCountBySex(dto); | |||||
| } | |||||
| @Override | |||||
| public long findCountByAge(WxCuerBasicInfoDto dto) { | |||||
| // TODO Auto-generated method stub | |||||
| return 0; | |||||
| } | |||||
| } | } | ||||
| @@ -113,7 +113,7 @@ | |||||
| </select> | </select> | ||||
| <select id="list" parameterType="com.simple.domain.po.WxCUserBasicInfo" resultMap="BaseResultMap"> | |||||
| <select id="list" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_c_user_basic_info where 1=1 | select <include refid="allColumns" /> from wx_c_user_basic_info where 1=1 | ||||
| <if test=" null != tenantId "> | <if test=" null != tenantId "> | ||||
| and `tenant_id` = #{tenantId} | and `tenant_id` = #{tenantId} | ||||
| @@ -141,7 +141,21 @@ | |||||
| </update> | </update> | ||||
| <select id="findCountBySex" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto"> | |||||
| select count(id) from wx_c_user_basic_info where sex =#{sex} | |||||
| <if test=" null != startTime "> | |||||
| and create_date >= #{startTime} | |||||
| </if> | |||||
| <if test=" null != endTime"> | |||||
| and create_date <= #{endTime} | |||||
| </if> | |||||
| </select> | |||||
| <select id="findCountBySex" parameterType="com.simple.domain.dto.WxCuerBasicInfoDto"> | |||||
| select count(id) from wx_c_user_basic_info where | |||||
| create_date >= #{startTime} | |||||
| and create_date <= #{endTime} | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||