package com.minpay.shouhuo; import com.minpay.common.bean.User; import com.minpay.common.constant.Constant; import com.minpay.common.format.IFormatService; import com.minpay.common.service.ILogService; import com.minpay.common.service.IPublicService; import com.minpay.common.util.RegexUtil; import com.minpay.db.table.mapper.VmGameRuleMapper; import com.minpay.db.table.model.VmGameRule; import com.minpay.db.table.model.VmGameRuleExample; import com.mysql.jdbc.StringUtils; import com.startup.minpay.frame.business.IMINAction; import com.startup.minpay.frame.business.MINHttpServletRequestContext; import com.startup.minpay.frame.business.res.MINActionResult; import com.startup.minpay.frame.constant.IMINBusinessConstant; import com.startup.minpay.frame.constant.IMINTransactionEnum; import com.startup.minpay.frame.data.format.MINCopyFormat; import com.startup.minpay.frame.exception.MINBusinessException; import com.startup.minpay.frame.jdbc.MINRowBounds; import com.startup.minpay.frame.service.base.IMINDataBaseService; import com.startup.minpay.frame.service.base.Service; import com.startup.minpay.frame.session.MINSession; import com.startup.minpay.frame.target.MINAction; import com.startup.minpay.frame.target.MINComponent; import com.startup.minpay.frame.target.MINParam; import com.startup.minpay.frame.target.MINValidator; import com.startup.minpay.util.DateTime; import java.util.List; /** * 游戏规则管理 * @author xbh * */ @MINComponent public class GameSetupManageAction implements IMINAction { public final static String QUERY_GAME_SETUP = "queryGameSetup"; public final static String ADD_GAME_SETUP = "addGameSetup"; public final static String MODIFY_GAME_SETUP = "modifyGameSetup"; public final static String DELETE_GAME_SETUP = "deleteGameSetup"; /** * 查询游戏规则 * @param session * @param page * @param limit * @param name * @param fapRequest * @return * @throws MINBusinessException */ @MINAction(value = QUERY_GAME_SETUP) public MINActionResult queryGameSetup( MINSession session, @MINParam(key = "page", defaultValue = "1") int page, @MINParam(key = "limit", defaultValue = "3") int limit, @MINParam(key = "name") String name, MINHttpServletRequestContext fapRequest ) throws MINBusinessException { User user = session.getUser(); String branch =user.getBranchId(); MINActionResult res = new MINActionResult(); VmGameRuleExample vmGameRuleExample = new VmGameRuleExample(); VmGameRuleExample.Criteria createCriteria = vmGameRuleExample.createCriteria(); createCriteria.andStateNotEqualTo("2"); createCriteria.andMechanismEqualTo(branch); if(!StringUtils.isNullOrEmpty(name)){ createCriteria.andNameEqualTo(name); } MINRowBounds rows = new MINRowBounds(page, limit); // 查询 List ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmGameRuleMapper.class).selectByExample(vmGameRuleExample, rows); ls = new MINCopyFormat("{state:'stateDesc',type:'typeDesc'}").format(ls); ls = Service.lookup(IFormatService.class).formatEnum(ls, "{stateDesc:'GAME_SETUP_STATE',typeDesc:'GAME_SETUP_TYPE'}"); // 格式化 ls = Service.lookup(IFormatService.class).formatDateTime(ls, "createTime"); // 设置返回值 res.set(IMINBusinessConstant.F_PAGING_LAY, ls); res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount()); return res; } /** * 添加充值规则 * @param desc * @param session * @return * @throws MINBusinessException */ @MINAction(value = ADD_GAME_SETUP, transaction = IMINTransactionEnum.CMT) public MINActionResult addGameSetup( @MINParam(key = "name") String name, @MINParam(key = "desc") String desc, @MINParam(key = "alipayid") String alipayid, @MINParam(key = "type") String type, @MINParam(key = "rewardGrade") String rewardGrade, @MINParam(key = "rewardAmtRatio") String rewardAmtRatio, @MINParam(key = "rewardType") String rewardType, @MINParam(key = "jackpotAmt") String jackpotAmt, @MINParam(key = "extractRatio") String extractRatio, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); String branch =user.getBranchId(); VmGameRuleExample vmGameRuleExample = new VmGameRuleExample(); vmGameRuleExample.createCriteria().andTypeEqualTo(type).andStateEqualTo("0").andMechanismEqualTo(branch); List ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmGameRuleMapper.class).selectByExample(vmGameRuleExample); if (ls.size()>0){ throw new MINBusinessException("当前类型已存在"); } if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){ throw new MINBusinessException("此用户没有权限,此操作"); } VmGameRule vmGameRule = new VmGameRule(); //类型为超级大彩蛋时候 if("2".equals(type)){ if(StringUtils.isNullOrEmpty(rewardGrade)||StringUtils.isNullOrEmpty(rewardAmtRatio)){ throw new MINBusinessException("彩蛋等级或中奖金额占比不能为空"); } vmGameRule.setRewardGrade(rewardGrade); vmGameRule.setRewardAmtRatio(rewardAmtRatio); vmGameRule.setRewardType(rewardType); if("0".equals(rewardType)){ if(StringUtils.isNullOrEmpty(jackpotAmt)){ throw new MINBusinessException("奖池金额不能为空"); } vmGameRule.setJackpotAmt(jackpotAmt); }else if("1".equals(rewardType)){ if(StringUtils.isNullOrEmpty(extractRatio)){ throw new MINBusinessException("抽取比例不能为空"); } vmGameRule.setExtractRatio(extractRatio); } } String id = Service.lookup(IPublicService.class).getSequence("GAME_RULE_NO"); String time = new DateTime().toDateTimeString(); id = time.concat(id); vmGameRule.setId(id); vmGameRule.setName(name); vmGameRule.setDesc(desc); vmGameRule.setCreateTime(time); vmGameRule.setAlipayid(alipayid); vmGameRule.setCreateUser(user.getId()); vmGameRule.setType(type); vmGameRule.setMechanism(branch); Service.lookup(IMINDataBaseService.class).insertSelective(VmGameRuleMapper.class, vmGameRule); String logInfo = user.getName()+"-添加游戏规则:" + id; Service.lookup(ILogService.class).logging(session, logInfo); return res; } @MINValidator(value = ADD_GAME_SETUP) public MINActionResult addGameSetupValidator( @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name, @MINParam(key = "type",regex = RegexUtil.NOT_NULL, error = "游戏规则不能为空") String type, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); return res; } /** * 编辑游戏规则 * @param id * @param name * @param desc * @param session * @return * @throws MINBusinessException */ @MINAction(value = MODIFY_GAME_SETUP, transaction = IMINTransactionEnum.CMT) public MINActionResult modifyGameSetup( @MINParam(key = "id") String id, @MINParam(key = "name") String name, @MINParam(key = "desc") String desc, @MINParam(key = "alipayid") String alipayid, @MINParam(key = "rewardGrade") String rewardGrade, @MINParam(key = "rewardAmtRatio") String rewardAmtRatio, @MINParam(key = "rewardType") String rewardType, @MINParam(key = "jackpotAmt") String jackpotAmt, @MINParam(key = "extractRatio") String extractRatio, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){ throw new MINBusinessException("此用户没有权限,此操作"); } VmGameRule vmGameRule = new VmGameRule(); vmGameRule.setId(id); vmGameRule.setRewardGrade(rewardGrade); vmGameRule.setRewardAmtRatio(rewardAmtRatio); vmGameRule.setName(name); vmGameRule.setDesc(desc); vmGameRule.setAlipayid(alipayid); if("0".equals(rewardType)){ if(StringUtils.isNullOrEmpty(jackpotAmt)){ throw new MINBusinessException("奖池金额不能为空"); } vmGameRule.setJackpotAmt(jackpotAmt); }else if("1".equals(rewardType)){ if(StringUtils.isNullOrEmpty(extractRatio)){ throw new MINBusinessException("抽取比例不能为空"); } vmGameRule.setExtractRatio(extractRatio); } vmGameRule.setRewardType(rewardGrade); Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule); String logInfo = user.getName()+"-编辑游戏规则:" + id; Service.lookup(ILogService.class).logging(session, logInfo); return res; } @MINValidator(value = MODIFY_GAME_SETUP) public MINActionResult modifyGameSetupValidator( @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id, @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); return res; } /** * 删除规则 * @param id * @param session * @return * @throws MINBusinessException */ @MINAction(value = DELETE_GAME_SETUP, transaction = IMINTransactionEnum.CMT) public MINActionResult deleteGameSetup( @MINParam(key = "id") String id, @MINParam(key = "state") String state, MINSession session ) throws MINBusinessException { MINActionResult res = new MINActionResult(); User user = session.getUser(); VmGameRule vmGameRule = new VmGameRule(); vmGameRule.setId(id); vmGameRule.setState(state); Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule); String logInfo = user.getName()+"-编辑游戏规则状态:" + id+"状态:"+state; Service.lookup(ILogService.class).logging(session, logInfo); return res; } @MINValidator(value = DELETE_GAME_SETUP) public MINActionResult deleteGameSetupValidator( @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id, @MINParam(key = "state",regex = RegexUtil.NOT_NULL, error = "数据异常") String state, MINSession session) throws MINBusinessException { MINActionResult res = new MINActionResult(); return res; } }