1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.qmth.distributed.print.api;
- import com.alibaba.fastjson.JSONObject;
- import com.qmth.boot.api.annotation.Aac;
- import com.qmth.boot.api.annotation.BOOL;
- import com.qmth.boot.api.constant.ApiConstant;
- import com.qmth.boot.api.exception.ApiException;
- import com.qmth.distributed.print.business.bean.result.CalculateNotifyResult;
- import com.qmth.teachcloud.common.config.DictionaryConfig;
- import com.qmth.teachcloud.common.contant.SystemConstant;
- import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
- import com.qmth.teachcloud.common.util.*;
- import io.swagger.annotations.*;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import java.io.UnsupportedEncodingException;
- import java.net.URLDecoder;
- import java.net.URLEncoder;
- import java.util.Objects;
- import java.util.Optional;
- /**
- * <p>
- * 回调接口前端控制器
- * </p>
- *
- * @author wangliang
- * @since 2022-04-26
- */
- @Api(tags = "回调接口Controller")
- @RestController
- @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.notify}")
- @Validated
- public class NotifyApiController {
- private final static Logger log = LoggerFactory.getLogger(NotifyApiController.class);
- @Resource
- DictionaryConfig dictionaryConfig;
- @ApiOperation(value = "教研分析进度回调")
- @ApiResponses({@ApiResponse(code = 200, message = "教研分析进度回调", response = CalculateNotifyResult.class)})
- @RequestMapping(value = "/analysis/progress", method = RequestMethod.POST)
- @Aac(auth = BOOL.FALSE)
- public Result analysisProgress(@ApiParam(value = "接收教研分析回调数据", required = true) @RequestBody String result) throws UnsupportedEncodingException {
- try {
- log.info("analysis_progress,result:{}", result);
- String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
- log.info("analysis_progress decodeJson:{}", decodeJson);
- String callbackPwd = dictionaryConfig.printOpenDomain().getCallbackPwd();
- Optional.ofNullable(callbackPwd).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("配置文件回调密码为空"));
- String sign = ServletUtil.getRequestAuthorization();
- Optional.ofNullable(sign).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("签名为空"));
- log.info("sign:{}", sign);
- String localSign = URLEncoder.encode(Base64Util.encode(ShaUtils.sha1(callbackPwd + decodeJson)), SystemConstant.CHARSET_NAME);
- log.info("localSign:{}", localSign);
- if (!Objects.equals(localSign, sign)) {
- throw ExceptionResultEnum.ERROR.exception("签名不匹配");
- }
- CalculateNotifyResult calculateNotifyResult = JSONObject.toJavaObject(JSONObject.parseObject(decodeJson), CalculateNotifyResult.class);
- String source = Base64Util.encode(ShaUtils.sha1(calculateNotifyResult.getExamId() + calculateNotifyResult.getCourseCode().toString()));
- log.info("source:{}", source);
- //TODO 此处加批次数据状态更新service方法
- //更新grade_batch(状态和进度)和grade_batch_paper(状态)
- } catch (Exception e) {
- log.error(SystemConstant.LOG_ERROR, e);
- //todo 生成txt文件
- if (e instanceof ApiException) {
- ResultUtil.error((ApiException) e, e.getMessage());
- } else {
- ResultUtil.error(e.getMessage());
- }
- }
- return ResultUtil.ok(System.currentTimeMillis());
- }
- }
|