北京经济技术开发区经开区虚拟城市项目-【后端】-服务,Poi,企业,地块等定制接口
13693261870
2023-10-05 7809d3861ba70b8751f739d1ddaca3a60109fe1a
添加获取令牌、获取企业信息接口
已修改3个文件
116 ■■■■ 文件已修改
src/main/java/com/smartearth/poiexcel/config/InitConfig.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/controller/EntController.java 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/service/EntService.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/config/InitConfig.java
@@ -26,7 +26,7 @@
    public void run(ApplicationArguments args) {
        // noinspection AlibabaRemoveCommentedCode
        try {
            test();
            //test();
            log.info("***************** 系统启动完毕 *****************" + "\n");
        } catch (Exception ex) {
src/main/java/com/smartearth/poiexcel/controller/EntController.java
@@ -1,6 +1,9 @@
package com.smartearth.poiexcel.controller;
import com.smartearth.poiexcel.entity.EntEntity;
import com.smartearth.poiexcel.entity.ResponseMsg;
import com.smartearth.poiexcel.service.EntService;
import com.smartearth.poiexcel.utils.StringHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
@@ -8,6 +11,9 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
 * 企业控制器
@@ -18,17 +24,49 @@
@RestController
@RequestMapping("/ent")
public class EntController extends BaseController {
    @ApiOperation(value = "查询记录数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "名称", dataType = "String", paramType = "query", required = false, example = "")
    })
    @GetMapping({"/selectCount"})
    public ResponseMsg<Integer> selectCount(String name) {
    @Resource
    EntService entService;
    @ApiOperation(value = "查询令牌")
    @GetMapping({"/selectToken"})
    public ResponseMsg<Object> selectToken() {
        try {
            //Result<TokenResult> rs = new Result<>();
            String token = entService.selectToken();
            return success(StringHelper.isEmpty(token) ? 0 : 1, token);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
    }
            return success(0);
    @ApiOperation(value = "查询企业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌", dataType = "String", paramType = "query", example = ""),
            @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "String", paramType = "query", example = "2023-06-29"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "String", paramType = "query", example = "2023-06-30"),
            @ApiImplicitParam(name = "qylabel", value = "标签", dataType = "Integer", paramType = "query", example = "开业"),
            @ApiImplicitParam(name = "showCount", value = "显示记录数", dataType = "Integer", paramType = "query", example = "10"),
            @ApiImplicitParam(name = "currentPage", value = "当前分页数", dataType = "Integer", paramType = "query", example = "1")
    })
    @GetMapping({"/selectEnts"})
    public ResponseMsg<Object> selectEnts(String token, String startDate, String endDate, String qylabel, Integer showCount, Integer currentPage) {
        try {
            if (StringHelper.isEmpty(token)) {
                token = entService.selectToken();
            }
            if (StringHelper.isEmpty(token)) {
                return fail("查询令牌失败");
            }
            if (null == showCount || showCount < 1) {
                showCount = 10;
            }
            if (null == currentPage || currentPage < 1) {
                currentPage = 1;
            }
            List<EntEntity> list = entService.selectEnts(token, startDate, endDate, qylabel, showCount, currentPage);
            return success(null == list || list.isEmpty() ? 0 : list.size(), list);
        } catch (Exception ex) {
            return fail(ex, -1);
        }
src/main/java/com/smartearth/poiexcel/service/EntService.java
@@ -1,5 +1,7 @@
package com.smartearth.poiexcel.service;
import com.alibaba.fastjson.JSONObject;
import com.smartearth.poiexcel.entity.*;
import com.smartearth.poiexcel.mapper.EntMapper;
import com.smartearth.poiexcel.utils.RestHelper;
import org.apache.commons.logging.Log;
@@ -12,6 +14,7 @@
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -37,17 +40,27 @@
    private final static String generateToken = "%s/yqfwg/app/generateToken";
    private final static String getEntBaseInfo = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&buildDate_startdate=%s&buildDate_enddate=%s&qylabel=%s&showCount=%d&currentPage=%d";
    private final static String getEntBaseInfo = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&showCount=%d&currentPage=%d";
    public String getToken() {
    /**
     * 获取令牌
     */
    public String selectToken() {
        try {
            String url = String.format(generateToken, host);
            Map<String, String> map = new HashMap<>(2);
            Map<String, Object> map = new HashMap<>(2);
            map.put("userName", user);
            map.put("passWord", pwd);
            return null;
            Result rs = postForRest(url, map, Result.class);
            if (null == rs || StaticData.I200 != rs.getCode()) {
                return null;
            }
            TokenResult tr = JSONObject.parseObject(rs.getData(), TokenResult.class);
            return tr.getCtoken();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
@@ -55,6 +68,45 @@
    }
    /**
     * 查询企业
     */
    public List<EntEntity> selectEnts(String token, String startDate, String endDate, String qylabel, Integer showCount, Integer currentPage) {
        try {
            String url = String.format(getEntBaseInfo, host, token, showCount, currentPage);
            if (null != startDate) {
                url += "&buildDate_startdate=" + startDate;
            }
            if (null != endDate) {
                url += "&buildDate_enddate=" + endDate;
            }
            if (null != qylabel) {
                url += "&qylabel=" + qylabel;
            }
            Result rs = getForRest(url, Result.class);
            if (null == rs || StaticData.I200 != rs.getCode()) {
                return null;
            }
            EntResult er = JSONObject.parseObject(rs.getData(), EntResult.class);
            return er.getPd().getList();
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        }
    }
    /**
     * get请求(Rest)
     */
    public <T> T getForRest(String url, Class<T> clazz) {
        RestTemplate rest = RestHelper.getRestTemplate();
        return rest.getForObject(url, clazz);
    }
    /**
     * post请求(Rest)
     */
    public <T> T postForRest(String url, Map<String, Object> map, Class<T> clazz) {