123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- package com.miaxis.app.controller.userInfo;
- import com.miaxis.common.constant.Constants;
- import java.security.KeyFactory;
- import java.security.PrivateKey;
- import java.security.Signature;
- import java.security.spec.PKCS8EncodedKeySpec;
- import java.util.*;
- import com.miaxis.common.utils.PrivateKeyUtil;
- import com.miaxis.newgzpt.domain.GzptVideoVip;
- import com.miaxis.newgzpt.vo.GzptVideoVipVO;
- import com.miaxis.userInfo.dto.UserVipDTO;
- import com.miaxis.userInfo.vo.UserVipTFVO;
- import com.miaxis.userInfo.vo.UserVipVO;
- import io.swagger.annotations.*;
- import com.miaxis.common.core.domain.Response;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.PutMapping;
- import org.springframework.web.bind.annotation.DeleteMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import org.springframework.web.bind.annotation.ModelAttribute;
- import com.miaxis.common.annotation.Log;
- import com.miaxis.common.core.controller.BaseController;
- import com.miaxis.common.enums.BusinessTypeEnum;
- import com.miaxis.userInfo.domain.UserVip;
- import com.miaxis.userInfo.service.IUserVipService;
- import com.miaxis.common.utils.poi.ExcelUtil;
- import com.miaxis.common.core.page.ResponsePageInfo;
- /**
- * 【会员信息】Controller
- *
- * @author miaxis
- * @date 2022-06-02
- */
- @RestController
- @RequestMapping(Constants.OPEN_PREFIX + "/userInfo/vip")
- @Api(tags = {"【app-会员信息】"})
- public class UserVipController extends BaseController {
- @Autowired
- private IUserVipService userVipService;
- /**
- * 获取会员信息详细信息
- *
- * @return
- */
- @GetMapping(value = "/{userId}")
- @ApiOperation("获取会员信息详细信息")
- public Response<UserVipVO> getUserInfoByUserId(
- @ApiParam(name = "userId", value = "会员信息参数", required = true)
- @PathVariable("userId") Long userId
- ) throws Exception {
- UserVip userVip = userVipService.getUserVipByUserId(userId);
- UserVipVO vo = new UserVipVO();
- if (userVip != null) {
- BeanUtils.copyProperties(userVip, vo);
- String sign = getSign(vo.getUserId(),vo.getSubject1(), vo.getSubject2(), vo.getSubject3(),vo.getSubject4(),vo.getSpSubject1(),vo.getSpSubject4());
- vo.setSign(sign);
- return Response.success(vo);
- } else {
- return Response.success(vo);
- }
- }
- /**
- * 获取会员信息0-1表示
- * @return
- */
- @GetMapping(value = "/info/{userId}")
- @ApiOperation("获取会员信息0-1表示")
- public Response<UserVipTFVO> getUserVipUserId(
- @ApiParam(name = "userId", value = "会员信息参数", required = true)
- @PathVariable("userId") Long userId
- ) throws Exception {
- UserVip userVip = userVipService.getUserVipByUserId(userId);
- UserVipTFVO vo = new UserVipTFVO();
- if (userVip != null) {
- BeanUtils.copyProperties(userVip, vo);
- Date now = new Date();
- //科一
- if(vo.getSubject1()!=null){
- if(now.compareTo(vo.getSubject1())>0) { //如果过期
- vo.setSubject1Int(0);
- } else {
- vo.setSubject1Int(1);
- }
- } else {
- vo.setSubject1Int(0);
- }
- //科二
- if(vo.getSubject2()!=null){
- if(now.compareTo(vo.getSubject2())>0) { //如果过期
- vo.setSubject2Int(0);
- } else {
- vo.setSubject2Int(1);
- }
- } else {
- vo.setSubject2Int(0);
- }
- //科三
- if(vo.getSubject3()!=null){
- if(now.compareTo(vo.getSubject3())>0) { //如果过期
- vo.setSubject3Int(0);
- } else {
- vo.setSubject3Int(1);
- }
- } else {
- vo.setSubject3Int(0);
- }
- //科四
- if(vo.getSubject4()!=null){
- if(now.compareTo(vo.getSubject4())>0) { //如果过期
- vo.setSubject4Int(0);
- } else {
- vo.setSubject4Int(1);
- }
- } else {
- vo.setSubject4Int(0);
- }
- //科一特训包
- if(vo.getSpSubject1()!=null){
- if(now.compareTo(vo.getSpSubject1())>0) { //如果过期
- vo.setSpSubject1Int(0);
- } else {
- vo.setSpSubject1Int(1);
- }
- } else {
- vo.setSpSubject1Int(0);
- }
- //科四特训包
- if(vo.getSpSubject4()!=null){
- if(now.compareTo(vo.getSpSubject4())>0) { //如果过期
- vo.setSpSubject4Int(0);
- } else {
- vo.setSpSubject4Int(1);
- }
- } else {
- vo.setSpSubject4Int(0);
- }
- String sign = getSignInt(vo.getUserId(),vo.getSubject1(), vo.getSubject2(), vo.getSubject3(),vo.getSubject4(),vo.getSpSubject1(),vo.getSpSubject4(),
- vo.getSubject1Int(),vo.getSubject2Int(),vo.getSubject3Int(),vo.getSubject4Int(),vo.getSpSubject1Int(),vo.getSpSubject4Int());
- vo.setSign(sign);
- return Response.success(vo);
- } else {
- return Response.success(vo);
- }
- }
- /**
- * 删除会员信息
- */
- @Log(title = "会员信息", businessType = BusinessTypeEnum.DELETE)
- @DeleteMapping("/{userId}")
- @ApiOperation("删除会员信息")
- public Response<Integer> removeByUserId(
- @ApiParam(name = "userId", value = "会员信息ids参数", required = true)
- @PathVariable Long userId
- ) {
- Map<String, Object> map = new HashMap<>();
- map.put("user_id", userId);
- return toResponse(userVipService.removeByMap(map) ? 1 : 0);
- }
- private String getSign(Long userId, Date subject1, Date subject2, Date subject3, Date subject4, Date spSubject1, Date spSubject4) throws Exception {
- String str = userId + "";
- if (subject1 != null) {
- str += subject1.getTime() + "";
- }
- if (subject2 != null) {
- str += subject2.getTime() + "";
- }
- if (subject3 != null) {
- str += subject3.getTime() + "";
- }
- if (subject4 != null) {
- str += subject4.getTime() + "";
- }
- if (spSubject1 != null) {
- str += spSubject1.getTime() + "";
- }
- if (subject4 != null) {
- str += spSubject4.getTime() + "";
- }
- // 进行签名服务
- Signature signature = Signature.getInstance("SHA256withRSA");
- KeyFactory kf = KeyFactory.getInstance("RSA");
- PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
- signature.initSign(privateKey);
- signature.update(str.getBytes("UTF-8"));
- byte[] signedData = signature.sign();
- return Base64.getEncoder().encodeToString(signedData);
- }
- 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 {
- String str = userId + "";
- if (subject1 != null) {
- str += subject1.getTime() + "";
- }
- if (subject2 != null) {
- str += subject2.getTime() + "";
- }
- if (subject3 != null) {
- str += subject3.getTime() + "";
- }
- if (subject4 != null) {
- str += subject4.getTime() + "";
- }
- if (spSubject1 != null) {
- str += spSubject1.getTime() + "";
- }
- if (spSubject4 != null) {
- str += spSubject4.getTime() + "";
- }
- if (subject1Int != null) {
- str += subject1Int + "";
- }
- if (subject2Int != null) {
- str += subject2Int + "";
- }
- if (subject3Int != null) {
- str += subject3Int + "";
- }
- if (subject4Int != null) {
- str += subject4Int + "";
- }
- if (spSubject1Int != null) {
- str += spSubject1Int + "";
- }
- if (spSubject4Int != null) {
- str += spSubject4Int + "";
- }
- // 进行签名服务
- Signature signature = Signature.getInstance("SHA256withRSA");
- KeyFactory kf = KeyFactory.getInstance("RSA");
- PrivateKey privateKey = kf.generatePrivate(new PKCS8EncodedKeySpec(Base64.getDecoder().decode(PrivateKeyUtil.rsaPrivateKey)));
- signature.initSign(privateKey);
- signature.update(str.getBytes("UTF-8"));
- byte[] signedData = signature.sign();
- return Base64.getEncoder().encodeToString(signedData);
- }
- }
|