GameSetupManageAction.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. package com.minpay.shouhuo;
  2. import com.minpay.common.bean.User;
  3. import com.minpay.common.constant.Constant;
  4. import com.minpay.common.format.IFormatService;
  5. import com.minpay.common.service.ILogService;
  6. import com.minpay.common.service.IPublicService;
  7. import com.minpay.common.util.RegexUtil;
  8. import com.minpay.db.table.mapper.VmGameRuleMapper;
  9. import com.minpay.db.table.model.VmGameRule;
  10. import com.minpay.db.table.model.VmGameRuleExample;
  11. import com.mysql.jdbc.StringUtils;
  12. import com.startup.minpay.frame.business.IMINAction;
  13. import com.startup.minpay.frame.business.MINHttpServletRequestContext;
  14. import com.startup.minpay.frame.business.res.MINActionResult;
  15. import com.startup.minpay.frame.constant.IMINBusinessConstant;
  16. import com.startup.minpay.frame.constant.IMINTransactionEnum;
  17. import com.startup.minpay.frame.data.format.MINCopyFormat;
  18. import com.startup.minpay.frame.exception.MINBusinessException;
  19. import com.startup.minpay.frame.jdbc.MINRowBounds;
  20. import com.startup.minpay.frame.service.base.IMINDataBaseService;
  21. import com.startup.minpay.frame.service.base.Service;
  22. import com.startup.minpay.frame.session.MINSession;
  23. import com.startup.minpay.frame.target.MINAction;
  24. import com.startup.minpay.frame.target.MINComponent;
  25. import com.startup.minpay.frame.target.MINParam;
  26. import com.startup.minpay.frame.target.MINValidator;
  27. import com.startup.minpay.util.DateTime;
  28. import java.util.List;
  29. /**
  30. * 游戏规则管理
  31. * @author xbh
  32. *
  33. */
  34. @MINComponent
  35. public class GameSetupManageAction implements IMINAction {
  36. public final static String QUERY_GAME_SETUP = "queryGameSetup";
  37. public final static String ADD_GAME_SETUP = "addGameSetup";
  38. public final static String MODIFY_GAME_SETUP = "modifyGameSetup";
  39. public final static String DELETE_GAME_SETUP = "deleteGameSetup";
  40. /**
  41. * 查询游戏规则
  42. * @param session
  43. * @param page
  44. * @param limit
  45. * @param name
  46. * @param fapRequest
  47. * @return
  48. * @throws MINBusinessException
  49. */
  50. @MINAction(value = QUERY_GAME_SETUP)
  51. public MINActionResult queryGameSetup(
  52. MINSession session,
  53. @MINParam(key = "page", defaultValue = "1") int page,
  54. @MINParam(key = "limit", defaultValue = "3") int limit,
  55. @MINParam(key = "name") String name,
  56. MINHttpServletRequestContext fapRequest
  57. ) throws MINBusinessException {
  58. User user = session.getUser();
  59. String branch =user.getBranchId();
  60. MINActionResult res = new MINActionResult();
  61. VmGameRuleExample vmGameRuleExample = new VmGameRuleExample();
  62. VmGameRuleExample.Criteria createCriteria = vmGameRuleExample.createCriteria();
  63. createCriteria.andStateNotEqualTo("2");
  64. createCriteria.andMechanismEqualTo(branch);
  65. if(!StringUtils.isNullOrEmpty(name)){
  66. createCriteria.andNameEqualTo(name);
  67. }
  68. MINRowBounds rows = new MINRowBounds(page, limit);
  69. // 查询
  70. List<VmGameRule> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmGameRuleMapper.class).selectByExample(vmGameRuleExample, rows);
  71. ls = new MINCopyFormat("{state:'stateDesc',type:'typeDesc'}").format(ls);
  72. ls = Service.lookup(IFormatService.class).formatEnum(ls, "{stateDesc:'GAME_SETUP_STATE',typeDesc:'GAME_SETUP_TYPE'}");
  73. // 格式化
  74. ls = Service.lookup(IFormatService.class).formatDateTime(ls, "createTime");
  75. // 设置返回值
  76. res.set(IMINBusinessConstant.F_PAGING_LAY, ls);
  77. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  78. return res;
  79. }
  80. /**
  81. * 添加充值规则
  82. * @param desc
  83. * @param session
  84. * @return
  85. * @throws MINBusinessException
  86. */
  87. @MINAction(value = ADD_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  88. public MINActionResult addGameSetup(
  89. @MINParam(key = "name") String name,
  90. @MINParam(key = "desc") String desc,
  91. @MINParam(key = "alipayid") String alipayid,
  92. @MINParam(key = "type") String type,
  93. @MINParam(key = "rewardGrade") String rewardGrade,
  94. @MINParam(key = "rewardAmtRatio") String rewardAmtRatio,
  95. @MINParam(key = "rewardType") String rewardType,
  96. @MINParam(key = "jackpotAmt") String jackpotAmt,
  97. @MINParam(key = "extractRatio") String extractRatio,
  98. MINSession session) throws MINBusinessException {
  99. MINActionResult res = new MINActionResult();
  100. User user = session.getUser();
  101. String branch =user.getBranchId();
  102. VmGameRuleExample vmGameRuleExample = new VmGameRuleExample();
  103. vmGameRuleExample.createCriteria().andTypeEqualTo(type).andStateEqualTo("0").andMechanismEqualTo(branch);
  104. List<VmGameRule> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmGameRuleMapper.class).selectByExample(vmGameRuleExample);
  105. if (ls.size()>0){
  106. throw new MINBusinessException("当前类型已存在");
  107. }
  108. if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){
  109. throw new MINBusinessException("此用户没有权限,此操作");
  110. }
  111. VmGameRule vmGameRule = new VmGameRule();
  112. //类型为超级大彩蛋时候
  113. if("2".equals(type)){
  114. if(StringUtils.isNullOrEmpty(rewardGrade)||StringUtils.isNullOrEmpty(rewardAmtRatio)){
  115. throw new MINBusinessException("彩蛋等级或中奖金额占比不能为空");
  116. }
  117. vmGameRule.setRewardGrade(rewardGrade);
  118. vmGameRule.setRewardAmtRatio(rewardAmtRatio);
  119. vmGameRule.setRewardType(rewardType);
  120. if("0".equals(rewardType)){
  121. if(StringUtils.isNullOrEmpty(jackpotAmt)){
  122. throw new MINBusinessException("奖池金额不能为空");
  123. }
  124. vmGameRule.setJackpotAmt(jackpotAmt);
  125. }else if("1".equals(rewardType)){
  126. if(StringUtils.isNullOrEmpty(extractRatio)){
  127. throw new MINBusinessException("抽取比例不能为空");
  128. }
  129. vmGameRule.setExtractRatio(extractRatio);
  130. }
  131. }
  132. String id = Service.lookup(IPublicService.class).getSequence("GAME_RULE_NO");
  133. String time = new DateTime().toDateTimeString();
  134. id = time.concat(id);
  135. vmGameRule.setId(id);
  136. vmGameRule.setName(name);
  137. vmGameRule.setDesc(desc);
  138. vmGameRule.setCreateTime(time);
  139. vmGameRule.setAlipayid(alipayid);
  140. vmGameRule.setCreateUser(user.getId());
  141. vmGameRule.setType(type);
  142. vmGameRule.setMechanism(branch);
  143. Service.lookup(IMINDataBaseService.class).insertSelective(VmGameRuleMapper.class, vmGameRule);
  144. String logInfo = user.getName()+"-添加游戏规则:" + id;
  145. Service.lookup(ILogService.class).logging(session, logInfo);
  146. return res;
  147. }
  148. @MINValidator(value = ADD_GAME_SETUP)
  149. public MINActionResult addGameSetupValidator(
  150. @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name,
  151. @MINParam(key = "type",regex = RegexUtil.NOT_NULL, error = "游戏规则不能为空") String type,
  152. MINSession session) throws MINBusinessException {
  153. MINActionResult res = new MINActionResult();
  154. return res;
  155. }
  156. /**
  157. * 编辑游戏规则
  158. * @param id
  159. * @param name
  160. * @param desc
  161. * @param session
  162. * @return
  163. * @throws MINBusinessException
  164. */
  165. @MINAction(value = MODIFY_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  166. public MINActionResult modifyGameSetup(
  167. @MINParam(key = "id") String id,
  168. @MINParam(key = "name") String name,
  169. @MINParam(key = "desc") String desc,
  170. @MINParam(key = "alipayid") String alipayid,
  171. @MINParam(key = "rewardGrade") String rewardGrade,
  172. @MINParam(key = "rewardAmtRatio") String rewardAmtRatio,
  173. @MINParam(key = "rewardType") String rewardType,
  174. @MINParam(key = "jackpotAmt") String jackpotAmt,
  175. @MINParam(key = "extractRatio") String extractRatio,
  176. MINSession session
  177. ) throws MINBusinessException {
  178. MINActionResult res = new MINActionResult();
  179. User user = session.getUser();
  180. if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){
  181. throw new MINBusinessException("此用户没有权限,此操作");
  182. }
  183. VmGameRule vmGameRule = new VmGameRule();
  184. vmGameRule.setId(id);
  185. vmGameRule.setRewardGrade(rewardGrade);
  186. vmGameRule.setRewardAmtRatio(rewardAmtRatio);
  187. vmGameRule.setName(name);
  188. vmGameRule.setDesc(desc);
  189. vmGameRule.setAlipayid(alipayid);
  190. if("0".equals(rewardType)){
  191. if(StringUtils.isNullOrEmpty(jackpotAmt)){
  192. throw new MINBusinessException("奖池金额不能为空");
  193. }
  194. vmGameRule.setJackpotAmt(jackpotAmt);
  195. }else if("1".equals(rewardType)){
  196. if(StringUtils.isNullOrEmpty(extractRatio)){
  197. throw new MINBusinessException("抽取比例不能为空");
  198. }
  199. vmGameRule.setExtractRatio(extractRatio);
  200. }
  201. vmGameRule.setRewardType(rewardGrade);
  202. Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule);
  203. String logInfo = user.getName()+"-编辑游戏规则:" + id;
  204. Service.lookup(ILogService.class).logging(session, logInfo);
  205. return res;
  206. }
  207. @MINValidator(value = MODIFY_GAME_SETUP)
  208. public MINActionResult modifyGameSetupValidator(
  209. @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id,
  210. @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name,
  211. MINSession session) throws MINBusinessException {
  212. MINActionResult res = new MINActionResult();
  213. return res;
  214. }
  215. /**
  216. * 删除规则
  217. * @param id
  218. * @param session
  219. * @return
  220. * @throws MINBusinessException
  221. */
  222. @MINAction(value = DELETE_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  223. public MINActionResult deleteGameSetup(
  224. @MINParam(key = "id") String id,
  225. @MINParam(key = "state") String state,
  226. MINSession session
  227. ) throws MINBusinessException {
  228. MINActionResult res = new MINActionResult();
  229. User user = session.getUser();
  230. VmGameRule vmGameRule = new VmGameRule();
  231. vmGameRule.setId(id);
  232. vmGameRule.setState(state);
  233. Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule);
  234. String logInfo = user.getName()+"-编辑游戏规则状态:" + id+"状态:"+state;
  235. Service.lookup(ILogService.class).logging(session, logInfo);
  236. return res;
  237. }
  238. @MINValidator(value = DELETE_GAME_SETUP)
  239. public MINActionResult deleteGameSetupValidator(
  240. @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id,
  241. @MINParam(key = "state",regex = RegexUtil.NOT_NULL, error = "数据异常") String state,
  242. MINSession session) throws MINBusinessException {
  243. MINActionResult res = new MINActionResult();
  244. return res;
  245. }
  246. }