工单每一步给客户发消息

This commit is contained in:
xiaofajia 2024-11-06 18:42:30 +08:00
parent ffbf0130d6
commit 5de31ac2c4
3 changed files with 109 additions and 8 deletions

View File

@ -87,6 +87,17 @@ public interface RepairWorkerService extends IService<RepairWorker> {
**/
void sentMessage(Long userId,String text);
/**
* 向指定用户发送消息(用户非员工)
*
* @author 小李
* @date 16:52 2024/11/6
* @param ticketId 工单ID
* @param text 消息通知内容
* @param isSMS 是否需要发短信
**/
void sentMessageToCus(String ticketId, String text, Boolean isSMS);
/**
* 通过班组长的id查该班组的员工
*

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.base.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.common.RepairRoleEnum;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
@ -13,6 +14,8 @@ import cn.iocoder.yudao.module.base.service.RepairWorkerService;
import cn.iocoder.yudao.module.base.vo.RepairWorkerPageReqVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerSaveReqVO;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
@ -20,9 +23,14 @@ import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDT
import cn.iocoder.yudao.module.system.api.permission.PermissionApi;
import cn.iocoder.yudao.module.system.api.permission.RoleApi;
import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.module.tickets.entity.DlRepairTickets;
import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem;
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
import cn.iocoder.yudao.module.tickets.service.DlRepairTitemService;
import cn.iocoder.yudao.util.SendSmsUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -31,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.yaml.snakeyaml.events.Event;
import javax.annotation.Resource;
import java.io.IOException;
@ -69,6 +78,14 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
@Lazy
private PermissionApi permissionApi;
@Resource
@Lazy
private DlRepairTicketsService repairTicketsService;
@Resource
@Lazy
private CustomerMainService customerMainService;
/**
* 批量创建维修工人
@ -111,7 +128,7 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
public String getWorkerRoleName(Long userId) {
RepairWorkerRespVO worker = workerMapper.getByUserId(userId);
//如果为空说明不是维修工查询当前用户的角色
if (null != worker){
if (null != worker) {
return worker.getWorkerTypeStr();
} else {
List<Long> roleIds = permissionApi.getRoleIdsByUserId(userId);
@ -173,12 +190,12 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
**/
@Override
public IPage<RepairWorkerRespVO> queryListPage(RepairWorkerPageReqVO pageReqVO, Page<RepairWorkerRespVO> page) {
IPage<RepairWorkerRespVO> respVOIPage= workerMapper.queryListPage(pageReqVO, page);
if(!respVOIPage.getRecords().isEmpty()){
IPage<RepairWorkerRespVO> respVOIPage = workerMapper.queryListPage(pageReqVO, page);
if (!respVOIPage.getRecords().isEmpty()) {
// 单位字典
List<DictDataRespDTO> recordTypeList = dictDataApi.getDictDataList(DICT_REPAIR_WORK_TYPE);
Map<String,String> typeMap = recordTypeList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue,DictDataRespDTO::getLabel));
respVOIPage.getRecords().stream().peek(item->item.setWorkTypeText(typeMap.get(item.getWorkType()))).collect(Collectors.toList());
Map<String, String> typeMap = recordTypeList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue, DictDataRespDTO::getLabel));
respVOIPage.getRecords().stream().peek(item -> item.setWorkTypeText(typeMap.get(item.getWorkType()))).collect(Collectors.toList());
}
return respVOIPage;
}
@ -201,11 +218,11 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
// 取所有的员工ID
Set<String> ids = titems.stream().flatMap(item -> Arrays.stream(item.getRepairIds().split(","))).collect(Collectors.toSet());
List<RepairWorker> repairWorkerList = baseMapper.selectList(new LambdaQueryWrapper<RepairWorker>().in(RepairWorker::getUserId, ids));
if(!repairWorkerList.isEmpty()){
if (!repairWorkerList.isEmpty()) {
// 单位字典
List<DictDataRespDTO> recordTypeList = dictDataApi.getDictDataList(DICT_REPAIR_WORK_TYPE);
Map<String,String> typeMap = recordTypeList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue,DictDataRespDTO::getLabel));
repairWorkerList.stream().peek(item->item.setWorkTypeText(typeMap.get(item.getWorkType()))).collect(Collectors.toList());
Map<String, String> typeMap = recordTypeList.stream().collect(Collectors.toMap(DictDataRespDTO::getValue, DictDataRespDTO::getLabel));
repairWorkerList.stream().peek(item -> item.setWorkTypeText(typeMap.get(item.getWorkType()))).collect(Collectors.toList());
}
//翻译工种
return repairWorkerList;
@ -241,6 +258,42 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
}
}
/**
* 向指定用户发送消息(用户非员工)
*
* @author 小李
* @date 16:52 2024/11/6
* @param ticketId 工单ID
* @param text 消息通知内容
* @param isSMS 是否需要发短信
**/
@Override
public void sentMessageToCus(String ticketId, String text, Boolean isSMS) {
try {
// 获取工单
DlRepairTickets tickets = repairTicketsService.getById(ticketId);
// 获取用户信息
CustomerMain customerMain = customerMainService.getById(tickets.getUserId());
// 准备发送参数
Map<String, Object> templateParams = new HashMap<>();
// 发送模版内容
templateParams.put("text", text);
// 发送站内信
sendApi.sendSingleMessageToMember(new NotifySendSingleToUserReqDTO()
.setUserId(customerMain.getUserId())
.setTemplateCode(TICKET_EMPLOY).setTemplateParams(templateParams));
//发送语音提醒
notifyMessageSocket.sendMessage(text, TenantContextHolder.getRequiredTenantId().toString(), String.valueOf(customerMain.getUserId()));
// 发送短信
if (isSMS) {
SendSmsUtil.sendMsgCommon(new String[]{text}, customerMain.getPhoneNumber(), "1400852709", "蓝安汽车小程序", "2143603");
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 通过班组长的id查该班组的员工
*

View File

@ -301,6 +301,11 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
repairOrderInfoService.saveOrderInfo(repairOrderInfo);
//最后记录操作日志--创建工单
repairRecordsService.saveRepairRecord(ticketsRespVO.getId(), null, RecordTypeEnum.CJGD.getCode(), "创建工单", ticketsRespVO.getImage());
// 通知客户
// 构建消息
String message = String.format("您的爱车%s已开始%s", ticketsRespVO.getCarNo(), repairOrderInfo.getGoodsTitle());
repairWorkerService.sentMessageToCus(ticketsRespVO.getId(), message, true);
return ticketsRespVO;
}
@ -931,6 +936,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
* @date 11:48 2024/10/14
**/
@Override
@DSTransactional
public void updateTake(String id,String image) {
// 改变时看看是否已经被接了
int update = baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
@ -944,6 +950,15 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
}
//最后记录操作日志--接单
repairRecordsService.saveRepairRecord(id, null, RecordTypeEnum.jd.getCode(), "接单", image);
// 通知客户
// 构建消息
DlRepairTickets tickets = baseMapper.selectById(id);
RepairWorker worker = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()).last("limit 1"));
List<DictDataRespDTO> dataList = dictDataApi.getDictDataList("repair_work_type");
DictDataRespDTO dictDataRespDTO = dataList.stream().filter(item -> item.getValue().equals(worker.getWorkType())).findFirst().orElse(null);
String message = String.format("您的爱车%s已由%s %s接单了", tickets.getCarNo(), (dictDataRespDTO != null ? dictDataRespDTO.getLabel() : "维修工"), worker.getUserName());
repairWorkerService.sentMessageToCus(id, message, false);
}
/**
@ -1078,6 +1093,22 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
repairWorkerService.sentMessage(id, message);
});
}
//通知客户开始施工施工完成
if (respVO.getRecordType().equals(RecordTypeEnum.KSSG.getCode()) || respVO.getRecordType().equals(RecordTypeEnum.SGWCZJ.getCode())){
// 构建消息
RepairWorker worker = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()).last("limit 1"));
List<DictDataRespDTO> dataList = dictDataApi.getDictDataList("repair_work_type");
DictDataRespDTO dictDataRespDTO = dataList.stream().filter(item -> item.getValue().equals(worker.getWorkType())).findFirst().orElse(null);
String newMessage = String.format(
"您的爱车%s已由%s %s%s",
tickets.getCarNo(),
(dictDataRespDTO != null ? dictDataRespDTO.getLabel() : "维修工"),
worker.getUserName(),
(respVO.getRecordType().equals(RecordTypeEnum.KSSG.getCode()) ? "开始施工" : "施工完成")
);
repairWorkerService.sentMessageToCus(tickets.getId(), newMessage, false);
}
}
private String createMessage(String who, String no, String projectName, String type, String finishType, String nextName) {
@ -1191,6 +1222,12 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
// 通知服务顾问
DlRepairTickets tickets = baseMapper.selectById(respVO.getId());
repairWorkerService.sentMessage(Long.valueOf(tickets.getAdviserId()), "您有新的工单可以出厂检验");
// 通知客户
// 构建消息
DictDataRespDTO repairType = dictDataApi.getDictData("repair_type", tickets.getRepairType());
String message = String.format("您的爱车%s已%s完成", tickets.getCarNo(), (repairType != null ? repairType.getLabel() : "维修保养"));
repairWorkerService.sentMessageToCus(tickets.getId(), message, true);
}
/**