| | |
| | | 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 org.apache.logging.log4j.util.Strings; |
| | | 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.doorplateAddress.entity.DoorplateAddressEntity; |
| | | import org.springblade.modules.doorplateAddress.service.IDoorplateAddressService; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.place.entity.PlaceEntity; |
| | | import org.springblade.modules.place.entity.PlaceExtEntity; |
| | | import org.springblade.modules.place.entity.PlacePoiLabel; |
| | | import org.springblade.modules.place.entity.PlaceRelEntity; |
| | | 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 com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 场所表 服务实现类 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 场所信息自定义新增 |
| | | * 场所信息自定义新增/修改 |
| | | * @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()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 新增场所信息 |
| | | boolean save = save(placeVO); |
| | | // 保存场所详情及任务信息 |
| | | savePlaceExtAndTaskInfo(placeVO); |
| | | // 场所标签信息绑定 |
| | | placeLabelBind(placeVO); |
| | | // 查看是否包含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); |
| | | placeVO.setId(one.getId()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 更新场所信息 |
| | | flag = updateById(placeVO); |
| | | // 保存场所详情及任务信息 |
| | | savePlaceExtAndTaskInfo(placeVO); |
| | | // 场所标签信息绑定(更新,调整) |
| | | placeLabelBind(placeVO); |
| | | }else { |
| | | // 设置基础数据 |
| | | placeVO.setCreateUser(AuthUtil.getUserId()); |
| | | placeVO.setCreateTime(new Date()); |
| | | // 设置来源( 1:地址总表 2:国控采集) |
| | | placeVO.setSource(2); |
| | | // 并生成36位的houseCode |
| | | placeVO.setHouseCode(IdUtils.getIdBy36()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 新增场所信息 |
| | | flag = save(placeVO); |
| | | // 保存场所详情及任务信息 |
| | | savePlaceExtAndTaskInfo(placeVO); |
| | | // 场所标签信息绑定 |
| | | placeLabelBind(placeVO); |
| | | } |
| | | // 位置绑定,通过定位去匹配所在网格 |
| | | // 返回结果 |
| | | return save; |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @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) { |
| | | // 批量新增 |
| | | List<String> labelList = Arrays.asList(placeVO.getLabel().split(",")); |
| | | // 遍历 |
| | | labelList.forEach(labelId->{ |
| | | labelList.forEach(labelId -> { |
| | | PlacePoiLabel placePoiLabel = new PlacePoiLabel(); |
| | | placePoiLabel.setPlaceId(placeVO.getId()); |
| | | placePoiLabel.setPoiCode(Integer.parseInt(labelId)); |
| | |
| | | public User bindUserHandle(PlaceVO placeVO) { |
| | | User newUser = new User(); |
| | | if (null!=placeVO.getPhone() && !placeVO.getPhone().equals("")) { |
| | | placeVO.setPrincipal(placeVO.getUsername()); |
| | | placeVO.setPrincipalPhone(placeVO.getPhone()); |
| | | //根据手机号查询库里的数据 |
| | | User userParams = new User(); |
| | | userParams.setPhone(placeVO.getPhone()); |
| | |
| | | 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.setPlaceName(placeExcel.getPlaceName()); |
| | | placeEntity.setLocaltion(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()); |
| | |
| | | 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; |
| | | } |
| | | } |