/**
*
*Service
/
public ServiceMessage<MemberFreedomRepModel> getMFListByPay(Long memberId,Long freedomType,Long paymentId,BigDecimal money) {
try { if(memberId==null || memberId==0){ return super.returnParamsError("memberId不能为空!"); } if(freedomType==null || freedomType==0){ return super.returnParamsError("freedomType不能为空!"); } if(paymentId==null || paymentId==0){ return super.returnParamsError("paymentId不能为空!"); } if(money.compareTo(BigDecimal.ZERO) <= 0){ return super.returnParamsError("充值金额不能为空!"); } if(!freedomType.equals(MemberRankType.chongzhijiangli.getType())){ return super.returnParamsError("此接口只提供给"+MemberRankType.chongzhijiangli.getTypeName()+"使用!"); } //先查询会员的角色 MemberRoleConnRepModel mm = new MemberRoleConnRepModel(); mm.setMemberId(memberId); ServiceMessage<List<MemberRoleConnRepModel>> msgRes = memberRoleConnRepModelService.queryByList(mm); if(!msgRes.getStatus().equals(MsgStatus.NORMAL) || msgRes.getResult()==null || msgRes.getResult().size()==0){ MemberRoleConnRepModel memberRoleConnRepModel = new MemberRoleConnRepModel(); memberRoleConnRepModel.setMemberId(memberId); memberRoleConnRepModelService.saveInitMemberRole(memberRoleConnRepModel); msgRes = memberRoleConnRepModelService.queryByList(mm); } List<Long> roleIds = new ArrayList<Long>(); List<Long> rankIds = new ArrayList<Long>(); for(MemberRoleConnRepModel me : msgRes.getResult()){ roleIds.add(me.getRoleId()); rankIds.add(me.getRankId()); } if(roleIds==null || roleIds.size() ==0 || rankIds==null || rankIds.size() ==0 ){ return super.returnParamsError("此会员没有角色!"); } MemberFreedomRepModel memberFreedom = new MemberFreedomRepModel(); memberFreedom.setRankIds(rankIds); memberFreedom.setRoleIds(roleIds); memberFreedom.setMemberId(memberId); memberFreedom.setFreedomType(freedomType); memberFreedom.setPaymentTypeId(paymentId); memberFreedom.setNoTime(DateUtils.getCurrentDateString()); List<MemberFreedomRepModel> list = super.memberFreedomRepMapper.getMFListByPay(memberFreedom) ; if(list==null || list.size() ==0 ){ return super.returnCorrectResult("此会员暂无充值特权!"); } MemberFreedomRepModel me = list.get(0);; //充值奖励 维护的数据是这样的 100:2,200:20 如果是 冲 300 则是 2 + 20 List<String> ruleList = new ArrayList<String>(); for(String str : me.getValue().split(",")){ ruleList.add(str); } BigDecimal ps = paySend(money,ruleList); me.setPaySend(ps); //查询各特权使用记录 MemberRankFreedomLogRepModel memberRankFreedomLogRep =new MemberRankFreedomLogRepModel(); memberRankFreedomLogRep.setMemberId(me.getMemberId()); memberRankFreedomLogRep.setRoleId(me.getRoleId()); memberRankFreedomLogRep.setFreedomId(me.getFreedomId()); if(me.getTimeRang().equals("rang")){ memberRankFreedomLogRep.setOverTime(me.getEndTime()); } HashMap ma = memberRankFreedomLogRepModelService.sumUserLog( memberRankFreedomLogRep); if(ma!=null){ logger.debug(ma.get("use_num")+"=============="+ma.get("money")); //如果超过 判断是周期/限制使用次数 /限制优惠金额 则此特权无效 if( (me.getUseNum() > 0 && Double.valueOf(ma.get("use_num").toString()) >= me.getUseNum()) || (me.getMemberQuota()!=null && me.getMemberQuota().compareTo(BigDecimal.valueOf(Double.valueOf(ma.get("money").toString()))) <= 0 )){ return super.returnCorrectResult("查询会员的特权列表成功!"); }else{ me.setMemberQuota(BigDecimal.valueOf(Double.valueOf(ma.get("use_num")==null || ma.get("use_num").equals("")?"0":ma.get("use_num").toString()))); me.setMemberUseNum(BigDecimal.valueOf(Double.valueOf(ma.get("money")==null || ma.get("money").equals("")?"0":ma.get("money").toString()))); } } return super.returnCorrectResult("查询会员的特权列表成功!",me); } catch (Exception e) { logger.error(e.getMessage(), e); return super.returnException("查询会员的特权列表失败!"); } }
}
<!-- sql --> <select id="getMFListByPay" resultMap="getMemberFreedomListMap" parameterType="MemberFreedomRepModel"> select cc.*,dd.* from (select cc.rank_id,cc.freedom_id,cc.time_rang,cc.begin_time,cc.end_time,cc.long_day,cc.get_time ,rr.role_id from member_rank_freedom_conn cc join (select role_id,rank_id from member_role_conn rr where rr.is_delete ='N' and rr.role_id in <foreach collection="roleIds" open="(" close=")" item="id" separator=","> #{id} </foreach> and member_id = #{memberId} ) rr on cc.rank_id = rr.rank_id where cc.is_delete ='N' and (cc.time_rang = 'all' or (cc.time_rang='rang' and cc.begin_time <= #{noTime} and #{noTime} <=end_time ) ) ) cc join (select ff.* from ( select f2.* from member_freedom f2 where f2.is_delete = 'N' and f2.freedom_type = #{freedomType} ) ff join ( (select max(ff.level) level,ff.freedom_type from member_freedom ff where ff.is_delete = 'N' and ff.freedom_type = #{freedomType} and ff.payment_type_id =#{paymentTypeId} and ff.id in (select cc.freedom_id from member_rank_freedom_conn cc where cc.rank_id in <foreach collection="rankIds" open="(" close=")" item="id" separator=","> #{id} </foreach> and cc.is_delete ='N' and (cc.time_rang = 'all' or (cc.time_rang='rang' and cc.begin_time <= #{noTime} and #{noTime}<=end_time ) ) ) group by ff.freedom_type) ) d1 on ff.freedom_type= d1.freedom_type and ff.level = d1.level ) dd on cc.freedom_id = dd.id </select>
//Mapper层 public List<MemberFreedomRepModel> getMFListByPay(MemberFreedomRepModel memberFreedomRepModel);
//model package com.j1.member.mysql.model; import java.math.BigDecimal; import java.text.Bidi; import java.util.List; import com.j1.member.mysql.entities.MemberFreedomRep; /** * * 特权明细 扩展类 * */ @SuppressWarnings("serial") public class MemberFreedomRepModel extends MemberFreedomRep { private List<Long> roleIds; private List<Long> rankIds; private String noTime; /** 特权ID **/ private Long freedomId; /** 有效时间限制(all/rang) **/ private String timeRang; /** 有效开始时间 **/ private String beginTime; /** 有效结束时间 **/ private String endTime; /** 持续时长(天) **/ private Long longDay; /** 获得时间 **/ private String getTime; /** 等级ID **/ private Long rankId; private String freedomTypeName; private Long roleId; private Long MemberId; private BigDecimal memberQuota; // 已使用限额 private BigDecimal memberUseNum; // 已使用次数 /** 冲值送的金额 */ private BigDecimal paySend = BigDecimal.ZERO; public BigDecimal getPaySend() { return paySend; } public void setPaySend(BigDecimal paySend) { this.paySend = paySend; } public Long getMemberId() { return MemberId; } public void setMemberId(Long memberId) { MemberId = memberId; } public BigDecimal getMemberQuota() { return memberQuota; } public void setMemberQuota(BigDecimal memberQuota) { this.memberQuota = memberQuota; } public BigDecimal getMemberUseNum() { return memberUseNum; } public void setMemberUseNum(BigDecimal memberUseNum) { this.memberUseNum = memberUseNum; } public List<Long> getRoleIds() { return roleIds; } public void setRoleIds(List<Long> roleIds) { this.roleIds = roleIds; } public Long getRoleId() { return roleId; } public void setRoleId(Long roleId) { this.roleId = roleId; } public Long getRankId() { return rankId; } public void setRankId(Long rankId) { this.rankId = rankId; } public Long getFreedomId() { return freedomId; } public void setFreedomId(Long freedomId) { this.freedomId = freedomId; } public String getTimeRang() { return timeRang; } public void setTimeRang(String timeRang) { this.timeRang = timeRang; } public String getBeginTime() { return beginTime; } public void setBeginTime(String beginTime) { this.beginTime = beginTime; } public String getEndTime() { return endTime; } public void setEndTime(String endTime) { this.endTime = endTime; } public Long getLongDay() { return longDay; } public void setLongDay(Long longDay) { this.longDay = longDay; } public String getGetTime() { return getTime; } public void setGetTime(String getTime) { this.getTime = getTime; } public List<Long> getRankIds() { return rankIds; } public void setRankIds(List<Long> rankIds) { this.rankIds = rankIds; } public String getNoTime() { return noTime; } public void setNoTime(String noTime) { this.noTime = noTime; } public String getFreedomTypeName() { return freedomTypeName; } public void setFreedomTypeName(String freedomTypeName) { this.freedomTypeName = freedomTypeName; } }
//测试
@Test public void test11() { MemberService service = J1SOAHessianHelper.getService(url, MemberService.class); MemberModel mm = new MemberModel(); List<Integer> list = new ArrayList<Integer>(); list.add(1851); list.add(1852); list.add(2649); mm.setMemberIdList(list); ServiceMessage<List<Member>> result = service.getMemberNameList(mm); System.out.println(JSON.toJSONString(result)); }