Commit 9d156871 by huangjinxin

fix:bean组织机构数据同步,工单一家多单分组优化

1 parent c3266f4a
...@@ -35,5 +35,5 @@ public interface OrgTeamEngineerDao extends JpaRepository<OrgTeamEngineerEntity, ...@@ -35,5 +35,5 @@ public interface OrgTeamEngineerDao extends JpaRepository<OrgTeamEngineerEntity,
@Query("UPDATE OrgTeamEngineerEntity tt SET tt.status = :status WHERE tt.teamId = :teamId AND tt.engineerCode IN :engineerCodes") @Query("UPDATE OrgTeamEngineerEntity tt SET tt.status = :status WHERE tt.teamId = :teamId AND tt.engineerCode IN :engineerCodes")
void updateStatusByEngineerCodes(String teamId, List<String> engineerCodes, int status); void updateStatusByEngineerCodes(String teamId, List<String> engineerCodes, int status);
OrgTeamEngineerEntity findByEngineerCode(String engineerCode); List<OrgTeamEngineerEntity> findByEngineerCode(String engineerCode);
} }
...@@ -2,5 +2,5 @@ package com.dituhui.pea.order.enums; ...@@ -2,5 +2,5 @@ package com.dituhui.pea.order.enums;
public enum AppointmentMethodEnum { public enum AppointmentMethodEnum {
// 指派方式(MANUAL人工/AUTO_NOW 自动立即/AUTO_BATCH/PROTECTION 自保点) // 指派方式(MANUAL人工/AUTO_NOW 自动立即/AUTO_BATCH/PROTECTION 自保点)
MANUAL, AUTO_NOW, AUTO_BATCH, PROTECTION MANUAL, AUTO_NOW, AUTO_BATCH, PROTECTION, CANCELED,
} }
...@@ -11,6 +11,7 @@ public enum BeanServiceFlowEnum { ...@@ -11,6 +11,7 @@ public enum BeanServiceFlowEnum {
PENDING("已联系", "PENDING"), PENDING("已联系", "PENDING"),
CONTACTED("准备服务", "CONTACTED"), CONTACTED("准备服务", "CONTACTED"),
STARTED("开始服务", "STARTED"), STARTED("开始服务", "STARTED"),
CANCELED("已取消", "CANCELED"),
FINISHED("结束服务", "FINISHED"); FINISHED("结束服务", "FINISHED");
private String name; private String name;
......
package com.dituhui.pea.order.feign.bean.enums;
import org.apache.commons.lang3.StringUtils;
import java.util.List;
public enum BeanRegionIdEnum {
// 上海大区,部门ID:1575934909016727553,华东大区:1575934912659275778
SHANGHAIDAQU("1575934909016727553"),
HUADONGDAQU("1575934912659275778"),
;
private String id;
BeanRegionIdEnum(String id) {
this.id = id;
}
public static Boolean getEnumByRegionId(String regionId) {
if (StringUtils.isBlank(regionId)) {
return false;
}
BeanRegionIdEnum[] beanRegionIdEnums = BeanRegionIdEnum.values();
for (BeanRegionIdEnum regionIdEnum : beanRegionIdEnums) {
if (regionId.equals(regionIdEnum.id)) {
return true;
}
}
return false;
}
}
...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.BusinessException; import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.order.common.RedisService; import com.dituhui.pea.order.common.RedisService;
import com.dituhui.pea.order.common.jackson.JsonUtil; import com.dituhui.pea.order.common.jackson.JsonUtil;
import com.dituhui.pea.order.dao.OrgBranchDao; import com.dituhui.pea.order.dao.OrgBranchDao;
...@@ -16,6 +17,7 @@ import com.dituhui.pea.order.entity.OrgGroupEntity; ...@@ -16,6 +17,7 @@ import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.feign.IBeanRemoteService; import com.dituhui.pea.order.feign.IBeanRemoteService;
import com.dituhui.pea.order.feign.bean.*; import com.dituhui.pea.order.feign.bean.*;
import com.dituhui.pea.order.feign.bean.enums.BeanOrgLevelEnum; import com.dituhui.pea.order.feign.bean.enums.BeanOrgLevelEnum;
import com.dituhui.pea.order.feign.bean.enums.BeanRegionIdEnum;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
...@@ -24,10 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,10 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/** /**
* 调用BEAN远程接口实现 * 调用BEAN远程接口实现
...@@ -42,6 +41,13 @@ public class BeanRemoteServiceImpl { ...@@ -42,6 +41,13 @@ public class BeanRemoteServiceImpl {
private final RedisService redisService; private final RedisService redisService;
//组织机构map,防止重复查询数据库 //组织机构map,防止重复查询数据库
private static Map<String, OrgBranchEntity> branchMap = new HashMap<>(); private static Map<String, OrgBranchEntity> branchMap = new HashMap<>();
// 上海大区,部门ID:1575934909016727553,华东大区:1575934912659275778
private static List<String> regionIds = new ArrayList<>() {
{
add("1575934909016727553");
add("1575934912659275778");
}
};
@Value("${bean.app-key}") @Value("${bean.app-key}")
private String appKey; private String appKey;
...@@ -154,21 +160,68 @@ public class BeanRemoteServiceImpl { ...@@ -154,21 +160,68 @@ public class BeanRemoteServiceImpl {
return Result.failed(beanR.getMessage()); return Result.failed(beanR.getMessage());
} }
for (Department department : beanR.getData()) { for (Department department : beanR.getData()) {
if (StringUtils.isBlank(department.getBsDeptId())) {
continue;
}
log.info("处理部门详情---->{}", department.getBsDeptId()); log.info("处理部门详情---->{}", department.getBsDeptId());
Result result = this.departmentDetail(accessToken, department.getBsDeptId()); Boolean isDisposeData = true;
if (!BeanRegionIdEnum.getEnumByRegionId(department.getBsDeptId())) {
log.info("处理部门详情ID不在所需同步大区---->{}", department.getBsDeptId());
isDisposeData = false;
}
if (isDisposeData) {
System.out.println(222);
Result result = this.departmentDetail(accessToken, department.getBsDeptId(), null);
log.info("处理部门详情,id:{},结果---->{}", department.getBsDeptId(), result.getCode()); log.info("处理部门详情,id:{},结果---->{}", department.getBsDeptId(), result.getCode());
if (result.getCode().equals(StatusCodeEnum.SUCCESS.getCode()) && ObjUtil.isNotNull(department.getChildren())) {
continue;
}
}
disposeChildren(department, accessToken, isDisposeData, null);
System.out.println(111);
} }
return Result.success(); return Result.success();
} }
/** /**
* 处理子部门
*
* @param departments
* @param accessToken
*/
private void disposeChildren(Department departments, String accessToken, Boolean isDisposeData, String parentId) {
for (Department department : departments.getChildren()) {
if (StringUtils.isBlank(department.getBsDeptId())) {
return;
}
log.info("处理部门详情---->{}", department.getBsDeptId());
if (!BeanRegionIdEnum.getEnumByRegionId(department.getBsDeptId())) {
log.info("处理部门详情ID不在所需同步大区---->{}", department.getBsDeptId());
} else {
isDisposeData = true;
}
if (isDisposeData) {
System.out.println(222);
Result result = this.departmentDetail(accessToken, department.getBsDeptId(), departments.getBsDeptId());
log.info("处理部门详情,id:{},结果---->{}", department.getBsDeptId(), result.getCode());
if (result.getCode().equals(StatusCodeEnum.SUCCESS.getCode()) && ObjUtil.isNotNull(department.getChildren())) {
continue;
}
}
disposeChildren(department, accessToken, isDisposeData, departments.getBsDeptId());
}
}
/**
* 处理单极机构,包含大区,分部,分站 * 处理单极机构,包含大区,分部,分站
* *
* @param token * @param token
* @param orgId * @param orgId
* @return * @return
*/ */
public Result departmentDetail(String token, String orgId) { public Result departmentDetail(String token, String orgId, String parentId) {
//获取token //获取token
BeanR<Department> departmentBeanR = beanRemoteService.departmentDetail(token, orgId); BeanR<Department> departmentBeanR = beanRemoteService.departmentDetail(token, orgId);
if (!departmentBeanR.getSuccess() || ObjUtil.isNull(departmentBeanR.getData())) { if (!departmentBeanR.getSuccess() || ObjUtil.isNull(departmentBeanR.getData())) {
...@@ -182,10 +235,11 @@ public class BeanRemoteServiceImpl { ...@@ -182,10 +235,11 @@ public class BeanRemoteServiceImpl {
if (ObjUtil.isNull(clusterEntity)) { if (ObjUtil.isNull(clusterEntity)) {
clusterEntity = new OrgClusterEntity(); clusterEntity = new OrgClusterEntity();
} }
clusterEntity.setName(data.getTagName()); clusterEntity.setName(StringUtils.isNotBlank(data.getDesc()) ? data.getDesc() : data.getTagName());
clusterEntity.setClusterId(data.getBsDeptId());
clusterEntity.setAbbreviation(data.getAbbreviation()); clusterEntity.setAbbreviation(data.getAbbreviation());
clusterEntity.setStatus(data.getEnable()); clusterEntity.setStatus(data.getEnable());
clusterEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList())); clusterEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "{}" : JSONObject.toJSONString(data.getManageCityList()));
clusterEntity.setMemo(data.getDesc()); clusterEntity.setMemo(data.getDesc());
clusterEntity.setCode(data.getCode()); clusterEntity.setCode(data.getCode());
clusterEntity.setPhone(data.getPhone()); clusterEntity.setPhone(data.getPhone());
...@@ -197,16 +251,18 @@ public class BeanRemoteServiceImpl { ...@@ -197,16 +251,18 @@ public class BeanRemoteServiceImpl {
if (ObjUtil.isNull(branchEntity)) { if (ObjUtil.isNull(branchEntity)) {
branchEntity = new OrgBranchEntity(); branchEntity = new OrgBranchEntity();
} }
branchEntity.setBranchName(data.getTagName()); // branchEntity.setBranchName(data.getTagName());
branchEntity.setBranchName(StringUtils.isNotBlank(data.getDesc()) ? data.getDesc() : data.getTagName());
branchEntity.setBranchId(data.getBsDeptId());
branchEntity.setAbbreviation(data.getAbbreviation()); branchEntity.setAbbreviation(data.getAbbreviation());
branchEntity.setStatus(data.getEnable()); branchEntity.setStatus(data.getEnable());
branchEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList())); branchEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "{}" : JSONObject.toJSONString(data.getManageCityList()));
branchEntity.setMemo(data.getDesc()); branchEntity.setMemo(data.getDesc());
branchEntity.setCode(data.getCode()); branchEntity.setCode(data.getCode());
branchEntity.setPhone(data.getPhone()); branchEntity.setPhone(data.getPhone());
branchEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled()); branchEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
branchEntity.setReserveTimeMax(data.getPartReserveTimeMax()); branchEntity.setReserveTimeMax(data.getPartReserveTimeMax());
branchEntity.setClusterId(data.getParentId()); branchEntity.setClusterId(parentId);
orgBranchDao.save(branchEntity); orgBranchDao.save(branchEntity);
branchMap.put(data.getBsDeptId(), branchEntity); branchMap.put(data.getBsDeptId(), branchEntity);
} }
...@@ -218,25 +274,27 @@ public class BeanRemoteServiceImpl { ...@@ -218,25 +274,27 @@ public class BeanRemoteServiceImpl {
if (ObjUtil.isNull(groupEntity)) { if (ObjUtil.isNull(groupEntity)) {
groupEntity = new OrgGroupEntity(); groupEntity = new OrgGroupEntity();
} }
groupEntity.setGroupName(data.getTagName()); // groupEntity.setGroupName(data.getTagName());
groupEntity.setGroupName(StringUtils.isNotBlank(data.getDesc()) ? data.getDesc() : data.getTagName());
groupEntity.setGroupId(data.getBsDeptId());
groupEntity.setAbbreviation(data.getAbbreviation()); groupEntity.setAbbreviation(data.getAbbreviation());
groupEntity.setStatus(data.getEnable()); groupEntity.setStatus(data.getEnable());
groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList())); groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "{}" : JSONObject.toJSONString(data.getManageCityList()));
groupEntity.setMemo(data.getDesc()); groupEntity.setMemo(data.getDesc());
groupEntity.setCode(data.getCode()); groupEntity.setCode(data.getCode());
groupEntity.setPhone(data.getPhone()); groupEntity.setPhone(data.getPhone());
groupEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled()); groupEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
groupEntity.setReserveTimeMax(data.getPartReserveTimeMax()); groupEntity.setReserveTimeMax(data.getPartReserveTimeMax());
//处理clusterId和branchId //处理clusterId和branchId
OrgBranchEntity branchEntity = branchMap.get(data.getParentId()); OrgBranchEntity branchEntity = branchMap.get(parentId);
if (ObjUtil.isNull(branchEntity)) { if (ObjUtil.isNull(branchEntity)) {
branchEntity = orgBranchDao.getByBranchId(data.getParentId()); branchEntity = orgBranchDao.getByBranchId(parentId);
if (ObjUtil.isNull(branchEntity)) { if (ObjUtil.isNull(branchEntity)) {
return Result.failed(); return Result.failed();
} }
branchMap.put(data.getParentId(), branchEntity); branchMap.put(parentId, branchEntity);
} }
groupEntity.setBranchId(data.getParentId()); groupEntity.setBranchId(parentId);
groupEntity.setClusterId(branchEntity.getClusterId()); groupEntity.setClusterId(branchEntity.getClusterId());
//处理分站外围 //处理分站外围
if (data.getDeptType().equals(BeanOrgLevelEnum.PERIPHERY.getCode())) { if (data.getDeptType().equals(BeanOrgLevelEnum.PERIPHERY.getCode())) {
...@@ -268,8 +326,8 @@ public class BeanRemoteServiceImpl { ...@@ -268,8 +326,8 @@ public class BeanRemoteServiceImpl {
} }
for (ServiceOrg serviceOrg : listBeanR.getData()) { for (ServiceOrg serviceOrg : listBeanR.getData()) {
log.info("处理网点部门详情---->{}", serviceOrg.getServiceOrgId()); log.info("处理网点部门详情---->{}", serviceOrg.getServiceOrgId());
Result result = this.serviceOrgDetail(accessToken, serviceOrg); // Result result = this.serviceOrgDetail(accessToken, serviceOrg);
log.info("处理网点部门详情,id:{},结果---->{}", serviceOrg.getServiceOrgId(), result.getCode()); // log.info("处理网点部门详情,id:{},结果---->{}", serviceOrg.getServiceOrgId(), result.getCode());
} }
return Result.success(); return Result.success();
} }
...@@ -285,6 +343,7 @@ public class BeanRemoteServiceImpl { ...@@ -285,6 +343,7 @@ public class BeanRemoteServiceImpl {
if (ObjUtil.isNull(groupEntity)) { if (ObjUtil.isNull(groupEntity)) {
groupEntity = new OrgGroupEntity(); groupEntity = new OrgGroupEntity();
} }
groupEntity.setGroupId(data.getServiceOrgId());
groupEntity.setGroupName(data.getName()); groupEntity.setGroupName(data.getName());
groupEntity.setStatus(data.getStatus()); groupEntity.setStatus(data.getStatus());
groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getServiceRange()) ? "" : JSONObject.toJSONString(data.getServiceRange())); groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getServiceRange()) ? "" : JSONObject.toJSONString(data.getServiceRange()));
...@@ -341,5 +400,4 @@ public class BeanRemoteServiceImpl { ...@@ -341,5 +400,4 @@ public class BeanRemoteServiceImpl {
return accessTokenR.getData(); return accessTokenR.getData();
} }
} }
...@@ -399,7 +399,10 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -399,7 +399,10 @@ public class DispatchServiceImpl implements DispatchService {
} }
item.setMultipleOrderList(multipleItems); item.setMultipleOrderList(multipleItems);
} }
Object groupkey = null; Object groupkey = "其他";
if (groupTagId.equals(OrderGroupEnum.five.getCode())) {
groupkey = "一家一台";
}
// 0:工单优先级,1:耗时,2:意向时间,3:分站/网点,4:技能,5:一家多单 // 0:工单优先级,1:耗时,2:意向时间,3:分站/网点,4:技能,5:一家多单
if (groupTagId.equals(OrderGroupEnum.zero.getCode()) && StringUtils.isNotEmpty(item.getBeanPriority())) { if (groupTagId.equals(OrderGroupEnum.zero.getCode()) && StringUtils.isNotEmpty(item.getBeanPriority())) {
// 分组字段:紧急、正常 数据库:1:紧急、0:正常 // 分组字段:紧急、正常 数据库:1:紧急、0:正常
...@@ -432,9 +435,9 @@ public class DispatchServiceImpl implements DispatchService { ...@@ -432,9 +435,9 @@ public class DispatchServiceImpl implements DispatchService {
} else if (groupTagId.equals(OrderGroupEnum.four.getCode()) && StringUtils.isNotEmpty(item.getSkill())) { } else if (groupTagId.equals(OrderGroupEnum.four.getCode()) && StringUtils.isNotEmpty(item.getSkill())) {
makeOrderMap(groupByMap, item, item.getSkill()); makeOrderMap(groupByMap, item, item.getSkill());
} else if (groupTagId.equals(OrderGroupEnum.five.getCode()) && StringUtils.isNotEmpty(item.getMultipleOrders())) { } else if (groupTagId.equals(OrderGroupEnum.five.getCode()) && StringUtils.isNotEmpty(item.getMultipleOrders())) {
makeOrderMap(groupByMap, item, "一家多台ID:" + item.getMultipleOrders()); makeOrderMap(groupByMap, item, "一家多台ID:" + o.getAddressId());
} else { } else {
makeOrderMap(groupByMap, item, "其他"); makeOrderMap(groupByMap, item, groupkey);
} }
return item; return item;
} }
......
...@@ -167,8 +167,11 @@ public class OrderCreateServiceImpl implements OrderCreateService { ...@@ -167,8 +167,11 @@ public class OrderCreateServiceImpl implements OrderCreateService {
entity.setAppointEngineerCodes(appointEngineerCodes); entity.setAppointEngineerCodes(appointEngineerCodes);
if (req.getIsAppointEngineer() == 1) { if (req.getIsAppointEngineer() == 1) {
EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(req.getAppointEngineerCodes().get(0)); EngineerInfoEntity engineerInfo = engineerInfoDao.getByEngineerCode(req.getAppointEngineerCodes().get(0));
OrgTeamEngineerEntity orgTeamEngineer = orgTeamEngineerDao.findByEngineerCode(req.getAppointEngineerCodes().get(0)); List<OrgTeamEngineerEntity> orgTeamEngineers = orgTeamEngineerDao.findByEngineerCode(req.getAppointEngineerCodes().get(0));
OrgTeamEntity byTeamId = orgTeamDao.getByTeamId(orgTeamEngineer.getTeamId()); if (CollectionUtils.isEmpty(orgTeamEngineers)) {
return Result.failed(StatusCodeEnum.FENDAN_TEAM_UNMATCHED);
}
OrgTeamEntity byTeamId = orgTeamDao.getByTeamId(orgTeamEngineers.get(0).getTeamId());
entity.setEngineerCode(engineerInfo.getEngineerCode()); entity.setEngineerCode(engineerInfo.getEngineerCode());
entity.setEngineerName(engineerInfo.getName()); entity.setEngineerName(engineerInfo.getName());
entity.setEngineerPhone(engineerInfo.getPhone()); entity.setEngineerPhone(engineerInfo.getPhone());
......
...@@ -18,6 +18,7 @@ import com.dituhui.pea.order.entity.OrderInfoEntity; ...@@ -18,6 +18,7 @@ import com.dituhui.pea.order.entity.OrderInfoEntity;
import com.dituhui.pea.order.entity.OrgBranchEntity; import com.dituhui.pea.order.entity.OrgBranchEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity; import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.SkillInfoEntity; import com.dituhui.pea.order.entity.SkillInfoEntity;
import com.dituhui.pea.order.enums.AppointmentMethodEnum;
import com.dituhui.pea.order.enums.BeanServiceFlowEnum; import com.dituhui.pea.order.enums.BeanServiceFlowEnum;
import com.dituhui.pea.order.enums.OrderStatusEnum; import com.dituhui.pea.order.enums.OrderStatusEnum;
import com.dituhui.pea.order.enums.ServiceStatusEnum; import com.dituhui.pea.order.enums.ServiceStatusEnum;
...@@ -154,9 +155,9 @@ public class OrderInfoServiceImpl implements OrderInfoService { ...@@ -154,9 +155,9 @@ public class OrderInfoServiceImpl implements OrderInfoService {
//记录流程 //记录流程
commonService.addOrderEvent(request.getOrderId(), "", "BEAN", "BEAN", OrderStatusEnum.NORMAL.getDescription(), request.getStage(), "", LocalDateTimeUtil.of(request.getHappen())); commonService.addOrderEvent(request.getOrderId(), "", "BEAN", "BEAN", OrderStatusEnum.NORMAL.getDescription(), request.getStage(), "", LocalDateTimeUtil.of(request.getHappen()));
} else if (request.getOrderStatus().equalsIgnoreCase(OrderStatusEnum.CANCELED.getCode())) { } else if (request.getOrderStatus().equalsIgnoreCase(OrderStatusEnum.CANCELED.getCode())) {
orderInfo.setServiceStatus(""); orderInfo.setServiceStatus(BeanServiceFlowEnum.CANCELED.getStatus());
orderInfo.setOrderStatus(OrderStatusEnum.CANCELED.getCode()); orderInfo.setOrderStatus(OrderStatusEnum.CANCELED.getCode());
orderInfo.setAppointmentStatus(""); orderInfo.setAppointmentStatus(AppointmentMethodEnum.CANCELED.name());
if (StringUtils.isBlank(request.getDescription())) { if (StringUtils.isBlank(request.getDescription())) {
orderInfo.setDescription(request.getDescription()); orderInfo.setDescription(request.getDescription());
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!