Administrator
2024-06-17 d83e4be3fe4e5a3c52d70ab36d64584e966c1800
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -13,6 +13,7 @@
import com.dy.pipIrrGlobal.pojoSe.SeCodeVerify;
import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.voSe.VoClient;
import com.dy.pipIrrGlobal.voSe.VoClientWechat;
import com.dy.pipIrrSell.client.dto.CodeVerifyDTO;
import com.dy.pipIrrSell.result.SellResultCode;
import com.dy.pipIrrSell.sms.AliyunSmsSv;
@@ -353,6 +354,55 @@
    }
    /**
     * 根据村ID获取12位行政区划
     * @param villageId
     * @return
     */
    @Operation(summary = "根据村ID获取12位行政区划", description = "根据村ID获取12位行政区划")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @GetMapping(path = "district")
    @SsoAop()
    public BaseResponse<Boolean> getDistrictNum(@RequestParam("villageId") @NotNull(message = "村编号不能为空") Long villageId){
        /**
         * 获取5级行政区划信息
         */
        Map map_districts = Optional.ofNullable(clientSv.getDistrictsByVillageId(villageId)).orElse(new HashMap());
        if(map_districts.size() <= 0) {
            return BaseResponseUtils.buildFail("区划信息有误");
        }
        String provinceNum = map_districts.get("provinceNum").toString();
        String cityNum = map_districts.get("cityNum").toString();
        String countyNum = map_districts.get("countyNum").toString();
        String townNum = map_districts.get("townNum").toString();
        String villageNum = map_districts.get("villageNum").toString();
        // 生成12位5级行政区划编码串及名称串
        Long districtNum = Long.parseLong(provinceNum + cityNum + countyNum + townNum + villageNum);
        //获取项目编码
        String projectNo = clientSv.getItemValue("projectNo");
        //转为int
        Integer projectNo1 = Integer.valueOf(projectNo);
        //转为16进制
//        String projectNo2 = Integer.toHexString(projectNo1);
//        log.info(projectNo2);
        String projectNo3 = String.format("%02x", projectNo1);
        log.info(projectNo3);
        Map map = new HashMap();
        map.put("districtNum", districtNum);
        map.put("projectNo",projectNo3);
        return BaseResponseUtils.buildSuccess(map);
    }
    /**
     * 发送验证码
     * @param phoneNumber
     * @return
@@ -463,6 +513,7 @@
        String sessionKey = job.getString("session_key");
        Long clientId = clientSv.getClientIdByPhone(phoneNumber);
        String SessionId = "";
        if(clientId != null) {
            // 添加微信用户账户记录
            SeOpenId seOpenId = new SeOpenId();
@@ -470,7 +521,11 @@
            seOpenId.setOpenId(openid);
            seOpenId.setSessionKey(sessionKey);
            seOpenId.setCreateTime(new Date());
            Long SessionId = clientSv.addOpenId(seOpenId);
            //Long SessionId = clientSv.addOpenId(seOpenId);
            Long rec = clientSv.addOpenId(seOpenId);
            if(rec != null) {
                SessionId = String.valueOf(rec);
            }
            return BaseResponseUtils.buildSuccess(SessionId);
        } else {
@@ -479,51 +534,53 @@
    }
    /**
     * 根据村ID获取12位行政区划
     * @param villageId
     * 获取农户基本信息,小程序首页使用
     * @param sessionId
     * @return
     */
    @Operation(summary = "根据村ID获取12位行政区划", description = "根据村ID获取12位行政区划")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "操作结果:true:成功,false:失败(BaseResponse.content)",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = Boolean.class))}
            )
    })
    @GetMapping(path = "district")
    @GetMapping(path = "/simple_info")
    @SsoAop()
    public BaseResponse<Boolean> getDistrictNum(@RequestParam("villageId") @NotNull(message = "村编号不能为空") Long villageId){
        /**
         * 获取5级行政区划信息
         */
        Map map_districts = Optional.ofNullable(clientSv.getDistrictsByVillageId(villageId)).orElse(new HashMap());
        if(map_districts.size() <= 0) {
            return BaseResponseUtils.buildFail("区划信息有误");
    public BaseResponse<VoClientWechat> getSimpleClientInfo(@RequestParam Long sessionId){
        try {
            VoClientWechat res = clientSv.getSimpleClientInfo(sessionId, null);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 登录凭证登录
     * @param code 临时登录凭证
     * @return
     */
    @GetMapping(path = "/code_login")
    @SsoAop()
    public BaseResponse<VoClientWechat> codeLogin(@RequestParam String code) throws IOException {
        // 登录凭证校验
        Map<String, Object> queryParams = new HashMap<>();
        queryParams.put("appid", appid);
        queryParams.put("secret", secret);
        queryParams.put("js_code", code);
        queryParams.put("grant_type", grantType);
        Map<String, String> headerParams = new HashMap<>();
        JSONObject job = restTemplateUtil.get(loginUrl, queryParams, headerParams);
        String openId = job.getString("openid");
        if(openId == null) {
            return BaseResponseUtils.buildFail(SellResultCode.LOGIN_FAIL.getMessage());
        }
        String provinceNum = map_districts.get("provinceNum").toString();
        String cityNum = map_districts.get("cityNum").toString();
        String countyNum = map_districts.get("countyNum").toString();
        String townNum = map_districts.get("townNum").toString();
        String villageNum = map_districts.get("villageNum").toString();
        // 生成12位5级行政区划编码串及名称串
        Long districtNum = Long.parseLong(provinceNum + cityNum + countyNum + townNum + villageNum);
        //获取项目编码
        String projectNo = clientSv.getItemValue("projectNo");
        //转为int
        Integer projectNo1 = Integer.valueOf(projectNo);
        //转为16进制
//        String projectNo2 = Integer.toHexString(projectNo1);
//        log.info(projectNo2);
        String projectNo3 = String.format("%02x", projectNo1);
        log.info(projectNo3);
        Map map = new HashMap();
        map.put("districtNum", districtNum);
        map.put("projectNo",projectNo3);
        return BaseResponseUtils.buildSuccess(map);
        try {
            VoClientWechat res = clientSv.getSimpleClientInfo(null, openId);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
}