Commit 8d4244f9 by huangjinxin

feat:提交组织同步相关,防止冲突

1 parent 26c731d8
......@@ -41,6 +41,11 @@ public class Result<T> {
*/
private T result;
public static <T> Result<T> success() {
return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), null);
}
public static <T> Result<T> success(T result) {
return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), result);
}
......
......@@ -2,22 +2,22 @@ package com.dituhui.pea.pojo.saas.resp;
public class GovPosition {
private long x;
private long y;
private Double x;
private Double y;
public void setX(long x) {
public void setX(Double x) {
this.x = x;
}
public long getX() {
public Double getX() {
return x;
}
public void setY(long y) {
public void setY(Double y) {
this.y = y;
}
public long getY() {
public Double getY() {
return y;
}
......
......@@ -50,5 +50,31 @@ public class OrgBranchEntity {
private LocalDateTime updateTime = LocalDateTime.now();
public OrgBranchEntity() {}
public OrgBranchEntity() {
}
/**
* 部门缩写
*/
private String abbreviation;
/**
* 部门编号
*/
private String code;
/**
* 部门负责人联系方式
*/
private String phone;
/**
* 是否启用外围仓 0未启用 1启用
*/
private Integer warehouseEnabled = 0;
/**
* 最长配件保留时长(天)
*/
private Integer reserveTimeMax = 0;
/**
* 帐号状态(0无效 1有效)
*/
private Integer status = 1;
}
......@@ -45,4 +45,29 @@ public class OrgClusterEntity {
public OrgClusterEntity() {
}
/**
* 部门描述 非必须
*/
private String memo;
/**
* 部门缩写
*/
private String abbreviation;
/**
* 部门编号
*/
private String code;
/**
* 部门负责人联系方式
*/
private String phone;
/**
* 是否启用外围仓 0未启用 1启用
*/
private Integer warehouseEnabled = 0;
/**
* 最长配件保留时长(天)
*/
private Integer reserveTimeMax = 0;
}
......@@ -62,15 +62,20 @@ public class Department {
/**
* 是否启用外围仓 0未启用 1启用
*/
private int peripheralWarehouseEnabled;
private Integer peripheralWarehouseEnabled;
/**
* 最长配件保留时长(天)
*/
private int partReserveTimeMax;
private Integer partReserveTimeMax;
/**
* 状态 1启用 0禁用
*/
private int enable;
private Integer enable;
/**
* 管辖区域
*/
private List<BaseAddress> manageCityList;
/**
* 子部门列表跟外层结构相同
......
package com.dituhui.pea.order.feign.bean;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class ManageCityDepartment extends Department{
/**
* 管辖区域
*/
private BaseAddress manageCityList;
}
//package com.dituhui.pea.order.feign.bean;
//
//import lombok.Getter;
//import lombok.Setter;
//
//@Setter
//@Getter
//public class ManageCityDepartment extends Department{
// /**
// * 管辖区域
// */
// private BaseAddress manageCityList;
//}
package com.dituhui.pea.order.feign.bean.enums;
import com.dituhui.pea.common.IResult;
/**
* boxi bean组织机构传输接口状态码枚举
* bean doc url https://publink-hz.feishu.cn/wiki/L4d1wwuGGiQcDqkGh3LcDJPon1i
* 集团 CLIQUE
* 大区 REGION
* 分部 BRANCH
* <p>
* 分站 STATION
* 外围 PERIPHERY
* 寄修中心 REPAIR_CENTER
*/
public enum BeanOrgLevelEnum implements IResult {
CLIQUE("CLIQUE", "集团"),
REGION("REGION", "大区"),
BRANCH("BRANCH", "分部"),
STATION("STATION", "分站"),
PERIPHERY("PERIPHERY", "外围"),
REPAIR_CENTER("REPAIR_CENTER", "寄修中心");
private String code;
private String message;
BeanOrgLevelEnum() {
}
BeanOrgLevelEnum(String code, String message) {
this.code = code;
this.message = message;
}
@Override
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Override
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package com.dituhui.pea.order.feign.bean;
package com.dituhui.pea.order.feign.bean.enums;
import com.dituhui.pea.common.IResult;
......
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.RedisService;
import com.dituhui.pea.order.common.jackson.JsonUtil;
import com.dituhui.pea.order.dao.OrgBranchDao;
import com.dituhui.pea.order.dao.OrgClusterDao;
import com.dituhui.pea.order.dao.OrgGroupDao;
import com.dituhui.pea.order.entity.OrgBranchEntity;
import com.dituhui.pea.order.entity.OrgClusterEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.feign.IBeanRemoteService;
import com.dituhui.pea.order.feign.bean.*;
import com.dituhui.pea.order.feign.bean.enums.BeanOrgLevelEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
......@@ -26,6 +40,8 @@ public class BeanRemoteServiceImpl {
private final IBeanRemoteService beanRemoteService;
private final RedisService redisService;
//组织机构map,防止重复查询数据库
private static Map<String, OrgBranchEntity> branchMap = new HashMap<>();
@Value("${bean.app-key}")
private String appKey;
......@@ -33,6 +49,15 @@ public class BeanRemoteServiceImpl {
@Value("${bean.secret-key}")
private String secretKey;
@Autowired
private OrgClusterDao orgClusterDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Autowired
private OrgGroupDao orgGroupDao;
//TODO 仅用于联通测试
public void testAllDepartment() {
......@@ -110,7 +135,92 @@ public class BeanRemoteServiceImpl {
}
public Result allDepartment() {
//获取token
final String accessToken = getAccessToken();
BeanR<List<Department>> beanR = beanRemoteService.allDepartment(accessToken);
if (!beanR.getSuccess() || ObjUtil.isNull(beanR.getData())) {
return Result.failed(beanR.getMessage());
}
for (Department department : beanR.getData()) {
log.info("处理部门详情---->{}" + department.getBsDeptId());
Result result = this.departmentDetail(accessToken, department.getBsDeptId());
log.info("处理部门详情,id:{},结果---->{}" + department.getBsDeptId(), result.getCode());
}
return Result.success();
}
public Result departmentDetail(String token, String orgId) {
//获取token
BeanR<Department> departmentBeanR = beanRemoteService.departmentDetail(token, orgId);
if (!departmentBeanR.getSuccess() || ObjUtil.isNull(departmentBeanR.getData())) {
return Result.failed(departmentBeanR.getMessage());
}
Department data = departmentBeanR.getData();
//处理大区,分部数据
if (StringUtils.isNotBlank(data.getDeptLevel())) {
if (data.getDeptLevel().equals(BeanOrgLevelEnum.REGION.getCode())) {
OrgClusterEntity clusterEntity = orgClusterDao.getByClusterId(data.getBsDeptId());
if (ObjUtil.isNull(clusterEntity)) {
clusterEntity = new OrgClusterEntity();
}
clusterEntity.setName(data.getTagName());
clusterEntity.setAbbreviation(data.getAbbreviation());
clusterEntity.setStatus(data.getEnable());
clusterEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList()));
clusterEntity.setMemo(data.getDesc());
clusterEntity.setCode(data.getCode());
clusterEntity.setPhone(data.getPhone());
clusterEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
clusterEntity.setReserveTimeMax(data.getPartReserveTimeMax());
orgClusterDao.save(clusterEntity);
} else if (data.getDeptLevel().equals(BeanOrgLevelEnum.BRANCH.getCode())) {
OrgBranchEntity branchEntity = orgBranchDao.getByBranchId(data.getBsDeptId());
if (ObjUtil.isNull(branchEntity)) {
branchEntity = new OrgBranchEntity();
}
branchEntity.setBranchName(data.getTagName());
branchEntity.setAbbreviation(data.getAbbreviation());
branchEntity.setStatus(data.getEnable());
branchEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList()));
branchEntity.setMemo(data.getDesc());
branchEntity.setCode(data.getCode());
branchEntity.setPhone(data.getPhone());
branchEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
branchEntity.setReserveTimeMax(data.getPartReserveTimeMax());
branchEntity.setClusterId(data.getParentId());
orgBranchDao.save(branchEntity);
branchMap.put(data.getBsDeptId(), branchEntity);
}
}
//处理分站外围数据
if (StringUtils.isNotBlank(data.getDeptType()) && (data.getDeptType().equals(BeanOrgLevelEnum.STATION.getCode())
|| data.getDeptType().equals(BeanOrgLevelEnum.PERIPHERY.getCode()))) {
OrgGroupEntity groupEntity = orgGroupDao.getByGroupId(data.getBsDeptId());
if (ObjUtil.isNull(groupEntity)) {
groupEntity = new OrgGroupEntity();
}
groupEntity.setGroupName(data.getTagName());
//groupEntity.setAbbreviation(data.getAbbreviation());
//groupEntity.setStatus(data.getEnable());
//groupEntity.setCitycodeList(CollectionUtils.isEmpty(data.getManageCityList()) ? "" : JSONObject.toJSONString(data.getManageCityList()));
//groupEntity.setMemo(data.getDesc());
//groupEntity.setCode(data.getCode());
//groupEntity.setPhone(data.getPhone());
//groupEntity.setWarehouseEnabled(data.getPeripheralWarehouseEnabled());
//groupEntity.setReserveTimeMax(data.getPartReserveTimeMax());
orgGroupDao.save(groupEntity);
return Result.success();
}
return Result.success();
}
/**
* 获取bean token
*
* @return
*/
private String getAccessToken() {
if (redisService.hasKey(CACHE_ACCESS_TOKEN_KEY) && redisService.getExpireTime(CACHE_ACCESS_TOKEN_KEY) > 500) {
......@@ -122,7 +232,8 @@ public class BeanRemoteServiceImpl {
throw new BusinessException("调用BEAN获取ACCESS_TOKEN接口错误--------> 空返回值");
}
final String accessToken = remoteBeanAccessToken.getAccess_token();
final long expireTime = Long.parseLong(remoteBeanAccessToken.getExpire_time());
//提前500秒到期
final long expireTime = Long.parseLong(remoteBeanAccessToken.getExpire_time()) - (System.currentTimeMillis() + 500 * 1000);
//存REDIS获取
redisService.set(CACHE_ACCESS_TOKEN_KEY, accessToken, expireTime);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!