Commit b8f5d925 authored by 赵啸非's avatar 赵啸非

添加消息发送

parent 350a04f1
...@@ -38,7 +38,9 @@ public class SubEventStartedService implements IApplicationStartedService { ...@@ -38,7 +38,9 @@ public class SubEventStartedService implements IApplicationStartedService {
public void start() { public void start() {
ThreadPool.getInstance().init(10); ThreadPool.getInstance().init(10);
new AlarmSendMsgThread().start(); AlarmSendMsgThread alarmSendMsgThread = new AlarmSendMsgThread();
ThreadPool.getInstance().execute(alarmSendMsgThread);
/* Constants.DEFAULT_TIMEOUT=12000; /* Constants.DEFAULT_TIMEOUT=12000;
......
package com.mortals.xhx.daemon.applicationservice; //package com.mortals.xhx.daemon.applicationservice;
//
import cn.hutool.core.date.DateUtil; //import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdcardUtil; //import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil; //import cn.hutool.core.util.StrUtil;
import com.mortals.framework.common.Rest; //import com.mortals.framework.common.Rest;
import com.mortals.framework.springcloud.service.IApplicationStartedService; //import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.common.code.SourceEnum; //import com.mortals.xhx.common.code.SourceEnum;
import com.mortals.xhx.common.code.YesNoEnum; //import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.hik.person.model.req.person.PersonReq; //import com.mortals.xhx.module.hik.person.model.req.person.PersonReq;
import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo; //import com.mortals.xhx.module.hik.person.model.rsp.person.PersonDataInfo;
import com.mortals.xhx.module.hik.person.service.IHikPersonService; //import com.mortals.xhx.module.hik.person.service.IHikPersonService;
import com.mortals.xhx.module.person.model.PersonEntity; //import com.mortals.xhx.module.person.model.PersonEntity;
import com.mortals.xhx.module.person.service.PersonService; //import com.mortals.xhx.module.person.service.PersonService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; //import org.springframework.util.ObjectUtils;
//
import java.util.Date; //import java.util.Date;
import java.util.List; //import java.util.List;
import java.util.Map; //import java.util.Map;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* 同步工作人员到本地注册人员中 // * 同步工作人员到本地注册人员中
* // *
* @author: // * @author:
* @date: 2023/4/24 10:50 // * @date: 2023/4/24 10:50
*/ // */
//@Component ////@Component
@Slf4j //@Slf4j
public class SyncWorkmanStartedService implements IApplicationStartedService { //public class SyncWorkmanStartedService implements IApplicationStartedService {
@Autowired ///* @Autowired
private PersonService personService; // private PersonService personService;
@Autowired // @Autowired
private IHikPersonService hikPersonService; // private IHikPersonService hikPersonService;*/
//
//
@Override // @Override
public void start() { // public void start() {
log.info("开始服务..[工作人员同步]"); // log.info("开始服务..[工作人员同步]");
//
PersonReq personReq = new PersonReq(); // PersonReq personReq = new PersonReq();
personReq.setPageNo(1); // personReq.setPageNo(1);
personReq.setPageSize(3); // personReq.setPageSize(3);
Rest<PersonDataInfo> personListRest = hikPersonService.getPersonList(personReq); // Rest<PersonDataInfo> personListRest = hikPersonService.getPersonList(personReq);
if (personListRest.getCode() == YesNoEnum.YES.getValue()) { // if (personListRest.getCode() == YesNoEnum.YES.getValue()) {
List<PersonEntity> collect = personListRest.getData().getList().parallelStream().map(work -> { // List<PersonEntity> collect = personListRest.getData().getList().parallelStream().map(work -> {
//判断是否存在,存在更新, // //判断是否存在,存在更新,
if (work.getCertificateType() == 990) { // if (work.getCertificateType() == 990) {
work.setCertificateNo(StrUtil.subSufByLength(work.getPersonId(), 20)); // work.setCertificateNo(StrUtil.subSufByLength(work.getPersonId(), 20));
} // }
PersonEntity personEntity = personService.getExtCache(work.getCertificateNo()); // PersonEntity personEntity = personService.getExtCache(work.getCertificateNo());
if (ObjectUtils.isEmpty(personEntity)) { // if (ObjectUtils.isEmpty(personEntity)) {
personEntity = new PersonEntity(); // personEntity = new PersonEntity();
personEntity.initAttrValue(); // personEntity.initAttrValue();
personEntity.setName(work.getPersonName()); // personEntity.setName(work.getPersonName());
personEntity.setGender(work.getGender() == 1 ? 0 : 1); // personEntity.setGender(work.getGender() == 1 ? 0 : 1);
personEntity.setIdCard(work.getCertificateNo()); // personEntity.setIdCard(work.getCertificateNo());
personEntity.setPhone(work.getPhoneNo()); // personEntity.setPhone(work.getPhoneNo());
try { // try {
personEntity.setBirthday(DateUtil.parse(IdcardUtil.getBirth(work.getCertificateNo()), "yyyyMMdd")); // personEntity.setBirthday(DateUtil.parse(IdcardUtil.getBirth(work.getCertificateNo()), "yyyyMMdd"));
} catch (Exception e) { // } catch (Exception e) {
} // }
personEntity.setServerIndexCode(work.getPersonPhoto().getServerIndexCode()); // personEntity.setServerIndexCode(work.getPersonPhoto().getServerIndexCode());
personEntity.setPicUrl(work.getPersonPhoto().getPicUri()); // personEntity.setPicUrl(work.getPersonPhoto().getPicUri());
personEntity.setSource(SourceEnum.海康系统.getValue()); // personEntity.setSource(SourceEnum.海康系统.getValue());
personEntity.setCreateTime(new Date()); // personEntity.setCreateTime(new Date());
personEntity.setCreateUserId(1L); // personEntity.setCreateUserId(1L);
personEntity.setCreateUserName("system"); // personEntity.setCreateUserName("system");
return personEntity; // return personEntity;
} // }
return personEntity; // return personEntity;
}).collect(Collectors.toList()); // }).collect(Collectors.toList());
//
Map<Boolean, List<PersonEntity>> booleanListMap = collect.parallelStream().collect(Collectors.partitioningBy(x -> x.getId() == null)); // Map<Boolean, List<PersonEntity>> booleanListMap = collect.parallelStream().collect(Collectors.partitioningBy(x -> x.getId() == null));
List<PersonEntity> savePersonList = booleanListMap.get(true); // List<PersonEntity> savePersonList = booleanListMap.get(true);
List<PersonEntity> updatePersonList = booleanListMap.get(false); // List<PersonEntity> updatePersonList = booleanListMap.get(false);
//
if (!ObjectUtils.isEmpty(savePersonList)) { // if (!ObjectUtils.isEmpty(savePersonList)) {
log.info("新增人员数量:{}", savePersonList.size()); // log.info("新增人员数量:{}", savePersonList.size());
personService.save(savePersonList); // personService.save(savePersonList);
} // }
//
if (!ObjectUtils.isEmpty(updatePersonList)) { // if (!ObjectUtils.isEmpty(updatePersonList)) {
log.info("更新人员数量:{}", updatePersonList.size()); // log.info("更新人员数量:{}", updatePersonList.size());
// personService.update(updatePersonList); // // personService.update(updatePersonList);
} // }
//
//
} // }
//
//
} // }
//
@Override // @Override
public void stop() { // public void stop() {
log.info("停止服务.."); // log.info("停止服务..");
} // }
//
@Override // @Override
public int getOrder() { // public int getOrder() {
return 11; // return 11;
} // }
//
//
} //}
...@@ -15,6 +15,7 @@ import com.mortals.framework.service.ITask; ...@@ -15,6 +15,7 @@ import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService; import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.framework.util.DataUtil; import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.base.system.user.model.UserEntity; import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.service.UserService; import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.busiz.rsp.register.AppointmentDataInfo; import com.mortals.xhx.busiz.rsp.register.AppointmentDataInfo;
...@@ -116,7 +117,7 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -116,7 +117,7 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
private void syncWaitAndFinQueue() { private void syncWaitAndFinQueue() {
RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(redisDb); RedisTemplate<String, String> redisTemplate = cacheService.selectDbRedisTemplate(redisDb);
// cacheService.select(redisDb);// // cacheService.select(redisDb);//
new Thread(() -> { Thread thread = new Thread(() -> {
List<WaitPersonInfo> waitPersonInfos = new ArrayList<>(); List<WaitPersonInfo> waitPersonInfos = new ArrayList<>();
List<FinPersonInfo> finPersonInfos = new ArrayList<>(); List<FinPersonInfo> finPersonInfos = new ArrayList<>();
List<EndPersonInfo> endPersonInfos = new ArrayList<>(); List<EndPersonInfo> endPersonInfos = new ArrayList<>();
...@@ -155,10 +156,10 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -155,10 +156,10 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
List<CpPersonInfo> cpPersonInfos = new ArrayList<>(); List<CpPersonInfo> cpPersonInfos = new ArrayList<>();
while (true) { while (true) {
String value = redisTemplate.opsForList().leftPop(RedisKey.KEY_CP_LIST_CACHE, 5 , TimeUnit.SECONDS); String value = redisTemplate.opsForList().leftPop(RedisKey.KEY_CP_LIST_CACHE, 5, TimeUnit.SECONDS);
log.info("cp:{}",value); log.info("cp:{}", value);
CpPersonInfo cpPersonInfo = JSON.parseObject(value, CpPersonInfo.class); CpPersonInfo cpPersonInfo = JSON.parseObject(value, CpPersonInfo.class);
log.info("cp obj:{}",JSON.toJSONString(cpPersonInfo)); log.info("cp obj:{}", JSON.toJSONString(cpPersonInfo));
if (ObjectUtils.isEmpty(cpPersonInfo)) { if (ObjectUtils.isEmpty(cpPersonInfo)) {
break; break;
} else { } else {
...@@ -217,11 +218,11 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -217,11 +218,11 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
//todo 构造发送消息。 //todo 构造发送消息。
AlarmRecordsEntity recordsEntity = new AlarmRecordsEntity(); AlarmRecordsEntity recordsEntity = new AlarmRecordsEntity();
recordsEntity.initAttrValue(); recordsEntity.initAttrValue();
double doTime = NumberUtil.div(Double.parseDouble((diff)+""), 60, 1); // 保留1位小数,四舍五入 double doTime = NumberUtil.div(Double.parseDouble((diff) + ""), 60, 1); // 保留1位小数,四舍五入
double upTime = NumberUtil.div(Double.parseDouble((diff-avgWait)+""), 60, 1); // 保留1位小数,四舍五入 double upTime = NumberUtil.div(Double.parseDouble((diff - avgWait) + ""), 60, 1); // 保留1位小数,四舍五入
String alarmContent = String.format("排队编号:%s:,%s业务叫号等待时间为%d分钟,超过了平均等待时长%d分钟!", String alarmContent = String.format("排队编号:%s:,%s业务叫号等待时间为%d分钟,超过了平均等待时长%d分钟!",
item.getQueueNo(), item.getBussinessName(),doTime,upTime); item.getQueueNo(), item.getBussinessName(), doTime, upTime);
recordsEntity.setAlarmContent(alarmContent); recordsEntity.setAlarmContent(alarmContent);
recordsEntity.setAlarmTime(new Date()); recordsEntity.setAlarmTime(new Date());
recordsEntity.setCreateTime(new Date()); recordsEntity.setCreateTime(new Date());
...@@ -265,10 +266,10 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -265,10 +266,10 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
AlarmRecordsEntity recordsEntity = new AlarmRecordsEntity(); AlarmRecordsEntity recordsEntity = new AlarmRecordsEntity();
recordsEntity.initAttrValue(); recordsEntity.initAttrValue();
double doTime = NumberUtil.div(Double.parseDouble((diff)+""), 60, 1); // 保留1位小数,四舍五入 double doTime = NumberUtil.div(Double.parseDouble((diff) + ""), 60, 1); // 保留1位小数,四舍五入
double upTime = NumberUtil.div(Double.parseDouble((diff-avgWait)+""), 60, 1); // 保留1位小数,四舍五入 double upTime = NumberUtil.div(Double.parseDouble((diff - avgWait) + ""), 60, 1); // 保留1位小数,四舍五入
String alarmContent = String.format("编号:%s:,%s业务办理时间为%d分钟,超过了平均办理时长%d分钟!", item.getBussinessName(),doTime,upTime); String alarmContent = String.format("编号:%s:,%s业务办理时间为%d分钟,超过了平均办理时长%d分钟!", item.getBussinessName(), doTime, upTime);
recordsEntity.setAlarmContent(alarmContent); recordsEntity.setAlarmContent(alarmContent);
recordsEntity.setAlarmTime(new Date()); recordsEntity.setAlarmTime(new Date());
recordsEntity.setCreateTime(new Date()); recordsEntity.setCreateTime(new Date());
...@@ -316,7 +317,7 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -316,7 +317,7 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
recordsEntity.initAttrValue(); recordsEntity.initAttrValue();
String alarmContent = String.format( String alarmContent = String.format(
"客户对窗口:%s:,工作人员%s 发起评价:%s,评价内容:%s!", "客户对窗口:%s:,工作人员%s 发起评价:%s,评价内容:%s!",
careCpRecordsEntity.getWindowName(),cpPersonInfo.getWorkmanName(),cpPersonInfo.getOptionId(),cpPersonInfo.getContent()); careCpRecordsEntity.getWindowName(), cpPersonInfo.getWorkmanName(), cpPersonInfo.getOptionId(), cpPersonInfo.getContent());
recordsEntity.setAlarmContent(alarmContent); recordsEntity.setAlarmContent(alarmContent);
recordsEntity.setAlarmTime(new Date()); recordsEntity.setAlarmTime(new Date());
recordsEntity.setCreateTime(new Date()); recordsEntity.setCreateTime(new Date());
...@@ -324,7 +325,8 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService { ...@@ -324,7 +325,8 @@ public class SyncAppointWaitAndFinTaskImpl implements ITaskExcuteService {
alarmRecordsService.save(recordsEntity); alarmRecordsService.save(recordsEntity);
} }
} }
}).start(); });
ThreadPool.getInstance().execute(thread);
} }
......
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