GameSetupManageAction.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. MINActionResult res = new MINActionResult();
  59. VmGameRuleExample vmGameRuleExample = new VmGameRuleExample();
  60. VmGameRuleExample.Criteria createCriteria = vmGameRuleExample.createCriteria();
  61. createCriteria.andStateNotEqualTo("2");
  62. if(!StringUtils.isNullOrEmpty(name)){
  63. createCriteria.andNameEqualTo(name);
  64. }
  65. MINRowBounds rows = new MINRowBounds(page, limit);
  66. // 查询
  67. List<VmGameRule> ls = Service.lookup(IMINDataBaseService.class).getMybatisMapper(VmGameRuleMapper.class).selectByExample(vmGameRuleExample, rows);
  68. ls = new MINCopyFormat("{state:'stateDesc',type:'typeDesc'}").format(ls);
  69. ls = Service.lookup(IFormatService.class).formatEnum(ls, "{stateDesc:'GAME_SETUP_STATE',typeDesc:'GAME_SETUP_TYPE'}");
  70. // 格式化
  71. ls = Service.lookup(IFormatService.class).formatDateTime(ls, "createTime");
  72. // 设置返回值
  73. res.set(IMINBusinessConstant.F_PAGING_LAY, ls);
  74. res.set(IMINBusinessConstant.F_PAGING_COUNT, rows.getCount());
  75. return res;
  76. }
  77. /**
  78. * 添加充值规则
  79. * @param desc
  80. * @param session
  81. * @return
  82. * @throws MINBusinessException
  83. */
  84. @MINAction(value = ADD_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  85. public MINActionResult addGameSetup(
  86. @MINParam(key = "name") String name,
  87. @MINParam(key = "desc") String desc,
  88. @MINParam(key = "alipayid") String alipayid,
  89. @MINParam(key = "type") String type,
  90. @MINParam(key = "rewardGrade") String rewardGrade,
  91. @MINParam(key = "rewardAmtRatio") String rewardAmtRatio,
  92. @MINParam(key = "rewardType") String rewardType,
  93. @MINParam(key = "jackpotAmt") String jackpotAmt,
  94. @MINParam(key = "extractRatio") String extractRatio,
  95. MINSession session) throws MINBusinessException {
  96. MINActionResult res = new MINActionResult();
  97. User user = session.getUser();
  98. if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){
  99. throw new MINBusinessException("此用户没有权限,此操作");
  100. }
  101. VmGameRule vmGameRule = new VmGameRule();
  102. //类型为超级大彩蛋时候
  103. if("2".equals(type)){
  104. if(StringUtils.isNullOrEmpty(rewardGrade)||StringUtils.isNullOrEmpty(rewardAmtRatio)){
  105. throw new MINBusinessException("彩蛋等级或中奖金额占比不能为空");
  106. }
  107. vmGameRule.setRewardGrade(rewardGrade);
  108. vmGameRule.setRewardAmtRatio(rewardAmtRatio);
  109. vmGameRule.setRewardType(rewardType);
  110. if("0".equals(rewardType)){
  111. if(StringUtils.isNullOrEmpty(jackpotAmt)){
  112. throw new MINBusinessException("奖池金额不能为空");
  113. }
  114. vmGameRule.setJackpotAmt(jackpotAmt);
  115. }else if("1".equals(rewardType)){
  116. if(StringUtils.isNullOrEmpty(extractRatio)){
  117. throw new MINBusinessException("抽取比例不能为空");
  118. }
  119. vmGameRule.setExtractRatio(extractRatio);
  120. }
  121. }
  122. String id = Service.lookup(IPublicService.class).getSequence("GAME_RULE_NO");
  123. String time = new DateTime().toDateTimeString();
  124. id = time.concat(id);
  125. vmGameRule.setId(id);
  126. vmGameRule.setName(name);
  127. vmGameRule.setDesc(desc);
  128. vmGameRule.setCreateTime(time);
  129. vmGameRule.setAlipayid(alipayid);
  130. vmGameRule.setCreateUser(user.getId());
  131. vmGameRule.setType(type);
  132. Service.lookup(IMINDataBaseService.class).insertSelective(VmGameRuleMapper.class, vmGameRule);
  133. String logInfo = user.getName()+"-添加游戏规则:" + id;
  134. Service.lookup(ILogService.class).logging(session, logInfo);
  135. return res;
  136. }
  137. @MINValidator(value = ADD_GAME_SETUP)
  138. public MINActionResult addGameSetupValidator(
  139. @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name,
  140. @MINParam(key = "type",regex = RegexUtil.NOT_NULL, error = "游戏规则不能为空") String type,
  141. MINSession session) throws MINBusinessException {
  142. MINActionResult res = new MINActionResult();
  143. return res;
  144. }
  145. /**
  146. * 编辑游戏规则
  147. * @param id
  148. * @param name
  149. * @param desc
  150. * @param session
  151. * @return
  152. * @throws MINBusinessException
  153. */
  154. @MINAction(value = MODIFY_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  155. public MINActionResult modifyGameSetup(
  156. @MINParam(key = "id") String id,
  157. @MINParam(key = "name") String name,
  158. @MINParam(key = "desc") String desc,
  159. @MINParam(key = "alipayid") String alipayid,
  160. @MINParam(key = "rewardGrade") String rewardGrade,
  161. @MINParam(key = "rewardAmtRatio") String rewardAmtRatio,
  162. @MINParam(key = "rewardType") String rewardType,
  163. @MINParam(key = "jackpotAmt") String jackpotAmt,
  164. @MINParam(key = "extractRatio") String extractRatio,
  165. MINSession session
  166. ) throws MINBusinessException {
  167. MINActionResult res = new MINActionResult();
  168. User user = session.getUser();
  169. if(!Constant.ADMINISTRATION_SYSTEM_NUMBER.equals(user.getBranchId())){
  170. throw new MINBusinessException("此用户没有权限,此操作");
  171. }
  172. VmGameRule vmGameRule = new VmGameRule();
  173. vmGameRule.setId(id);
  174. vmGameRule.setRewardGrade(rewardGrade);
  175. vmGameRule.setRewardAmtRatio(rewardAmtRatio);
  176. vmGameRule.setName(name);
  177. vmGameRule.setDesc(desc);
  178. vmGameRule.setAlipayid(alipayid);
  179. if("0".equals(rewardType)){
  180. if(StringUtils.isNullOrEmpty(jackpotAmt)){
  181. throw new MINBusinessException("奖池金额不能为空");
  182. }
  183. vmGameRule.setJackpotAmt(jackpotAmt);
  184. }else if("1".equals(rewardType)){
  185. if(StringUtils.isNullOrEmpty(extractRatio)){
  186. throw new MINBusinessException("抽取比例不能为空");
  187. }
  188. vmGameRule.setExtractRatio(extractRatio);
  189. }
  190. vmGameRule.setRewardType(rewardGrade);
  191. Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule);
  192. String logInfo = user.getName()+"-编辑游戏规则:" + id;
  193. Service.lookup(ILogService.class).logging(session, logInfo);
  194. return res;
  195. }
  196. @MINValidator(value = MODIFY_GAME_SETUP)
  197. public MINActionResult modifyGameSetupValidator(
  198. @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id,
  199. @MINParam(key = "name",regex = RegexUtil.NOT_NULL, error = "名称不能为空") String name,
  200. MINSession session) throws MINBusinessException {
  201. MINActionResult res = new MINActionResult();
  202. return res;
  203. }
  204. /**
  205. * 删除规则
  206. * @param id
  207. * @param session
  208. * @return
  209. * @throws MINBusinessException
  210. */
  211. @MINAction(value = DELETE_GAME_SETUP, transaction = IMINTransactionEnum.CMT)
  212. public MINActionResult deleteGameSetup(
  213. @MINParam(key = "id") String id,
  214. @MINParam(key = "state") String state,
  215. MINSession session
  216. ) throws MINBusinessException {
  217. MINActionResult res = new MINActionResult();
  218. User user = session.getUser();
  219. VmGameRule vmGameRule = new VmGameRule();
  220. vmGameRule.setId(id);
  221. vmGameRule.setState(state);
  222. Service.lookup(IMINDataBaseService.class).updateByPrimaryKeySelective(VmGameRuleMapper.class, vmGameRule);
  223. String logInfo = user.getName()+"-编辑游戏规则状态:" + id+"状态:"+state;
  224. Service.lookup(ILogService.class).logging(session, logInfo);
  225. return res;
  226. }
  227. @MINValidator(value = DELETE_GAME_SETUP)
  228. public MINActionResult deleteGameSetupValidator(
  229. @MINParam(key = "id",regex = RegexUtil.NOT_NULL, error = "数据异常") String id,
  230. @MINParam(key = "state",regex = RegexUtil.NOT_NULL, error = "数据异常") String state,
  231. MINSession session) throws MINBusinessException {
  232. MINActionResult res = new MINActionResult();
  233. return res;
  234. }
  235. }