2024-06-15 18:34:28 +08:00

255 lines
8.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.zhgd.xmgl.async;
import com.zhgd.xmgl.call.HousingDataCall;
import com.zhgd.xmgl.call.WkServiceuCall;
import com.zhgd.xmgl.modules.basicdata.entity.Notice;
import com.zhgd.xmgl.modules.basicdata.service.INoticeService;
import com.zhgd.xmgl.modules.project.entity.ProjectEnterprise;
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
import com.zhgd.xmgl.modules.project.service.IProjectUfaceConfigService;
import com.zhgd.xmgl.modules.worker.entity.*;
import com.zhgd.xmgl.modules.worker.mapper.WorkerInfoMapper;
import com.zhgd.xmgl.modules.worker.service.impl.WorkerInfoServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @program: wisdomSite
* @description: 异步人员任务
* @author: Mr.Peng
* @create: 2021-07-05 11:50
**/
@Slf4j
@Component
public class AsyncWorker {
@Lazy
@Autowired
private WorkerInfoServiceImpl workerInfoService;
@Lazy
@Autowired
private WorkerInfoMapper workerInfoMapper;
@Lazy
@Autowired
private HousingDataCall housingDataCall;
@Lazy
@Autowired
private INoticeService noticeService;
@Lazy
@Autowired
private IProjectUfaceConfigService projectUfaceConfigService;
@Lazy
@Autowired
private WkServiceuCall wkServiceuCall;
@Lazy
@Autowired
private AsyncWorker asyncWorker;
/**
* 批量数据发送任务
*
* @param map
*/
@Async("sendWorkerExecutor")
public void sendBatchWorkerInfo(Map<String, Object> map) {
try {
List<WorkerInfo> list = workerInfoMapper.selectSendWorkerList(map);
if (list.size() > 0) {
for (WorkerInfo info : list) {
housingDataCall.sendAddWork(info.getProjectSn(), info);
}
}
log.info("--------------------------------批量发送人员信息执行完成-------------------------------");
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 批量数据发送任务
*
* @param
*/
@Async("sendWorkerExecutor")
public void sendBatchWokerDevAsync(Map<String, Object> map, ProjectUfaceConfig projectUfaceConfig, List<UfaceDev> allDevList) {
try {
Long userId = MapUtils.getLong(map, "userId");
List<WorkerInfo> workerList = workerInfoMapper.selectProjectWorkerInfoList(map);
if (workerList.size() > 0) {
if (projectUfaceConfig.getSupplierType() == 9) {
//isc下发
projectUfaceConfigService.buildAndSendBatchWorkerForHk(projectUfaceConfig, allDevList, workerList, userId);
} else {
for (WorkerInfo info : workerList) {
try {
info.setNoticeUserId(userId);
projectUfaceConfigService.sendBatchWorkerInfo(info, projectUfaceConfig, allDevList);
} catch (Exception e) {
log.error("下发人员异常,人员名称:{}", info.getWorkerName() + "," + e.getMessage());
noticeFail(info.getWorkerName(), userId, e);
log.error("error", e);
}
}
if (userId != null) {
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Notice notice = new Notice();
notice.setAccountId(userId);
notice.setMsg("已经完成批量向设备下发" + workerList.size() + "个人");
notice.setTitle("人员批量下发设备提醒");
notice.setSendTime(format1.format(new Date()));
notice.setType("1");
noticeService.addNotice(notice, true);
}
log.info("--------------------------------批量向设备下发人员执行完成-------------------------------");
}
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 下发人员失败的提示
*
* @param workerName
* @param userId
* @param e
*/
private void noticeFail(String workerName, Long userId, Exception e) {
if (userId != null) {
java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Notice notice = new Notice();
notice.setAccountId(userId);
notice.setMsg("下发人员异常,人员名称:" + workerName + "," + e.getMessage());
notice.setTitle("人员批量下发设备提醒");
notice.setSendTime(format1.format(new Date()));
notice.setType("1");
noticeService.addNotice(notice, true);
}
}
/**
* 单个人员数据发送任务
*
* @param info
*/
@Async("sendWorkerExecutor")
public void sendWorkerInfoById(WorkerInfo info) {
try {
housingDataCall.sendAddWork(info.getProjectSn(), info);
log.info("--------------------------------单个发送人员信息执行完成-------------------------------");
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 人员退场异步任务
*
* @param info 1 删除2退场
*/
@Async("sendExitWorkerExecutor")
public void sendExitWorkById(WorkerInfo info, Integer type) {
try {
housingDataCall.sendExitWork(info.getProjectSn(), info);
log.info("--------------------------------单个发送人员退场执行完成-------------------------------");
if (type == 1) {
//万科退场
wkServiceuCall.removeWork(info.getProjectSn(), info);
} else {
wkServiceuCall.sendAddWork(info.getProjectSn(), info);
}
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 班组编辑或修改
*
* @param
*/
@Async("sendWorkerExecutor")
public void sendAddOrUpdateTeam(TeamInfo teamInfo, DepartmentInfo departmentInfo, Integer type) {
try {
if (type == 1) {
housingDataCall.sendAddOrUpdateTeam(teamInfo.getProjectSn(), teamInfo.getId());
//向万科平台发送数据
wkServiceuCall.sendAddDepartmentGroup(teamInfo, null, 1, teamInfo.getProjectSn());
} else {
//向万科平台发送数据
wkServiceuCall.sendAddDepartmentGroup(null, departmentInfo, 2, teamInfo.getProjectSn());
}
//log.info("--------------------------------单个发送班组执行完成-------------------------------");
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 向外部上传设备
*
* @param
*/
@Async("sendWorkerExecutor")
public void saveUfaceDev(UfaceDev ufaceDev) {
try {
//向万科上传人脸设备
wkServiceuCall.sentAddUfaceDev(ufaceDev);
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 单个人员数据发送任务
*
* @param info
*/
@Async("sendWorkerExecutor")
public void sendAndOrEditWorkerInfo(WorkerInfo info) {
try {
wkServiceuCall.sendAddWork(info.getProjectSn(), info);
log.info("--------------------------------单个发送人员信息执行完成-------------------------------");
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 添加企业
*
* @param enterpriseInfo
*/
@Async("sendWorkerExecutor")
public void addEnterpriseInfo(EnterpriseInfo enterpriseInfo) {
try {
wkServiceuCall.addEnterpriseInfo(enterpriseInfo);
} catch (Exception e) {
log.error("error", e);
}
}
/**
* 解除企业绑定
*
* @param projectEnterprise
*/
@Async("sendWorkerExecutor")
public void removeEnterpriseInfo(ProjectEnterprise projectEnterprise) {
try {
wkServiceuCall.removeEnterpriseInfo(projectEnterprise);
} catch (Exception e) {
log.error("error", e);
}
}
}