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 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
|
@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){
|
success = Constants.ONE;
|
r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
|
}catch (Exception e){
|
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){
|
success = Constants.ONE;
|
r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
|
}catch (Exception e){
|
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){
|
success = Constants.ONE;
|
r = ApiResponse.failed(StringUtils.defaultString(e.getMessage(),"操作失败"));
|
}catch (Exception e){
|
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){
|
e.printStackTrace();
|
}
|
}
|
|
}
|