新增相关方人员车辆大华同步执行器
parent
3277481dc1
commit
857efdb611
|
|
@ -0,0 +1,140 @@
|
||||||
|
package com.zcloud.primeport.command;
|
||||||
|
|
||||||
|
import com.alibaba.cola.exception.BizException;
|
||||||
|
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||||
|
import com.zcloud.primeport.domain.gateway.PersonApplyGateway;
|
||||||
|
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||||
|
import com.zcloud.primeport.domain.model.PersonApplyE;
|
||||||
|
import com.zcloud.primeport.domain.model.XgfApplyPersonE;
|
||||||
|
import com.zcloud.primeport.dto.PersonApplyUpdateCmd;
|
||||||
|
import jodd.util.Base64;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相关方人员同步大华平台。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DaHuaPersonSyncExe {
|
||||||
|
|
||||||
|
private static final int RELATED_PARTY = 3;
|
||||||
|
|
||||||
|
private final DaHuaGateway daHuaGateway;
|
||||||
|
private final PersonApplyGateway personApplyGateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相关方人员审核通过后,按证件号判断新增或更新大华人员。
|
||||||
|
*/
|
||||||
|
public void syncApprovedPersons(Long applyId) {
|
||||||
|
XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(applyId);
|
||||||
|
if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<PersonApplyE> persons = personApplyGateway.personListByxgfApplyPersonId(applyId);
|
||||||
|
if (persons == null || persons.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (PersonApplyE person : persons) {
|
||||||
|
String paperNumber = decodeUserCard(person.getUserCard());
|
||||||
|
Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(paperNumber);
|
||||||
|
DaHuaPersonSyncCmd syncCmd = buildSyncCmd(dahuaPersonId, person.getEmployeePersonUserName(),
|
||||||
|
paperNumber, person.getUserPhone(), person.getUserFaceUrl(),
|
||||||
|
apply.getVisitStartTime(), apply.getVisitEndTime());
|
||||||
|
Map<String, Object> result;
|
||||||
|
if (dahuaPersonId == null) {
|
||||||
|
syncCmd.setId(daHuaGateway.generatePersonId());
|
||||||
|
result = daHuaGateway.syncPerson(syncCmd);
|
||||||
|
} else {
|
||||||
|
result = daHuaGateway.updatePerson(syncCmd);
|
||||||
|
}
|
||||||
|
checkResult(result, "同步大华人员失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相关方人员信息修改后,同步更新大华人员。
|
||||||
|
*/
|
||||||
|
public void syncUpdatedPerson(PersonApplyE original, PersonApplyUpdateCmd updated) {
|
||||||
|
if (original == null || !Integer.valueOf(RELATED_PARTY).equals(updated.getPersonBelongType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String originalPaperNumber = decodeUserCard(original.getUserCard());
|
||||||
|
Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(originalPaperNumber);
|
||||||
|
if (dahuaPersonId == null) {
|
||||||
|
throw new BizException("未找到对应的大华人员");
|
||||||
|
}
|
||||||
|
String updatedPaperNumber = decodeUserCard(updated.getUserCard());
|
||||||
|
DaHuaPersonSyncCmd syncCmd = buildSyncCmd(dahuaPersonId, updated.getEmployeePersonUserName(),
|
||||||
|
updatedPaperNumber, updated.getUserPhone(), updated.getUserFaceUrl(),
|
||||||
|
updated.getVisitStartTime(), updated.getVisitEndTime());
|
||||||
|
checkResult(daHuaGateway.updatePerson(syncCmd), "修改大华人员失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除相关方人员时,同步删除对应的大华人员。
|
||||||
|
*/
|
||||||
|
public void syncDeletedPersons(List<PersonApplyE> persons) {
|
||||||
|
if (persons == null || persons.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Long> dahuaPersonIds = new ArrayList<>();
|
||||||
|
for (PersonApplyE person : persons) {
|
||||||
|
XgfApplyPersonE apply = personApplyGateway.getXgfApplyPersonById(person.getXgfApplyPersonId());
|
||||||
|
if (apply == null || !Integer.valueOf(RELATED_PARTY).equals(apply.getPersonBelongType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Long dahuaPersonId = daHuaGateway.findPersonIdByPaperNumber(decodeUserCard(person.getUserCard()));
|
||||||
|
if (dahuaPersonId != null) {
|
||||||
|
dahuaPersonIds.add(dahuaPersonId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!dahuaPersonIds.isEmpty()) {
|
||||||
|
checkResult(daHuaGateway.deletePerson(dahuaPersonIds, null), "删除大华人员失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DaHuaPersonSyncCmd buildSyncCmd(Long id, String name, String paperNumber, String phone,
|
||||||
|
String faceUrl, String startTime, String endTime) {
|
||||||
|
DaHuaPersonSyncCmd cmd = new DaHuaPersonSyncCmd();
|
||||||
|
cmd.setService("evo-thirdParty");
|
||||||
|
cmd.setId(id);
|
||||||
|
cmd.setName(name);
|
||||||
|
cmd.setCode("hbqa" + paperNumber);
|
||||||
|
cmd.setPaperType(111);
|
||||||
|
cmd.setPaperNumber(paperNumber);
|
||||||
|
cmd.setDepartmentId(1L);
|
||||||
|
cmd.setDepartmentType(2);
|
||||||
|
cmd.setType(3);
|
||||||
|
cmd.setPhone(phone);
|
||||||
|
cmd.setValidStartTime(startTime + " 00:00:00");
|
||||||
|
cmd.setValidEndTime(endTime + " 23:59:59");
|
||||||
|
|
||||||
|
DaHuaPersonSyncCmd.PersonBiosignature face = new DaHuaPersonSyncCmd.PersonBiosignature();
|
||||||
|
face.setType(3);
|
||||||
|
face.setIndex(1);
|
||||||
|
face.setPath(faceUrl);
|
||||||
|
cmd.setPersonBiosignatures(Collections.singletonList(face));
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String decodeUserCard(String userCard) {
|
||||||
|
try {
|
||||||
|
return Base64.decodeToString(userCard);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BizException("用户身份证解析错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkResult(Map<String, Object> result, String message) {
|
||||||
|
if (result == null || !Boolean.TRUE.equals(result.get("passed"))) {
|
||||||
|
Object errorMessage = result == null ? null : result.get("errMsg");
|
||||||
|
throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,82 @@
|
||||||
|
package com.zcloud.primeport.command;
|
||||||
|
|
||||||
|
import com.alibaba.cola.exception.BizException;
|
||||||
|
import com.zcloud.primeport.domain.enums.VehicleBelongTypeEnum;
|
||||||
|
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||||
|
import com.zcloud.primeport.domain.gateway.VehicleApplyGateway;
|
||||||
|
import com.zcloud.primeport.domain.model.DaHuaCarAddCmd;
|
||||||
|
import com.zcloud.primeport.domain.model.VehicleApplyE;
|
||||||
|
import com.zcloud.primeport.plan.mjDevice.dto.CarEnum;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相关方车辆同步大华平台。
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class DaHuaVehicleSyncExe {
|
||||||
|
|
||||||
|
private final DaHuaGateway daHuaGateway;
|
||||||
|
private final VehicleApplyGateway vehicleApplyGateway;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 相关方车辆审核通过后,同步新增大华车辆。
|
||||||
|
*/
|
||||||
|
public void syncApprovedVehicle(Long vehicleApplyId) {
|
||||||
|
VehicleApplyE vehicle = vehicleApplyGateway.getById(vehicleApplyId);
|
||||||
|
if (!isRelatedPartyVehicle(vehicle)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
syncAddedVehicle(vehicle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除相关方车辆时,同步删除对应的大华车辆。
|
||||||
|
*/
|
||||||
|
public void syncDeletedVehicles(List<VehicleApplyE> vehicles) {
|
||||||
|
if (vehicles == null || vehicles.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> carNumList = new ArrayList<>();
|
||||||
|
for (VehicleApplyE vehicle : vehicles) {
|
||||||
|
if (isRelatedPartyVehicle(vehicle)) {
|
||||||
|
carNumList.add(vehicle.getLicenceNo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!carNumList.isEmpty()) {
|
||||||
|
checkResult(daHuaGateway.deleteCar(carNumList), "删除大华车辆失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void syncAddedVehicle(VehicleApplyE vehicle) {
|
||||||
|
checkResult(daHuaGateway.addCar(buildCarCmd(vehicle)), "新增大华车辆失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
private DaHuaCarAddCmd buildCarCmd(VehicleApplyE vehicle) {
|
||||||
|
DaHuaCarAddCmd cmd = new DaHuaCarAddCmd();
|
||||||
|
cmd.setCarNum(vehicle.getLicenceNo());
|
||||||
|
cmd.setCarNumColor(CarEnum.getMenuKeyByPath(vehicle.getLicenceType()));
|
||||||
|
// 大华车辆类型与本地字典不一致,该字段可选,不能直接透传本地 vehicleType。
|
||||||
|
cmd.setDepartmentId(1L);
|
||||||
|
cmd.setDepartmentName(vehicle.getVehicleDepartmentName());
|
||||||
|
cmd.setService("evo-thirdParty");
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isRelatedPartyVehicle(VehicleApplyE vehicle) {
|
||||||
|
return vehicle != null
|
||||||
|
&& VehicleBelongTypeEnum.XGF_VEHICLES.getCode().equals(vehicle.getVehicleBelongType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkResult(Map<String, Object> result, String message) {
|
||||||
|
if (result == null || !Boolean.TRUE.equals(result.get("passed"))) {
|
||||||
|
Object errorMessage = result == null ? null : result.get("errMsg");
|
||||||
|
throw new BizException(message + (errorMessage == null ? "" : ": " + errorMessage));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue