FdkkV4Service.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. String url = mainUrl + String.format(UPGRADE_TO_V4,num);
  35. log.info("v3场景升级v4,url:{}",url);
  36. ResponseEntity<Result> responseEntity = restTemplate.getForEntity(url, Result.class);
  37. log.info("v3场景升级v4,url:{},结果,{}",url, JSONObject.toJSONString(responseEntity.getBody()));
  38. if(responseEntity.getStatusCode() != HttpStatus.OK){
  39. log.error("场景升级失败,请稍后再试!");
  40. }
  41. Integer code = responseEntity.getBody().getCode();
  42. if(code != 0){
  43. String msg = "场景升级失败,请稍后再试!";
  44. if(code == 7019){
  45. msg = "场景升级中,请勿重复升级";
  46. }else if(code == 7020){
  47. msg = "场景已升级,不能重复升级";
  48. }
  49. log.error(msg);
  50. return;
  51. }
  52. //修改场景状态为升级中
  53. LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
  54. wrapper.set(ScenePro::getIsUpgrade,2).eq(ScenePro::getNum,num);
  55. sceneProService.update(wrapper);
  56. }
  57. }