| | |
| | | package org.springblade.modules.place.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.node.TreeNode; |
| | | 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.PlaceExtEntity; |
| | | import org.springblade.modules.place.entity.PlacePoiLabel; |
| | | import org.springblade.modules.place.service.IPlaceExtService; |
| | | import org.springblade.modules.place.service.IPlacePoiLabelService; |
| | | import org.springblade.modules.place.vo.PlaceVO; |
| | | import org.springblade.modules.place.mapper.PlaceMapper; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.core.mp.base.BaseServiceImpl; |
| | | import org.springblade.modules.system.entity.User; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class PlaceServiceImpl extends ServiceImpl<PlaceMapper, PlaceEntity> implements IPlaceService { |
| | | @Autowired |
| | | private IUserService userService; |
| | | |
| | | @Autowired |
| | | private IPlacePoiLabelService placePoiLabelService; |
| | | |
| | | @Autowired |
| | | private IPlaceExtService placeExtService; |
| | | |
| | | @Override |
| | | public IPage<PlaceVO> selectPlacePage(IPage<PlaceVO> page, PlaceVO place) { |
| | |
| | | public List<TreeNode> 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()); |
| | | placeVO.setUpdateUser(AuthUtil.getUserId()); |
| | | placeVO.setUpdateTime(new Date()); |
| | | // 绑定用户信息 |
| | | bindUserHandle(placeVO); |
| | | // 新增场所信息 |
| | | boolean save = save(placeVO); |
| | | // 场所标签信息绑定 |
| | | placeLabelBind(placeVO); |
| | | // 返回结果 |
| | | return save; |
| | | } |
| | | |
| | | /** |
| | | * 场所标签信息绑定入库 |
| | | * @param placeVO |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void placeLabelBind(PlaceVO 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); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 场所负责人和用户绑定 |
| | | * @param placeVO |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void bindUserHandle(PlaceVO placeVO) { |
| | | if (null!=placeVO.getPhone() && !placeVO.getPhone().equals("")) { |
| | | //根据手机号查询库里的数据 |
| | | 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()); |
| | | // 目前暂定居民角色,默认密码为 123456 |
| | | newUser.setRoleId("1717429059648606209"); |
| | | newUser.setPassword("123456"); |
| | | // 用户新增 |
| | | boolean submit = userService.submit(newUser); |
| | | //绑定id |
| | | placeVO.setPrincipalUserId(newUser.getId()); |
| | | //给人员打上场所负责人的标签 |
| | | |
| | | // 用户插入后同时给场所详情表插入一条该场所信息 |
| | | if (submit){ |
| | | PlaceExtEntity placeExtEntity = new PlaceExtEntity(); |
| | | placeExtEntity.setPlaceId(placeVO.getId()); |
| | | //新增 |
| | | placeExtService.savePlaceExt(placeExtEntity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |