| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import liquibase.repackaged.org.apache.commons.lang3.StringUtils; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.common.node.TreeStringNode; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.modules.grid.service.IGridService; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.entity.UserHouseLabelEntity; |
| | | import org.springblade.modules.house.excel.HouseHoldExcel; |
| | | import org.springblade.modules.house.mapper.HouseholdMapper; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.house.service.IUserHouseLabelService; |
| | | import org.springblade.modules.house.vo.HouseholdLabelVO; |
| | | import org.springblade.modules.house.vo.HouseholdOtherVO; |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springblade.modules.place.entity.PlaceEntity; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.DictBiz; |
| | | import org.springblade.modules.system.entity.User; |
| | |
| | | import org.springframework.util.StopWatch; |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 住户 服务实现类 |
| | |
| | | public class HouseholdServiceImpl extends ServiceImpl<HouseholdMapper, HouseholdEntity> implements IHouseholdService { |
| | | |
| | | @Autowired |
| | | private IGridService gridService; |
| | | private IUserHouseLabelService userHouseLabelService; |
| | | |
| | | @Autowired |
| | | private IDictBizService dictBizService; |
| | |
| | | @Autowired |
| | | private IDeptService deptService; |
| | | |
| | | @Autowired |
| | | private IPlaceService placeService; |
| | | |
| | | @Override |
| | | public IPage<HouseholdVO> selectHouseholdPage(IPage<HouseholdVO> page, HouseholdVO household) { |
| | | StopWatch stopWatch = new StopWatch(); |
| | | stopWatch.start(); |
| | | // doInsert(); |
| | | // 执行业务等 |
| | | Dept dept = deptService.getById(AuthUtil.getDeptId()); |
| | | if (null!=dept){ |
| | | household.setRegionCode(dept.getRegionCode()); |
| | | } |
| | | List<HouseholdVO> householdVOS = baseMapper.selectHouseholdPage(page, household); |
| | | // 遍历 |
| | | // for (HouseholdVO householdVO : householdVOS) { |
| | | // // 设置对应的网格名称 |
| | | // GridVO gridVO = gridService.getGridDetailByHouseCode(householdVO.getHouseCode()); |
| | | // if (null!= gridVO){ |
| | | // householdVO.setGridName(gridVO.getGridName()); |
| | | // } |
| | | // } |
| | | // 返回 |
| | | stopWatch.stop(); |
| | | System.out.println("selectHouseholdPage:" + stopWatch.getTotalTimeMillis()); |
| | | return page.setRecords(householdVOS); |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean saveOrUpdateHousehold(HouseholdEntity household) { |
| | | // 判断添加人是否房屋业主 |
| | | // Long count = count(Wrappers.<HouseholdEntity>lambdaQuery() |
| | | // .eq(HouseholdEntity::getHouseCode, household.getHouseCode()) |
| | | // .eq(HouseholdEntity::getAssociatedUserId, AuthUtil.getUserId()) |
| | | // .eq(HouseholdEntity::getRelationship, 1)); |
| | | // if (count == 0) { |
| | | // return false; |
| | | // } |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean saveOrUpdateHousehold(HouseholdVO household) { |
| | | boolean flag = false; |
| | | household.setUpdateTime(new Date()); |
| | | household.setUpdateUser(AuthUtil.getUserId()); |
| | |
| | | flag = updateById(household); |
| | | // 更新用户信息 |
| | | updateUserInfo(household); |
| | | // 更新标签信息 |
| | | updateUserLabelInfo(household); |
| | | } else { |
| | | // 新增 |
| | | household.setCreateTime(new Date()); |
| | |
| | | flag = save(household); |
| | | // 更新用户信息 |
| | | updateUserInfo(household); |
| | | // 更新标签信息 |
| | | updateUserLabelInfo(household); |
| | | } |
| | | return flag; |
| | | } |
| | | |
| | | /** |
| | | * 更新用户标签信息 |
| | | * @param household |
| | | */ |
| | | public void updateUserLabelInfo(HouseholdVO household) { |
| | | if (household.getHouseholdLabelList().size()>0){ |
| | | List<HouseholdLabelVO> householdLabelList = household.getHouseholdLabelList(); |
| | | for (HouseholdLabelVO householdLabelVO : householdLabelList) { |
| | | if (!Strings.isBlank(household.getHouseCode())) { |
| | | householdLabelVO.setHouseCode(household.getHouseCode()); |
| | | } |
| | | householdLabelVO.setHouseholdId(household.getId()); |
| | | // 先删除对应绑定的信息 |
| | | userHouseLabelService.saveOrUpdateHouseholdLabel(householdLabelVO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | User userParams = new User(); |
| | | userParams.setPhone(householdEntity.getPhoneNumber()); |
| | | User user = userService.getOne(Condition.getQueryWrapper(userParams)); |
| | | if (null==user) { |
| | | User userParams1 = new User(); |
| | | userParams1.setAccount(householdEntity.getPhoneNumber()); |
| | | userParams1.setIsDeleted(0); |
| | | user = userService.getOne(Condition.getQueryWrapper(userParams1)); |
| | | } |
| | | if (null!=user) { |
| | | //如果用户存在,则该用户id绑定场所 |
| | | householdEntity.setAssociatedUserId(user.getId()); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 住户 删除 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean removeHousehold(String ids) { |
| | | List<Long> idList = Func.toLongList(ids); |
| | | // 同时删除当前住户对应的标签 |
| | | removeHouseholdLabel(idList); |
| | | // 同时删除对应的用户信息 |
| | | removeHouseholdUser(idList); |
| | | // 删除住户信息 |
| | | boolean removeByIds = removeByIds(idList); |
| | | // 返回 |
| | | return removeByIds; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 同时删除对应的用户信息 |
| | | * @param idList |
| | | */ |
| | | public void removeHouseholdUser(List<Long> idList) { |
| | | for (Long id : idList) { |
| | | HouseholdEntity householdEntity = getById(id); |
| | | // 如果是业主 |
| | | if (householdEntity.getRelationship()==1){ |
| | | // 查询对应的用户 |
| | | User user = userService.getById(householdEntity.getAssociatedUserId()); |
| | | // 判断角色 |
| | | if (!Strings.isBlank(user.getRoleId())){ |
| | | List<String> stringList = Arrays.asList(user.getRoleId().split(",")); |
| | | // 查询场所 |
| | | QueryWrapper<PlaceEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("is_deleted",0).eq("principal_user_id",user.getId()); |
| | | List<PlaceEntity> placeEntityList = placeService.list(queryWrapper); |
| | | if (stringList.size()>1){ |
| | | // 查询是否对应有场所负责人,如果有则不删除,如果没有则删除对应的角色 |
| | | List<String> arrayList = new ArrayList<>(); |
| | | if (placeEntityList.size()==0){ |
| | | for (String roleId : stringList) { |
| | | if (!roleId.equals("1717429059648606209")){ |
| | | arrayList.add(roleId); |
| | | } |
| | | } |
| | | } |
| | | user.setRoleId(StringUtils.join(arrayList, ",")); |
| | | // 更新用户 |
| | | userService.updateById(user); |
| | | }else { |
| | | // 查询是否对应有场所负责人,如果有则不删除,如果没有则删除对应的用户 |
| | | if (placeEntityList.size()==0){ |
| | | userService.removeById(user.getId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除住户标签信息 |
| | | * @param idList |
| | | */ |
| | | public void removeHouseholdLabel(List<Long> idList) { |
| | | for (Long id : idList) { |
| | | QueryWrapper<UserHouseLabelEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("household_id",id); |
| | | userHouseLabelService.remove(wrapper); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<HouseholdVO> getAllHouseHold(HouseholdVO household) { |
| | | return baseMapper.getAllHouseHold(household); |
| | | } |
| | | |
| | | /** |
| | | * 住户列表查询 |
| | | * @param household |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<HouseholdVO> selectHouseholdList(HouseholdVO household) { |
| | | List<HouseholdVO> householdVOS = baseMapper.selectHouseholdList(household); |
| | | // 遍历 |
| | | for (HouseholdVO householdVO : householdVOS) { |
| | | if (householdVO.getHouseholdLabelList().size()>0){ |
| | | List<String> labelNameList = householdVO.getHouseholdLabelList().stream().map(householdLabelVO -> householdLabelVO.getLabelName()) |
| | | .collect(Collectors.toList()); |
| | | householdVO.setLabelName(String.join(",",labelNameList)); |
| | | } |
| | | } |
| | | // 返回 |
| | | return householdVOS; |
| | | } |
| | | } |