FdkkV4Service.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package com.fdkankan.contro.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  4. import com.fdkankan.contro.common.Result;
  5. import com.fdkankan.contro.entity.ScenePro;
  6. import com.fdkankan.contro.service.ISceneProService;
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.http.HttpStatus;
  12. import org.springframework.http.ResponseEntity;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.util.ObjectUtils;
  15. import org.springframework.web.client.RestTemplate;
  16. @Service
  17. public class FdkkV4Service {
  18. private static final Logger log = LoggerFactory.getLogger(FdkkV4Service.class);
  19. private final String UPGRADE_TO_V4="/api/user/scene/upgradeToV4?num=%s";
  20. @Value("${main.url}")
  21. private String mainUrl;
  22. private RestTemplate restTemplate = new RestTemplate();
  23. @Autowired
  24. private ISceneProService sceneProService;
  25. /**
  26. * 场景升级
  27. * @param num 场景码
  28. * @return
  29. * @throws Exception
  30. */
  31. public void upgradeToV4(String num){
  32. // 如果场景在旧表中存在,则需要升级,否则不需要升级
  33. ScenePro scenePro = sceneProService.getByNum(num);
  34. if(ObjectUtils.isEmpty(scenePro)){
  35. log.error("scene_pro 表中不存在该记录,退出升级!");
  36. return;
  37. }
  38. String url = mainUrl + String.format(UPGRADE_TO_V4,num);
  39. log.info("v3场景升级v4,url:{}",url);
  40. ResponseEntity<Result> responseEntity = restTemplate.getForEntity(url, Result.class);
  41. log.info("v3场景升级v4,url:{},结果,{}",url, JSONObject.toJSONString(responseEntity.getBody()));
  42. if(responseEntity.getStatusCode() != HttpStatus.OK){
  43. log.error("场景升级失败,请稍后再试!");
  44. }
  45. Integer code = responseEntity.getBody().getCode();
  46. if(code != 0){
  47. String msg = "场景升级失败,请稍后再试!";
  48. if(code == 7019){
  49. msg = "场景升级中,请勿重复升级";
  50. }else if(code == 7020){
  51. msg = "场景已升级,不能重复升级";
  52. }
  53. log.error(msg);
  54. return;
  55. }
  56. //修改场景状态为升级中
  57. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  58. wrapper.set(ScenePro::getStatus,0).set(ScenePro::getIsUpgrade,2).eq(ScenePro::getNum,num);
  59. sceneProService.update(wrapper);
  60. }
  61. }