识别每小时新订单收取 + 推送微信公众号通知

This commit is contained in:
kuang.yife 2023-10-29 23:53:07 +08:00
parent 2d1c925e47
commit 9a2524bbde
8 changed files with 150 additions and 0 deletions

View File

@ -16,6 +16,8 @@ public class CustomerAddress extends BaseEntity {
@Excel(name = "消费者地址id", cellType = Excel.ColumnType.NUMERIC) @Excel(name = "消费者地址id", cellType = Excel.ColumnType.NUMERIC)
private Long customerAddressId; private Long customerAddressId;
private List<Long> customerAddressIds;
@Excel(name = "消费者id", cellType = Excel.ColumnType.NUMERIC) @Excel(name = "消费者id", cellType = Excel.ColumnType.NUMERIC)
private Long customerId; private Long customerId;

View File

@ -45,6 +45,12 @@
#{id} #{id}
</foreach> </foreach>
</if> </if>
<if test="customerAddressIds != null and customerAddressIds.size > 0">
AND customer_address_id IN
<foreach collection="customerAddressIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where> </where>
</select> </select>

View File

@ -45,6 +45,16 @@
<artifactId>ghy-payment</artifactId> <artifactId>ghy-payment</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-worker</artifactId>
</dependency>
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-custom</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,7 @@
package com.ghy.quartz.service;
public interface OrderAlertTaskService {
void getSuitableOrderAlertWorker();
}

View File

@ -0,0 +1,94 @@
package com.ghy.quartz.service.impl;
import com.ghy.common.enums.OrderStatus;
import com.ghy.common.enums.WxMsgEnum;
import com.ghy.common.utils.WechatMsgUtils;
import com.ghy.customer.domain.CustomerAddress;
import com.ghy.customer.service.CustomerAddressService;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderMasterService;
import com.ghy.quartz.service.OrderAlertTaskService;
import com.ghy.worker.domain.Worker;
import com.ghy.worker.domain.WorkerArea;
import com.ghy.worker.service.WorkerAreaService;
import com.ghy.worker.service.WorkerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
public class OrderAlertTaskServiceImpl implements OrderAlertTaskService {
@Autowired
private OrderMasterService orderMasterService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private WorkerAreaService workerAreaService;
@Autowired
private WorkerService workerService;
@Override
public void getSuitableOrderAlertWorker() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH");
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String startTime = format.format(new Date()) + ":00:00";
String endTime = format.format(new Date()) + ":59:59";
// 找到合适时间的订单
OrderMaster orderMaster = new OrderMaster();
orderMaster.setDeptId(101L);
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
orderMaster.setWorkerId(-1L);
orderMaster.setCreateTimeStart(LocalDateTime.parse(startTime, df));
orderMaster.setCreateTimeEnd(LocalDateTime.parse(endTime, df));
List<OrderMaster> orderMasters = orderMasterService.selectOrderMasterList(orderMaster);
if(CollectionUtils.isNotEmpty(orderMasters)){
List<Long> addressList = orderMasters.stream().map(OrderMaster::getAddressId).collect(Collectors.toList());
CustomerAddress customerAddress = new CustomerAddress();
customerAddress.setCustomerAddressIds(addressList);
List<CustomerAddress> customerAddresses = customerAddressService.getCustomerAddressList(customerAddress);
if(CollectionUtils.isNotEmpty(customerAddresses)){
List<Long> cityIds = customerAddresses.stream().map(CustomerAddress::getCityId).collect(Collectors.toList());
WorkerArea workerArea = new WorkerArea();
workerArea.setCityIds(cityIds);
List<WorkerArea> workerAreaList = workerAreaService.getWorkerAreaList(workerArea);
List<Long> workIds = workerAreaList.stream().map(WorkerArea::getWorkerId).distinct().collect(Collectors.toList());
if(CollectionUtils.isNotEmpty(workIds)){
workIds.forEach(model->{
// 通知师傅新订单
try {
Worker assignWorker = workerService.selectById(model);
// 消息组装
Map<String, Object> paramsNew = new HashMap<>();
// 订单编号
paramsNew.put("character_string6", "newOrder");
// 名称
paramsNew.put("thing14", "需求大厅有新订单哦,请尽快查看");
// 预约时间
paramsNew.put("time4", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", new Date()));
// 消息推送
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getWxOpenId(), WxMsgEnum.TEXT, paramsNew);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
}
}

View File

@ -0,0 +1,23 @@
package com.ghy.quartz.task;
import com.ghy.quartz.service.OrderAlertTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component("orderAlertTask")
public class OrderAlertTask {
@Autowired
private OrderAlertTaskService orderAlertTaskService;
public void getSuitableOrder(){
try {
orderAlertTaskService.getSuitableOrderAlertWorker();
}catch (Exception e){
log.error(e.getMessage());
}
}
}

View File

@ -28,6 +28,8 @@ public class WorkerArea extends BaseEntity {
private Long cityId; private Long cityId;
private SysArea cityArea; private SysArea cityArea;
private List<Long> cityIds;
@Excel(name = "区/县区域id", cellType = Excel.ColumnType.NUMERIC) @Excel(name = "区/县区域id", cellType = Excel.ColumnType.NUMERIC)
private Long districtId; private Long districtId;
private SysArea districtArea; private SysArea districtArea;

View File

@ -66,6 +66,12 @@
<if test="districtId != null"> <if test="districtId != null">
AND wa.district_id = #{districtId} AND wa.district_id = #{districtId}
</if> </if>
<if test="cityIds != null and cityIds.size > 0">
AND wa.city_id in
<foreach collection="cityIds" item="cityId" open="(" separator="," close=")">
#{cityId}
</foreach>
</if>
<if test="districtIds != null and districtIds.size > 0"> <if test="districtIds != null and districtIds.size > 0">
AND wa.district_id in AND wa.district_id in
<foreach collection="districtIds" item="districtId" open="(" separator="," close=")"> <foreach collection="districtIds" item="districtId" open="(" separator="," close=")">