ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java
@@ -11,6 +11,7 @@ import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.domain.ZInfoUser; import com.ruoyi.domain.ZfRelation; import com.ruoyi.service.ZInfoUserService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -146,7 +147,6 @@ /** * 查询家庭主要成员及关系 */ @GetMapping("/relation") public AjaxResult listMyRelation() { SysUser user = SecurityUtils.getLoginUser().getUser(); @@ -154,6 +154,22 @@ return zInfoUserService.searchMyRelation(userId); } @PostMapping("/relation") public AjaxResult addRelation(@RequestBody ZfRelation zfRelation){ return zInfoUserService.addRelation(zfRelation); } @PutMapping("/relation") public AjaxResult updateRelation(@RequestBody ZfRelation zfRelation){ return zInfoUserService.updateRelation(zfRelation); } @DeleteMapping("/relation/{ids}") public AjaxResult deleteRelation(@PathVariable Long[] ids){ return zInfoUserService.deleteRelation(ids); } } zhang-content/src/main/java/com/ruoyi/domain/ZfRelation.java
@@ -1,5 +1,7 @@ package com.ruoyi.domain; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; import lombok.Data; import lombok.ToString; @@ -15,8 +17,12 @@ public class ZfRelation implements Serializable { private static final long serialVersionUID = 1L; @TableId(value = "id", type = IdType.AUTO) private Long id; private Long myId; private Long otherId; private String relation; } zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java
@@ -17,6 +17,8 @@ private static final long serialVersionUID = 1L; private Long id; /** * 名字 */ zhang-content/src/main/java/com/ruoyi/service/ZInfoUserService.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.domain.ZInfoUser; import com.ruoyi.domain.ZfRelation; import java.util.List; @@ -20,4 +21,10 @@ List<ZInfoUser> selectByCondition(ZInfoUser zInfoUser); AjaxResult searchMyRelation(Long userId); AjaxResult addRelation(ZfRelation zfRelation); AjaxResult updateRelation(ZfRelation zfRelation); AjaxResult deleteRelation(Long[] ids); } zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
@@ -28,6 +28,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; @@ -42,58 +43,57 @@ @Resource ZInfoUserService zInfoUserService; @Resource IZfPropertyService zfPropertyService; @Override public List<ZfProperty> selectByCondition(ZfProperty zfProperty) { String familyIds = listFamilyIds(); LambdaQueryWrapper<ZfProperty> lambdaQueryWrapper = buildCondition(zfProperty,familyIds); LambdaQueryWrapper<ZfProperty> lambdaQueryWrapper = buildCondition(zfProperty, familyIds); List<ZfProperty> list = list(lambdaQueryWrapper); log.info("返回的数据为:{}",list); log.info("返回的数据为:{}", list); return list; } private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty) { LambdaQueryWrapper<ZfProperty> lqw = new LambdaQueryWrapper<>(); lqw.like(!StringUtils.isEmpty(zfProperty.getType()),ZfProperty::getType, zfProperty.getType()); lqw.like(!StringUtils.isEmpty(zfProperty.getTitle()),ZfProperty::getTitle, zfProperty.getTitle()); lqw.like(!StringUtils.isEmpty(zfProperty.getLocation()),ZfProperty::getLocation, zfProperty.getLocation()); lqw.like(!StringUtils.isEmpty(zfProperty.getHolder()),ZfProperty::getHolder, zfProperty.getHolder()); lqw.like(!StringUtils.isEmpty(zfProperty.getAddress()),ZfProperty::getAddress, zfProperty.getAddress()); lqw.like(!StringUtils.isEmpty(zfProperty.getRemark()),ZfProperty::getRemark, zfProperty.getRemark()); lqw.like(zfProperty.getCreateTime()!=null,ZfProperty::getCreateTime, zfProperty.getCreateTime()); lqw.like(!StringUtils.isEmpty(zfProperty.getType()), ZfProperty::getType, zfProperty.getType()) .like(!StringUtils.isEmpty(zfProperty.getTitle()), ZfProperty::getTitle, zfProperty.getTitle()) .like(!StringUtils.isEmpty(zfProperty.getLocation()), ZfProperty::getLocation, zfProperty.getLocation()) .like(!StringUtils.isEmpty(zfProperty.getHolder()), ZfProperty::getHolder, zfProperty.getHolder()) .like(!StringUtils.isEmpty(zfProperty.getAddress()), ZfProperty::getAddress, zfProperty.getAddress()) .like(!StringUtils.isEmpty(zfProperty.getRemark()), ZfProperty::getRemark, zfProperty.getRemark()) .like(zfProperty.getCreateTime() != null, ZfProperty::getCreateTime, zfProperty.getCreateTime()); return lqw; } private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty,String familyIds) { private LambdaQueryWrapper<ZfProperty> buildCondition(ZfProperty zfProperty, String familyIds) { LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty); if (familyIds.contains(",")) { String[] familyList = familyIds.split(","); for (String familyId : familyList) { lqw.or().eq(ZfProperty::getFamilyId,familyId); } }else { lqw.eq(ZfProperty::getFamilyId,familyIds); lqw.in(ZfProperty::getFamilyId,familyList); } else { lqw.eq(ZfProperty::getFamilyId, familyIds); } return lqw; } private String listFamilyIds(){ private String listFamilyIds() { SysUser user = SecurityUtils.getLoginUser().getUser(); Long userId = user.getUserId(); LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId,userId); zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId, userId); ZInfoUser zInfoUser = zInfoUserService.getOne(zInfoUserLambdaQueryWrapper); return zInfoUser.getFamilyId(); } @Override public AjaxResult selectPropertyList(ZfProperty zfProperty,Integer pageNum,Integer pageSize) { public AjaxResult selectPropertyList(ZfProperty zfProperty, Integer pageNum, Integer pageSize) { String familyIds = listFamilyIds(); LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty,familyIds); Page<ZfProperty> zfPropertyPage = new Page<>(pageNum,pageSize); LambdaQueryWrapper<ZfProperty> lqw = buildCondition(zfProperty, familyIds); Page<ZfProperty> zfPropertyPage = new Page<>(pageNum, pageSize); Page<ZfProperty> pageResult = page(zfPropertyPage, lqw); HashMap<String, Object> data = MapUtils.getResult(pageResult); return AjaxResult.success(data); @@ -141,7 +141,7 @@ } return AjaxResult.success("导入数据成功"); } } zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.MapUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.domain.ZInfoUser; import com.ruoyi.domain.ZfEvent; @@ -19,8 +21,10 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -102,6 +106,7 @@ UserRelationDto userRelationDto = new UserRelationDto(); BeanUtils.copyProperties(otherUser,userRelationDto); userRelationDto.setRelation(relation.getRelation()); userRelationDto.setId(relation.getId()); otherUserList.add(userRelationDto); return relation; } @@ -109,4 +114,53 @@ return AjaxResult.success(otherUserList); } /** * 检查传入对方的id是否存在 * @param zfRelation */ private void checkRelation(ZfRelation zfRelation){ LambdaQueryWrapper<ZInfoUser> lqw = new LambdaQueryWrapper<>(); lqw.eq(ZInfoUser::getUserId, zfRelation.getOtherId()); ZInfoUser zInfoUser2 = getOne(lqw); if (zInfoUser2==null){ throw new RuntimeException("对方的id不存在"); } } @Override @Transactional public AjaxResult addRelation(ZfRelation zfRelation) { checkRelation(zfRelation); //获取自己的id并传入 SysUser user = SecurityUtils.getLoginUser().getUser(); Long userId = user.getUserId(); zfRelation.setMyId(userId); zfRelationService.save(zfRelation); return AjaxResult.success(); } @Override @Transactional public AjaxResult updateRelation(ZfRelation zfRelation) { checkRelation(zfRelation); zfRelationService.updateById(zfRelation); return AjaxResult.success(); } @Override public AjaxResult deleteRelation(Long[] ids) { boolean flag = zfRelationService.removeByIds(Arrays.asList(ids)); if (flag){ return AjaxResult.success(); }else { return AjaxResult.error(); } } } zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java
@@ -111,9 +111,8 @@ LambdaQueryWrapper<ZfEquipment> lqw = buildCondition(zfEquipment); if (familyIds.contains(",")) { String[] familyList = familyIds.split(","); for (String familyId : familyList) { lqw.or().eq(ZfEquipment::getFamilyId, familyId); } lqw.in(ZfEquipment::getFamilyId,familyList); } else { lqw.eq(ZfEquipment::getFamilyId, familyIds); } zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java
@@ -13,6 +13,7 @@ import com.ruoyi.domain.ZInfoUser; import com.ruoyi.domain.ZfEvent; import com.ruoyi.domain.ZfEvent; import com.ruoyi.domain.ZfProperty; import com.ruoyi.mapper.ZfEventMapper; import com.ruoyi.service.ZInfoUserService; import com.ruoyi.service.ZfEventService; @@ -130,9 +131,7 @@ LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent); if (familyIds.contains(",")) { String[] familyList = familyIds.split(","); for (String familyId : familyList) { lqw.or().eq(ZfEvent::getFamilyId,familyId); } lqw.in(ZfEvent::getFamilyId,familyList); }else { lqw.eq(ZfEvent::getFamilyId,familyIds); }