TenantInfoController.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package com.ym.mec.web.controller;
  2. import com.ym.mec.auth.api.client.SysUserFeignService;
  3. import com.ym.mec.auth.api.entity.SysUser;
  4. import com.ym.mec.biz.dal.dto.TenantInfoDto;
  5. import com.ym.mec.biz.dal.entity.TenantContractRecord;
  6. import com.ym.mec.biz.dal.entity.TenantInfo;
  7. import com.ym.mec.biz.dal.entity.TenantProductSumm;
  8. import com.ym.mec.biz.service.TenantInfoSendMsgService;
  9. import com.ym.mec.biz.service.TenantInfoService;
  10. import com.ym.mec.common.controller.BaseController;
  11. import com.ym.mec.common.entity.HttpResponseResult;
  12. import com.ym.mec.common.page.WrapperUtil;
  13. import com.ym.mec.common.tenant.TenantContextHolder;
  14. import com.ym.mec.util.validator.ValidationKit;
  15. import io.swagger.annotations.*;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.http.HttpStatus;
  19. import org.springframework.security.access.prepost.PreAuthorize;
  20. import org.springframework.validation.BindingResult;
  21. import org.springframework.web.bind.annotation.*;
  22. import javax.validation.Valid;
  23. import java.math.BigDecimal;
  24. import java.util.Map;
  25. import java.util.Objects;
  26. import java.util.Optional;
  27. import static com.ym.mec.biz.service.impl.TenantInfoSendMsgServiceImpl.OPEN;
  28. /**
  29. * @author hgw
  30. * Created by 2021-12-07
  31. */
  32. @RequestMapping("tenantInfo")
  33. @Api(tags = "机构管理")
  34. @RestController
  35. public class TenantInfoController extends BaseController {
  36. @Autowired
  37. private TenantInfoService tenantInfoService;
  38. @Autowired
  39. private SysUserFeignService sysUserFeignService;
  40. @Autowired
  41. private TenantInfoSendMsgService tenantInfoSendMsgService;
  42. @ApiOperation("添加机构信息")
  43. @PostMapping(value = "/add")
  44. @PreAuthorize("@pcs.hasPermissions('tenantInfo/add')")
  45. public Object addTenantInfo(@Valid @RequestBody TenantInfoDto dto) {
  46. tenantInfoService.addTenantInfo(dto);
  47. return succeed();
  48. }
  49. @ApiOperation("修改机构信息")
  50. @PostMapping(value = "/update")
  51. @PreAuthorize("@pcs.hasPermissions('tenantInfo/update')")
  52. public Object updateTenantInfo(@Valid @RequestBody TenantInfoDto dto, BindingResult bindingResult) {
  53. ValidationKit.ignoreFields(bindingResult, "productInfo", "config");
  54. tenantInfoService.updateTenantInfo(dto);
  55. return succeed();
  56. }
  57. @ApiOperation("修改机构启用停用状态")
  58. @GetMapping(value = "/opsState/{id}")
  59. @PreAuthorize("@pcs.hasPermissions('tenantInfo/opsState')")
  60. public Object opsState(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id, Integer state) {
  61. Map<String, Object> openPar = tenantInfoService.opsTenantState(id, state);
  62. //有返回密码(第一次开通机构会生成登录密码并返回)就发送邮件及短信提醒
  63. String pw = WrapperUtil.toStr(openPar, "pw");
  64. TenantInfo tenantInfo = (TenantInfo) openPar.get("tenantInfo");
  65. if (StringUtils.isNotBlank(pw) && Objects.nonNull(tenantInfo)) {
  66. Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), pw, "https://online.dayaedu.com"};
  67. tenantInfoSendMsgService.platformSendToAll(OPEN, tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg);
  68. }
  69. return succeed();
  70. }
  71. @ApiOperation("查询单个机构详情")
  72. @GetMapping(value = "/info/{id}")
  73. public Object queryTenantInfo(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) {
  74. return succeed(tenantInfoService.queryTenantInfo(id));
  75. }
  76. @ApiOperation("查询单个机构详情")
  77. @GetMapping(value = "/checkInfo/{id}")
  78. public Object queryTenantInfoCheck(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) {
  79. return succeed(tenantInfoService.queryTenantInfoCheck(id));
  80. }
  81. @ApiOperation("查询机构产品")
  82. @GetMapping(value = "/queryTenantInfoSumm")
  83. public HttpResponseResult<TenantProductSumm> queryTenantInfoProductSumm() {
  84. Integer tenantId = TenantContextHolder.getTenantId();
  85. return succeed(tenantInfoService.queryTenantInfoProductSumm(tenantId));
  86. }
  87. @ApiOperation("查询用户机构信息")
  88. @GetMapping(value = "/queryUserTenantInfo")
  89. public Object queryUserTenantInfo() {
  90. SysUser user = sysUserFeignService.queryUserInfo();
  91. if (user == null || user.getId() == null) {
  92. return failed(HttpStatus.FORBIDDEN, "请登录");
  93. }
  94. return succeed(tenantInfoService.queryTenantInfo(user.getTenantId()));
  95. }
  96. @ApiImplicitParams({
  97. @ApiImplicitParam(name = "search", dataType = "String", value = "关键字"),
  98. @ApiImplicitParam(name = "createdName", dataType = "String", value = "创建人"),
  99. @ApiImplicitParam(name = "payState", dataType = "Integer", value = "支付状态 缴费状态 0未缴费 1已缴费"),
  100. @ApiImplicitParam(name = "state", dataType = "Integer", value = "机构状态 1启动 2停用"),
  101. @ApiImplicitParam(name = "startDate", dataType = "String", value = "开始时间"),
  102. @ApiImplicitParam(name = "endDate", dataType = "String", value = "结束时间"),
  103. @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
  104. @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
  105. })
  106. @ApiOperation("分页查询")
  107. @PostMapping(value = "/queryPage")
  108. @PreAuthorize("@pcs.hasPermissions('tenantInfo/queryPage')")
  109. public Object queryPage(@RequestBody Map<String, Object> param) {
  110. return succeed(tenantInfoService.queryPage(param));
  111. }
  112. @ApiImplicitParams({
  113. @ApiImplicitParam(name = "id", dataType = "Integer", value = "机构id"),
  114. @ApiImplicitParam(name = "type", dataType = "Integer", value = "0开通 1续费"),
  115. @ApiImplicitParam(name = "renewCount", dataType = "Integer", value = "若是续费,则需要传入续费时长"),
  116. })
  117. @ApiOperation("获取机构付款及续费时需要预览的协议")
  118. @GetMapping(value = "/getContract/{id}")
  119. public Object getContract(@PathVariable("id") Integer id, Integer type, Integer renewCount) {
  120. TenantContractRecord.TenantContractRecordEnum en = Optional.ofNullable(type)
  121. .filter(t -> TenantContractRecord.TenantContractRecordEnum.RENEW.getType().equals(t))
  122. .map(t -> TenantContractRecord.TenantContractRecordEnum.RENEW)
  123. .orElse(TenantContractRecord.TenantContractRecordEnum.OPEN);
  124. return succeed(tenantInfoService.getContract(id, en, renewCount));
  125. }
  126. @ApiOperation("机构支付")
  127. @GetMapping(value = "/pay/{id}")
  128. public Object pay(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id) throws Exception {
  129. return succeed(tenantInfoService.tenantOpenPay(id));
  130. }
  131. @ApiOperation("机构续费")
  132. @GetMapping(value = "/renew/{id}")
  133. public Object tenantRenewPay(@ApiParam(value = "机构ID", required = true) @PathVariable("id") Integer id, Integer val) throws Exception {
  134. return succeed(tenantInfoService.tenantRenewPay(id, val));
  135. }
  136. @ApiOperation(value = "机构充值")
  137. @GetMapping("/recharge/{amount}")
  138. @PreAuthorize("@pcs.hasPermissions('tenantInfo/recharge')")
  139. public HttpResponseResult<Map<String, Object>> recharge(
  140. @ApiParam(value = "充值金额", required = true) @PathVariable("amount") Double amount
  141. ) throws Exception {
  142. Integer tenantId = TenantContextHolder.getTenantId();
  143. return succeed(tenantInfoService.recharge(tenantId, new BigDecimal(amount)));
  144. }
  145. @ApiOperation(value = "轮询查询订单状态")
  146. @GetMapping("/rechargeCheck/{orderNo}")
  147. @PreAuthorize("@pcs.hasPermissions('tenantInfo/rechargeCheck')")
  148. public HttpResponseResult<Boolean> rechargeCheck(
  149. @ApiParam(value = "订单号", required = true) @PathVariable("orderNo") String orderNo
  150. ) throws Exception {
  151. return succeed(tenantInfoService.rechargeCheck(orderNo));
  152. }
  153. @ApiOperation(value = "测试临期提醒")
  154. @GetMapping("/testCheck")
  155. public Object testCheck() {
  156. tenantInfoService.checkTenantState();
  157. return succeed();
  158. }
  159. }