guang
2023-05-06 7201205af85508421037119ba66b3a6a48de61ec
提交 | 用户 | age
6044ac 1 package com.hx.other.service.controller;
G 2
3 import com.hx.common.BaseController;
4 import com.hx.other.service.model.Employee;
5 import com.hx.other.service.model.OrdersTotal;
6 import com.hx.other.service.model.PerformanceInfo;
7 import com.hx.other.service.model.User;
8 import com.hx.other.service.service.EmployeeService;
9 import com.hx.other.service.service.OrdersTotalService;
10 import com.hx.other.service.service.PerformanceInfoService;
11 import com.hx.other.service.service.UserService;
12 import com.hx.resultTool.Result;
13 import org.springframework.web.bind.annotation.RequestMapping;
14 import org.springframework.web.bind.annotation.RestController;
15
16 import javax.annotation.Resource;
17 import java.math.BigDecimal;
18 import java.util.*;
19
20 /**
21  * @Author: cmg
22  * @Date: 2023/4/23 15:30
23  */
24 @RestController
25 @RequestMapping("/init/data")
26 public class InitDataController extends BaseController {
27
28     @Resource
29     private EmployeeService employeeService;
30
31     @Resource
32     private UserService userService;
33
34     @Resource
35     private OrdersTotalService ordersTotalService;
36
37     @Resource
38     private PerformanceInfoService performanceInfoService;
39
40     @RequestMapping("/data")
41     public Result initData()
42     {
43
44         String[] XING = new String[]{"赵", "钱", "孙", "李", "周", "吴", "郑", "王", "冯", "陈", "褚", "卫", "蒋", "沈", "韩", "杨", "朱", "秦", "尤", "许"};
45         String[] MING = new String[]{"晓", "霜", "碧", "凡", "夏", "菡", "曼", "香", "若", "烟", "半", "梦", "雅", "绿", "冰", "蓝", "灵", "槐", "平", "安", "书", "翠", "翠", "风", "代", "云", "梦", "曼", "幼", "翠", "梦", "琪", "之", "雅", "之", "桃", "慕", "青", "尔", "岚", "初", "夏", "沛", "菡", "傲", "珊", "曼", "文", "乐", "菱", "惜", "文", "香", "寒",};
46         String[] USER_LEVEL = new String[]{"准会员", "普卡", "潜客", "金卡", "钻石卡", "银卡", "黑钻卡"};
47         String[] CHANNEL_TYPE = new String[]{"PR渠道", "TMK渠道", "三方平台", "会员", "前员工", "医生", "天猫", "大众点评", "微博", "抖音", "新氧", "爱尔健员工", "私域", "百度", "红人合作", "艾芯荟", "路过"};
48         String[] SHOP_ID = new String[]{"4eefc8a1bfa611ecaeb57cd30a51ed1a", "605e391b620d11ebb06bb8599f4cafbe", "b88e3cd8620d11ebb06bb8599f4cafbe",
49                 "b96aa6d1620d11ebb06bb8599f4cafbe", "bb4e8a7d620d11ebb06bb8599f4cafbe", "cd8b395f945c11ecaeb57cd30a51ed1a"};
50         String[] SHOP_NAME = new String[]{"北京光华店", "新天地店", "东银店", "", "杭州店", "静安店", "古北店"};
51         String[] USER_STATUS = new String[]{"active_member", "sleeping_member", "deep_sleep_member"};
52
53         String[] PROJECT_NAME = new String[]{"玻尿酸", "Fotona","海菲秀","皮秒","乔雅登","OPT"};
54         String[] PROJECT_ID = new String[]{"000075ee7afc11ebb06bb8599f4cafbe", "007cc926647911ebb06bb8599f4cafbe","018cbc9e8b9711ebb06bb8599f4cafbe","01abe206620e11ebb06bb8599f4cafbe",
55                 "035d7079647711ebb06bb8599f4cafbe","03b0269b620e11ebb06bb8599f4cafbe"};
56
57
58         Random random = new Random();
59
60         //初始化顾问
61         Employee employee = new Employee();
62         employee.setCnName("王小雅");
63         employeeService.insert(employee);
64
65         int xLen = XING.length;
66         int mLen = MING.length;
67         Set<String> set = new HashSet<>();
68         List<Employee> employeeList = new ArrayList<Employee>();
69         for(int i = 0;i < 30;i ++)
70         {
71             employee = new Employee();
72             employee.setCnName(XING[random.nextInt(xLen)] + MING[random.nextInt(mLen)]);
73
74             if(set.contains(employee.getCnName()))
75             {
76                 continue;
77             }
78             set.add(employee.getCnName());
79
80             employeeService.insert(employee);
81             employeeList.add(employee);
82         }
83
84         //初始化用户
85         User user;
86         int ranInt;
87         Calendar calendar;
88         List<User> userList = new ArrayList<>();
89         set.clear();
90         Map<String, User> map = new HashMap<>();
91         for(int i = 0;i < 200;i ++)
92         {
93             user = new User();
94             user.setName(XING[random.nextInt(xLen)] + MING[random.nextInt(mLen)]);
95
96             if(set.contains(user.getName()))
97             {
98                 continue;
99             }
100             set.add(user.getName());
101
102             user.setGender(random.nextInt(2) + 1);
103
104             ranInt = random.nextInt(employeeList.size());
105             user.setHisCorpUserId(employeeList.get(ranInt).getId());
106             user.setHisCorpUserName(employeeList.get(ranInt).getCnName());
107             user.setUserLevel(USER_LEVEL[random.nextInt(USER_LEVEL.length)]);
108             user.setChannelType(CHANNEL_TYPE[random.nextInt(CHANNEL_TYPE.length)]);
109
110             ranInt = random.nextInt(SHOP_ID.length);
111             user.setShopId(SHOP_ID[ranInt]);
112             user.setShopName(SHOP_NAME[ranInt]);
113
114             user.setUserStatus(USER_STATUS[random.nextInt(USER_STATUS.length)]);
115
116             calendar = Calendar.getInstance();
117             calendar.add(Calendar.YEAR, -1);
118             calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(720) - 360);
119
120             user.setCreateTime(calendar.getTime());
121
122             userService.insert(user);
123
124             userList.add(user);
125             map.put(user.getId(), user);
126         }
127
128         //初始化订单
129         OrdersTotal ordersTotal;
130         List<OrdersTotal> ordersTotalList = new ArrayList<>();
131         for(int i = 0;i < 10000; i ++)
132         {
133             ordersTotal = new OrdersTotal();
134             ordersTotal.setActualTotal(BigDecimal.valueOf(random.nextInt(10000)));
135             ordersTotal.setOrderNo(UUID.randomUUID().toString());
136
137             user = userList.get(random.nextInt(userList.size()));
138             ordersTotal.setShopId(user.getShopId());
139             ordersTotal.setShopName(user.getShopName());
140             ordersTotal.setUserId(user.getId());
141             ordersTotal.setUserName(user.getName());
142
143             calendar = Calendar.getInstance();
144             calendar.add(Calendar.YEAR, -1);
145             calendar.add(Calendar.DAY_OF_YEAR, random.nextInt(720) - 360);
146             ordersTotal.setCreateTime(calendar.getTime());
147
148             ordersTotalService.insert(ordersTotal);
149
150             ordersTotalList.add(ordersTotal);
151         }
152
153         //初始化业绩
154         PerformanceInfo performanceInfo;
155         for(int i = 0;i < 10000;i ++)
156         {
157             performanceInfo = new PerformanceInfo();
158
159             ranInt = random.nextInt(ordersTotalList.size());
160             ordersTotal = ordersTotalList.get(ranInt);
161             performanceInfo.setPerformanceTotal(ordersTotal.getActualTotal());
162
163             user = map.get(ordersTotal.getUserId());
164             performanceInfo.setBelongConsultantId(user.getHisCorpUserName());
165             performanceInfo.setBelongConsultantId(user.getHisCorpUserId());
166             performanceInfo.setUserId(user.getId());
167             performanceInfo.setUserName(user.getName());
168
169             employee = employeeList.get(random.nextInt(employeeList.size()));
170             performanceInfo.setDeductionDoctorId(employee.getId());
171             performanceInfo.setDeductionDoctorName(employee.getCnName());
172
173             performanceInfo.setDeductionTime(ordersTotal.getCreateTime());
174
175             employee = employeeList.get(random.nextInt(employeeList.size()));
176             performanceInfo.setNurseCorpUserId(employee.getId());
177             performanceInfo.setNurseCorpUserName(employee.getCnName());
178
179             ranInt = random.nextInt(SHOP_ID.length);
180             performanceInfo.setServiceShopId(SHOP_ID[ranInt]);
181             performanceInfo.setServiceShopName(SHOP_NAME[ranInt]);
182
183             performanceInfo.setCreateTime(ordersTotal.getCreateTime());
184
185             ranInt = random.nextInt(PROJECT_ID.length);
186             performanceInfo.setCommonId(PROJECT_ID[ranInt]);
187             performanceInfo.setCommonName(PROJECT_NAME[ranInt]);
188
189             performanceInfoService.insert(performanceInfo);
190         }
191
192         return Result.success();
193     }
194
195
196 }