1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package com.fdkankan.contro.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
- import com.fdkankan.contro.common.Result;
- import com.fdkankan.contro.entity.ScenePro;
- import com.fdkankan.contro.service.ISceneProService;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.http.HttpStatus;
- import org.springframework.http.ResponseEntity;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ObjectUtils;
- import org.springframework.web.client.RestTemplate;
- @Service
- public class FdkkV4Service {
- private static final Logger log = LoggerFactory.getLogger(FdkkV4Service.class);
- private final String UPGRADE_TO_V4="/api/user/scene/upgradeToV4?num=%s";
- @Value("${main.url}")
- private String mainUrl;
- private RestTemplate restTemplate = new RestTemplate();
- @Autowired
- private ISceneProService sceneProService;
- /**
- * 场景升级
- * @param num 场景码
- * @return
- * @throws Exception
- */
- public void upgradeToV4(String num){
- // 如果场景在旧表中存在,则需要升级,否则不需要升级
- ScenePro scenePro = sceneProService.getByNum(num);
- if(ObjectUtils.isEmpty(scenePro)){
- log.error("scene_pro 表中不存在该记录,退出升级!");
- return;
- }
- String url = mainUrl + String.format(UPGRADE_TO_V4,num);
- log.info("v3场景升级v4,url:{}",url);
- ResponseEntity<Result> responseEntity = restTemplate.getForEntity(url, Result.class);
- log.info("v3场景升级v4,url:{},结果,{}",url, JSONObject.toJSONString(responseEntity.getBody()));
- if(responseEntity.getStatusCode() != HttpStatus.OK){
- log.error("场景升级失败,请稍后再试!");
- }
- Integer code = responseEntity.getBody().getCode();
- if(code != 0){
- String msg = "场景升级失败,请稍后再试!";
- if(code == 7019){
- msg = "场景升级中,请勿重复升级";
- }else if(code == 7020){
- msg = "场景已升级,不能重复升级";
- }
- log.error(msg);
- return;
- }
- //修改场景状态为升级中
- LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
- wrapper.set(ScenePro::getStatus,0).set(ScenePro::getIsUpgrade,2).eq(ScenePro::getNum,num);
- sceneProService.update(wrapper);
- }
- }
|