|
@ -24,10 +24,16 @@ import com.alibaba.excel.ExcelReader; |
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.JSON; |
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
import com.alibaba.fastjson.TypeReference; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
import com.aliyun.dingtalk.module.DingTalkResult; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient; |
|
|
|
|
|
import com.dingtalk.api.DingTalkClient; |
|
|
|
|
|
import com.dingtalk.api.request.OapiDepartmentGetRequest; |
|
|
|
|
|
import com.dingtalk.api.response.OapiDepartmentGetResponse; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
@ -40,9 +46,11 @@ import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
|
|
|
import com.epmet.commons.tools.redis.common.CustomerDingDingRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
|
|
import com.epmet.commons.tools.redis.common.bean.DingMiniInfoCache; |
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
@ -50,10 +58,8 @@ import com.epmet.constant.CustomerGridConstant; |
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dao.*; |
|
|
import com.epmet.dto.*; |
|
|
import com.epmet.dto.*; |
|
|
import com.epmet.dto.form.IcNeighborHoodAddFormDTO; |
|
|
import com.epmet.dto.V2UserGetuserinfoResDTO; |
|
|
import com.epmet.dto.form.ImportInfoFormDTO; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.ImportTaskCommonFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.NeighborHoodOptionFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.yt.ChooseGridFormDTO; |
|
|
import com.epmet.dto.form.yt.ChooseGridFormDTO; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.dto.result.*; |
|
|
import com.epmet.entity.*; |
|
|
import com.epmet.entity.*; |
|
@ -64,8 +70,13 @@ import com.epmet.model.ImportNeighborHoodInfoListener; |
|
|
import com.epmet.model.NeighborHoodInfoModel; |
|
|
import com.epmet.model.NeighborHoodInfoModel; |
|
|
import com.epmet.redis.IcHouseRedis; |
|
|
import com.epmet.redis.IcHouseRedis; |
|
|
import com.epmet.service.*; |
|
|
import com.epmet.service.*; |
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import com.github.pagehelper.Page; |
|
|
import com.github.pagehelper.Page; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
|
|
import com.taobao.api.ApiException; |
|
|
|
|
|
import com.taobao.dingtalk.client.DingTalkClientToken; |
|
|
|
|
|
import com.taobao.dingtalk.client.DingTalkClientUser; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
import org.apache.commons.collections4.ListUtils; |
|
@ -134,6 +145,10 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao |
|
|
private IcNeighborHoodDao neighborHoodDao; |
|
|
private IcNeighborHoodDao neighborHoodDao; |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerAgencyDao customerAgencyDao; |
|
|
private CustomerAgencyDao customerAgencyDao; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DingTalkClientToken dingTalkClientToken; |
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DingTalkClientUser dingTalkClientUser; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageData<IcNeighborHoodDTO> page(Map<String, Object> params) { |
|
|
public PageData<IcNeighborHoodDTO> page(Map<String, Object> params) { |
|
@ -263,6 +278,92 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<BuildingResultDTO> getNeighborhoodListForDingding(ChooseGridFormDTO dto) throws ApiException, IOException { |
|
|
|
|
|
|
|
|
|
|
|
DingMiniInfoCache dingMiniInfo = CustomerDingDingRedis.getDingMiniInfo(dto.getMiniAppId()); |
|
|
|
|
|
if (dingMiniInfo == null){ |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉应用配置异常", "获取钉钉应用配置异常"); |
|
|
|
|
|
} |
|
|
|
|
|
// 1、获取企业内部应用的accessToken文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-access_token-of-an-internal-app
|
|
|
|
|
|
String accessToken = ""; |
|
|
|
|
|
DingTalkResult<String> dingTalkResult = dingTalkClientToken.getAppAccessTokenToken(dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret()); |
|
|
|
|
|
if (!dingTalkResult.success() || StringUtils.isBlank(dingTalkResult.getData())) { |
|
|
|
|
|
log.error(String.format("获取企业内部应用的accessToken失败,customKey:%s,customSecret:%s", dingMiniInfo.getSuiteKey(), dingMiniInfo.getSuiteSecret())); |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取企业内部应用的accessToken异常", "获取企业内部应用的accessToken"); |
|
|
|
|
|
} |
|
|
|
|
|
accessToken = dingTalkResult.getData(); |
|
|
|
|
|
log.info(String.format("1、获取企业内部应用的accessToken返参:%s", accessToken)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2、通过免登码获取用户信息,文档地址:https://open.dingtalk.com/document/orgapp-server/obtain-the-userid-of-a-user-by-using-the-log-free
|
|
|
|
|
|
DingTalkResult<String> v2UserGetuserinfoRes = dingTalkClientToken.getUserInfo(accessToken, dto.getAuthCode()); |
|
|
|
|
|
if (!v2UserGetuserinfoRes.success() || StringUtils.isBlank(v2UserGetuserinfoRes.getData())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "通过免登码获取用户信息异常", "通过免登码获取用户信息异常"); |
|
|
|
|
|
} |
|
|
|
|
|
log.info(String.format("2、通过免登码获取用户信息返参:%s", v2UserGetuserinfoRes.getData())); |
|
|
|
|
|
V2UserGetuserinfoResDTO v2UserGetuserinfoResDTO = JSON.parseObject(v2UserGetuserinfoRes.getData(), V2UserGetuserinfoResDTO.class); |
|
|
|
|
|
if (null == v2UserGetuserinfoResDTO || StringUtils.isBlank(v2UserGetuserinfoResDTO.getUserid())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取钉钉用户userid为空", "获取钉钉用户userid为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3、查询用户详情,文档地址:https://open.dingtalk.com/document/isvapp-server/query-user-details
|
|
|
|
|
|
DingTalkResult<String> v2UserGetRes = dingTalkClientToken.getUserDetail(v2UserGetuserinfoResDTO.getUserid(), accessToken); |
|
|
|
|
|
if (!v2UserGetRes.success() || StringUtils.isBlank(v2UserGetRes.getData())) { |
|
|
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "根据userId查询用户详情失败", "根据userId查询用户详情失败"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
String meDate = v2UserGetRes.getData(); |
|
|
|
|
|
|
|
|
|
|
|
// String meDate = "{\"boss\":false,\"unionid\":\"VIx9CsJWZkf69QppBXBQgQiEiE\",\"role_list\":[{\"group_name\":\"默认\",\"name\":\"子管理员\",\"id\":3027676245}],\"exclusive_account\":false,\"mobile\":\"15610026580\",\"active\":true,\"admin\":true,\"remark\":\"\",\"telephone\":\"\",\"avatar\":\"\",\"hide_mobile\":false,\"userid\":\"0432130611865705\",\"senior\":false,\"work_place\":\"\",\"dept_order_list\":[{\"dept_id\":721913981,\"order\":177917621779460497}],\"real_authed\":true,\"name\":\"樊平\",\"dept_id_list\":[721913981],\"state_code\":\"86\",\"email\":\"\",\"leader_in_dept\":[{\"leader\":false,\"dept_id\":721913981}]}";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
|
JsonNode root = mapper.readTree(meDate); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取 "dept_order_list" 节点
|
|
|
|
|
|
JsonNode deptOrderList = root.path("dept_order_list"); |
|
|
|
|
|
|
|
|
|
|
|
int maxOrder = Integer.MIN_VALUE; |
|
|
|
|
|
String maxDeptId = null; |
|
|
|
|
|
|
|
|
|
|
|
// 遍历 "dept_order_list" 节点,找到最大的 "order" 值对应的 "dept_id"
|
|
|
|
|
|
for (JsonNode node : deptOrderList) { |
|
|
|
|
|
int order = node.path("order").asInt(); |
|
|
|
|
|
String deptId = node.path("dept_id").asText(); |
|
|
|
|
|
|
|
|
|
|
|
if (order > maxOrder) { |
|
|
|
|
|
maxOrder = order; |
|
|
|
|
|
maxDeptId = deptId; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/get"); |
|
|
|
|
|
OapiDepartmentGetRequest req = new OapiDepartmentGetRequest(); |
|
|
|
|
|
req.setId(maxDeptId); |
|
|
|
|
|
req.setLang("zh_CN"); |
|
|
|
|
|
req.setHttpMethod("GET"); |
|
|
|
|
|
OapiDepartmentGetResponse rsp = client.execute(req, accessToken); |
|
|
|
|
|
String deptBody = rsp.getBody(); |
|
|
|
|
|
// String deptBody = "{\"errcode\":0,\"sourceIdentifier\":\"2353453\",\"userPermits\":\"user123\",\"orgDeptOwner\":\"manager4220\",\"outerDept\":true,\"errmsg\":\"ok\",\"deptManagerUseridList\":\"manager4220\",\"parentid\":1,\"groupContainSubDept\":false,\"outerPermitUsers\":\"\",\"outerPermitDepts\":\"420606536\",\"createDeptGroup\":true,\"name\":\"销售一部\",\"deptGroupChatId\":\"chat3d322af37b1d20447cf382add2062dec\",\"id\":420606536,\"autoAddUser\":true,\"deptHiding\":true,\"deptPermits\":\"420682732\",\"order\":2353453}";
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(deptBody)) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(deptBody); |
|
|
|
|
|
if (StringUtils.isNotBlank(jsonObject.getString("name"))) { |
|
|
|
|
|
String agencyName = jsonObject.getString("name"); |
|
|
|
|
|
LambdaQueryWrapper<CustomerAgencyEntity> customerAgencyEntityLambdaQueryWrapper = new LambdaQueryWrapper<CustomerAgencyEntity>().eq(CustomerAgencyEntity::getOrganizationName,agencyName); |
|
|
|
|
|
List<CustomerAgencyEntity> agencyEntities= customerAgencyDao.selectList(customerAgencyEntityLambdaQueryWrapper); |
|
|
|
|
|
if (agencyEntities.size()>0){ |
|
|
|
|
|
dto.setAgencyId(agencyEntities.get(0).getId()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
PageHelper.startPage(dto.getPageNo(), dto.getPageSize()); |
|
|
|
|
|
List<BuildingResultDTO> list = icBuildingDao.listBuildingInfo(dto.getCustomerId(), dto.getAgencyId(), dto.getGridId(), dto.getBuildingName()); |
|
|
|
|
|
return list; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param ids |
|
|
* @param ids |
|
|
* @Description 通过ID查询小区信息 |
|
|
* @Description 通过ID查询小区信息 |
|
|