From 1836f7863882ceae0e5c246556196be48bd12384 Mon Sep 17 00:00:00 2001 From: Jinquan_Ou <Jinquan@gdut.com> Date: 星期六, 08 四月 2023 00:13:27 +0800 Subject: [PATCH] 111 --- zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java | 2 zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java | 54 ++++++++++++++++++ zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java | 5 - zhang-content/src/main/java/com/ruoyi/domain/ZfRelation.java | 6 ++ ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java | 18 +++++ zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java | 5 - zhang-content/src/main/java/com/ruoyi/service/ZInfoUserService.java | 7 ++ zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java | 44 +++++++------- 8 files changed, 112 insertions(+), 29 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java index 7b630a1..32a7be2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZInfoUserController.java +++ b/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); + } + } diff --git a/zhang-content/src/main/java/com/ruoyi/domain/ZfRelation.java b/zhang-content/src/main/java/com/ruoyi/domain/ZfRelation.java index f4f8a84..a453668 100644 --- a/zhang-content/src/main/java/com/ruoyi/domain/ZfRelation.java +++ b/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; } diff --git a/zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java b/zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java index 00062a0..173279b 100644 --- a/zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java +++ b/zhang-content/src/main/java/com/ruoyi/domain/dto/UserRelationDto.java @@ -17,6 +17,8 @@ private static final long serialVersionUID = 1L; + private Long id; + /** * 鍚嶅瓧 */ diff --git a/zhang-content/src/main/java/com/ruoyi/service/ZInfoUserService.java b/zhang-content/src/main/java/com/ruoyi/service/ZInfoUserService.java index b52fec8..594e02e 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/ZInfoUserService.java +++ b/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); } diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java index a6d3abf..bcd6416 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java +++ b/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("瀵煎叆鏁版嵁鎴愬姛"); - + } } diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java index 21a2b81..9fa02f2 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java +++ b/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("瀵规柟鐨刬d涓嶅瓨鍦�"); + } + } + + @Override + @Transactional + public AjaxResult addRelation(ZfRelation zfRelation) { + checkRelation(zfRelation); + + //鑾峰彇鑷繁鐨刬d骞朵紶鍏� + 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(); + } + } + + } diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java index e39e56e..7b85359 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEquipmentServiceImpl.java +++ b/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); } diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java index 151a865..fb803c4 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java +++ b/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); } -- Gitblit v1.9.1