Administrator
2024-06-19 6f6c6a480d02b7c91e72821e29a937d5927e38cc
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/client/ClientCtrl.java
@@ -8,14 +8,16 @@
import com.dy.pipIrrGlobal.pojoBa.BaClient;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.voSe.VoClient;
import com.dy.pipIrrSell.util.RestTemplateUtil;
import com.dy.pipIrrSell.wechatpay.PayInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
@@ -35,10 +37,23 @@
@Slf4j
@Tag(name = "农户管理", description = "农户操作")
@RestController
@RequestMapping(path="client")
@RequestMapping(path = "client")
@RequiredArgsConstructor
public class ClientCtrl {
    private final ClientSv clientSv;
    //private final RedisUtils redisUtils;
    private final RestTemplateUtil restTemplateUtil;
    private final String privateCertFileName = PayInfo.privateCertFileName;
    private final String appid = PayInfo.appid;
    private final String secret = PayInfo.secret;
    private final String mchid = PayInfo.mchid;
    private final String schema = PayInfo.schema;
    private final String signType = PayInfo.signType;
    private final String description = PayInfo.description;
    private final String loginUrl = PayInfo.loginUrl;
    private final String notifyUrl = PayInfo.notifyUrl;
    private final String grantType = PayInfo.grantType;
    /**
     * 获取农户列表
@@ -62,58 +77,6 @@
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询农户异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 获取交易记录
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页交易记录", description = "返回一页交易记录")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "getOperates")
    @SsoAop()
    public BaseResponse<Map> getOperates(QueryOperate vo){
        try {
           Map res = clientSv.getOperates(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询交易记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
    /**
     * 获取交易汇总记录
     * @param vo
     * @return
     */
    @Operation(summary = "获得一页交易汇总记录", description = "返回一页交易汇总记录")
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
                    description = "返回一页农户数据(BaseResponse.content:QueryResultVo[{}])",
                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
                            schema = @Schema(implementation = BaClient.class))}
            )
    })
    @GetMapping(path = "getStatistics")
    @SsoAop()
    public BaseResponse<Map> getStatistics(QueryStatistic vo){
        try {
            Map res = clientSv.getStatistics(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询交易汇总记录异常", e);
            return BaseResponseUtils.buildException(e.getMessage()) ;
        }
    }
@@ -163,13 +126,13 @@
    @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> add(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid DtoClient po, @Parameter(hidden = true) BindingResult bindingResult){
    public BaseResponse<Boolean> add(@RequestBody @Valid DtoClient po, BindingResult bindingResult) {
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        // 接收村编号(主键)
        Long villageId = po.getVillageid();
        Long villageId = po.getVillageId();
        /**
         * 获取5级行政区划信息
@@ -229,7 +192,7 @@
    }
    /**
     * 生成10为农户编号
     * 生成10位农户编号
     * 1. 到农户表中查询6位区划串开头的最大的农户编号
     * 2. 是否取到记录
     *      2.1 取到
@@ -273,13 +236,13 @@
    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid DtoClient po, @Parameter(hidden = true) BindingResult bindingResult){
    public BaseResponse<Boolean> update(@RequestBody @Valid DtoClient po, BindingResult bindingResult){
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        // 接收村编号(主键)
        Long villageId = po.getVillageid();
        Long villageId = po.getVillageId();
        /**
         * 获取5级行政区划信息
@@ -377,4 +340,53 @@
        }
        return BaseResponseUtils.buildSuccess(map_WaterTypes);
    }
    /**
     * 根据村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);
    }
}