DzCardsController.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package com.ruoyi.web.controller.dz;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletResponse;
  4. import javax.validation.ValidationException;
  5. import com.ruoyi.common.core.domain.entity.SysUser;
  6. import com.ruoyi.common.enums.ExamType;
  7. import com.ruoyi.common.utils.NumberUtils;
  8. import com.ruoyi.common.utils.SecurityUtils;
  9. import com.ruoyi.dz.domain.DzAgent;
  10. import com.ruoyi.dz.service.IDzAgentService;
  11. import com.ruoyi.enums.CardAction;
  12. import com.ruoyi.enums.CardType;
  13. import com.ruoyi.enums.UserTypeEnum;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiOperation;
  16. import io.swagger.annotations.ApiParam;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.*;
  20. import com.ruoyi.common.annotation.Log;
  21. import com.ruoyi.common.core.controller.BaseController;
  22. import com.ruoyi.common.core.domain.AjaxResult;
  23. import com.ruoyi.common.enums.BusinessType;
  24. import com.ruoyi.dz.domain.DzCards;
  25. import com.ruoyi.dz.service.IDzCardsService;
  26. import com.ruoyi.common.utils.poi.ExcelUtil;
  27. import com.ruoyi.common.core.page.TableDataInfo;
  28. /**
  29. * 学习卡Controller
  30. *
  31. * @author ruoyi
  32. * @date 2025-09-12
  33. */
  34. @RestController
  35. @RequestMapping("/dz/cards")
  36. @Api(tags = "后台-学习卡管理")
  37. public class DzCardsController extends BaseController
  38. {
  39. @Autowired
  40. private IDzCardsService dzCardsService;
  41. @Autowired
  42. private IDzAgentService agentService;
  43. /**
  44. * 查询学习卡列表
  45. */
  46. @PreAuthorize("@ss.hasPermi('dz:cards:list')")
  47. @GetMapping("/list")
  48. @ApiOperation("列表")
  49. public TableDataInfo list(DzCards dzCards)
  50. {
  51. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  52. String userType = sysUser.getUserType();
  53. if(UserTypeEnum.isInstitution(userType)){
  54. dzCards.setDeptId(SecurityUtils.getDeptId());
  55. } else if(UserTypeEnum.isSchool(userType)){
  56. dzCards.setCampusId(sysUser.getUserTypeId());
  57. }
  58. if((UserTypeEnum.isAgent(userType)||UserTypeEnum.isTeacher(userType))&&null==dzCards.getAgentId()){
  59. //代理商及老师只能查看分配给自己的卡
  60. DzAgent agent = agentService.selectDzAgentByUserId(SecurityUtils.getUserId());
  61. if (null!=agent){
  62. if(NumberUtils.isPositive(agent.getParentId())) {
  63. dzCards.setLeafAgentId(agent.getAgentId());
  64. } else {
  65. dzCards.setAgentId(agent.getAgentId());
  66. }
  67. }
  68. }
  69. startPage();
  70. List<DzCards> list = dzCardsService.selectDzCardsList(dzCards);
  71. return getDataTable(list);
  72. }
  73. /**
  74. * 导出学习卡列表
  75. */
  76. @PreAuthorize("@ss.hasPermi('dz:cards:export')")
  77. @Log(title = "学习卡", businessType = BusinessType.EXPORT)
  78. @PostMapping("/export")
  79. public void export(HttpServletResponse response, DzCards dzCards)
  80. {
  81. List<DzCards> list = dzCardsService.selectDzCardsList(dzCards);
  82. ExcelUtil<DzCards> util = new ExcelUtil<DzCards>(DzCards.class);
  83. util.exportExcel(response, list, "学习卡数据");
  84. }
  85. /**
  86. * 获取学习卡详细信息
  87. */
  88. @PreAuthorize("@ss.hasPermi('dz:cards:query')")
  89. @GetMapping(value = "/{cardId}")
  90. @ApiOperation("详情")
  91. public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
  92. {
  93. return success(dzCardsService.selectDzCardsByCardId(cardId));
  94. }
  95. /**
  96. * 新增学习卡
  97. */
  98. @PreAuthorize("@ss.hasPermi('dz:cards:add')")
  99. @Log(title = "学习卡", businessType = BusinessType.INSERT)
  100. @PostMapping
  101. public AjaxResult add(@RequestBody DzCards dzCards)
  102. {
  103. return toAjax(dzCardsService.insertDzCards(dzCards));
  104. }
  105. /**
  106. * 修改学习卡
  107. */
  108. @PreAuthorize("@ss.hasPermi('dz:cards:edit')")
  109. @Log(title = "学习卡", businessType = BusinessType.UPDATE)
  110. @PutMapping
  111. public AjaxResult edit(@RequestBody DzCards dzCards)
  112. {
  113. return toAjax(dzCardsService.updateDzCards(dzCards));
  114. }
  115. /**
  116. * 删除学习卡
  117. */
  118. @PreAuthorize("@ss.hasPermi('dz:cards:remove')")
  119. @Log(title = "学习卡", businessType = BusinessType.DELETE)
  120. @DeleteMapping("/{cardIds}")
  121. public AjaxResult remove(@PathVariable Long[] cardIds)
  122. {
  123. return toAjax(dzCardsService.deleteDzCardsByCardIds(cardIds));
  124. }
  125. @Log(title = "制卡", businessType = BusinessType.INSERT)
  126. @PostMapping("/issueCard")
  127. @ApiOperation("制卡")
  128. public AjaxResult issueCard(@ApiParam("机构") Long institutionId, @ApiParam("卡类型") String type, @ApiParam("数量") Integer count)
  129. {
  130. dzCardsService.issueCard(institutionId, getCardType(institutionId, type), count);
  131. return AjaxResult.success();
  132. }
  133. @Log(title = "分配卡", businessType = BusinessType.INSERT)
  134. @PostMapping("/assignCard")
  135. @ApiOperation("分配卡")
  136. public AjaxResult assignCard(@ApiParam("代理商") @RequestParam Long agentId, @ApiParam("卡类型") String type, @ApiParam(value = "卡类型") Integer cardType,
  137. @ApiParam("开始号") @RequestParam String begin, @ApiParam("结束号") @RequestParam String end,
  138. @ApiParam("省份") @RequestParam(required = false) String location,
  139. @ApiParam("考生类型") @RequestParam(required = false) ExamType examType,
  140. @ApiParam("学校") @RequestParam(required = false) Long schoolId,
  141. @ApiParam("有效天数") @RequestParam(required = false) Integer days)
  142. {
  143. SysUser sysUser = SecurityUtils.getLoginUser().getUser();
  144. DzAgent agent = agentService.selectDzAgentByAgentId(agentId);
  145. CardType ct = getCardType(agent.getDeptId(), null != cardType ? cardType.toString() : type);
  146. if(UserTypeEnum.Agent.getVal().equals(sysUser.getUserType())) { // 代理商分配
  147. if (!sysUser.getUserTypeId().equals(agent.getParentId())) {
  148. throw new ValidationException("只能分配给下级代理");
  149. }
  150. dzCardsService.assignCard(sysUser.getUserTypeId(), agentId, ct, begin, end, location, examType, schoolId, days);
  151. } else if(UserTypeEnum.Institution.getVal().equals(sysUser.getUserType())) { // 机构分配卡给自己的下级
  152. if (!sysUser.getDeptId().equals(agent.getDeptId())) {
  153. throw new ValidationException("只能分配给下级代理");
  154. }
  155. dzCardsService.assignCard(NumberUtils.isPositive(agent.getParentId()) ? agent.getParentId() : agentId, agentId, ct, begin, end, location, examType, schoolId, days);
  156. } else { // 平台指定, TODO 暂只支持二级代理
  157. dzCardsService.assignCard(NumberUtils.isPositive(agent.getParentId()) ? agent.getParentId() : agentId, agentId, ct, begin, end, location, examType, schoolId, days);
  158. }
  159. return AjaxResult.success();
  160. }
  161. @Log(title = "直接开卡", businessType = BusinessType.INSERT)
  162. @PostMapping("/openCard")
  163. @ApiOperation("直接开卡")
  164. public AjaxResult openCard(@ApiParam("代理商") Long agentId, @ApiParam("省份") String location, @ApiParam("学校") Long schoolId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end,
  165. @ApiParam("有效天数") @RequestParam(required = false) Integer days)
  166. {
  167. return AjaxResult.success(dzCardsService.openCard(agentId, location, schoolId, begin, end, days));
  168. }
  169. @Log(title = "分配校区", businessType = BusinessType.INSERT)
  170. @PostMapping("/changeCampus")
  171. @ApiOperation("分配校区")
  172. public AjaxResult changeCampus(@ApiParam("校区") Long campusId, @ApiParam("开始号") String begin, @ApiParam("结束号") String end)
  173. {
  174. return AjaxResult.success(dzCardsService.changeCampus(campusId, begin, end));
  175. }
  176. @Log(title = "修改卡", businessType = BusinessType.UPDATE)
  177. @PostMapping("/changeCard")
  178. @ApiOperation("修改卡 重卡/关卡/支付")
  179. public AjaxResult changeCard(@ApiParam("操作") @RequestParam CardAction action, @ApiParam("卡ID") @RequestParam Long[] cardIds)
  180. {
  181. dzCardsService.changeCard(action, cardIds);
  182. return AjaxResult.success();
  183. }
  184. private CardType getCardType(Long institutionId, String type) {
  185. if(!NumberUtils.isNumeric(type)) {
  186. return CardType.valueOf(type);
  187. }
  188. if(Integer.parseInt(type) == 9) {
  189. return CardType.Experience;
  190. }
  191. return (null == institutionId || institutionId.equals(101L)) ? CardType.Platform : CardType.Dept;
  192. }
  193. }