wuzeyu
2024-06-06 b81dcbba7174fc935cbe29d867f493d45cc701c5
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;
@@ -47,7 +48,7 @@
@Slf4j
@Tag(name = "农户管理", description = "农户操作")
@RestController
@RequestMapping(path="client")
@RequestMapping(path = "client")
@RequiredArgsConstructor
public class ClientCtrl {
    private final ClientSv clientSv;
@@ -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
@@ -409,6 +459,7 @@
     * @param po
     * @param bindingResult
     * @return
     * @throws IOException
     */
    @Operation(summary = "校验验证码", description = "校验验证码")
    @ApiResponses(value = {
@@ -478,41 +529,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);
        Map map = new HashMap();
        map.put("districtNum", districtNum);
        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()) ;
        }
    }
}