|
|
@ -17,30 +17,29 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.mybatis.entity.DataScope; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.StaffRoleDao; |
|
|
|
import com.epmet.dto.StaffRoleDTO; |
|
|
|
import com.epmet.dto.form.CommonUserFormDTO; |
|
|
|
import com.epmet.dto.form.CustomerStaffRoleListFormDTO; |
|
|
|
import com.epmet.dto.form.RoleStaffIdFormDTO; |
|
|
|
import com.epmet.dto.form.RolesUsersListFormDTO; |
|
|
|
import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.StaffRoleEntity; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.service.StaffRoleService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 工作人员-角色关系表 |
|
|
@ -48,61 +47,12 @@ import java.util.*; |
|
|
|
* @author generator generator@elink-cn.com |
|
|
|
* @since v1.0.0 2020-04-22 |
|
|
|
*/ |
|
|
|
@Slf4j |
|
|
|
@Service |
|
|
|
public class StaffRoleServiceImpl extends BaseServiceImpl<StaffRoleDao, StaffRoleEntity> implements StaffRoleService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<StaffRoleDTO> page(Map<String, Object> params) { |
|
|
|
IPage<StaffRoleEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, StaffRoleDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<StaffRoleDTO> list(Map<String, Object> params) { |
|
|
|
List<StaffRoleEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, StaffRoleDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<StaffRoleEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<StaffRoleEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
|
|
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public StaffRoleDTO get(String id) { |
|
|
|
StaffRoleEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, StaffRoleDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(StaffRoleDTO dto) { |
|
|
|
StaffRoleEntity entity = ConvertUtils.sourceToTarget(dto, StaffRoleEntity.class); |
|
|
|
insert(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(StaffRoleDTO dto) { |
|
|
|
StaffRoleEntity entity = ConvertUtils.sourceToTarget(dto, StaffRoleEntity.class); |
|
|
|
updateById(entity); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private GovOrgOpenFeignClient govOrgOpenFeignClient; |
|
|
|
/** |
|
|
|
* 查询具有某角色的staff列表 |
|
|
|
* @param roleKey |
|
|
@ -209,4 +159,47 @@ public class StaffRoleServiceImpl extends BaseServiceImpl<StaffRoleDao, StaffRol |
|
|
|
return baseDao.selectRoleStaffIds(formDTO.getCustomerId(),formDTO.getRoleIds()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<CustomerGridStaffResultDTO> getGridStaffList(GridStaffFormDTO formDTO) { |
|
|
|
//有这些条件 优先查询用户信息
|
|
|
|
List<CustomerGridStaffResultDTO> staffList = baseDao.getStaffList(formDTO); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(staffList)){ |
|
|
|
log.warn("getGridStaffList getStaffList return empty,param:{}", JSON.toJSONString(formDTO)); |
|
|
|
return new PageData<>(null,NumConstant.ZERO); |
|
|
|
} |
|
|
|
//继续查询 在网格里的人
|
|
|
|
Result<List<CustomerStaffGridResultDTO>> staffGridResult = govOrgOpenFeignClient.getStaffGridList(formDTO.getOrgId(),formDTO.getOrgType()); |
|
|
|
if (staffGridResult == null || !staffGridResult.success() || CollectionUtils.isEmpty(staffGridResult.getData())){ |
|
|
|
log.warn("getGridStaffList getStaffGridList return empty,param orgId:{},orgType:{}",formDTO.getOrgId(),formDTO.getOrgType()); |
|
|
|
return new PageData<>(null,NumConstant.ZERO); |
|
|
|
} |
|
|
|
Map<String, List<CustomerStaffGridResultDTO>> userGridListMap = staffGridResult.getData().stream() |
|
|
|
.collect(Collectors.groupingBy(CustomerStaffGridResultDTO::getUserId)); |
|
|
|
List<CustomerGridStaffResultDTO> result = new ArrayList<>(); |
|
|
|
Integer offset = formDTO.getOffset(); |
|
|
|
Integer pageSize = formDTO.getPageSize(); |
|
|
|
|
|
|
|
AtomicInteger count = new AtomicInteger(); |
|
|
|
staffList.forEach(staff->{ |
|
|
|
List<CustomerStaffGridResultDTO> dtoList = userGridListMap.get(staff.getUserId()); |
|
|
|
if (dtoList == null){ |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
dtoList.forEach(grid-> { |
|
|
|
CustomerGridStaffResultDTO staffNew = ConvertUtils.sourceToTarget(staff, CustomerGridStaffResultDTO.class); |
|
|
|
staffNew.setGridId(grid.getGridId()); |
|
|
|
staffNew.setGridName(grid.getGridName()); |
|
|
|
staffNew.setAgencyId(grid.getAgencyId()); |
|
|
|
if (count.intValue() >= offset && result.size() < pageSize) { |
|
|
|
result.add(staffNew); |
|
|
|
} |
|
|
|
count.getAndIncrement(); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
return new PageData<>(result,result.size()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|