|
|
@ -17,6 +17,7 @@ |
|
|
|
|
|
|
|
package com.elink.esua.epdc.modules.consult.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
@ -36,6 +37,7 @@ import com.elink.esua.epdc.modules.consult.redis.GridOperatorInfoRedis; |
|
|
|
import com.elink.esua.epdc.modules.consult.service.GridOperatorInfoService; |
|
|
|
import com.elink.esua.epdc.modules.feign.AdminFeignClient; |
|
|
|
import com.elink.esua.epdc.rocketmq.dto.OrganizationModifyDTO; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -89,55 +91,105 @@ public class GridOperatorInfoServiceImpl extends BaseServiceImpl<GridOperatorInf |
|
|
|
@Override |
|
|
|
public GridOperatorInfoDTO get(String id) { |
|
|
|
GridOperatorInfoEntity entity = baseDao.selectById(id); |
|
|
|
GridOperatorInfoDTO gridOperatorInfoDTO = ConvertUtils.sourceToTarget(entity, GridOperatorInfoDTO.class); |
|
|
|
if (StringUtils.isNotBlank(entity.getAllDeptIds())) { |
|
|
|
String[] depts = entity.getAllDeptIds().split(","); |
|
|
|
List<String> ids = Arrays.asList(depts); |
|
|
|
String[] allDeptIds = new String[(ids.subList(1, ids.size())).size()]; |
|
|
|
gridOperatorInfoDTO.setAllDeptIds((ids.subList(1, ids.size())).toArray(allDeptIds)); |
|
|
|
} |
|
|
|
return gridOperatorInfoDTO; |
|
|
|
return ConvertUtils.sourceToTarget(entity, GridOperatorInfoDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(GridOperatorInfoDTO dto) { |
|
|
|
List<Long> operatorGridIdList = getOperatorGridId(dto); |
|
|
|
if (CollUtil.isEmpty(operatorGridIdList)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
GridOperatorInfoEntity entity = ConvertUtils.sourceToTarget(dto, GridOperatorInfoEntity.class); |
|
|
|
Result<ParentAndAllDeptDTO> parentResult = null; |
|
|
|
if (dto.getAllDeptIds() != null && dto.getAllDeptIds().length > 1) { |
|
|
|
parentResult = adminFeignClient.getParentAndAllDept(dto.getAllDeptIds()[dto.getAllDeptIds().length - 1]); |
|
|
|
for (Long deptId : operatorGridIdList) { |
|
|
|
// 填充部门信息字段
|
|
|
|
this.fillDeptInfoByGridId(entity, deptId); |
|
|
|
if (null == entity.getDeptId() || StringUtils.isBlank(entity.getAllDeptNames())) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
entity.setId(null); |
|
|
|
baseDao.insert(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过前端选择的部门id,组装网格id集合 |
|
|
|
* |
|
|
|
* @param selectedDeptIds |
|
|
|
* @return java.util.List<java.lang.Long> |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 10:30 |
|
|
|
*/ |
|
|
|
private List<Long> getOperatorGridId(List<Long[]> selectedDeptIds) { |
|
|
|
if (CollUtil.isEmpty(selectedDeptIds)) { |
|
|
|
throw new RenException("请选择网格人员所属部门"); |
|
|
|
} |
|
|
|
if (parentResult != null) { |
|
|
|
if (!parentResult.success() || parentResult.getData() == null) { |
|
|
|
throw new RenException("获取部门信息失败"); |
|
|
|
} else { |
|
|
|
ParentAndAllDeptDTO deptDTO = parentResult.getData(); |
|
|
|
entity.setAllDeptIds(deptDTO.getAllDeptIds()); |
|
|
|
entity.setAllDeptNames(deptDTO.getAllDeptNames()); |
|
|
|
entity.setParentDeptIds(deptDTO.getParentDeptIds()); |
|
|
|
entity.setParentDeptNames(deptDTO.getParentDeptNames()); |
|
|
|
entity.setDeptId(deptDTO.getGridId()); |
|
|
|
List<Long> operatorGridIdList = Lists.newArrayList(); |
|
|
|
for (Long[] selectedDeptIdArray : selectedDeptIds) { |
|
|
|
if (selectedDeptIdArray.length == NumConstant.THREE) { |
|
|
|
operatorGridIdList.add(selectedDeptIdArray[NumConstant.TWO]); |
|
|
|
} |
|
|
|
} |
|
|
|
insert(entity); |
|
|
|
return operatorGridIdList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取需要进行绑定的网格id,并移除已绑定的网格 |
|
|
|
* |
|
|
|
* @param operatorInfo |
|
|
|
* @return java.util.List<java.lang.Long> |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 11:19 |
|
|
|
*/ |
|
|
|
private List<Long> getOperatorGridId(GridOperatorInfoDTO operatorInfo) { |
|
|
|
List<Long> operatorGridIdList = getOperatorGridId(operatorInfo.getSelectedDeptIds()); |
|
|
|
if (CollUtil.isEmpty(operatorGridIdList)) { |
|
|
|
throw new RenException("获取网格人员所属网格失败"); |
|
|
|
} |
|
|
|
|
|
|
|
QueryWrapper<GridOperatorInfoEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq("real_name", operatorInfo.getRealName()) |
|
|
|
.eq("mobile", operatorInfo.getMobile()); |
|
|
|
List<GridOperatorInfoEntity> entityList = baseDao.selectList(wrapper); |
|
|
|
if (CollUtil.isNotEmpty(entityList)) { |
|
|
|
for (GridOperatorInfoEntity operatorInfoEntity : entityList) { |
|
|
|
Long deptId = operatorInfoEntity.getDeptId(); |
|
|
|
if (operatorGridIdList.contains(deptId)) { |
|
|
|
operatorGridIdList.remove(deptId); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return operatorGridIdList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装网格人员机构信息 |
|
|
|
* |
|
|
|
* @param gridOperator 网格员对象 |
|
|
|
* @param gridId 网格id |
|
|
|
* @return void |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2020/3/12 13:37 |
|
|
|
*/ |
|
|
|
private void fillDeptInfoByGridId(GridOperatorInfoEntity gridOperator, Long gridId) { |
|
|
|
Result<ParentAndAllDeptDTO> adminResult = adminFeignClient.getParentAndAllDept(String.valueOf(gridId)); |
|
|
|
if (!adminResult.success() || null == adminResult.getData()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
ParentAndAllDeptDTO deptInfo = adminResult.getData(); |
|
|
|
gridOperator.setAllDeptIds(deptInfo.getAllDeptIds()); |
|
|
|
gridOperator.setAllDeptNames(deptInfo.getAllDeptNames()); |
|
|
|
gridOperator.setParentDeptIds(deptInfo.getParentDeptIds()); |
|
|
|
gridOperator.setParentDeptNames(deptInfo.getParentDeptNames()); |
|
|
|
gridOperator.setDeptId(gridId); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(GridOperatorInfoDTO dto) { |
|
|
|
GridOperatorInfoEntity entity = ConvertUtils.sourceToTarget(dto, GridOperatorInfoEntity.class); |
|
|
|
String[] allDeptIds = dto.getAllDeptIds(); |
|
|
|
Result<ParentAndAllDeptDTO> parentResult = adminFeignClient.getParentAndAllDept(String.valueOf(allDeptIds[allDeptIds.length - 1])); |
|
|
|
if (!parentResult.success() || parentResult.getData() == null) { |
|
|
|
throw new RenException("获取部门信息失败"); |
|
|
|
} else { |
|
|
|
ParentAndAllDeptDTO deptDTO = parentResult.getData(); |
|
|
|
entity.setAllDeptIds(deptDTO.getAllDeptIds()); |
|
|
|
entity.setAllDeptNames(deptDTO.getAllDeptNames()); |
|
|
|
entity.setParentDeptIds(deptDTO.getParentDeptIds()); |
|
|
|
entity.setParentDeptNames(deptDTO.getParentDeptNames()); |
|
|
|
entity.setDeptId(deptDTO.getGridId()); |
|
|
|
} |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
|
|
|
@ -174,10 +226,10 @@ public class GridOperatorInfoServiceImpl extends BaseServiceImpl<GridOperatorInf |
|
|
|
|
|
|
|
@Override |
|
|
|
public boolean isExistsByDutyId(String dutyCategoryId) { |
|
|
|
QueryWrapper queryWrapper= new QueryWrapper(); |
|
|
|
queryWrapper.eq(StringUtils.isNotBlank(dutyCategoryId),"DUTY_CATEGORY_ID",dutyCategoryId); |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq(StringUtils.isNotBlank(dutyCategoryId), "DUTY_CATEGORY_ID", dutyCategoryId); |
|
|
|
Integer integer = baseDao.selectCount(queryWrapper); |
|
|
|
if(integer>0){ |
|
|
|
if (integer > 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
@ -197,17 +249,16 @@ public class GridOperatorInfoServiceImpl extends BaseServiceImpl<GridOperatorInf |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* 组织机构信息处理 |
|
|
|
* |
|
|
|
* @params [dto, gridList] |
|
|
|
* @return java.util.List<com.elink.esua.epdc.modules.consult.entity.GridOperatorInfoEntity> |
|
|
|
* @params [dto, gridList] |
|
|
|
* @author liuchuang |
|
|
|
* @since 2020/3/7 14:12 |
|
|
|
*/ |
|
|
|
private List<GridOperatorInfoEntity> handleOrganizationInfo(OrganizationModifyDTO dto, List<GridOperatorInfoDTO> gridList) { |
|
|
|
List<GridOperatorInfoEntity> entities = new ArrayList<>(); |
|
|
|
for (GridOperatorInfoDTO grid: gridList) { |
|
|
|
for (GridOperatorInfoDTO grid : gridList) { |
|
|
|
GridOperatorInfoEntity entity = new GridOperatorInfoEntity(); |
|
|
|
if (StringUtils.isNotEmpty(grid.getParentDeptIds()) && StringUtils.isNotEmpty(grid.getParentDeptNames())) { |
|
|
|
List<String> parentDeptIds = Arrays.asList(grid.getParentDeptIds().split(",")); |
|
|
@ -220,8 +271,8 @@ public class GridOperatorInfoServiceImpl extends BaseServiceImpl<GridOperatorInf |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(grid.getAllDeptIdsStr()) && StringUtils.isNotEmpty(grid.getAllDeptNames())) { |
|
|
|
List<String> allDeptIds = Arrays.asList(grid.getAllDeptIdsStr().split(",")); |
|
|
|
if (StringUtils.isNotEmpty(grid.getAllDeptIds()) && StringUtils.isNotEmpty(grid.getAllDeptNames())) { |
|
|
|
List<String> allDeptIds = Arrays.asList(grid.getAllDeptIds().split(",")); |
|
|
|
List<String> allDeptNames = Arrays.asList(grid.getAllDeptNames().split("-")); |
|
|
|
int index = allDeptIds.indexOf(dto.getDeptId().toString()); |
|
|
|
if (index >= 0 && allDeptNames.size() > index) { |
|
|
|