Commit 21327692 by 邹磊浩

修改代码

parent 98947620
package com.pz.web.task;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pz.common.utils.DateUtils;
import com.pz.common.utils.spring.SpringUtils;
import com.pz.merchant.domain.Company;
import com.pz.merchant.domain.Employees;
......@@ -19,6 +21,7 @@ import org.apache.poi.ss.formula.functions.T;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
......@@ -65,12 +68,33 @@ public class InsertTestOrderTask {
private final EmployeesDivideMapper employeesDivideMapper;
public static List<Integer> businessIds = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
public static List<Integer> businessIds = Arrays.asList(1, 2, 3, 4, 5, 6);
public static Map<Integer, Integer> orderNumMap = new HashMap<>();
static {
//上海
orderNumMap.put(5, 53);
//北京
orderNumMap.put(15, 50);
//杭州
orderNumMap.put(14, 48);
//合肥
orderNumMap.put(17, 32);
//长沙
orderNumMap.put(18, 38);
//贵阳
orderNumMap.put(19, 25);
//西安
orderNumMap.put(16, 27);
}
// @Scheduled(cron = "0 0 0 * * ?") // 凌晨12点执行
@Scheduled(cron = "0 0 0 * * ?") // 凌晨12点执行
@Transactional
public void insertOrder() throws InterruptedException {
// 就诊人员
List<UserVsitor> userVsitors = userVsitorMapper.selectList(Wrappers.<UserVsitor>lambdaQuery().last("limit 20"));
List<UserVsitor> userVsitors = userVsitorMapper.selectList(Wrappers.<UserVsitor>lambdaQuery().orderByDesc(UserVsitor::getId).last("limit 50"));
// 查询固定机构
List<Company> companies = companyMapper.selectList(Wrappers.<Company>lambdaQuery().in(Company::getId, 5, 14, 15, 16, 17, 18, 19));
// 加入线程池并发执行
......@@ -78,26 +102,38 @@ public class InsertTestOrderTask {
for (Company company : companies) {
List<Employees> employees = employeesMapper.selectList(Wrappers.<Employees>lambdaQuery().eq(Employees::getCompanyId, company.getId()).last("limit 10"));
Employees element = getRandomElement(employees);
executorService.submit(() -> {
for (Integer businessId : businessIds) {
//获取服务价格
List<Services> services = servicesMapper.selectList(Wrappers.<Services>lambdaQuery().eq(Services::getBid, businessId).eq(Services::getCityId, company.getCityId()));
// 每日单量
Integer num = RandomUtil.randomInt(4, 10);
Integer num = orderNumMap.get(company.getId());
for (int i = 0; i <= num; i++) {
//接单人员
UserVsitor randomElement = getRandomElement(userVsitors);
for (Services service : services) {
UserVsitor vsitor = getRandomElement(userVsitors);
//随机业务
Integer businessId = getRandomElement(businessIds);
//获取服务价格
List<Services> services = servicesMapper.selectList(Wrappers.<Services>lambdaQuery().eq(Services::getBid, businessId).eq(Services::getCityId, company.getCityId()));
//随机服务
Services service = getRandomElement(services);
Long orderId = saveTotalOrder(businessId, element.getId(), company.getCityId().intValue(), company.getId(), service);
Integer status = RandomUtil.randomInt(0, 2);
List<Hospital> hospitals = hospitalMapper.selectList(Wrappers.<Hospital>lambdaQuery().eq(Hospital::getCityId, company.getCityId()).last("limit 50"));
//随机医院
Hospital hospital = getRandomElement(hospitals);
//新增业务
randomOrder(businessId, orderId.intValue(), 2, hospital.getId(), vsitor.getId(), element);
}
});
}
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
public void randomOrder(Integer businessId, Integer orderId, Integer status, Integer hid, Integer vid, Employees element) {
Date dateStr = randomTime();
Date date = subtractMinutes(dateStr, 31);
switch (businessId) {
case 0:
StoreOrder storeOrder = new StoreOrder();
storeOrder.setOrderId(orderId.intValue());
storeOrder.setOrderId(orderId);
Integer storeId = RandomUtil.randomInt(1, 5);
storeOrder.setGoodsId(storeId);
Integer addressId = RandomUtil.randomInt(1, 9);
......@@ -105,6 +141,7 @@ public class InsertTestOrderTask {
storeOrder.setStatus(status);
storeOrder.setLogistics("顺丰速运");
storeOrder.setLogisticsCode("SF" + RandomUtil.randomNumbers(16));
storeOrder.setCreateTime(date);
storeOrderMapper.insert(storeOrder);
break;
case 1:
......@@ -112,25 +149,27 @@ public class InsertTestOrderTask {
yypzOrder.setOrderId(orderId.intValue());
yypzOrder.setPhone(generateRandomPhoneNumber());
yypzOrder.setStatus(status);
yypzOrder.setVisitTime(randomTime());
yypzOrder.setHid(hospital.getId());
yypzOrder.setVisitor(randomElement.getId());
yypzOrder.setVisitTime(dateStr);
yypzOrder.setHid(hid);
yypzOrder.setVisitor(vid);
yypzOrder.setCreateTime(date);
yypzOrderMapper.insert(yypzOrder);
break;
case 2:
DbghOrder dbghOrder = new DbghOrder();
dbghOrder.setOrderId(orderId.intValue());
dbghOrder.setHid(hospital.getId());
dbghOrder.setHid(hid);
dbghOrder.setStatus(status);
dbghOrder.setVisitTime(randomTime());
dbghOrder.setVisitor(randomElement.getId());
dbghOrder.setVisitTime(dateStr);
dbghOrder.setVisitor(vid);
dbghOrder.setCreateTime(date);
dbghOrderMapper.insert(dbghOrder);
break;
case 3:
DbwzOrder dbwzOrder = new DbwzOrder();
dbwzOrder.setOrderId(orderId.intValue());
dbwzOrder.setStatus(status);
dbwzOrder.setVisitTime(randomTime());
dbwzOrder.setVisitTime(dateStr);
dbwzOrder.setChiefComplaint("电话沟通");
dbwzOrder.setHistoryOfPresentIllness("电话沟通");
dbwzOrder.setLastMedicalTreatmentSituation("电话沟通");
......@@ -138,16 +177,18 @@ public class InsertTestOrderTask {
dbwzOrder.setPostTreatmentCondition("电话沟通");
dbwzOrder.setRelatedReports("电话沟通");
dbwzOrder.setServiceRequirements("电话沟通");
dbwzOrder.setVisitor(randomElement.getId());
dbwzOrder.setVisitor(vid);
dbwzOrder.setCreateTime(date);
dbwzOrderMapper.insert(dbwzOrder);
break;
case 4:
ZyphOrder zyphOrder = new ZyphOrder();
zyphOrder.setOrderId(orderId.intValue());
zyphOrder.setHid(hospital.getId());
zyphOrder.setHid(hid);
zyphOrder.setStatus(status);
zyphOrder.setVisitor(randomElement.getId());
zyphOrder.setOverTime(randomTime());
zyphOrder.setVisitor(vid);
zyphOrder.setOverTime(dateStr);
zyphOrder.setCreateTime(date);
zyphOrderMapper.insert(zyphOrder);
break;
case 5:
......@@ -158,62 +199,59 @@ public class InsertTestOrderTask {
dbmyOrder.setAddressInfo("***");
dbmyOrder.setPzShr(element.getName());
dbmyOrder.setPzShPhone(element.getPhone());
dbmyOrder.setCreateTime(date);
dbmyOrderMapper.insert(dbmyOrder);
break;
case 6:
ZqghOrder zqghOrder = new ZqghOrder();
zqghOrder.setOrderId(orderId.intValue());
zqghOrder.setHid(hospital.getId());
zqghOrder.setHid(hid);
zqghOrder.setStatus(status);
zqghOrder.setOverTime(randomTime());
zqghOrder.setOverTime(dateStr);
zqghOrder.setDoctorId(1);
zqghOrder.setCreateTime(date);
zqghOrderMapper.insert(zqghOrder);
break;
default:
break;
}
}
}
}
});
}
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
}
public Date randomTime() {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 9); // 设置小时为9点
calendar.set(Calendar.MINUTE, 0); // 设置分钟为0分
calendar.set(Calendar.SECOND, 0); // 设置秒钟为0秒
Calendar calendar = new GregorianCalendar();
calendar.set(Calendar.HOUR_OF_DAY, 9); // 设置开始时间为早上9点
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long startTimeInMillis = calendar.getTimeInMillis(); // 获取当天9点的时间戳
long startMillis = calendar.getTimeInMillis(); // 获取开始时间的毫秒数
// 计算10点与9点之间的毫秒数范围
long range = 60 * 60 * 1000; // 1小时的毫秒数
long randomOffset = (long) (Math.random() * range); // 在范围内生成随机偏移量
calendar.set(Calendar.HOUR_OF_DAY, 18); // 设置结束时间为晚上6点
long endMillis = calendar.getTimeInMillis(); // 获取结束时间的毫秒数
// 计算随机时间的时间戳
long randomTimeInMillis = startTimeInMillis + randomOffset;
long randomMillis = startMillis + (long) (Math.random() * (endMillis - startMillis)); // 生成随机的时间毫秒数
// 将时间戳转换为Date类型
Date randomTime = new Date(randomTimeInMillis);
Date randomDate = new Date(randomMillis); // 转换为Date类型
return randomTime;
return randomDate;
}
public Date subtractMinutes(Date date, int minutes) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, -minutes);
return calendar.getTime();
}
public Long saveTotalOrder(Integer businessId, Integer emId, Integer cityId, Integer companyId, Services services) {
//随机评价
Integer i = RandomUtil.randomInt(0, 1);
//创建主订单
TotalOrder totalOrder = new TotalOrder();
Random random = new Random();
Integer status = RandomUtil.randomInt(1, 3);
totalOrder.setStatus(status);
Integer suborderStatus = RandomUtil.randomInt(0, 3);
totalOrder.setSuborderStatus(suborderStatus);
// Integer status = RandomUtil.randomInt(0, 3);
totalOrder.setStatus(2);
// Integer suborderStatus = RandomUtil.randomInt(0, 3);
totalOrder.setSuborderStatus(2);
totalOrder.setPayMoney(services.getPrice().doubleValue());
totalOrder.setIsSatisfaction(i);
totalOrder.setIsSatisfaction(1);
totalOrder.setBusinessId(businessId);
totalOrder.setFinishTime(randomTime());
totalOrder.setServiceId(services.getId());
......@@ -263,6 +301,9 @@ public class InsertTestOrderTask {
}
public static <T> T getRandomElement(List<T> list) {
if (CollectionUtils.isEmpty(list)) {
return null;
}
Random random = new Random();
int index = random.nextInt(list.size());
return list.get(index);
......
......@@ -56,7 +56,7 @@
and co.uid = #{bo.userId}
</if>
</where>
order by tlo.create_time desc
order by tlo.visit_time desc
</select>
<select id="selectSonOrderInfoByTotalId" resultType="com.pz.merchant.domain.vo.SonOrderVo">
......
......@@ -60,7 +60,7 @@
and co.uid = #{bo.userId}
</if>
</where>
order by tlo.create_time desc
order by tlo.visit_time desc
</select>
<select id="selectSonOrderInfoByTotalId" resultType="com.pz.merchant.domain.vo.SonOrderVo">
......
......@@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and co.uid = #{bo.userId}
</if>
</where>
order by tlo.create_time desc
order by tlo.visit_time desc
</select>
<select id="selectSonOrderInfoByTotalId" resultType="com.pz.merchant.domain.vo.SonOrderVo">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment