Browse Source

添加同步功能

523096025 4 years ago
parent
commit
83e8d0d506

+ 41 - 6
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/controller/CaptchaController.java

@@ -1,13 +1,20 @@
 package com.huimv.manager.modular.controller;
 
-import cn.dustlight.captcha.annotations.CodeValue;
-import cn.dustlight.captcha.annotations.SendCode;
+
+import com.huimv.manager.exception.RRException;
+import com.huimv.manager.util.VerifyUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.concurrent.TimeUnit;
+
 /**
  * <p>
  * 验证码前端控制器
@@ -21,9 +28,37 @@ import org.springframework.web.bind.annotation.RestController;
 @Slf4j
 public class CaptchaController {
 
+    @Autowired
+    private RedisTemplate<String, String> redisTemplate;
+
+    //    @GetMapping("/send")
+//    @SendCode
+    public void getCaptcha(HttpServletRequest request) {
+
+
+//        log.info(code);
+        String remoteHost = request.getRemoteHost();
+    }
+
     @GetMapping("/send")
-    @SendCode()
-    public void getCaptcha(@CodeValue String code){
-        log.info(code);
+    public void createImg(HttpServletRequest request, HttpServletResponse response)  {
+        try {
+            //设置响应类型,告诉浏览器输出的内容为图片
+            response.setContentType("image/jpeg");
+            //设置响应头信息,告诉浏览器不要缓存此内容
+            response.setHeader("Pragma", "No-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            response.setDateHeader("Expire", 0);
+            VerifyUtil randomValidateCode = new VerifyUtil();
+            //输出验证码图片
+            String code = randomValidateCode.getRandcode(request, response);
+            log.info(code);
+            //将生成的随机验证码存放到redis中
+            String remoteHost = request.getRemoteHost();
+            redisTemplate.opsForValue().set(remoteHost,code,300, TimeUnit.SECONDS);
+        } catch (Exception e) {
+            log.error("获取验证码异常:",e);
+            throw new RRException("获取验证码失败!");
+        }
     }
-}
+}

+ 7 - 0
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/entity/MobileUnit.java

@@ -39,4 +39,11 @@ public class MobileUnit implements Serializable {
     @Column(name = "remark")
     private String remark;
 
+    /**
+     * 接口名称
+     */
+    @ApiModelProperty("接口名称")
+    @Column(name = "api")
+    private String api;
+
 }

+ 2 - 0
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/repository/MobileUnitRepository.java

@@ -26,4 +26,6 @@ public interface MobileUnitRepository extends JpaRepository<MobileUnit, Integer>
 
 
     void deleteMobileUnitByIdIn(@Param("list") List<Integer> list);
+
+    List<MobileUnit> findByShortNameLike(String shortName);
 }

+ 3 - 0
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/repository/MobileUserRepository.java

@@ -16,4 +16,7 @@ public interface MobileUserRepository extends JpaRepository<MobileUser, Integer>
 
     @Query(nativeQuery = true ,value = "select * from mobile_user where user_name like %?1% limit ?2 , ?3")
     List<MobileUser> findAll(String name, Integer startPage, Integer pageSize);
+
+    @Query(nativeQuery = true ,value = "select MAX(id) from mobile_user")
+    Integer findID();
 }

+ 24 - 0
huimv-mobile-video/huimv-manager/src/main/java/com/huimv/manager/modular/service/impl/MobileUserServiceImpl.java

@@ -6,6 +6,7 @@ import com.huimv.manager.enums.AuthExceptionEnum;
 import com.huimv.manager.exception.AuthException;
 import com.huimv.manager.exception.RRException;
 import com.huimv.manager.modular.entity.MobileUser;
+import com.huimv.manager.modular.repository.MobileUnitRepository;
 import com.huimv.manager.modular.repository.MobileUserRepository;
 import com.huimv.manager.modular.service.MobileUserService;
 import com.huimv.manager.result.R;
@@ -17,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.DigestUtils;
 import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestTemplate;
 
 import java.util.HashMap;
 import java.util.List;
@@ -66,6 +68,12 @@ public class MobileUserServiceImpl implements MobileUserService {
     }
 
 
+    @Autowired
+    MobileUnitRepository mobileUnitRepository;
+
+    String ycgApi = mobileUnitRepository.findByShortNameLike("油车港").get(0).getApi();
+    String wyApi = mobileUnitRepository.findByShortNameLike("武义").get(0).getApi();
+    String wjjApi = mobileUnitRepository.findByShortNameLike("王江泾").get(0).getApi();
 
     @Override
     public Result add(MobileUser entity){
@@ -73,6 +81,15 @@ public class MobileUserServiceImpl implements MobileUserService {
             return new Result(10002, ResultStatus.addNull);
         }
         try {
+            RestTemplate restTemplate  = new RestTemplate();
+            Integer id = mobileUserRepository.findID();
+            Integer grantClass = entity.getGrantClass();
+            if (grantClass ==null){
+                return new Result(10000,"msg");
+            }
+            restTemplate.getForEntity(ycgApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
+            restTemplate.getForEntity(wyApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
+            restTemplate.getForEntity(wjjApi+"/video/mobileUser/register?id="+(id+1)+"&password=123456",null);
             mobileUserRepository.save(entity);
             return new Result(10000,ResultStatus.addSuccess);
         }catch (Exception e){
@@ -85,6 +102,13 @@ public class MobileUserServiceImpl implements MobileUserService {
         if (ids == null || ids.length==0){
             return new Result(10002,ResultStatus.deleteNull);
         }
+
+        RestTemplate restTemplate  = new RestTemplate();
+        restTemplate.getForEntity(wjjApi+"/video/mobileUser/remove?ids="+ids,null);
+        restTemplate.getForEntity(wyApi+"/video/mobileUser/remove?ids="+ids,null);
+        restTemplate.getForEntity(ycgApi+"/video/mobileUser/remove?ids="+ids,null);
+
+
         try {
             for (Integer id : ids) {
                 mobileUserRepository.deleteById(id);