liukangdong
2024-08-07 b0a4d23b83b9cdbdee15263acdd4e7353a8286a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.doumee.api.business;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.api.BaseController;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.biz.zbom.ZbomIAMService;
import com.doumee.biz.zbom.model.IamUpdateRoleModel;
import com.doumee.biz.zbom.model.IamUpdateShopModel;
import com.doumee.biz.zbom.model.IamUpdateUserModel;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.utils.Constants;
import com.doumee.dao.web.reqeust.GenerateQRCodeRequest;
import com.doumee.service.business.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
 
/**
 * @author 江蹄蹄
 * @date 2024/07/04 14:40
 */
@Api(tags = "对外【IAM、PAD端】推送提供接口")
@RestController
@Slf4j
@RequestMapping("/push")
public class PushController extends BaseController {
    @Autowired
    private ZbomIAMService zbomIAMService;
    @Autowired
    private UsersService usersService;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @ApiOperation("【IAM】组织信息更新推送")
    @PostMapping("/iam/updateShopInfo")
    public ApiResponse<String> updateShopInfo(@RequestHeader(name = "token") String token,
                                      @RequestHeader(name = "uuid") String uuid ,
                                      @RequestHeader(name = "timestamp") String timestamp,
                                      @RequestBody List<IamUpdateShopModel> shopList,
                                      HttpServletRequest request ) {
        int success = Constants.ZERO;
        ApiResponse<String> r = null;
        try {
            zbomIAMService.updateShopInfo(token,uuid,timestamp,shopList);
            r  = ApiResponse.successIam("操作成功");
        }catch (BusinessException e){
            log.error("【IAM】组织信息更新推送===失败:"+e.getMessage());
            success = Constants.ONE;
            r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
        }catch (Exception e){
            log.error("【IAM】组织信息更新推送===失败:"+e.getMessage());
            e.printStackTrace();
            success = Constants.ONE;
            r = ApiResponse.failed("操作失败");
        }finally {
            zbomIAMService.saveInterfaceLog("/push/iam/updateUserInfo",Constants.ONE,"IAM推送组织信息", token, uuid, timestamp, shopList,success, JSONObject.toJSONString(r));
        }
        return r;
    }
    @ApiOperation("【IAM】人员账号信息更新推送")
    @PostMapping("/iam/updateUserInfo")
    public ApiResponse<String> updateUserInfo(@RequestHeader(name = "token") String token,
                                      @RequestHeader(name = "uuid") String uuid ,
                                      @RequestHeader(name = "timestamp") String timestamp,
                                      @RequestBody IamUpdateUserModel upateUserModel,
                                      HttpServletRequest request) {
        int success = Constants.ZERO;
        ApiResponse<String> r = null;
        try {
            zbomIAMService.updateUserInfo(token,uuid,timestamp,upateUserModel);
            r  = ApiResponse.successIam("操作成功");
        }catch (BusinessException e){
            log.error("【IAM】人员账号信息更新推送===失败:"+e.getMessage());
              success = Constants.ONE;
            r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
        }catch (Exception e){
            log.error("【IAM】人员账号信息更新推送===失败:"+e.getMessage());
            success = Constants.ONE;
            e.getMessage();
            r = ApiResponse.failed("操作失败");
        }finally {
            zbomIAMService.saveInterfaceLog("/push/iam/updateUserInfo",Constants.ONE,"IAM推送人员账号信息", token, uuid, timestamp, upateUserModel,success, JSONObject.toJSONString(r));
        }
        return r;
    }
    @ApiOperation("【IAM】角色信息更新推送")
    @PostMapping("/iam/updateRoleInfo")
    public ApiResponse<String> updateRoleInfo(@RequestHeader(name = "token") String token,
                                      @RequestHeader(name = "uuid") String uuid ,
                                      @RequestHeader(name = "timestamp") String timestamp,
                                      @RequestBody IamUpdateRoleModel upateModel,
                                      HttpServletRequest request) {
        int success = Constants.ZERO;
        ApiResponse<String> r = null;
        try {
            zbomIAMService.updateRoleInfo(token,uuid,timestamp,upateModel);
            r  = ApiResponse.successIam("操作成功");
        }catch (BusinessException e){
            log.error("【IAM】角色信息更新推送===失败:"+e.getMessage());
              success = Constants.ONE;
            r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
        }catch (Exception e){
            log.error("【IAM】角色信息更新推送===失败:"+e.getMessage());
            success = Constants.ONE;
            e.getMessage();
            r = ApiResponse.failed("操作失败");
        }finally {
            zbomIAMService.saveInterfaceLog("/push/iam/updateRoleInfo",Constants.ONE,"IAM推送角色账号信息", token, uuid, timestamp, upateModel,success, JSONObject.toJSONString(r));
        }
        return r;
    }
 
    @PreventRepeat(lockTime = 2000)
    @ApiOperation(value = "生成消费者C端小程序码(可带参数)", notes = "生成消费者C端小程序码,生成业务类型:0:产品;1:案例;2:实景三种对应内容详情页的分享码,签名使用参数APPKEY,请联系系统管理员获取")
    @PostMapping("/pad/getQrCode")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "sign", value = "签名(使用timestamp+appkey进行md5加密)", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Long", name = "timestamp", value = "时间戳(当前时间毫秒,2小时内有效)", required = true),
    })
    public void getQrCode(@RequestParam(value = "sign")String sign,
                          @RequestParam(value = "timestamp")Long timestamp,
                          @RequestBody GenerateQRCodeRequest generateQRCodeRequest, HttpServletResponse response) {
        if(StringUtils.isBlank(sign) || timestamp == null){
            throw  new BusinessException(com.doumee.core.constants.ResponseStatus.BAD_REQUEST);
        }
        String interfaceKey = systemDictDataBiz.queryByCode(Constants.ZBOM,Constants.ZBOM_PAD_INTERFACE_KEY).getCode();
        //判断时间戳是否超过两小时
        if(System.currentTimeMillis()-timestamp > 2 * 60 * 3600 * 1000){
            throw new BusinessException(com.doumee.core.constants.ResponseStatus.NOT_ALLOWED.getCode(),"token已失效!");
        }
        String token = DigestUtils.md5Hex(timestamp+interfaceKey);
        if(!token.equals(sign)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token已失效!");
        }
        try{
            response.setHeader("Cache-Control", "no-store, no-cache");
            response.setContentType("image/jpeg");
            InputStream inputStream = usersService.getQrCode(generateQRCodeRequest);
            ImageIO.write(ImageIO.read(inputStream),"png",response.getOutputStream());
        }catch (Exception e){
            log.error("生成消费者C端小程序码===失败:"+e.getMessage());
            e.printStackTrace();
        }
    }
 
}