From 3820d90eda1d95b2265388ff3a329e45511798bd Mon Sep 17 00:00:00 2001 From: JIAL <2287346125@qq.com> Date: Fri, 12 Jan 2024 09:15:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=81=E6=9F=A5=E6=9F=A5=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bizquery/controller/BizController.java | 9 ++-- .../bizquery/controller/BizQccController.java | 22 ++------ .../bizquery/dto/{Biz.java => BizDto.java} | 2 +- .../JIAL/demo/bizquery/entity/QccInfo.java | 28 ++++++++++ .../JIAL/demo/bizquery/mapper/BizMapper.java | 11 +--- .../demo/bizquery/mapper/QccInfoMapper.java | 17 ++++++ .../demo/bizquery/service/BizService.java | 7 +-- .../demo/bizquery/service/QccInfoService.java | 16 ++++++ .../bizquery/service/impl/BizServiceImpl.java | 5 +- .../service/impl/QccInfoServiceImpl.java | 19 +++++++ src/main/java/com/JIAL/utils/JSONHelper.java | 53 +++++++++++++++++++ 11 files changed, 148 insertions(+), 41 deletions(-) rename src/main/java/com/JIAL/demo/bizquery/dto/{Biz.java => BizDto.java} (87%) create mode 100644 src/main/java/com/JIAL/demo/bizquery/entity/QccInfo.java create mode 100644 src/main/java/com/JIAL/demo/bizquery/mapper/QccInfoMapper.java create mode 100644 src/main/java/com/JIAL/demo/bizquery/service/QccInfoService.java create mode 100644 src/main/java/com/JIAL/demo/bizquery/service/impl/QccInfoServiceImpl.java create mode 100644 src/main/java/com/JIAL/utils/JSONHelper.java diff --git a/src/main/java/com/JIAL/demo/bizquery/controller/BizController.java b/src/main/java/com/JIAL/demo/bizquery/controller/BizController.java index 5096864..e64ad0d 100644 --- a/src/main/java/com/JIAL/demo/bizquery/controller/BizController.java +++ b/src/main/java/com/JIAL/demo/bizquery/controller/BizController.java @@ -1,14 +1,13 @@ package com.JIAL.demo.bizquery.controller; import com.JIAL.common.R; -import com.JIAL.demo.bizquery.dto.Biz; +import com.JIAL.demo.bizquery.dto.BizDto; import com.JIAL.demo.bizquery.service.BizService; import com.JIAL.utils.StringUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.HashMap; @@ -31,12 +30,12 @@ public class BizController { BizService bizService; @PostMapping("list") - public R> queryBizList(@RequestParam("name") String name) { + public R> queryBizList(@RequestParam("name") String name) { log.info("开始调用sql----------------------"); log.info(name); log.info(String.valueOf(bizService == null)); - List resultList = bizService.queryBizListByName(name); + List resultList = bizService.queryBizListByName(name); log.info(resultList.toString()); return R.success(resultList); diff --git a/src/main/java/com/JIAL/demo/bizquery/controller/BizQccController.java b/src/main/java/com/JIAL/demo/bizquery/controller/BizQccController.java index dd7b5c5..9ec8828 100644 --- a/src/main/java/com/JIAL/demo/bizquery/controller/BizQccController.java +++ b/src/main/java/com/JIAL/demo/bizquery/controller/BizQccController.java @@ -2,6 +2,7 @@ package com.JIAL.demo.bizquery.controller; import com.JIAL.API.qichacha.QccApiUntils; import com.JIAL.common.R; import com.JIAL.utils.HttpHelper; +import com.JIAL.utils.JSONHelper; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.methods.HttpHead; import org.junit.Test; @@ -43,18 +44,12 @@ public class BizQccController { @PostMapping public R> queryCompanyInfo(@RequestParam("name") String name) { - log.info("Qcc_Key: {}", Qcc_Key); - log.info("Qcc_SecretKey: {}", Qcc_SecretKey); - log.info("Qcc_Url: {}", Qcc_Url); - log.info("unitName: {}", name); - - String paramStr = "searchKey="; String status = ""; // 判断 name 是否为空,避免拼接出现异常,将传入的 if (name != null && !name.isEmpty()) { // 拼接参数字符串 - paramStr += "无锡江南电缆有限公司"; + paramStr += name; } try{ @@ -68,10 +63,10 @@ public class BizQccController { String tokenJson = HttpHelper.httpGet(reqUri, reqHeader.getAllHeaders()); log.info("tokenJson: {}", tokenJson); - status = FormartJson(tokenJson, "Status"); + status = JSONHelper.formartJson(tokenJson, "Status"); log.info("Status:{}", status); if (!QccApiUntils.HttpCodeRegex.isAbnornalRequest(status)) { - PrettyPrintJson(tokenJson); + JSONHelper.prettyPrintJson(tokenJson); } } catch (Exception e1) { @@ -81,13 +76,4 @@ public class BizQccController { return null; } - // 获取当前时间的毫秒级Unix时间戳 - - @Test - public void Test() { - log.info("Qcc_Key: {}", Qcc_Key); - log.info("Qcc_SecretKey: {}", Qcc_SecretKey); - log.info("Qcc_Url: {}", Qcc_Url); - } - } diff --git a/src/main/java/com/JIAL/demo/bizquery/dto/Biz.java b/src/main/java/com/JIAL/demo/bizquery/dto/BizDto.java similarity index 87% rename from src/main/java/com/JIAL/demo/bizquery/dto/Biz.java rename to src/main/java/com/JIAL/demo/bizquery/dto/BizDto.java index f68e928..2cd96cc 100644 --- a/src/main/java/com/JIAL/demo/bizquery/dto/Biz.java +++ b/src/main/java/com/JIAL/demo/bizquery/dto/BizDto.java @@ -12,7 +12,7 @@ import java.io.Serializable; * @Version 1.0 */ @Data -public class Biz implements Serializable { +public class BizDto implements Serializable { private static final long serialVersionUID = 1L; private String kunnr; diff --git a/src/main/java/com/JIAL/demo/bizquery/entity/QccInfo.java b/src/main/java/com/JIAL/demo/bizquery/entity/QccInfo.java new file mode 100644 index 0000000..3e9bbce --- /dev/null +++ b/src/main/java/com/JIAL/demo/bizquery/entity/QccInfo.java @@ -0,0 +1,28 @@ +package com.JIAL.demo.bizquery.entity; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @ClassName QccInfo + * @Description qcc_info表对应的实体类 + * @Author JIAL + * @Date 2024/1/12 8:59 + * @Version 1.0 + */ +@Data +public class QccInfo { + + String name; + + String qccJson; + + @TableField(fill = FieldFill.INSERT) //插入时填充字段 + private LocalDateTime createTime; + + @TableField(fill = FieldFill.INSERT_UPDATE) //插入和更新时填充字段 + private LocalDateTime updateTime; +} diff --git a/src/main/java/com/JIAL/demo/bizquery/mapper/BizMapper.java b/src/main/java/com/JIAL/demo/bizquery/mapper/BizMapper.java index 341411d..13b5af8 100644 --- a/src/main/java/com/JIAL/demo/bizquery/mapper/BizMapper.java +++ b/src/main/java/com/JIAL/demo/bizquery/mapper/BizMapper.java @@ -1,16 +1,9 @@ package com.JIAL.demo.bizquery.mapper; -import com.JIAL.demo.bizquery.dto.Biz; -import com.alibaba.druid.support.logging.LogFactory; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.github.yulichang.base.MPJBaseMapper; +import com.JIAL.demo.bizquery.dto.BizDto; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import org.springframework.stereotype.Service; -import sun.rmi.runtime.Log; import java.util.List; @@ -25,7 +18,7 @@ import java.util.List; @Repository public interface BizMapper { @Select("select kunnr,name1 from openquery(hana2,'select top 10 * from SAPHANADB.kna1 where name1 like ''%${name}%'' and name1 not like ''冻结''')") - List queryBizListByName(String name); + List queryBizListByName(String name); @Select("select * from openquery(hana2,'select max(erdat) from SAPHANADB.likp where kunnr = ''${kunnr}'' and erdat >= ''${time}''')") String queryLatestShippingDate(String kunnr, String time); diff --git a/src/main/java/com/JIAL/demo/bizquery/mapper/QccInfoMapper.java b/src/main/java/com/JIAL/demo/bizquery/mapper/QccInfoMapper.java new file mode 100644 index 0000000..3d10204 --- /dev/null +++ b/src/main/java/com/JIAL/demo/bizquery/mapper/QccInfoMapper.java @@ -0,0 +1,17 @@ +package com.JIAL.demo.bizquery.mapper; + +import com.JIAL.demo.bizquery.entity.QccInfo; +import com.github.yulichang.base.MPJBaseMapper; +import org.apache.ibatis.annotations.Mapper; + +/** + * @ClassName QccInfoMapper + * @Description TODO + * @Author JIAL + * @Date 2024/1/12 9:06 + * @Version 1.0 + */ +@Mapper +public interface QccInfoMapper extends MPJBaseMapper { + +} diff --git a/src/main/java/com/JIAL/demo/bizquery/service/BizService.java b/src/main/java/com/JIAL/demo/bizquery/service/BizService.java index 4b25026..4d8ebc3 100644 --- a/src/main/java/com/JIAL/demo/bizquery/service/BizService.java +++ b/src/main/java/com/JIAL/demo/bizquery/service/BizService.java @@ -1,9 +1,6 @@ package com.JIAL.demo.bizquery.service; -import com.JIAL.demo.bizquery.dto.Biz; -import com.github.yulichang.base.MPJBaseService; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; +import com.JIAL.demo.bizquery.dto.BizDto; import java.util.List; @@ -16,7 +13,7 @@ import java.util.List; */ public interface BizService { - List queryBizListByName(String name); + List queryBizListByName(String name); String queryLatestShippingDate(String kunnr, String time); diff --git a/src/main/java/com/JIAL/demo/bizquery/service/QccInfoService.java b/src/main/java/com/JIAL/demo/bizquery/service/QccInfoService.java new file mode 100644 index 0000000..dfd030f --- /dev/null +++ b/src/main/java/com/JIAL/demo/bizquery/service/QccInfoService.java @@ -0,0 +1,16 @@ +package com.JIAL.demo.bizquery.service; + +import com.JIAL.demo.bizquery.entity.QccInfo; +import com.github.yulichang.base.MPJBaseService; + +/** + * @ClassName QccInfoService + * @Description TODO + * @Author JIAL + * @Date 2024/1/12 9:05 + * @Version 1.0 + */ +public interface QccInfoService extends MPJBaseService { + + +} diff --git a/src/main/java/com/JIAL/demo/bizquery/service/impl/BizServiceImpl.java b/src/main/java/com/JIAL/demo/bizquery/service/impl/BizServiceImpl.java index f9a368f..72b4730 100644 --- a/src/main/java/com/JIAL/demo/bizquery/service/impl/BizServiceImpl.java +++ b/src/main/java/com/JIAL/demo/bizquery/service/impl/BizServiceImpl.java @@ -1,9 +1,8 @@ package com.JIAL.demo.bizquery.service.impl; -import com.JIAL.demo.bizquery.dto.Biz; +import com.JIAL.demo.bizquery.dto.BizDto; import com.JIAL.demo.bizquery.mapper.BizMapper; import com.JIAL.demo.bizquery.service.BizService; -import com.github.yulichang.base.MPJBaseServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -30,7 +29,7 @@ public class BizServiceImpl implements BizService { * @return: java.util.List */ @Override - public List queryBizListByName(String name) { + public List queryBizListByName(String name) { return bizMapper.queryBizListByName(name); } diff --git a/src/main/java/com/JIAL/demo/bizquery/service/impl/QccInfoServiceImpl.java b/src/main/java/com/JIAL/demo/bizquery/service/impl/QccInfoServiceImpl.java new file mode 100644 index 0000000..69dcdf5 --- /dev/null +++ b/src/main/java/com/JIAL/demo/bizquery/service/impl/QccInfoServiceImpl.java @@ -0,0 +1,19 @@ +package com.JIAL.demo.bizquery.service.impl; + +import com.JIAL.demo.bizquery.entity.QccInfo; +import com.JIAL.demo.bizquery.mapper.QccInfoMapper; +import com.JIAL.demo.bizquery.service.QccInfoService; +import com.github.yulichang.base.MPJBaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @ClassName QccInfoServiceImpl + * @Description TODO + * @Author JIAL + * @Date 2024/1/12 9:05 + * @Version 1.0 + */ +@Service +public class QccInfoServiceImpl extends MPJBaseServiceImpl implements QccInfoService { + +} diff --git a/src/main/java/com/JIAL/utils/JSONHelper.java b/src/main/java/com/JIAL/utils/JSONHelper.java new file mode 100644 index 0000000..e5c2c2f --- /dev/null +++ b/src/main/java/com/JIAL/utils/JSONHelper.java @@ -0,0 +1,53 @@ +package com.JIAL.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.json.JSONException; +import org.json.JSONObject; + +import static java.lang.System.out; + +/** + * @ClassName JSONHelper + * @Description JSON字符串工具类 + * @Author JIAL + * @Date 2024/1/12 8:07 + * @Version 1.0 + */ +@Slf4j +public class JSONHelper { + /** + * @title FormartJson + * @description 获取JSON中对应key的Value值 + * @author JIAL + * @param: jsonString + * @param: key + * @updateTime 2024/1/12 8:08 + * @return: java.lang.String + */ + public static String formartJson(String jsonString, String key) throws JSONException { + JSONObject jObject = new JSONObject(jsonString); + return (String) jObject.get(key); + } + + /** + * @title PrettyPrintJson + * @description 控制台和日志打印格式化的JSON字符串 + * @author JIAL + * @param: jsonString + * @updateTime 2024/1/12 8:08 + */ + public static void prettyPrintJson(String jsonString) throws JSONException { + try { + ObjectMapper mapper = new ObjectMapper(); + Object obj = mapper.readValue(jsonString, Object.class); + String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(obj); + out.println(indented); + log.info("Qcc result tokenJson: {}", indented); + + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } +}