|
|
@ -17,23 +17,45 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.dto.result.OptionResultDTO; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dao.CustomerGridDao; |
|
|
|
import com.epmet.dao.PlacePatrolTeamDao; |
|
|
|
import com.epmet.dto.PlacePatrolTeamDTO; |
|
|
|
import com.epmet.dto.CustomerGridDTO; |
|
|
|
import com.epmet.dto.PlacePatrolTeamStaffDTO; |
|
|
|
import com.epmet.dto.form.AddPlacePatrolTeamFormDTO; |
|
|
|
import com.epmet.dto.form.EditPlacePatrolTeamFormDTO; |
|
|
|
import com.epmet.dto.form.GetListPlaceOrgFormDTO; |
|
|
|
import com.epmet.dto.form.GetListPlacePatrolTeamFormDTO; |
|
|
|
import com.epmet.dto.result.GetListPlaceOrgResultDTO; |
|
|
|
import com.epmet.dto.result.GetListPlacePatrolTeamResultDTO; |
|
|
|
import com.epmet.dto.result.PlaceOrgDetailResultDTO; |
|
|
|
import com.epmet.dto.result.PlacePatrolTeamDetailResultDTO; |
|
|
|
import com.epmet.entity.PlaceOrgEntity; |
|
|
|
import com.epmet.entity.PlacePatrolTeamEntity; |
|
|
|
import com.epmet.entity.PlacePatrolTeamStaffEntity; |
|
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
|
import com.epmet.service.PlacePatrolTeamService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import com.epmet.service.PlacePatrolTeamStaffService; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import org.apache.ibatis.annotations.Param; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
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.Arrays; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 场所分队管理 |
|
|
@ -43,58 +65,195 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
@Service |
|
|
|
public class PlacePatrolTeamServiceImpl extends BaseServiceImpl<PlacePatrolTeamDao, PlacePatrolTeamEntity> implements PlacePatrolTeamService { |
|
|
|
private static final Logger log = LoggerFactory.getLogger(PlacePatrolTeamServiceImpl.class); |
|
|
|
@Autowired |
|
|
|
private EpmetAdminOpenFeignClient epmetAdminOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private PlacePatrolTeamStaffService placePatrolTeamStaffService; |
|
|
|
@Autowired |
|
|
|
private CustomerGridDao customerGridDao; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<PlacePatrolTeamDTO> page(Map<String, Object> params) { |
|
|
|
IPage<PlacePatrolTeamEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, PlacePatrolTeamDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 新增九小场所巡查分队人员管理 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public List<PlacePatrolTeamDTO> list(Map<String, Object> params) { |
|
|
|
List<PlacePatrolTeamEntity> entityList = baseDao.selectList(getWrapper(params)); |
|
|
|
|
|
|
|
return ConvertUtils.sourceToTarget(entityList, PlacePatrolTeamDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
private QueryWrapper<PlacePatrolTeamEntity> getWrapper(Map<String, Object> params){ |
|
|
|
String id = (String)params.get(FieldConstant.ID_HUMP); |
|
|
|
|
|
|
|
QueryWrapper<PlacePatrolTeamEntity> wrapper = new QueryWrapper<>(); |
|
|
|
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void add(AddPlacePatrolTeamFormDTO formDTO) { |
|
|
|
//1.分队主表新增数据
|
|
|
|
PlacePatrolTeamEntity entity = ConvertUtils.sourceToTarget(formDTO, PlacePatrolTeamEntity.class); |
|
|
|
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(formDTO.getCustomerId(), formDTO.getStaffId()); |
|
|
|
entity.setAgencyId(staffInfoCache.getAgencyId()); |
|
|
|
entity.setPids(staffInfoCache.getAgencyPIds()); |
|
|
|
insert(entity); |
|
|
|
//2.分队成员表新增数据
|
|
|
|
List<PlacePatrolTeamStaffEntity> entityList = new ArrayList<>(); |
|
|
|
formDTO.getMemberList().forEach(m -> { |
|
|
|
PlacePatrolTeamStaffEntity entity1 = new PlacePatrolTeamStaffEntity(); |
|
|
|
entity1.setCustomerId(formDTO.getCustomerId()); |
|
|
|
entity1.setPlacePatrolTeamId(entity.getId()); |
|
|
|
entity1.setName(m.getName()); |
|
|
|
entity1.setMobile(m.getMobile()); |
|
|
|
entityList.add(entity1); |
|
|
|
}); |
|
|
|
placePatrolTeamStaffService.insertBatch(entityList); |
|
|
|
|
|
|
|
return wrapper; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 修改九小场所巡查分队人员管理数据 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public PlacePatrolTeamDTO get(String id) { |
|
|
|
PlacePatrolTeamEntity entity = baseDao.selectById(id); |
|
|
|
return ConvertUtils.sourceToTarget(entity, PlacePatrolTeamDTO.class); |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void edit(EditPlacePatrolTeamFormDTO formDTO) { |
|
|
|
//1.修改分队主表信息
|
|
|
|
PlacePatrolTeamEntity entity = baseDao.selectById(formDTO.getTeamId()); |
|
|
|
if (null == entity) { |
|
|
|
throw new RenException(String.format("修改九小场所下巡查分队人员信息失败,分队信息不存在,分队Id->%s", formDTO.getTeamId())); |
|
|
|
} |
|
|
|
entity = ConvertUtils.sourceToTarget(formDTO, PlacePatrolTeamEntity.class); |
|
|
|
baseDao.updateById(entity); |
|
|
|
//2.全删全增分队成员字表数据
|
|
|
|
List<PlacePatrolTeamStaffEntity> entityList = new ArrayList<>(); |
|
|
|
for (EditPlacePatrolTeamFormDTO.Member m : formDTO.getMemberList()) { |
|
|
|
PlacePatrolTeamStaffEntity entity1 = new PlacePatrolTeamStaffEntity(); |
|
|
|
entity1.setCustomerId(entity.getCustomerId()); |
|
|
|
entity1.setPlacePatrolTeamId(entity.getId()); |
|
|
|
entity1.setName(m.getName()); |
|
|
|
entity1.setMobile(m.getMobile()); |
|
|
|
entityList.add(entity1); |
|
|
|
} |
|
|
|
placePatrolTeamStaffService.delByTeamId(formDTO.getTeamId()); |
|
|
|
placePatrolTeamStaffService.insertBatch(entityList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 删除九小场所巡查分队人员管理数据 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(PlacePatrolTeamDTO dto) { |
|
|
|
PlacePatrolTeamEntity entity = ConvertUtils.sourceToTarget(dto, PlacePatrolTeamEntity.class); |
|
|
|
insert(entity); |
|
|
|
public void del(String teamId) { |
|
|
|
//1.删除分队主表数据
|
|
|
|
if (baseDao.deleteById(teamId) < NumConstant.ONE) { |
|
|
|
throw new RenException(String.format("修改九小场所下组织信息删除失败,场所Id->%s", teamId)); |
|
|
|
} |
|
|
|
//2.删除分队成员字表数据
|
|
|
|
placePatrolTeamStaffService.delByTeamId(teamId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 九小场所巡查分队人员管理详情 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(PlacePatrolTeamDTO dto) { |
|
|
|
PlacePatrolTeamEntity entity = ConvertUtils.sourceToTarget(dto, PlacePatrolTeamEntity.class); |
|
|
|
updateById(entity); |
|
|
|
public PlacePatrolTeamDetailResultDTO detail(String teamId) { |
|
|
|
PlacePatrolTeamDetailResultDTO resultDTO = new PlacePatrolTeamDetailResultDTO(); |
|
|
|
//1.查询场所基础信息
|
|
|
|
GetListPlacePatrolTeamFormDTO dto = new GetListPlacePatrolTeamFormDTO(); |
|
|
|
dto.setTeamId(teamId); |
|
|
|
List<PlacePatrolTeamDetailResultDTO> result = baseDao.getList(dto); |
|
|
|
if (CollectionUtils.isEmpty(result)) { |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
resultDTO = result.get(0); |
|
|
|
|
|
|
|
//2.查询网格信息
|
|
|
|
List<String> gridIds = new ArrayList<>(); |
|
|
|
for (String str : resultDTO.getGridIds().split(",")) { |
|
|
|
gridIds.add(str); |
|
|
|
} |
|
|
|
gridIds = gridIds.stream().distinct().collect(Collectors.toList()); |
|
|
|
List<CustomerGridDTO> gridList = customerGridDao.selectGridListByIds(gridIds); |
|
|
|
|
|
|
|
//3.查询九小场所信息
|
|
|
|
Result<List<OptionResultDTO>> nineList = epmetAdminOpenFeignClient.getNineSmallPlacesOption(); |
|
|
|
if (!nineList.success()) { |
|
|
|
throw new RenException("获取九小场所基本信息失败......"); |
|
|
|
} |
|
|
|
|
|
|
|
//4.分别封装网格。九小场所数据
|
|
|
|
//网格
|
|
|
|
StringBuffer gridNames = new StringBuffer(""); |
|
|
|
for (String str : resultDTO.getGridIds().split(",")) { |
|
|
|
gridList.forEach(r -> { |
|
|
|
if (str.equals(r.getGridName())) { |
|
|
|
gridNames.append("".equals(gridNames) ? r.getGridName() : "," + r.getGridName()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
resultDTO.setGridNames(gridNames.toString()); |
|
|
|
//九小场所
|
|
|
|
StringBuffer ninePlaceNames = new StringBuffer(""); |
|
|
|
for (String str : resultDTO.getNinePlaceVals().split(",")) { |
|
|
|
nineList.getData().forEach(r -> { |
|
|
|
if (str.equals(r.getValue())) { |
|
|
|
ninePlaceNames.append("".equals(ninePlaceNames) ? r.getLabel() : "," + r.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
resultDTO.setNinePlaceNames(ninePlaceNames.toString()); |
|
|
|
|
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author sun |
|
|
|
* @Description 九小场所巡查分队人员管理列表查询 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
public GetListPlacePatrolTeamResultDTO getList(GetListPlacePatrolTeamFormDTO formDTO) { |
|
|
|
GetListPlacePatrolTeamResultDTO resultDTO = new GetListPlacePatrolTeamResultDTO(); |
|
|
|
//1.根据条件查询分队及成员数据
|
|
|
|
PageInfo<PlacePatrolTeamDetailResultDTO> result = |
|
|
|
PageHelper.startPage(formDTO.getPageNo(), formDTO.getPageSize(), formDTO.getIsPage()).doSelectPageInfo(() -> baseDao.getList(formDTO)); |
|
|
|
if (CollectionUtils.isEmpty(result.getList())) { |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
resultDTO.setTotal((int) result.getTotal()); |
|
|
|
|
|
|
|
//2.查询网格信息
|
|
|
|
List<String> gridIds = new ArrayList<>(); |
|
|
|
for (PlacePatrolTeamDetailResultDTO dto : result.getList()) { |
|
|
|
for (String str : dto.getGridIds().split(",")) { |
|
|
|
gridIds.add(str); |
|
|
|
} |
|
|
|
} |
|
|
|
gridIds = gridIds.stream().distinct().collect(Collectors.toList()); |
|
|
|
List<CustomerGridDTO> gridList = customerGridDao.selectGridListByIds(gridIds); |
|
|
|
|
|
|
|
//3.查询九小场所信息
|
|
|
|
Result<List<OptionResultDTO>> nineList = epmetAdminOpenFeignClient.getNineSmallPlacesOption(); |
|
|
|
if (!nineList.success()) { |
|
|
|
throw new RenException("获取九小场所基本信息失败......"); |
|
|
|
} |
|
|
|
|
|
|
|
//4.封装网格、九小场所数据
|
|
|
|
for (PlacePatrolTeamDetailResultDTO dto : result.getList()) { |
|
|
|
StringBuffer gridNames = new StringBuffer(""); |
|
|
|
for (String str : dto.getGridIds().split(",")) { |
|
|
|
gridList.forEach(r -> { |
|
|
|
if (str.equals(r.getGridName())) { |
|
|
|
gridNames.append("".equals(gridNames) ? r.getGridName() : "," + r.getGridName()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
dto.setGridNames(gridNames.toString()); |
|
|
|
StringBuffer ninePlaceNames = new StringBuffer(""); |
|
|
|
for (String str : dto.getNinePlaceVals().split(",")) { |
|
|
|
nineList.getData().forEach(r -> { |
|
|
|
if (str.equals(r.getValue())) { |
|
|
|
ninePlaceNames.append("".equals(ninePlaceNames) ? r.getLabel() : "," + r.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
dto.setNinePlaceNames(ninePlaceNames.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
resultDTO.setList(result.getList()); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
} |