shiqian 3 gadi atpakaļ
vecāks
revīzija
44efe434d7

+ 2 - 1
boman-web-core/src/main/java/com/boman/web/core/controller/CzrkController.java

@@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.UUID;
 
 /**
  * 常住人口Controller
@@ -162,7 +163,7 @@ public class CzrkController extends BaseController {
     /**
      * 外部访问czrk的字段
      */
-    @PostMapping("/getInfo")
+    @GetMapping("/open/getInfo")
     public AjaxResult getInfo(String appKey, String appSecret, String idCard) {
         return czrkService.getInfo(appKey, appSecret, idCard);
     }

+ 2 - 0
boman-web-core/src/main/java/com/boman/web/core/mapper/IpTimesMapper.java

@@ -25,4 +25,6 @@ public interface IpTimesMapper {
     JSONObject getByIp(String ip);
 
     List<JSONObject> getAllColumns(String tableName);
+
+    JSONObject countByUsername(@Param("username") String username, @Param("pwd") String pwd);
 }

+ 38 - 6
boman-web-core/src/main/java/com/boman/web/core/service/czrk/CzrkServiceImpl.java

@@ -192,6 +192,15 @@ public class CzrkServiceImpl implements ICzrkService {
         }
     }
 
+    private void packCzrkJzdzAddr(List<CzrkJzdz> czrkJzdzList) {
+        if (isEmpty(czrkJzdzList)) return;
+        for (CzrkJzdz czrkJzdz : czrkJzdzList) {
+            // 户籍地
+            String province = nullToEmpty(czrkJzdz.getProvince()), city = nullToEmpty(czrkJzdz.getCity()), region = nullToEmpty(czrkJzdz.getRegion()), villageTowns = nullToEmpty(czrkJzdz.getTown()), village = nullToEmpty(czrkJzdz.getVillage()),  nowIn = nullToEmpty(czrkJzdz.getNowIn());
+            czrkJzdz.setNowIn(province + city + region + villageTowns + village + nowIn);
+        }
+    }
+
     private void startPage() {
         PageDomain pageDomain = TableSupport.buildPageRequest();
         Integer pageNum = pageDomain.getPageNum();
@@ -1001,15 +1010,19 @@ public class CzrkServiceImpl implements ICzrkService {
 
     @Override
     public AjaxResult getInfo(String appKey, String appSecret, String idCard) {
-        // checkAuth(appKey, appSecret);
-        String ip = IpUtils.getIpAddr(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        JSONObject jsonObject = ipTimesService.getByIp(ip);
+        checkAuth(appKey, appSecret);
+        checkIdCard(idCard);
+
+//        String ip = IpUtils.getIpAddr(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+//        log.info("调用ip:{}", ip);
+//        JSONObject jsonObject = ipTimesService.getByIp(ip);
+        JSONObject jsonObject = ipTimesService.countByUsername(appKey, appSecret);
         if (jsonObject == null || jsonObject.size() == 0) {
-            String errorMsg = "当前ip非法访问, ip: " + ip;
-            log.error(errorMsg + "appKey:{}, appSecret:{}, idCard:{}", appKey, appSecret, idCard);
-            return AjaxResult.error(errorMsg);
+            log.error("appKey:{}, appSecret:{}, idCard:{}", appKey, appSecret, idCard);
+            return AjaxResult.error("appKey or appSecret is error");
         }
 
+        String ip = jsonObject.getString("ip");
         String today = DateUtils.getDate();
         String redisKey = IP_TIMES + jsonObject.getString("ip") + ":" + today;
         Integer cacheTimes = redisService.getCacheObject(redisKey);
@@ -1028,6 +1041,14 @@ public class CzrkServiceImpl implements ICzrkService {
 
         long time = DateUtils.getTodayEnd().getTime(),time1 = DateUtils.getNowDate().getTime();
         redisService.setCacheObject(redisKey, cacheTimes, ((time - time1) / 1000), TimeUnit.SECONDS);
+        packAddr(Collections.singletonList(czrk));
+
+        CzrkJzdz czrkJzdz = new CzrkJzdz();
+        czrkJzdz.setCzrkId(czrk.getId());
+        List<CzrkJzdz> czrkJzdzList = czrkJzdzService.selectCzrkJzdzList(czrkJzdz);
+        packCzrkJzdzAddr(czrkJzdzList);
+        czrk.setCzrkJzdzList(czrkJzdzList);
+        log.info("appKey:{}, appSecret:{}, idCard:{}, 查询到信息,czrk:{}", appKey, appSecret, idCard, JSON.toJSONString(czrk));
         return AjaxResult.success(czrk);
     }
 
@@ -1038,4 +1059,15 @@ public class CzrkServiceImpl implements ICzrkService {
     private void setIntoRedis(String key, Object result) {
         redisService.setCacheObject(key, result, 1L, TimeUnit.HOURS);
     }
+
+    private void checkAuth(String appKey, String appSecret) {
+        if (isEmpty(appKey) || isEmpty(appSecret) ) {
+            throw new RuntimeException("appKey or appSecret must not be empty");
+        }
+    }
+    private void checkIdCard(String idCard) {
+        if (isEmpty(idCard) ) {
+            throw new RuntimeException("idCard must not be empty");
+        }
+    }
 }

+ 1 - 0
boman-web-core/src/main/java/com/boman/web/core/service/ip/IpTimesService.java

@@ -13,6 +13,7 @@ public interface IpTimesService {
     List<JSONObject> list(String ip, String times);
 
     JSONObject getById(Long id);
+    JSONObject countByUsername(String username, String pwd);
     JSONObject getByIp(String ip);
 
     int saveOrUpdate(JSONObject jsonObject);

+ 5 - 0
boman-web-core/src/main/java/com/boman/web/core/service/ip/IpTimesServiceImpl.java

@@ -32,6 +32,11 @@ public class IpTimesServiceImpl implements IpTimesService {
         return mapper.getById(id);
     }
 
+    @Override
+    public JSONObject countByUsername(String username, String pwd) {
+        return mapper.countByUsername(username, pwd);
+    }
+
     @Override
     public JSONObject getByIp(String ip) {
         return mapper.getByIp(ip);

+ 1 - 1
boman-web-core/src/main/resources/mapper/CzrkMapper.xml

@@ -546,7 +546,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <select id="getColumnNamesByIdCard" resultMap="CzrkResult">
-        SELECT ${columnNames}
+        SELECT id, ${columnNames}
         from czrk
         where id_card = #{idCard} limit 1;
     </select>

+ 4 - 0
boman-web-core/src/main/resources/mapper/IpTimesMapper.xml

@@ -30,6 +30,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         show full columns from czrk;
     </select>
 
+    <select id="countByUsername" resultType="com.alibaba.fastjson.JSONObject">
+        select * from ip_times where username = #{username} and pwd = #{pwd};
+    </select>
+
     <insert id="save">
         insert into ip_times
         <trim prefix="(" suffix=")" suffixOverrides=",">