From 6044ac660b623034eaf0d7d8512aff99463458d1 Mon Sep 17 00:00:00 2001 From: guang <guang@guang.com> Date: 星期一, 24 四月 2023 15:34:01 +0800 Subject: [PATCH] 初始 --- src/main/java/com/hx/other/service/controller/InitDataController.java | 196 ++++++++++++++++++++++++++++++++ src/main/java/com/hx/other/service/model/QueryRecord.java | 2 src/main/java/com/hx/other/service/vo/BaseVo.java | 2 src/main/resources/application-local.properties | 2 src/main/resources/application-prod.properties | 2 src/main/java/com/hx/other/service/controller/SqlQueryController.java | 93 ++++++++++++++ pom.xml | 2 src/main/java/com/hx/other/service/model/OrdersTotal.java | 2 8 files changed, 293 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 17c4e88..6a42bf0 100644 --- a/pom.xml +++ b/pom.xml @@ -160,7 +160,7 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> - <mainClass>com.hx.phiappt.PhiPreSysApplication</mainClass> + <mainClass>com.hx.other.service.PhiOtherService</mainClass> <layout>ZIP</layout> <includes> <include> diff --git a/src/main/java/com/hx/other/service/controller/InitDataController.java b/src/main/java/com/hx/other/service/controller/InitDataController.java new file mode 100644 index 0000000..e90d1af --- /dev/null +++ b/src/main/java/com/hx/other/service/controller/InitDataController.java @@ -0,0 +1,196 @@ +package com.hx.other.service.controller; + +import com.hx.common.BaseController; +import com.hx.other.service.model.Employee; +import com.hx.other.service.model.OrdersTotal; +import com.hx.other.service.model.PerformanceInfo; +import com.hx.other.service.model.User; +import com.hx.other.service.service.EmployeeService; +import com.hx.other.service.service.OrdersTotalService; +import com.hx.other.service.service.PerformanceInfoService; +import com.hx.other.service.service.UserService; +import com.hx.resultTool.Result; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.*; + +/** + * @Author: cmg + * @Date: 2023/4/23 15:30 + */ +@RestController +@RequestMapping("/init/data") +public class InitDataController extends BaseController { + + @Resource + private EmployeeService employeeService; + + @Resource + private UserService userService; + + @Resource + private OrdersTotalService ordersTotalService; + + @Resource + private PerformanceInfoService performanceInfoService; + + @RequestMapping("/data") + public Result initData() + { + + String[] XING = new String[]{"璧�", "閽�", "瀛�", "鏉�", "鍛�", "鍚�", "閮�", "鐜�", "鍐�", "闄�", "瑜�", "鍗�", "钂�", "娌�", "闊�", "鏉�", "鏈�", "绉�", "灏�", "璁�"}; + String[] MING = new String[]{"鏅�", "闇�", "纰�", "鍑�", "澶�", "鑿�", "鏇�", "棣�", "鑻�", "鐑�", "鍗�", "姊�", "闆�", "缁�", "鍐�", "钃�", "鐏�", "妲�", "骞�", "瀹�", "涔�", "缈�", "缈�", "椋�", "浠�", "浜�", "姊�", "鏇�", "骞�", "缈�", "姊�", "鐞�", "涔�", "闆�", "涔�", "妗�", "鎱�", "闈�", "灏�", "宀�", "鍒�", "澶�", "娌�", "鑿�", "鍌�", "鐝�", "鏇�", "鏂�", "涔�", "鑿�", "鎯�", "鏂�", "棣�", "瀵�",}; + String[] USER_LEVEL = new String[]{"鍑嗕細鍛�", "鏅崱", "娼滃", "閲戝崱", "閽荤煶鍗�", "閾跺崱", "榛戦捇鍗�"}; + String[] CHANNEL_TYPE = new String[]{"PR娓犻亾", "TMK娓犻亾", "涓夋柟骞冲彴", "浼氬憳", "鍓嶅憳宸�", "鍖荤敓", "澶╃尗", "澶т紬鐐硅瘎", "寰崥", "鎶栭煶", "鏂版哀", "鐖卞皵鍋ュ憳宸�", "绉佸煙", "鐧惧害", "绾汉鍚堜綔", "鑹捐姱鑽�", "璺繃"}; + String[] SHOP_ID = new String[]{"4eefc8a1bfa611ecaeb57cd30a51ed1a", "605e391b620d11ebb06bb8599f4cafbe", "b88e3cd8620d11ebb06bb8599f4cafbe", + "b96aa6d1620d11ebb06bb8599f4cafbe", "bb4e8a7d620d11ebb06bb8599f4cafbe", "cd8b395f945c11ecaeb57cd30a51ed1a"}; + String[] SHOP_NAME = new String[]{"鍖椾含鍏夊崕搴�", "鏂板ぉ鍦板簵", "涓滈摱搴�", "", "鏉窞搴�", "闈欏畨搴�", "鍙ゅ寳搴�"}; + String[] USER_STATUS = new String[]{"active_member", "sleeping_member", "deep_sleep_member"}; + + String[] PROJECT_NAME = new String[]{"鐜诲翱閰�", "Fotona","娴疯彶绉�","鐨","涔旈泤鐧�","OPT"}; + String[] PROJECT_ID = new String[]{"000075ee7afc11ebb06bb8599f4cafbe", "007cc926647911ebb06bb8599f4cafbe","018cbc9e8b9711ebb06bb8599f4cafbe","01abe206620e11ebb06bb8599f4cafbe", + "035d7079647711ebb06bb8599f4cafbe","03b0269b620e11ebb06bb8599f4cafbe"}; + + + Random random = new Random(); + + //鍒濆鍖栭【闂� + Employee employee = new Employee(); + employee.setCnName("鐜嬪皬闆�"); + employeeService.insert(employee); + + int xLen = XING.length; + int mLen = MING.length; + Set<String> set = new HashSet<>(); + List<Employee> employeeList = new ArrayList<Employee>(); + for(int i = 0;i < 30;i ++) + { + employee = new Employee(); + employee.setCnName(XING[random.nextInt(xLen)] + MING[random.nextInt(mLen)]); + + if(set.contains(employee.getCnName())) + { + continue; + } + set.add(employee.getCnName()); + + employeeService.insert(employee); + employeeList.add(employee); + } + + //鍒濆鍖栫敤鎴� + User user; + int ranInt; + Calendar calendar; + List<User> userList = new ArrayList<>(); + set.clear(); + Map<String, User> map = new HashMap<>(); + for(int i = 0;i < 200;i ++) + { + user = new User(); + user.setName(XING[random.nextInt(xLen)] + MING[random.nextInt(mLen)]); + + if(set.contains(user.getName())) + { + continue; + } + set.add(user.getName()); + + user.setGender(random.nextInt(2) + 1); + + ranInt = random.nextInt(employeeList.size()); + user.setHisCorpUserId(employeeList.get(ranInt).getId()); + user.setHisCorpUserName(employeeList.get(ranInt).getCnName()); + user.setUserLevel(USER_LEVEL[random.nextInt(USER_LEVEL.length)]); + user.setChannelType(CHANNEL_TYPE[random.nextInt(CHANNEL_TYPE.length)]); + + ranInt = random.nextInt(SHOP_ID.length); + user.setShopId(SHOP_ID[ranInt]); + user.setShopName(SHOP_NAME[ranInt]); + + user.setUserStatus(USER_STATUS[random.nextInt(USER_STATUS.length)]); + + calendar = Calendar.getInstance(); + calendar.add(Calendar.YEAR, -1); + calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(720) - 360); + + user.setCreateTime(calendar.getTime()); + + userService.insert(user); + + userList.add(user); + map.put(user.getId(), user); + } + + //鍒濆鍖栬鍗� + OrdersTotal ordersTotal; + List<OrdersTotal> ordersTotalList = new ArrayList<>(); + for(int i = 0;i < 10000; i ++) + { + ordersTotal = new OrdersTotal(); + ordersTotal.setActualTotal(BigDecimal.valueOf(random.nextInt(10000))); + ordersTotal.setOrderNo(UUID.randomUUID().toString()); + + user = userList.get(random.nextInt(userList.size())); + ordersTotal.setShopId(user.getShopId()); + ordersTotal.setShopName(user.getShopName()); + ordersTotal.setUserId(user.getId()); + ordersTotal.setUserName(user.getName()); + + calendar = Calendar.getInstance(); + calendar.add(Calendar.YEAR, -1); + calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(720) - 360); + ordersTotal.setCreateTime(calendar.getTime()); + + ordersTotalService.insert(ordersTotal); + + ordersTotalList.add(ordersTotal); + } + + //鍒濆鍖栦笟缁� + PerformanceInfo performanceInfo; + for(int i = 0;i < 10000;i ++) + { + performanceInfo = new PerformanceInfo(); + + ranInt = random.nextInt(ordersTotalList.size()); + ordersTotal = ordersTotalList.get(ranInt); + performanceInfo.setPerformanceTotal(ordersTotal.getActualTotal()); + + user = map.get(ordersTotal.getUserId()); + performanceInfo.setBelongConsultantId(user.getHisCorpUserName()); + performanceInfo.setBelongConsultantId(user.getHisCorpUserId()); + performanceInfo.setUserId(user.getId()); + performanceInfo.setUserName(user.getName()); + + employee = employeeList.get(random.nextInt(employeeList.size())); + performanceInfo.setDeductionDoctorId(employee.getId()); + performanceInfo.setDeductionDoctorName(employee.getCnName()); + + performanceInfo.setDeductionTime(ordersTotal.getCreateTime()); + + employee = employeeList.get(random.nextInt(employeeList.size())); + performanceInfo.setNurseCorpUserId(employee.getId()); + performanceInfo.setNurseCorpUserName(employee.getCnName()); + + ranInt = random.nextInt(SHOP_ID.length); + performanceInfo.setServiceShopId(SHOP_ID[ranInt]); + performanceInfo.setServiceShopName(SHOP_NAME[ranInt]); + + performanceInfo.setCreateTime(ordersTotal.getCreateTime()); + + ranInt = random.nextInt(PROJECT_ID.length); + performanceInfo.setCommonId(PROJECT_ID[ranInt]); + performanceInfo.setCommonName(PROJECT_NAME[ranInt]); + + performanceInfoService.insert(performanceInfo); + } + + return Result.success(); + } + + +} diff --git a/src/main/java/com/hx/other/service/controller/SqlQueryController.java b/src/main/java/com/hx/other/service/controller/SqlQueryController.java index 1d88b38..bc41cd9 100644 --- a/src/main/java/com/hx/other/service/controller/SqlQueryController.java +++ b/src/main/java/com/hx/other/service/controller/SqlQueryController.java @@ -49,16 +49,16 @@ public Result query(@RequestBody(required = false) BaseVo baseVo) { - if(baseVo == null || StringUtils.isEmpty(baseVo.getContent())) + if(baseVo == null || StringUtils.isEmpty(baseVo.getKeyWord())) { throwParamException("璇疯緭鍏ユ煡璇㈡潯浠�"); } QueryRecord queryRecord = new QueryRecord(); - queryRecord.setContent(baseVo.getContent()); + queryRecord.setContent(baseVo.getKeyWord()); //鍏堜粠妯℃澘閲屽尮閰� - String sql = sqlQueryTempService.selectByContent(baseVo.getContent()); + String sql = sqlQueryTempService.selectByContent(baseVo.getKeyWord()); if(StringUtils.isEmpty(sql)) { //璁板綍鍚慳i鏌ヨ鏃剁殑姣鏁� @@ -66,7 +66,7 @@ //妯℃澘閲屾病鏈夛紝浠巃i閲屾煡璇� JSONObject obj = new JSONObject(); - obj.put("msg", baseVo.getContent()); + obj.put("msg", baseVo.getKeyWord()); obj = AiQueryUtil.aiQuery(sqlAiApi, obj); //璁板綍ai杩斿洖鐨勮豹绉掓暟 @@ -134,4 +134,89 @@ return Result.success(sqlVo); } + + @PostMapping("/query/test") + public Result queryTest(@RequestBody(required = false) BaseVo baseVo) + { + + if(baseVo == null || StringUtils.isEmpty(baseVo.getKeyWord())) + { + throwParamException("璇疯緭鍏ユ煡璇㈡潯浠�"); + } + + QueryRecord queryRecord = new QueryRecord(); + queryRecord.setContent(baseVo.getKeyWord()); + + //鍏堜粠妯℃澘閲屽尮閰� + String sql = sqlQueryTempService.selectByContent(baseVo.getKeyWord()); + if(StringUtils.isEmpty(sql)) + { + //璁板綍鍚慳i鏌ヨ鏃剁殑姣鏁� + queryRecord.setQueryTime(Calendar.getInstance().getTimeInMillis()); + + //妯℃澘閲屾病鏈夛紝浠巃i閲屾煡璇� + JSONObject obj = new JSONObject(); + obj.put("msg", baseVo.getKeyWord()); + obj = AiQueryUtil.aiQuery(sqlAiApi, obj); + + //璁板綍ai杩斿洖鐨勮豹绉掓暟 + queryRecord.setAiResultTime(Calendar.getInstance().getTimeInMillis()); + + if(obj != null && 100 == obj.getIntValue("code")) + { + //鍒ゆ柇杩斿洖鏄惁sql + if(obj.getBooleanValue("isSql")) + { + //鏄痵ql + sql = obj.getString("now"); + //璁板綍ai杩斿洖鐨勭粨鏋� + queryRecord.setAiResult(obj.getString("origin")); + + } + + //璁板綍ai鏌ヨ鐨刢ontent + queryRecord.setAiQueryContent(obj.getString("content")); + } + }else{ + queryRecord.setIsFromQuery(BaseEntity.YES); + } + + List<Map<String, Object>> list = null; + if(!StringUtils.isEmpty(sql)) + { + //璁板綍鏌ヨ鐨剆ql + queryRecord.setSqlStr(sql); + + list = AiQueryUtil.jdbcQuery(jdbcTemplate, sql); + + //璁板綍sql鏌ヨ杩斿洖鐨勮豹绉掓暟 + queryRecord.setSqlTime(Calendar.getInstance().getTimeInMillis()); + } + + SqlVo sqlVo = new SqlVo(); + sqlVo.setIsArr(1); + sqlVo.setStatus(StringUtils.isEmpty(sql) ? 0 : 1); + sqlVo.setMsg(list == null ? "鏌ユ棤淇℃伅" : list); + + if(list != null) + { + //褰撹繑鍥炴槸涓粺璁℃暟鍊兼椂锛岀洿鎺ヨ繑鍥炴暟鍊� + if(list.size() == 1) + { + Set<String> set = list.get(0).keySet(); + if(set.size() == 1) { + for (String key : set) { + if (key.toUpperCase().indexOf("COUNT") != -1 || key.toUpperCase().indexOf("SUM") != -1) { + sqlVo.setIsArr(0); + sqlVo.setMsg(list.get(0).get(key)); + } + } + } + } + } + + queryRecordService.insert(queryRecord); + + return Result.success(sqlVo); + } } diff --git a/src/main/java/com/hx/other/service/model/OrdersTotal.java b/src/main/java/com/hx/other/service/model/OrdersTotal.java index 8d24261..6bf4179 100644 --- a/src/main/java/com/hx/other/service/model/OrdersTotal.java +++ b/src/main/java/com/hx/other/service/model/OrdersTotal.java @@ -26,7 +26,7 @@ private String userName; @Unique - @Column(comment = "璁㈠崟缂栧彿锛屼互S寮�澶�, SyyyyMMdd0000000(鍓嶇紑浠庡瓧鍏歌幏鍙�)", length = 32, type = MySqlTypeConstant.VARCHAR,isNull = false) + @Column(comment = "璁㈠崟缂栧彿锛屼互S寮�澶�, SyyyyMMdd0000000(鍓嶇紑浠庡瓧鍏歌幏鍙�)", length = 64, type = MySqlTypeConstant.VARCHAR,isNull = false) private String orderNo; @Index diff --git a/src/main/java/com/hx/other/service/model/QueryRecord.java b/src/main/java/com/hx/other/service/model/QueryRecord.java index 48c7cc7..29968ed 100644 --- a/src/main/java/com/hx/other/service/model/QueryRecord.java +++ b/src/main/java/com/hx/other/service/model/QueryRecord.java @@ -19,7 +19,7 @@ @Column(comment = "鏌ヨ鍐呭", type = MySqlTypeConstant.VARCHAR, isNull = false) private String content; - @Column(comment = "鍚慉I鏌ヨ鍐呭", length = 5000, type = MySqlTypeConstant.VARCHAR, isNull = false) + @Column(comment = "鍚慉I鏌ヨ鍐呭", length = 5000, type = MySqlTypeConstant.VARCHAR) private String aiQueryContent; @Column(comment = "AI杩斿洖缁撴灉", length = 1000, type = MySqlTypeConstant.VARCHAR) diff --git a/src/main/java/com/hx/other/service/vo/BaseVo.java b/src/main/java/com/hx/other/service/vo/BaseVo.java index fd34eb3..2695ee3 100644 --- a/src/main/java/com/hx/other/service/vo/BaseVo.java +++ b/src/main/java/com/hx/other/service/vo/BaseVo.java @@ -12,5 +12,5 @@ private String id; - private String content; + private String keyWord; } diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index 7df50a7..2a882f0 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -35,3 +35,5 @@ pagehelper.params=count=countSql pagehelper.reasonable=true pagehelper.support-methods-arguments=true + +forest.timeout=10000 \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 7df50a7..adaa88d 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -35,3 +35,5 @@ pagehelper.params=count=countSql pagehelper.reasonable=true pagehelper.support-methods-arguments=true + +forest.timeout=10000 -- Gitblit v1.8.0