UserVipController.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package com.miaxis.app.controller.userInfo;
  2. import com.miaxis.common.constant.Constants;
  3. import java.security.KeyFactory;
  4. import java.security.PrivateKey;
  5. import java.security.Signature;
  6. import java.security.spec.PKCS8EncodedKeySpec;
  7. import java.util.*;
  8. import com.miaxis.common.utils.PrivateKeyUtil;
  9. import com.miaxis.newgzpt.domain.GzptVideoVip;
  10. import com.miaxis.newgzpt.vo.GzptVideoVipVO;
  11. import com.miaxis.userInfo.dto.UserVipDTO;
  12. import com.miaxis.userInfo.vo.UserVipTFVO;
  13. import com.miaxis.userInfo.vo.UserVipVO;
  14. import io.swagger.annotations.*;
  15. import com.miaxis.common.core.domain.Response;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.web.bind.annotation.GetMapping;
  19. import org.springframework.web.bind.annotation.PostMapping;
  20. import org.springframework.web.bind.annotation.PutMapping;
  21. import org.springframework.web.bind.annotation.DeleteMapping;
  22. import org.springframework.web.bind.annotation.PathVariable;
  23. import org.springframework.web.bind.annotation.RequestBody;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RestController;
  26. import org.springframework.web.bind.annotation.ModelAttribute;
  27. import com.miaxis.common.annotation.Log;
  28. import com.miaxis.common.core.controller.BaseController;
  29. import com.miaxis.common.enums.BusinessTypeEnum;
  30. import com.miaxis.userInfo.domain.UserVip;
  31. import com.miaxis.userInfo.service.IUserVipService;
  32. import com.miaxis.common.utils.poi.ExcelUtil;
  33. import com.miaxis.common.core.page.ResponsePageInfo;
  34. /**
  35. * 【会员信息】Controller
  36. *
  37. * @author miaxis
  38. * @date 2022-06-02
  39. */
  40. @RestController
  41. @RequestMapping(Constants.OPEN_PREFIX + "/userInfo/vip")
  42. @Api(tags = {"【app-会员信息】"})
  43. public class UserVipController extends BaseController {
  44. @Autowired
  45. private IUserVipService userVipService;
  46. /**
  47. * 获取会员信息详细信息
  48. *
  49. * @return
  50. */
  51. @GetMapping(value = "/{userId}")
  52. @ApiOperation("获取会员信息详细信息")
  53. public Response<UserVipVO> getUserInfoByUserId(
  54. @ApiParam(name = "userId", value = "会员信息参数", required = true)
  55. @PathVariable("userId") Long userId
  56. ) throws Exception {
  57. UserVip userVip = userVipService.getUserVipByUserId(userId);
  58. UserVipVO vo = new UserVipVO();
  59. if (userVip != null) {
  60. BeanUtils.copyProperties(userVip, vo);
  61. String sign = getSign(vo.getUserId(),vo.getSubject1(), vo.getSubject2(), vo.getSubject3(),vo.getSubject4(),vo.getSpSubject1(),vo.getSpSubject4());
  62. vo.setSign(sign);
  63. return Response.success(vo);
  64. } else {
  65. return Response.success(vo);
  66. }
  67. }
  68. /**
  69. * 获取会员信息0-1表示
  70. * @return
  71. */
  72. @GetMapping(value = "/info/{userId}")
  73. @ApiOperation("获取会员信息0-1表示")
  74. public Response<UserVipTFVO> getUserVipUserId(
  75. @ApiParam(name = "userId", value = "会员信息参数", required = true)
  76. @PathVariable("userId") Long userId
  77. ) throws Exception {
  78. UserVip userVip = userVipService.getUserVipByUserId(userId);
  79. UserVipTFVO vo = new UserVipTFVO();
  80. if (userVip != null) {
  81. BeanUtils.copyProperties(userVip, vo);
  82. Date now = new Date();
  83. //科一
  84. if(vo.getSubject1()!=null){
  85. if(now.compareTo(vo.getSubject1())>0) { //如果过期
  86. vo.setSubject1Int(0);
  87. } else {
  88. vo.setSubject1Int(1);
  89. }
  90. } else {
  91. vo.setSubject1Int(0);
  92. }
  93. //科二
  94. if(vo.getSubject2()!=null){
  95. if(now.compareTo(vo.getSubject2())>0) { //如果过期
  96. vo.setSubject2Int(0);
  97. } else {
  98. vo.setSubject2Int(1);
  99. }
  100. } else {
  101. vo.setSubject2Int(0);
  102. }
  103. //科三
  104. if(vo.getSubject3()!=null){
  105. if(now.compareTo(vo.getSubject3())>0) { //如果过期
  106. vo.setSubject3Int(0);
  107. } else {
  108. vo.setSubject3Int(1);
  109. }
  110. } else {
  111. vo.setSubject3Int(0);
  112. }
  113. //科四
  114. if(vo.getSubject4()!=null){
  115. if(now.compareTo(vo.getSubject4())>0) { //如果过期
  116. vo.setSubject4Int(0);
  117. } else {
  118. vo.setSubject4Int(1);
  119. }
  120. } else {
  121. vo.setSubject4Int(0);
  122. }
  123. //科一特训包
  124. if(vo.getSpSubject1()!=null){
  125. if(now.compareTo(vo.getSpSubject1())>0) { //如果过期
  126. vo.setSpSubject1Int(0);
  127. } else {
  128. vo.setSpSubject1Int(1);
  129. }
  130. } else {
  131. vo.setSpSubject1Int(0);
  132. }
  133. //科四特训包
  134. if(vo.getSpSubject4()!=null){
  135. if(now.compareTo(vo.getSpSubject4())>0) { //如果过期
  136. vo.setSpSubject4Int(0);
  137. } else {
  138. vo.setSpSubject4Int(1);
  139. }
  140. } else {
  141. vo.setSpSubject4Int(0);
  142. }
  143. String sign = getSignInt(vo.getUserId(),vo.getSubject1(), vo.getSubject2(), vo.getSubject3(),vo.getSubject4(),vo.getSpSubject1(),vo.getSpSubject4(),
  144. vo.getSubject1Int(),vo.getSubject2Int(),vo.getSubject3Int(),vo.getSubject4Int(),vo.getSpSubject1Int(),vo.getSpSubject4Int());
  145. vo.setSign(sign);
  146. return Response.success(vo);
  147. } else {
  148. return Response.success(vo);
  149. }
  150. }
  151. /**
  152. * 删除会员信息
  153. */
  154. @Log(title = "会员信息", businessType = BusinessTypeEnum.DELETE)
  155. @DeleteMapping("/{userId}")
  156. @ApiOperation("删除会员信息")
  157. public Response<Integer> removeByUserId(
  158. @ApiParam(name = "userId", value = "会员信息ids参数", required = true)
  159. @PathVariable Long userId
  160. ) {
  161. Map<String, Object> map = new HashMap<>();
  162. map.put("user_id", userId);
  163. return toResponse(userVipService.removeByMap(map) ? 1 : 0);
  164. }
  165. private String getSign(Long userId, Date subject1, Date subject2, Date subject3, Date subject4, Date spSubject1, Date spSubject4) throws Exception {
  166. String str = userId + "";
  167. if (subject1 != null) {
  168. str += subject1.getTime() + "";
  169. }
  170. if (subject2 != null) {
  171. str += subject2.getTime() + "";
  172. }
  173. if (subject3 != null) {
  174. str += subject3.getTime() + "";
  175. }
  176. if (subject4 != null) {
  177. str += subject4.getTime() + "";
  178. }
  179. if (spSubject1 != null) {
  180. str += spSubject1.getTime() + "";
  181. }
  182. if (subject4 != null) {
  183. str += spSubject4.getTime() + "";
  184. }
  185. // 进行签名服务
  186. Signature signature = Signature.getInstance("SHA256withRSA");
  187. KeyFactory kf = KeyFactory.getInstance("RSA");
  188. PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
  189. signature.initSign(privateKey);
  190. signature.update(str.getBytes("UTF-8"));
  191. byte[] signedData = signature.sign();
  192. return Base64.getEncoder().encodeToString(signedData);
  193. }
  194. private String getSignInt(Long userId, Date subject1, Date subject2, Date subject3, Date subject4, Date spSubject1, Date spSubject4, Integer subject1Int, Integer subject2Int, Integer subject3Int, Integer subject4Int, Integer spSubject1Int, Integer spSubject4Int) throws Exception {
  195. String str = userId + "";
  196. if (subject1 != null) {
  197. str += subject1.getTime() + "";
  198. }
  199. if (subject2 != null) {
  200. str += subject2.getTime() + "";
  201. }
  202. if (subject3 != null) {
  203. str += subject3.getTime() + "";
  204. }
  205. if (subject4 != null) {
  206. str += subject4.getTime() + "";
  207. }
  208. if (spSubject1 != null) {
  209. str += spSubject1.getTime() + "";
  210. }
  211. if (spSubject4 != null) {
  212. str += spSubject4.getTime() + "";
  213. }
  214. if (subject1Int != null) {
  215. str += subject1Int + "";
  216. }
  217. if (subject2Int != null) {
  218. str += subject2Int + "";
  219. }
  220. if (subject3Int != null) {
  221. str += subject3Int + "";
  222. }
  223. if (subject4Int != null) {
  224. str += subject4Int + "";
  225. }
  226. if (spSubject1Int != null) {
  227. str += spSubject1Int + "";
  228. }
  229. if (spSubject4Int != null) {
  230. str += spSubject4Int + "";
  231. }
  232. // 进行签名服务
  233. Signature signature = Signature.getInstance("SHA256withRSA");
  234. KeyFactory kf = KeyFactory.getInstance("RSA");
  235. PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
  236. signature.initSign(privateKey);
  237. signature.update(str.getBytes("UTF-8"));
  238. byte[] signedData = signature.sign();
  239. return Base64.getEncoder().encodeToString(signedData);
  240. }
  241. }