| | |
| | | */ |
| | | package org.springblade.modules.place.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.node.TreeNode; |
| | | import liquibase.repackaged.org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.node.TreeStringNode; |
| | | import org.springblade.common.utils.IdUtils; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.modules.place.entity.PlaceEntity; |
| | | import org.springblade.modules.place.entity.PlacePoiLabel; |
| | | import org.springblade.modules.doorplateAddress.entity.DoorplateAddressEntity; |
| | | import org.springblade.modules.doorplateAddress.service.IDoorplateAddressService; |
| | | import org.springblade.modules.grid.entity.GridEntity; |
| | | import org.springblade.modules.grid.entity.GridRangeEntity; |
| | | import org.springblade.modules.grid.mapper.GridMapper; |
| | | import org.springblade.modules.grid.service.IGridRangeService; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.grid.service.IGridmanService; |
| | | import org.springblade.modules.grid.vo.GridVO; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.entity.UserHouseLabelEntity; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.place.entity.*; |
| | | import org.springblade.modules.place.excel.PlaceAndRelExcel; |
| | | import org.springblade.modules.place.excel.PlaceExcel; |
| | | import org.springblade.modules.place.service.IPlaceExtService; |
| | | import org.springblade.modules.place.service.IPlacePoiLabelService; |
| | | import org.springblade.modules.place.service.IPlaceRelService; |
| | | import org.springblade.modules.place.vo.PlacePoiLabelVO; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.place.mapper.PlaceMapper; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 场所表 服务实现类 |
| | |
| | | * @since 2023-10-28 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, PlaceEntity> implements IPlaceService { |
| | | private final IUserService userService; |
| | | private final IPlacePoiLabelService placePoiLabelService; |
| | | @Autowired |
| | | private IUserService userService; |
| | | |
| | | @Autowired |
| | | private IPlacePoiLabelService placePoiLabelService; |
| | | |
| | | @Autowired |
| | | private IPlaceExtService placeExtService; |
| | | |
| | | @Autowired |
| | | private IPlaceRelService placeRelService; |
| | | |
| | | @Autowired |
| | | private IDoorplateAddressService doorplateAddressService; |
| | | |
| | | @Autowired |
| | | private IGridService gridService; |
| | | |
| | | @Autowired |
| | | private IGridRangeService gridRangeService; |
| | | |
| | | @Autowired |
| | | private IGridmanService gridmanService; |
| | | |
| | | @Autowired |
| | | private GridMapper gridMapper; |
| | | |
| | | @Autowired |
| | | private IHouseholdService householdService; |
| | | |
| | | /** |
| | | * 自定义列表查询 |
| | | * @param page |
| | | * @param place |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) { |
| | | return page.setRecords(baseMapper.selectPlacePage(page, place)); |
| | | List<String> regionChildCodesList = SysCache.getRegionChildCodesByDeptId(AuthUtil.getDeptId()); |
| | | Integer isAdministrator = AuthUtil.isAdministrator()==true?1:2; |
| | | List<String> list = new ArrayList<>(); |
| | | if (null!=place.getRoleName() && !place.getRoleName().equals("")){ |
| | | if (place.getRoleName().equals("网格员")){ |
| | | // 查询对应的房屋地址code |
| | | list = gridService.getAddressCodeListByUserId(AuthUtil.getUserId()); |
| | | } |
| | | } |
| | | List<PlaceVO> placeVOS = baseMapper.selectPlacePage(page, place,list,regionChildCodesList,isAdministrator); |
| | | // 返回 |
| | | return page.setRecords(placeVOS); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<TreeNode> selectPlaceNodeList(Long userId) { |
| | | public List<TreeStringNode> selectPlaceNodeList(Long userId) { |
| | | return baseMapper.selectPlaceNodeList(userId.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 场所信息自定义新增/修改 |
| | | * @param placeVO |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean addVO(PlaceVO placeVO) { |
| | | |
| | | placeVO.setCreateUser(AuthUtil.getUserId()); |
| | | placeVO.setCreateTime(new Date()); |
| | | public Boolean addOrUpdate(PlaceVO placeVO) { |
| | | boolean flag = false; |
| | | placeVO.setUpdateUser(AuthUtil.getUserId()); |
| | | placeVO.setUpdateTime(new Date()); |
| | | |
| | | //根据手机号查询库里的数据 |
| | | User userParams = new User(); |
| | | userParams.setPhone(placeVO.getPhone()); |
| | | User user = userService.getOne(Condition.getQueryWrapper(userParams)); |
| | | |
| | | if (user != null){ |
| | | //如果用户存在,则该用户id绑定场所 |
| | | placeVO.setPrincipalUserId(user.getId()); |
| | | }else{ |
| | | //如果用户不存在,则新增一个用户 |
| | | User newUser = new User(); |
| | | newUser.setAccount(placeVO.getPhone()); |
| | | newUser.setPhone(placeVO.getPhone()); |
| | | |
| | | newUser.setName(placeVO.getUsername()); |
| | | newUser.setRealName(placeVO.getUsername()); |
| | | newUser.setRoleId("1717429193350434818"); |
| | | newUser.setPassword("123456"); |
| | | |
| | | userService.submit(newUser); |
| | | //绑定id |
| | | placeVO.setPrincipalUserId(newUser.getId()); |
| | | // 查看是否包含houseCode,如果有,则更新 |
| | | if (!Strings.isBlank(placeVO.getHouseCode())){ |
| | | // 更新,先查询场所信息 |
| | | QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("house_code",placeVO.getHouseCode()); |
| | | PlaceEntity one = getOne(wrapper); |
| | | if (null!=one) { |
| | | placeVO.setId(one.getId()); |
| | | } |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 设置完善状态 |
| | | setPlaceStatus(placeVO); |
| | | // 更新场所信息 |
| | | flag = updateById(placeVO); |
| | | }else { |
| | | // 设置基础数据 |
| | | placeVO.setCreateUser(AuthUtil.getUserId()); |
| | | placeVO.setCreateTime(new Date()); |
| | | // 设置来源( 1:地址总表 2:国控采集) |
| | | placeVO.setSource(2); |
| | | // 并生成36位的houseCode |
| | | placeVO.setHouseCode(IdUtils.getIdBy36()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 设置完善状态 |
| | | setPlaceStatus(placeVO); |
| | | // 新增场所信息 |
| | | flag = save(placeVO); |
| | | } |
| | | |
| | | boolean save = save(placeVO); |
| | | |
| | | |
| | | List<String> labelList = Arrays.asList(placeVO.getLabel().split(",")); |
| | | |
| | | labelList.forEach(labelId->{ |
| | | PlacePoiLabel placePoiLabel = new PlacePoiLabel(); |
| | | placePoiLabel.setPlaceId(placeVO.getId()); |
| | | placePoiLabel.setPoiCode(Integer.parseInt(labelId)); |
| | | placePoiLabelService.save(placePoiLabel); |
| | | }); |
| | | |
| | | |
| | | return save; |
| | | // 保存场所详情及任务信息 |
| | | savePlaceExtAndTaskInfo(placeVO); |
| | | // 场所标签信息绑定(更新,调整) |
| | | placeLabelBind(placeVO); |
| | | // 网格绑定 |
| | | gridBind(placeVO); |
| | | // 网格编号绑定场所-新 |
| | | gridCodeBind(placeVO); |
| | | // 房屋编号绑定 |
| | | // houseCodeBind(placeVO); |
| | | // 返回结果 |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 房屋绑定 |
| | | * @param placeVO |
| | | */ |
| | | public void houseCodeBind(PlaceVO placeVO) { |
| | | String houseCode = placeVO.getHouseCode(); |
| | | List<String> list = Arrays.asList(houseCode.split(",")); |
| | | if (list.size()>1){ |
| | | // 处理对应的绑定房屋数据 |
| | | List<Long> longs = new ArrayList<>(); |
| | | // 把其他单个的场所数据删除 |
| | | for (String code : list) { |
| | | // 先查询对应的场所id |
| | | QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("house_code",code).eq("is_deleted",0); |
| | | PlaceEntity one = getOne(wrapper); |
| | | if (null!=one){ |
| | | longs.add(one.getId()); |
| | | // 删除对应的单个编号的场所 |
| | | removeById(one.getId()); |
| | | } |
| | | } |
| | | if (longs.size()>0) { |
| | | // 删除对应的详情 |
| | | removePlaceExt(longs); |
| | | // 删除对应的标签绑定信息 |
| | | removePlaceLabel(longs); |
| | | } |
| | | }else { |
| | | // 一对一,暂时不处理,后续考虑需加绑定关系表 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置场所完善状态 |
| | | * @param placeVO |
| | | */ |
| | | private void setPlaceStatus(PlaceVO placeVO) { |
| | | if (!Strings.isBlank(placeVO.getPrincipal()) |
| | | && !Strings.isBlank(placeVO.getPrincipalPhone()) |
| | | && !Strings.isBlank(placeVO.getLocation()) |
| | | && !Strings.isBlank(placeVO.getPlaceName()) |
| | | && !Strings.isBlank(placeVO.getImageUrls()) |
| | | ){ |
| | | // 已完善 |
| | | placeVO.setStatus(2); |
| | | }else { |
| | | // 未完善 |
| | | placeVO.setStatus(1); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 网格绑定 |
| | | * @param placeVO |
| | | */ |
| | | public void gridBind(PlaceVO placeVO) { |
| | | if (null!=placeVO.getGridId()){ |
| | | // 判断关联关系表是否存在 |
| | | QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("house_code",placeVO.getHouseCode()); |
| | | GridRangeEntity one = gridRangeService.getOne(wrapper); |
| | | if (null==one){ |
| | | // 新增 |
| | | GridRangeEntity gridRangeEntity = new GridRangeEntity(); |
| | | gridRangeEntity.setHouseCode(placeVO.getHouseCode()); |
| | | gridRangeEntity.setGridId(placeVO.getGridId()); |
| | | // 插入 |
| | | gridRangeService.save(gridRangeEntity); |
| | | }else { |
| | | // 修改绑定 |
| | | one.setGridId(placeVO.getGridId()); |
| | | // 修改 |
| | | gridRangeService.updateById(one); |
| | | } |
| | | }else { |
| | | // 判断角色,如果是网格员则直接使用网格员的网格id,如果是民警则采用点落面的方式进行获取网格的id |
| | | if (!Strings.isBlank(placeVO.getRoleName())) { |
| | | // 网格员角色位置绑定 |
| | | gridmanPositionHandle(placeVO); |
| | | // 民警角色位置绑定 |
| | | policePositionHandle(placeVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 网格编号绑定 |
| | | * @param placeVO |
| | | */ |
| | | public void gridCodeBind(PlaceVO placeVO) { |
| | | // 无网格编号时 |
| | | if (Strings.isBlank(placeVO.getGridCode())){ |
| | | // 判断角色,如果是网格员则直接使用网格员的网格id,如果是民警则采用点落面的方式进行获取网格的id |
| | | if (!Strings.isBlank(placeVO.getRoleName())) { |
| | | // 网格员场所网格编号绑定-新 |
| | | gridmanGridCodePositionHandle(placeVO); |
| | | // 民警角色时通过位置绑定网格-新 |
| | | policeGridCodePositionHandle(placeVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 网格员角色位置绑定-grid_id |
| | | * @param placeVO |
| | | */ |
| | | public void gridmanPositionHandle(PlaceVO placeVO) { |
| | | if (placeVO.getRoleName().equals("网格员")) { |
| | | // 判断网格员,查询对应网格人对应的网格id |
| | | Integer gridId = gridmanService.getGridIdByUserId(AuthUtil.getUserId()); |
| | | if (null != gridId) { |
| | | // 判断关联关系表是否存在 |
| | | QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("grid_id", gridId).eq("house_code", placeVO.getHouseCode()); |
| | | GridRangeEntity one = gridRangeService.getOne(wrapper); |
| | | if (null == one) { |
| | | // 新增 |
| | | GridRangeEntity gridRangeEntity = new GridRangeEntity(); |
| | | gridRangeEntity.setHouseCode(placeVO.getHouseCode()); |
| | | gridRangeEntity.setGridId(gridId); |
| | | // 插入 |
| | | gridRangeService.save(gridRangeEntity); |
| | | }else { |
| | | // 修改绑定 |
| | | one.setGridId(placeVO.getGridId()); |
| | | // 修改 |
| | | gridRangeService.updateById(one); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 网格员角色位置绑定-grid_code |
| | | * @param placeVO |
| | | */ |
| | | public void gridmanGridCodePositionHandle(PlaceVO placeVO) { |
| | | if (placeVO.getRoleName().equals("网格员")) { |
| | | // 判断网格员,查询对应网格人对应的网格 |
| | | GridEntity grid = gridService.getGridByUserId(AuthUtil.getUserId()); |
| | | if (null != grid && !Strings.isBlank(grid.getGridCode())) { |
| | | // 场所编号绑定 |
| | | placeVO.setGridCode(grid.getGridCode()); |
| | | // 更新场所信息 |
| | | updateById(placeVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 民警角色位置绑定 |
| | | * @param placeVO |
| | | */ |
| | | private void policePositionHandle(PlaceVO placeVO) { |
| | | // 是民警且位置信息存在 |
| | | if (placeVO.getRoleName().equals("民警") && !Strings.isBlank(placeVO.getLng())) { |
| | | //点坐标解析 |
| | | String point = "'POINT(" + placeVO.getLng() + " " + placeVO.getLat() +")'"; |
| | | // String point = "'POINT(" + villageInfoExcel.getLatitude() + " " + villageInfoExcel.getLongitude() +")'"; |
| | | GridEntity gridEntity = gridMapper.spatialAnalysis(point); |
| | | if (null != gridEntity) { |
| | | // 判断关联关系表是否存在 |
| | | QueryWrapper<GridRangeEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("grid_id", gridEntity.getId()).eq("house_code", placeVO.getHouseCode()); |
| | | GridRangeEntity one = gridRangeService.getOne(wrapper); |
| | | if (null == one) { |
| | | // 新增 |
| | | GridRangeEntity gridRangeEntity = new GridRangeEntity(); |
| | | gridRangeEntity.setHouseCode(placeVO.getHouseCode()); |
| | | gridRangeEntity.setGridId(gridEntity.getId()); |
| | | // 插入 |
| | | gridRangeService.save(gridRangeEntity); |
| | | }else { |
| | | // 修改绑定 |
| | | one.setGridId(placeVO.getGridId()); |
| | | // 修改 |
| | | gridRangeService.updateById(one); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 民警角色时通过位置绑定网格 |
| | | * @param placeVO |
| | | */ |
| | | private void policeGridCodePositionHandle(PlaceVO placeVO) { |
| | | // 是民警且位置信息存在 |
| | | if (placeVO.getRoleName().equals("民警") && !Strings.isBlank(placeVO.getLng())) { |
| | | //点坐标解析 |
| | | String point = "'POINT(" + placeVO.getLng() + " " + placeVO.getLat() +")'"; |
| | | // String point = "'POINT(" + villageInfoExcel.getLatitude() + " " + villageInfoExcel.getLongitude() +")'"; |
| | | GridEntity gridEntity = gridMapper.spatialAnalysis(point); |
| | | if (null != gridEntity && !Strings.isBlank(gridEntity.getGridCode())) { |
| | | // 场所编号绑定 |
| | | placeVO.setGridCode(gridEntity.getGridCode()); |
| | | // 更新场所信息 |
| | | updateById(placeVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 场所标签信息绑定入库 |
| | | * @param placeVO |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void placeLabelBind(PlaceVO placeVO) { |
| | | // 先查询对于的场所是否已有标签信息 |
| | | // 查询对应已存在的从业人员 |
| | | QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",placeVO.getId()); |
| | | List<PlacePoiLabel> oldList = placePoiLabelService.list(wrapper); |
| | | if (oldList.size()>0){ |
| | | // 先将老的全部删除,然后批量插入 |
| | | QueryWrapper<PlacePoiLabel> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("place_id",placeVO.getId()); |
| | | boolean remove = placePoiLabelService.remove(queryWrapper); |
| | | if (remove){ |
| | | // 批量新增 |
| | | savePlaceLabel(placeVO); |
| | | } |
| | | }else { |
| | | savePlaceLabel(placeVO); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入场所标签信息 |
| | | * @param placeVO |
| | | */ |
| | | public void savePlaceLabel(PlaceVO placeVO) { |
| | | if (!Strings.isBlank(placeVO.getLabel())) { |
| | | // 批量新增 |
| | | List<String> labelList = Arrays.asList(placeVO.getLabel().split(",")); |
| | | if (labelList.size() > 1) { |
| | | // 只处理小类 |
| | | // 遍历 |
| | | labelList.forEach(labelId -> { |
| | | // 处理小类 |
| | | if (labelId.length() > 4) { |
| | | // 切割成三个,分别是大类,中类,小类 |
| | | String bigString = labelId.substring(0, 2); |
| | | String midString = labelId.substring(0, 4); |
| | | // 大类 |
| | | PlacePoiLabel big = new PlacePoiLabel(); |
| | | big.setPlaceId(placeVO.getId()); |
| | | big.setPoiCode(Integer.parseInt(bigString)); |
| | | big.setType(1); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | big.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(big); |
| | | // 中类 |
| | | PlacePoiLabel mid = new PlacePoiLabel(); |
| | | mid.setPlaceId(placeVO.getId()); |
| | | mid.setPoiCode(Integer.parseInt(midString)); |
| | | mid.setType(2); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | mid.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(mid); |
| | | // 小类 |
| | | PlacePoiLabel min = new PlacePoiLabel(); |
| | | min.setPlaceId(placeVO.getId()); |
| | | min.setPoiCode(Integer.parseInt(labelId)); |
| | | min.setType(3); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | min.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(min); |
| | | } |
| | | }); |
| | | } else { |
| | | // 处理单个 |
| | | String labelCode = labelList.get(0); |
| | | // 切割成三个,分别是大类,中类,小类 |
| | | String bigString = labelCode.substring(0, 2); |
| | | String midString = labelCode.substring(0, 4); |
| | | // 大类 |
| | | PlacePoiLabel big = new PlacePoiLabel(); |
| | | big.setPlaceId(placeVO.getId()); |
| | | big.setPoiCode(Integer.parseInt(bigString)); |
| | | big.setType(1); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | big.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(big); |
| | | // 中类 |
| | | PlacePoiLabel mid = new PlacePoiLabel(); |
| | | mid.setPlaceId(placeVO.getId()); |
| | | mid.setPoiCode(Integer.parseInt(midString)); |
| | | mid.setType(2); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | mid.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(mid); |
| | | // 处理小类 |
| | | if (labelCode.length() > 4) { |
| | | // 小类 |
| | | PlacePoiLabel min = new PlacePoiLabel(); |
| | | min.setPlaceId(placeVO.getId()); |
| | | min.setPoiCode(Integer.parseInt(labelCode)); |
| | | min.setType(3); |
| | | if (!Strings.isBlank(placeVO.getColor())) { |
| | | min.setColor(placeVO.getColor()); |
| | | } |
| | | placePoiLabelService.save(min); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 场所负责人和用户绑定 |
| | | * @param placeVO |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public User bindUserHandle(PlaceVO placeVO) { |
| | | User newUser = new User(); |
| | | if (null!=placeVO.getPrincipalPhone() && !placeVO.getPrincipalPhone().equals("")) { |
| | | placeVO.setPrincipal(placeVO.getPrincipal()); |
| | | placeVO.setPrincipalPhone(placeVO.getPrincipalPhone()); |
| | | //根据手机号查询库里的数据 |
| | | User userParams = new User(); |
| | | userParams.setPhone(placeVO.getPrincipalPhone()); |
| | | userParams.setIsDeleted(0); |
| | | User user = userService.getOne(Condition.getQueryWrapper(userParams)); |
| | | if (null==user){ |
| | | User userParams1 = new User(); |
| | | userParams1.setAccount(placeVO.getPrincipalPhone()); |
| | | userParams1.setIsDeleted(0); |
| | | user = userService.getOne(Condition.getQueryWrapper(userParams1)); |
| | | } |
| | | |
| | | if (null!=user) { |
| | | //如果用户存在,则该用户id绑定场所 |
| | | placeVO.setPrincipalUserId(user.getId()); |
| | | newUser = user; |
| | | // 判断用户是否包含了居民角色,不包含则需更新 |
| | | if (!user.getRoleId().contains("1717429059648606209")){ |
| | | user.setRoleId(user.getRoleId() + ",1717429059648606209"); |
| | | //更新 |
| | | userService.updateById(user); |
| | | } |
| | | } else { |
| | | //如果用户不存在,则新增一个用户 |
| | | newUser.setAccount(placeVO.getPrincipalPhone()); |
| | | newUser.setPhone(placeVO.getPrincipalPhone()); |
| | | newUser.setName(placeVO.getPrincipal()); |
| | | newUser.setRealName(placeVO.getPrincipal()); |
| | | // 社区群众部门 |
| | | newUser.setDeptId("1727979636479037441"); |
| | | // 目前暂定居民角色, |
| | | newUser.setRoleId("1717429059648606209"); |
| | | //默认密码为 123456 |
| | | newUser.setPassword("123456"); |
| | | // 设置机构 |
| | | // 用户新增 |
| | | boolean submit = userService.submit(newUser); |
| | | //绑定id |
| | | placeVO.setPrincipalUserId(newUser.getId()); |
| | | //给人员打上场所负责人的标签 |
| | | baseMapper.saveUserLabel(newUser.getId(),1002); |
| | | } |
| | | } |
| | | return newUser; |
| | | } |
| | | |
| | | /** |
| | | * 保存场所详情及任务信息 |
| | | * @param placeVO |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void savePlaceExtAndTaskInfo(PlaceVO placeVO) { |
| | | PlaceExtEntity placeExtEntity = new PlaceExtEntity(); |
| | | placeExtEntity.setPlaceId(placeVO.getId()); |
| | | // 判断是否已存在,已存在则不新增 |
| | | QueryWrapper<PlaceExtEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0) |
| | | .eq("place_id",placeVO.getId()); |
| | | PlaceExtEntity one = placeExtService.getOne(wrapper); |
| | | if (null == one) { |
| | | placeExtEntity.setPlaceId(placeVO.getId()); |
| | | // 默认给待完善状态 |
| | | placeExtEntity.setConfirmFlag(4); |
| | | placeExtEntity.setCreateTime(new Date()); |
| | | placeExtEntity.setUpdateTime(new Date()); |
| | | placeExtEntity.setCreateUser(AuthUtil.getUserId()); |
| | | placeExtEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | // 新增场所详情 |
| | | placeExtService.save(placeExtEntity); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 历史场所挂接处理-临时 |
| | | * @param place |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object historyPlaceHandle(PlaceVO place) { |
| | | // 查询所有的场所(手机号不为空) |
| | | List<PlaceVO> list = baseMapper.getPlaceNotNullPhone(); |
| | | // 遍历 |
| | | for (PlaceVO placeVO : list) { |
| | | User user = bindUserHandle(placeVO); |
| | | if (null!=user){ |
| | | placeVO.setPrincipalUserId(user.getId()); |
| | | //更新场所用户id绑定 |
| | | baseMapper.updatePlaceEntity(placeVO); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 历史场所标签挂接处理-临时 |
| | | * @param place |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public Object historyPlaceLabelHandle(PlaceVO place) { |
| | | // 查询所有的场所 |
| | | List<PlaceVO> list = baseMapper.getAllHistoryPlace(); |
| | | // 遍历 |
| | | for (PlaceVO placeVO : list) { |
| | | if (null!=placeVO.getLabel()){ |
| | | String[] split = placeVO.getLabel().split(","); |
| | | for (String s : split) { |
| | | PlacePoiLabel placePoiLabel = new PlacePoiLabel(); |
| | | placePoiLabel.setPlaceId(placeVO.getId()); |
| | | placePoiLabel.setPoiCode(Integer.parseInt(s)); |
| | | placePoiLabelService.save(placePoiLabel); |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 场所表 自定义详情查询 |
| | | * @param place |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PlaceVO getDetail(PlaceVO place) { |
| | | // 查询场所信息 |
| | | PlaceVO placeVO = baseMapper.getDetail(place); |
| | | // 门牌信息 |
| | | if (null != placeVO) { |
| | | if (null != place.getAddressType() && place.getAddressType() == 4) { |
| | | // 查询地址编码信息(社区派出所相关信息) |
| | | DoorplateAddressEntity addressEntity = placeRelService.getDoorplateAddressEntity(placeVO); |
| | | placeVO.setDoorplateAddressEntity(addressEntity); |
| | | // 查询网格信息--商超 |
| | | placeVO.setGrid(gridService.getGridDetailByParam(placeVO)); |
| | | } else { |
| | | // 管理后台查询赋值颜色 |
| | | if (placeVO.getPlacePoiLabelVOList().size() > 0) { |
| | | PlacePoiLabelVO placePoiLabelVO = placeVO.getPlacePoiLabelVOList().get(0); |
| | | if (!Strings.isBlank(placePoiLabelVO.getColor())) { |
| | | placeVO.setColor(placePoiLabelVO.getColor()); |
| | | } |
| | | } |
| | | // 查询地址门牌信息 |
| | | QueryWrapper<DoorplateAddressEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("address_code", placeVO.getHouseCode()); |
| | | List<DoorplateAddressEntity> list = doorplateAddressService.list(wrapper); |
| | | if (list.size() > 0) { |
| | | placeVO.setDoorplateAddressEntity(list.get(0)); |
| | | placeVO.setNeiCode(list.get(0).getNeiCode()); |
| | | } |
| | | // 查询场所对应的网格数据 |
| | | placeVO.setGrid(gridService.getPlaceGridDetailByHouseCode(placeVO.getHouseCode())); |
| | | // 设置详情信息 |
| | | QueryWrapper<PlaceExtEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted", 0).eq("place_id", placeVO.getId()); |
| | | placeVO.setPlaceExtEntity(placeExtService.getOne(queryWrapper)); |
| | | } |
| | | } |
| | | // 返回 |
| | | return placeVO; |
| | | } |
| | | |
| | | /** |
| | | * 场所数据到导入 |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | public void importPlace(List<PlaceExcel> data, Boolean isCovered) { |
| | | for (PlaceExcel placeExcel : data) { |
| | | // 判断是否存在,不存在则插入,否则不操作 |
| | | QueryWrapper<PlaceEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0) |
| | | .eq("house_code",placeExcel.getHouseCode()); |
| | | PlaceEntity one = getOne(wrapper); |
| | | if (null == one){ |
| | | Long userId = updateUser(placeExcel); |
| | | // 插入场所 |
| | | PlaceEntity placeEntity = new PlaceEntity(); |
| | | placeEntity.setHouseCode(placeExcel.getHouseCode()); |
| | | placeEntity.setPrincipalUserId(userId); |
| | | placeEntity.setPrincipal(placeExcel.getName()); |
| | | placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber()); |
| | | placeEntity.setCreateTime(new Date()); |
| | | placeEntity.setCreateUser(AuthUtil.getUserId()); |
| | | placeEntity.setUpdateTime(new Date()); |
| | | placeEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | //一个一个插入,防止同一个表中有相同的数据 |
| | | save(placeEntity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新用户信息 |
| | | * @param placeExcel |
| | | * @return |
| | | */ |
| | | public Long updateUser(PlaceExcel placeExcel) { |
| | | if (!Strings.isBlank(placeExcel.getPhoneNumber()) && |
| | | !Strings.isBlank(placeExcel.getName())) { |
| | | PlaceVO placeVO = new PlaceVO(); |
| | | placeVO.setPhone(placeExcel.getPhoneNumber()); |
| | | placeVO.setUsername(placeExcel.getName()); |
| | | // 更新场所负责人 |
| | | User user = bindUserHandle(placeVO); |
| | | // 返回 |
| | | return user.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 更新用户信息 |
| | | * @param placeExcel |
| | | * @return |
| | | */ |
| | | public Long updateUser(PlaceAndRelExcel placeExcel) { |
| | | if (!Strings.isBlank(placeExcel.getPhoneNumber()) && |
| | | !Strings.isBlank(placeExcel.getName())) { |
| | | PlaceVO placeVO = new PlaceVO(); |
| | | placeVO.setPhone(placeExcel.getPhoneNumber()); |
| | | placeVO.setUsername(placeExcel.getName()); |
| | | // 更新场所负责人 |
| | | User user = bindUserHandle(placeVO); |
| | | // 返回 |
| | | return user.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 场所(商超)导入 |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importAndRelPlace(List<PlaceAndRelExcel> data, Boolean isCovered) { |
| | | for (PlaceAndRelExcel placeExcel : data) { |
| | | // 判断是否存在,不存在则插入,否则不操作 |
| | | PlaceEntity one = baseMapper.getPlaceAndRelInfo(placeExcel); |
| | | if (null == one){ |
| | | Long userId = updateUser(placeExcel); |
| | | // 插入场所 |
| | | PlaceEntity placeEntity = new PlaceEntity(); |
| | | placeEntity.setPlaceName(placeExcel.getPlaceName()); |
| | | placeEntity.setLocation(placeExcel.getAddress()); |
| | | placeEntity.setPrincipalUserId(userId); |
| | | placeEntity.setPrincipal(placeExcel.getName()); |
| | | placeEntity.setPrincipalPhone(placeExcel.getPhoneNumber()); |
| | | placeEntity.setPrincipalUserId(userId); |
| | | placeEntity.setCreateTime(new Date()); |
| | | placeEntity.setCreateUser(AuthUtil.getUserId()); |
| | | placeEntity.setUpdateTime(new Date()); |
| | | placeEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | // 并生成36位的houseCode |
| | | placeEntity.setHouseCode(IdUtils.getIdBy36()); |
| | | // 商超数据 |
| | | placeEntity.setSource(3); |
| | | //一个一个插入,防止同一个表中有相同的数据 |
| | | save(placeEntity); |
| | | // 插入标签关系表 |
| | | savPlaceLabelBind(placeExcel,placeEntity); |
| | | // 插入关联数据表 |
| | | PlaceRelEntity placeRelEntity = new PlaceRelEntity(); |
| | | placeRelEntity.setPlaceId(placeEntity.getId()); |
| | | placeRelEntity.setStreetName(placeExcel.getStreetName()); |
| | | placeRelEntity.setCommunityName(placeExcel.getCommunityName()); |
| | | placeRelEntity.setGridName(placeExcel.getGridName()); |
| | | placeRelEntity.setBuildingName(placeExcel.getBuildingName()); |
| | | placeRelEntity.setDoorplateNum(placeExcel.getDoorplateNum()); |
| | | placeRelEntity.setFloor(placeExcel.getFloor()); |
| | | placeRelEntity.setCreateTime(new Date()); |
| | | placeRelEntity.setCreateUser(AuthUtil.getUserId()); |
| | | placeRelEntity.setUpdateTime(new Date()); |
| | | placeRelEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | // 新增 |
| | | placeRelService.save(placeRelEntity); |
| | | }else { |
| | | // 只更新商铺信息 |
| | | Long userId = updateUser(placeExcel); |
| | | // 插入场所 |
| | | PlaceEntity placeEntity = new PlaceEntity(); |
| | | placeEntity.setId(one.getId()); |
| | | placeEntity.setPlaceName(placeExcel.getPlaceName()); |
| | | placeEntity.setLocation(placeExcel.getAddress()); |
| | | placeEntity.setPrincipalUserId(userId); |
| | | placeEntity.setCreateTime(new Date()); |
| | | placeEntity.setCreateUser(AuthUtil.getUserId()); |
| | | placeEntity.setUpdateTime(new Date()); |
| | | placeEntity.setUpdateUser(AuthUtil.getUserId()); |
| | | //一个一个插入,防止同一个表中有相同的数据 |
| | | updateById(placeEntity); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 插入标签关系表 |
| | | * @param placeExcel |
| | | */ |
| | | public void savPlaceLabelBind(PlaceAndRelExcel placeExcel,PlaceEntity placeEntity) { |
| | | if (!Strings.isBlank(placeExcel.getLabelCode())){ |
| | | PlaceVO placeVO = new PlaceVO(); |
| | | placeVO.setId(placeEntity.getId()); |
| | | placeVO.setLabel(placeExcel.getLabelCode()); |
| | | // 插入标签 |
| | | placeLabelBind(placeVO); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 场所数据处理-用户信息(场所负责人信息写入到场所表) |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Object placeUserHandle() { |
| | | // 查询出有用户id 的场所 |
| | | List<PlaceEntity> list = baseMapper.getHasUserIdPlaceList(); |
| | | // 遍历 |
| | | for (PlaceEntity placeEntity : list) { |
| | | // 查询对应的用户信息 |
| | | User user = userService.getById(placeEntity.getPrincipalUserId()); |
| | | if (null!=user) { |
| | | // 设置场所负责人,手机号 |
| | | if (null != user.getRealName() && !user.getRealName().equals("")) { |
| | | placeEntity.setPrincipal(user.getRealName()); |
| | | } |
| | | if (null != user.getPhone() && !user.getPhone().equals("")) { |
| | | placeEntity.setPrincipalPhone(user.getPhone()); |
| | | } |
| | | // 更新场所信息 |
| | | updateById(placeEntity); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 自定义修改 |
| | | * @param placeVO |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean updatePlace(PlaceVO placeVO) { |
| | | boolean flag = false; |
| | | // 修改场所信息 |
| | | flag = updateById(placeVO); |
| | | // 修改标签绑定信息 |
| | | // 返回 |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 场所标签数据处理 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Object placeLabelHandle() { |
| | | // 查询所有的标签绑定 |
| | | List<PlacePoiLabel> list = placePoiLabelService.getPlacePoiLabelList(); |
| | | // 遍历 |
| | | for (PlacePoiLabel placePoiLabel : list) { |
| | | // 处理单个 |
| | | String labelCode = placePoiLabel.getPoiCode().toString(); |
| | | // 切割成三个,分别是大类,中类,小类 |
| | | String bigString = labelCode.substring(0,2); |
| | | String midString = labelCode.substring(0,4); |
| | | // 大类 |
| | | PlacePoiLabel big = new PlacePoiLabel(); |
| | | big.setPlaceId(placePoiLabel.getPlaceId()); |
| | | big.setPoiCode(Integer.parseInt(bigString)); |
| | | big.setType(1); |
| | | // 保存前先判断 |
| | | QueryWrapper<PlacePoiLabel> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("place_id",placePoiLabel.getPlaceId()).eq("poi_code",Integer.parseInt(bigString)); |
| | | PlacePoiLabel one = placePoiLabelService.getOne(queryWrapper); |
| | | if (null==one) { |
| | | placePoiLabelService.save(big); |
| | | } |
| | | // 中类 |
| | | PlacePoiLabel mid = new PlacePoiLabel(); |
| | | mid.setPlaceId(placePoiLabel.getPlaceId()); |
| | | mid.setPoiCode(Integer.parseInt(midString)); |
| | | mid.setType(2); |
| | | // 保存前先判断 |
| | | QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",placePoiLabel.getPlaceId()).eq("poi_code",Integer.parseInt(midString)); |
| | | PlacePoiLabel two = placePoiLabelService.getOne(wrapper); |
| | | if (null==two) { |
| | | placePoiLabelService.save(mid); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 历史场所详情数据处理 |
| | | * @param place |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object historyPlaceExtHandle(PlaceVO place) { |
| | | // 查询所有的场所数据(除去详情表已有的) |
| | | List<PlaceEntity> list = baseMapper.getPlaceListByNoExt(); |
| | | // 遍历更新 |
| | | for (PlaceEntity placeEntity : list) { |
| | | QueryWrapper<PlaceExtEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("place_id",placeEntity.getId()).eq("is_deleted",0); |
| | | PlaceExtEntity one = placeExtService.getOne(queryWrapper); |
| | | if (null==one){ |
| | | // 新增 |
| | | PlaceExtEntity placeExtEntity = new PlaceExtEntity(); |
| | | if (null!=placeEntity.getPrincipalUserId()){ |
| | | // 待审核 |
| | | placeExtEntity.setConfirmFlag(1); |
| | | }else { |
| | | // 待完善 |
| | | placeExtEntity.setConfirmFlag(4); |
| | | } |
| | | placeExtEntity.setPlaceId(placeEntity.getId()); |
| | | // 插入 |
| | | placeExtService.save(placeExtEntity); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 商超数据处理 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Object placeAndRelHandle() { |
| | | // 查询未处理的商超数据 |
| | | List<PlaceEntity> placeEntityList = baseMapper.placeAndRelHandle(); |
| | | // 处理 |
| | | for (PlaceEntity placeEntity : placeEntityList) { |
| | | if (Strings.isBlank(placeEntity.getHouseCode())){ |
| | | // 并生成36位的houseCode |
| | | placeEntity.setHouseCode(IdUtils.getIdBy36()); |
| | | // 商超数据 |
| | | placeEntity.setSource(3); |
| | | // 更新 |
| | | updateById(placeEntity); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据编号集合查询对应的场所(按颜色区分近多少天没有发过任务的场所) |
| | | * @param stringList |
| | | * @param tableName |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<PlaceVO> getPlaceListByParam(List<String> stringList,String tableName) { |
| | | return baseMapper.getPlaceListByParam(stringList,tableName); |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * @param longs |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean removePlace(List<Long> longs) { |
| | | // 删除场所负责人对应的用户 |
| | | removeUser(longs); |
| | | // 删除 |
| | | boolean removeByIds = removeByIds(longs); |
| | | // 删除对应的详情 |
| | | removePlaceExt(longs); |
| | | // 删除对应的标签绑定信息 |
| | | removePlaceLabel(longs); |
| | | // 返回 |
| | | return removeByIds; |
| | | } |
| | | |
| | | /** |
| | | * 删除场所负责人对应的用户 |
| | | * @param longs |
| | | */ |
| | | public void removeUser(List<Long> longs) { |
| | | // 遍历 |
| | | for (Long id : longs) { |
| | | PlaceEntity placeEntity = getById(id); |
| | | if (null!=placeEntity.getPrincipalUserId()){ |
| | | User user = userService.getById(placeEntity.getPrincipalUserId()); |
| | | // 查询场所判断是否还绑定有其他的场所 |
| | | QueryWrapper<PlaceEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("principal_user_id",user.getId()); |
| | | List<PlaceEntity> placeEntityList = list(queryWrapper); |
| | | // 如果没有(1个 当前的还没有删除) |
| | | if (placeEntityList.size()==1){ |
| | | // 判断角色 |
| | | if (!Strings.isBlank(user.getRoleId())){ |
| | | // 判断是否还绑定其他的房屋,如果有,则不操作用户 |
| | | QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("is_deleted",0).eq("associated_user_id",user.getId()); |
| | | List<HouseholdEntity> householdEntityList = householdService.list(wrapper); |
| | | // 即没有房屋和场所了就删除对应的居民角色 |
| | | if (householdEntityList.size()==0) { |
| | | List<String> stringList = Arrays.asList(user.getRoleId().split(",")); |
| | | // 查看当前用户的角色是否只有一个 |
| | | if (stringList.size() > 1) { |
| | | // 查询是否对应有场所负责人,如果有则不删除,如果没有则删除对应的角色 |
| | | List<String> arrayList = new ArrayList<>(); |
| | | for (String roleId : stringList) { |
| | | if (!roleId.equals("1717429059648606209")) { |
| | | arrayList.add(roleId); |
| | | } |
| | | } |
| | | user.setRoleId(StringUtils.join(arrayList, ",")); |
| | | // 更新用户 |
| | | userService.updateById(user); |
| | | } else { |
| | | // 删除当前用户 |
| | | userService.removeById(user.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除场所对应的详情 |
| | | * @param longs |
| | | */ |
| | | public void removePlaceExt(List<Long> longs) { |
| | | for (Long id : longs) { |
| | | QueryWrapper<PlaceExtEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",id); |
| | | placeExtService.remove(wrapper); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除对应的标签绑定信息 |
| | | * @param longs |
| | | */ |
| | | public void removePlaceLabel(List<Long> longs) { |
| | | for (Long id : longs) { |
| | | QueryWrapper<PlacePoiLabel> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("place_id",id); |
| | | placePoiLabelService.remove(wrapper); |
| | | } |
| | | } |
| | | } |