guang
2023-04-24 6044ac660b623034eaf0d7d8512aff99463458d1
初始
7个文件已修改
1个文件已添加
301 ■■■■■ 已修改文件
pom.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/other/service/controller/InitDataController.java 196 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/other/service/controller/SqlQueryController.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/other/service/model/OrdersTotal.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/other/service/model/QueryRecord.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/hx/other/service/vo/BaseVo.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-local.properties 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application-prod.properties 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
src/main/java/com/hx/other/service/controller/InitDataController.java
New file
@@ -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();
    }
}
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))
        {
            //记录向ai查询时的毫秒数
@@ -66,7 +66,7 @@
            //模板里没有,从ai里查询
            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))
        {
            //记录向ai查询时的毫秒数
            queryRecord.setQueryTime(Calendar.getInstance().getTimeInMillis());
            //模板里没有,从ai里查询
            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"))
                {
                    //是sql
                    sql = obj.getString("now");
                    //记录ai返回的结果
                    queryRecord.setAiResult(obj.getString("origin"));
                }
                //记录ai查询的content
                queryRecord.setAiQueryContent(obj.getString("content"));
            }
        }else{
            queryRecord.setIsFromQuery(BaseEntity.YES);
        }
        List<Map<String, Object>> list = null;
        if(!StringUtils.isEmpty(sql))
        {
            //记录查询的sql
            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);
    }
}
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
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 = "向AI查询内容", length = 5000, type = MySqlTypeConstant.VARCHAR, isNull = false)
    @Column(comment = "向AI查询内容", length = 5000, type = MySqlTypeConstant.VARCHAR)
    private String aiQueryContent;
    @Column(comment = "AI返回结果", length = 1000, type = MySqlTypeConstant.VARCHAR)
src/main/java/com/hx/other/service/vo/BaseVo.java
@@ -12,5 +12,5 @@
    private String id;
    private String content;
    private String keyWord;
}
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
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