| | |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.domain.ZInfoUser; |
| | | import com.ruoyi.domain.ZfEvent; |
| | | import com.ruoyi.domain.*; |
| | | import com.ruoyi.domain.ZfEvent; |
| | | import com.ruoyi.domain.ZfEvent; |
| | | import com.ruoyi.mapper.ZfEventMapper; |
| | | import com.ruoyi.service.ZAuthorityService; |
| | | import com.ruoyi.service.ZInfoUserService; |
| | | import com.ruoyi.service.ZfEventService; |
| | | import com.ruoyi.util.ArraysUtil; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.ruoyi.constant.MenuAuthority.EVENT_LIST; |
| | | import static com.ruoyi.constant.MenuAuthority.PROPERTY_LIST; |
| | | import static com.ruoyi.constant.MenuAuthority.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | ZfEventService zfEventService; |
| | | |
| | | private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent) { |
| | | @Resource |
| | | ZAuthorityService zAuthorityService; |
| | | |
| | | private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent,List<Long> familyIdList) { |
| | | LambdaQueryWrapper<ZfEvent> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.orderByDesc(ZfEvent::getCreateTime); |
| | | lqw.like(!StringUtils.isEmpty(zfEvent.getAddress()), ZfEvent::getAddress, zfEvent.getAddress()); |
| | | lqw.like(!StringUtils.isEmpty(zfEvent.getPeople()), ZfEvent::getPeople, zfEvent.getPeople()); |
| | | lqw.like(!StringUtils.isEmpty(zfEvent.getTitle()), ZfEvent::getTitle, zfEvent.getTitle()); |
| | | lqw.like(!StringUtils.isEmpty(zfEvent.getRemark()), ZfEvent::getRemark, zfEvent.getRemark()); |
| | | lqw.eq(zfEvent.getHappenTime() != null, ZfEvent::getHappenTime, zfEvent.getHappenTime()); |
| | | lqw.in(ZfEvent::getFamilyId,familyIdList); |
| | | lqw.between(zfEvent.getHappenStartTime() != null && zfEvent.getHappenEndTime() != null, ZfEvent::getHappenTime, zfEvent.getHappenStartTime(), zfEvent.getHappenEndTime()); |
| | | return lqw; |
| | | } |
| | | |
| | | private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent, String familyIds, String secondFamilyAuthority) { |
| | | //模糊查询的条件 |
| | | LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent); |
| | | |
| | | //定义一个布尔标记,标记第一家庭号是否有逗号 |
| | | boolean flag = false; |
| | | |
| | | StringBuilder secondFamilyIdsBuffer = new StringBuilder(); |
| | | |
| | | //处理传入的secondFamilyAuthority 3{2007 2018 2015},4{2007 2019} |
| | | |
| | | if (StringUtils.isNotEmpty(secondFamilyAuthority)) { |
| | | |
| | | if (secondFamilyAuthority.contains(",")) { |
| | | //逗号隔开得到如下串:3{2007 2018 2015} |
| | | String[] authorityList = secondFamilyAuthority.split(","); |
| | | for (String authorityAndId : authorityList) { |
| | | setSecondFamilyAuthority(secondFamilyIdsBuffer, authorityAndId); |
| | | } |
| | | |
| | | //把后面的逗号去掉 |
| | | if (secondFamilyIdsBuffer.length() > 1) { |
| | | secondFamilyIdsBuffer.deleteCharAt(secondFamilyIdsBuffer.length() - 1); |
| | | } |
| | | |
| | | } else { |
| | | setSecondFamilyAuthority(secondFamilyIdsBuffer, secondFamilyAuthority); |
| | | //把后面的逗号去掉 |
| | | if (secondFamilyIdsBuffer.length() > 1) { |
| | | secondFamilyIdsBuffer.deleteCharAt(secondFamilyIdsBuffer.length() - 1); |
| | | } |
| | | } |
| | | } |
| | | //将StringBuffer转成String |
| | | String secondFamilyIds = secondFamilyIdsBuffer.toString(); |
| | | |
| | | //第一家庭号的条件 |
| | | if (familyIds.contains(",")) { |
| | | flag = true; |
| | | } |
| | | |
| | | //第二家庭号的条件 |
| | | if (StringUtils.isNotEmpty(secondFamilyIds)) { |
| | | if (secondFamilyIds.contains(",")) { |
| | | String[] secondFamilyIdList = secondFamilyIds.split(","); |
| | | if (flag) { |
| | | //如果第一家庭号和第二家庭号都有逗号 |
| | | String[] familyList = familyIds.split(","); |
| | | String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIdList); |
| | | lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | } else { |
| | | //如果第一家庭号没有逗号但是第二家庭号有逗号 |
| | | String[] totalFamilyIdList = ArraysUtil.appendToArray(secondFamilyIdList, familyIds); |
| | | lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | } |
| | | |
| | | } else { |
| | | if (flag) { |
| | | //如果第一家庭号有逗号但第二家庭号没有逗号 |
| | | String[] familyList = familyIds.split(","); |
| | | String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIds); |
| | | lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | } else { |
| | | //如果第一家庭号和第二家庭号都没有逗号 |
| | | String[] totalFamilyIdList = ArraysUtil.appendToArray(familyIds, secondFamilyIds); |
| | | lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | } |
| | | } |
| | | } else { |
| | | //如果没有第二家庭号 |
| | | if (flag) { |
| | | String[] familyList = familyIds.split(","); |
| | | lqw.in(ZfEvent::getFamilyId, familyList); |
| | | } else { |
| | | lqw.eq(ZfEvent::getFamilyId, familyIds); |
| | | } |
| | | |
| | | } |
| | | |
| | | lqw.orderByDesc(ZfEvent::getCreateTime); |
| | | private LambdaQueryWrapper<ZfEvent> uniqueCondition(ZfEvent zfEvent){ |
| | | LambdaQueryWrapper<ZfEvent> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(!StringUtils.isEmpty(zfEvent.getAddress()), ZfEvent::getAddress, zfEvent.getAddress()); |
| | | lqw.eq(!StringUtils.isEmpty(zfEvent.getPeople()), ZfEvent::getPeople, zfEvent.getPeople()); |
| | | lqw.eq(!StringUtils.isEmpty(zfEvent.getTitle()), ZfEvent::getTitle, zfEvent.getTitle()); |
| | | lqw.eq(!StringUtils.isEmpty(zfEvent.getRemark()), ZfEvent::getRemark, zfEvent.getRemark()); |
| | | lqw.eq(zfEvent.getFamilyId()!=null,ZfEvent::getFamilyId,zfEvent.getFamilyId()); |
| | | lqw.eq(zfEvent.getHappenTime() != null, ZfEvent::getHappenTime, zfEvent.getHappenTime()); |
| | | return lqw; |
| | | } |
| | | |
| | | private void setSecondFamilyAuthority(StringBuilder secondFamilyIdsBuffer, String authorityAndId) { |
| | | //得到权限串 |
| | | String authorities = authorityAndId.substring(2, authorityAndId.length() - 1); |
| | | |
| | | if (authorities.contains(" ")) { |
| | | //空格隔开得到菜单id,看是否有对应的权限 |
| | | String[] authorityIdList = authorities.split(" "); |
| | | for (String s : authorityIdList) { |
| | | if (s.equals(EVENT_LIST)) { |
| | | secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(","); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | if (authorities.equals(EVENT_LIST)) { |
| | | secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(","); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private ZInfoUser getMySelf() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId, userId); |
| | | return zInfoUserService.getOne(zInfoUserLambdaQueryWrapper); |
| | | } |
| | | |
| | | private String listFamilyIds() { |
| | | ZInfoUser mySelf = getMySelf(); |
| | | return mySelf.getFamilyId(); |
| | | } |
| | | |
| | | private String listSecondFamilyIds() { |
| | | ZInfoUser mySelf = getMySelf(); |
| | | return mySelf.getSecondFamilyId(); |
| | | } |
| | | // private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent, String familyIds, String secondFamilyAuthority) { |
| | | // //模糊查询的条件 |
| | | // LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent); |
| | | // |
| | | // //定义一个布尔标记,标记第一家庭号是否有逗号 |
| | | // boolean flag = false; |
| | | // |
| | | // StringBuilder secondFamilyIdsBuffer = new StringBuilder(); |
| | | // |
| | | // //处理传入的secondFamilyAuthority 3{2007 2018 2015},4{2007 2019} |
| | | // |
| | | // if (StringUtils.isNotEmpty(secondFamilyAuthority)) { |
| | | // |
| | | // if (secondFamilyAuthority.contains(",")) { |
| | | // //逗号隔开得到如下串:3{2007 2018 2015} |
| | | // String[] authorityList = secondFamilyAuthority.split(","); |
| | | // for (String authorityAndId : authorityList) { |
| | | // setSecondFamilyAuthority(secondFamilyIdsBuffer, authorityAndId); |
| | | // } |
| | | // |
| | | // //把后面的逗号去掉 |
| | | // if (secondFamilyIdsBuffer.length() > 1) { |
| | | // secondFamilyIdsBuffer.deleteCharAt(secondFamilyIdsBuffer.length() - 1); |
| | | // } |
| | | // |
| | | // } else { |
| | | // setSecondFamilyAuthority(secondFamilyIdsBuffer, secondFamilyAuthority); |
| | | // //把后面的逗号去掉 |
| | | // if (secondFamilyIdsBuffer.length() > 1) { |
| | | // secondFamilyIdsBuffer.deleteCharAt(secondFamilyIdsBuffer.length() - 1); |
| | | // } |
| | | // } |
| | | // } |
| | | // //将StringBuffer转成String |
| | | // String secondFamilyIds = secondFamilyIdsBuffer.toString(); |
| | | // |
| | | // //第一家庭号的条件 |
| | | // if (familyIds.contains(",")) { |
| | | // flag = true; |
| | | // } |
| | | // |
| | | // //第二家庭号的条件 |
| | | // if (StringUtils.isNotEmpty(secondFamilyIds)) { |
| | | // if (secondFamilyIds.contains(",")) { |
| | | // String[] secondFamilyIdList = secondFamilyIds.split(","); |
| | | // if (flag) { |
| | | // //如果第一家庭号和第二家庭号都有逗号 |
| | | // String[] familyList = familyIds.split(","); |
| | | // String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIdList); |
| | | // lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | // } else { |
| | | // //如果第一家庭号没有逗号但是第二家庭号有逗号 |
| | | // String[] totalFamilyIdList = ArraysUtil.appendToArray(secondFamilyIdList, familyIds); |
| | | // lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | // } |
| | | // |
| | | // } else { |
| | | // if (flag) { |
| | | // //如果第一家庭号有逗号但第二家庭号没有逗号 |
| | | // String[] familyList = familyIds.split(","); |
| | | // String[] totalFamilyIdList = ArraysUtil.appendToArray(familyList, secondFamilyIds); |
| | | // lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | // } else { |
| | | // //如果第一家庭号和第二家庭号都没有逗号 |
| | | // String[] totalFamilyIdList = ArraysUtil.appendToArray(familyIds, secondFamilyIds); |
| | | // lqw.in(ZfEvent::getFamilyId, totalFamilyIdList); |
| | | // } |
| | | // } |
| | | // } else { |
| | | // //如果没有第二家庭号 |
| | | // if (flag) { |
| | | // String[] familyList = familyIds.split(","); |
| | | // lqw.in(ZfEvent::getFamilyId, familyList); |
| | | // } else { |
| | | // lqw.eq(ZfEvent::getFamilyId, familyIds); |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // lqw.orderByDesc(ZfEvent::getCreateTime); |
| | | // return lqw; |
| | | // } |
| | | // |
| | | // private void setSecondFamilyAuthority(StringBuilder secondFamilyIdsBuffer, String authorityAndId) { |
| | | // //得到权限串 |
| | | // String authorities = authorityAndId.substring(2, authorityAndId.length() - 1); |
| | | // |
| | | // if (authorities.contains(" ")) { |
| | | // //空格隔开得到菜单id,看是否有对应的权限 |
| | | // String[] authorityIdList = authorities.split(" "); |
| | | // for (String s : authorityIdList) { |
| | | // if (s.equals(EVENT_LIST)) { |
| | | // secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(","); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } else { |
| | | // if (authorities.equals(EVENT_LIST)) { |
| | | // secondFamilyIdsBuffer.append(authorityAndId.charAt(0)).append(","); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // private ZInfoUser getMySelf() { |
| | | // SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | // Long userId = user.getUserId(); |
| | | // LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | // zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId, userId); |
| | | // return zInfoUserService.getOne(zInfoUserLambdaQueryWrapper); |
| | | // } |
| | | // |
| | | // private Long listFamilyId() { |
| | | // ZInfoUser mySelf = getMySelf(); |
| | | // return mySelf.getFamilyId(); |
| | | // } |
| | | // |
| | | // private String listSecondFamilyIds() { |
| | | // ZInfoUser mySelf = getMySelf(); |
| | | // return mySelf.getSecondFamilyId(); |
| | | // } |
| | | |
| | | @Override |
| | | public List<ZfEvent> selectByCondition(ZfEvent zfEvent) { |
| | | String familyIds = listFamilyIds(); |
| | | String secondFamilyIds = listSecondFamilyIds(); |
| | | LambdaQueryWrapper<ZfEvent> lambdaQueryWrapper = buildCondition(zfEvent, familyIds, secondFamilyIds); |
| | | // Long familyId = listFamilyId(); |
| | | // String secondFamilyIds = listSecondFamilyIds(); |
| | | //要查自己家庭的 |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | //也要查别人授权的 |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | //加上自己家庭的id |
| | | idList.add(familyId); |
| | | |
| | | LambdaQueryWrapper<ZfEvent> lambdaQueryWrapper = buildCondition(zfEvent, idList); |
| | | List<ZfEvent> beanRecords = list(lambdaQueryWrapper); |
| | | log.info("从数据库中查到的为:{}", beanRecords); |
| | | return markOwnData(familyIds, beanRecords); |
| | | } |
| | | |
| | | private static List<ZfEvent> markOwnData(String familyIds, List<ZfEvent> beanRecords) { |
| | | return beanRecords.stream().peek(record -> { |
| | | String recordFamilyId = record.getFamilyId(); |
| | | if (familyIds.contains(",")) { |
| | | String[] familyIdList = familyIds.split(","); |
| | | for (String familyId : familyIdList) { |
| | | if (familyId.equals(recordFamilyId)) { |
| | | record.setOwnData(1); |
| | | } |
| | | } |
| | | } else { |
| | | if (familyIds.equals(recordFamilyId)) { |
| | | record.setOwnData(1); |
| | | } |
| | | } |
| | | }).collect(Collectors.toList()); |
| | | return markOwnData(familyId, beanRecords); |
| | | } |
| | | |
| | | @Override |
| | | public List<ZfEvent> selectByIds(Long[] ids) { |
| | | List<ZfEvent> list = new ArrayList<>(); |
| | | if(ids.length!=0) |
| | | list = listByIds(Arrays.asList(ids)); |
| | | else |
| | | list = list(); |
| | | return list; |
| | | } |
| | | |
| | | public List<ZfEvent> markOwnData(Long familyId,List<ZfEvent> beanRecords){ |
| | | return beanRecords.stream().peek( |
| | | bean -> { |
| | | if (bean.getFamilyId() == familyId) { |
| | | bean.setOwnData(1); |
| | | } else { |
| | | bean.setOwnData(0); |
| | | } |
| | | } |
| | | ).sorted((a,b)-> b.getOwnData()-a.getOwnData()).collect(Collectors.toList()); |
| | | } |
| | | |
| | | // private static List<ZfEvent> markOwnData(String familyIds, List<ZfEvent> beanRecords) { |
| | | // return beanRecords.stream().peek(record -> { |
| | | // String recordFamilyId = record.getFamilyId(); |
| | | // if (familyIds.contains(",")) { |
| | | // String[] familyIdList = familyIds.split(","); |
| | | // for (String familyId : familyIdList) { |
| | | // if (familyId.equals(recordFamilyId)) { |
| | | // record.setOwnData(1); |
| | | // } |
| | | // } |
| | | // } else { |
| | | // if (familyIds.equals(recordFamilyId)) { |
| | | // record.setOwnData(1); |
| | | // } |
| | | // } |
| | | // }).collect(Collectors.toList()); |
| | | // } |
| | | |
| | | @Override |
| | | public AjaxResult selectDataList(ZfEvent zfEvent, Integer pageNum, Integer pageSize) { |
| | | String familyIds = listFamilyIds(); |
| | | String secondFamilyAuthority = listSecondFamilyIds(); |
| | | LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent, familyIds, secondFamilyAuthority); |
| | | //要查自己家庭的 |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | //也要查别人授权的 |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | //加上自己家庭的id |
| | | idList.add(familyId); |
| | | // String familyIds = listFamilyIds(); |
| | | // String secondFamilyAuthority = listSecondFamilyIds(); |
| | | LambdaQueryWrapper<ZfEvent> lqw = buildCondition(zfEvent, idList); |
| | | |
| | | |
| | | Page<ZfEvent> zfEventPage = new Page<>(pageNum, pageSize); |
| | | Page<ZfEvent> pageResult = page(zfEventPage, lqw); |
| | | |
| | | List<ZfEvent> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | List<ZfEvent> dtoResult = markOwnData(familyIds, beanRecords); |
| | | List<ZfEvent> dtoResult = markOwnData(familyId, beanRecords); |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult); |
| | | return AjaxResult.success(data); |
| | | } |
| | | |
| | | // @Override |
| | | // public AjaxResult addData(ZfEvent zfEvent) { |
| | | // |
| | | // String familyIds = listFamilyIds(); |
| | | // boolean flag = false;//判断当前用户的id是否有权加入当前家庭id的对象 |
| | | // if (familyIds.contains(",")) { |
| | | // String[] familyList = familyIds.split(","); |
| | | // for (String familyId : familyList) { |
| | | // if (familyId.equals(zfEvent.getFamilyId())) { |
| | | // flag = true; |
| | | // } |
| | | // } |
| | | // } else { |
| | | // if (zfEvent.getFamilyId().equals(familyIds)) { |
| | | // flag = true; |
| | | // } |
| | | // } |
| | | // if (flag) { |
| | | // if (save(zfEvent)) { |
| | | // return AjaxResult.success(); |
| | | // } else { |
| | | // return AjaxResult.error(); |
| | | // } |
| | | // |
| | | // } else { |
| | | // throw new RuntimeException("你没有操作该家庭号为" + zfEvent.getFamilyId() + "数据的权限"); |
| | | // } |
| | | // } |
| | | |
| | | @Override |
| | | public AjaxResult addData(ZfEvent zfEvent) { |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | | String familyIds = listFamilyIds(); |
| | | boolean flag = false;//判断当前用户的id是否有权加入当前家庭id的对象 |
| | | if (familyIds.contains(",")) { |
| | | String[] familyList = familyIds.split(","); |
| | | for (String familyId : familyList) { |
| | | if (familyId.equals(zfEvent.getFamilyId())) { |
| | | flag = true; |
| | | } |
| | | } |
| | | } else { |
| | | if (zfEvent.getFamilyId().equals(familyIds)) { |
| | | flag = true; |
| | | } |
| | | } |
| | | if (flag) { |
| | | if (save(zfEvent)) { |
| | | return AjaxResult.success(); |
| | | } else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } else { |
| | | throw new RuntimeException("你没有操作该家庭号为" + zfEvent.getFamilyId() + "数据的权限"); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult addData2(ZfEvent zfEvent) { |
| | | ZInfoUser mySelf = getMySelf(); |
| | | String myFamilyId = mySelf.getFamilyId(); |
| | | |
| | | if (StringUtils.isNotEmpty(zfEvent.getFamilyId())) { |
| | | throw new RuntimeException("导入数据时您不能指定家庭号"); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(myFamilyId)) { |
| | | if(familyId == null){ |
| | | throw new RuntimeException("您还未加入任何家庭"); |
| | | } |
| | | |
| | | if (myFamilyId.contains(",")) { |
| | | String[] myFamilyIds = myFamilyId.split(","); |
| | | //默认添加第一个家庭的数据 |
| | | zfEvent.setFamilyId(myFamilyIds[0]); |
| | | } else { |
| | | zfEvent.setFamilyId(myFamilyId); |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_ADD)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | familyIdList.add(familyId); |
| | | |
| | | if (zfEvent.getFamilyId()!=null && !familyIdList.contains(zfEvent.getFamilyId())) { |
| | | throw new RuntimeException("你没有权限操作此家庭的数据"); |
| | | } |
| | | |
| | | |
| | | if(zfEvent.getFamilyId() == null){ |
| | | //默认添加自己家庭的数据 |
| | | zfEvent.setFamilyId(familyId); |
| | | } |
| | | |
| | | //判断是否有重复数据 |
| | | LambdaQueryWrapper<ZfEvent> lqw = uniqueCondition(zfEvent); |
| | | List<ZfEvent> list = list(lqw); |
| | | |
| | | if(list.size()>0){ |
| | | throw new RuntimeException("请勿新增重复数据"); |
| | | } |
| | | |
| | | if (save(zfEvent)) { |
| | |
| | | } |
| | | } |
| | | |
| | | // @Override |
| | | // public AjaxResult addData2(ZfEvent zfEvent) { |
| | | // ZInfoUser mySelf = getMySelf(); |
| | | // String myFamilyId = mySelf.getFamilyId(); |
| | | // |
| | | // if (StringUtils.isNotEmpty(zfEvent.getFamilyId())) { |
| | | // throw new RuntimeException("导入数据时您不能指定家庭号"); |
| | | // } |
| | | // |
| | | // if (StringUtils.isEmpty(myFamilyId)) { |
| | | // throw new RuntimeException("您还未加入任何家庭"); |
| | | // } |
| | | // |
| | | // if (myFamilyId.contains(",")) { |
| | | // String[] myFamilyIds = myFamilyId.split(","); |
| | | // //默认添加第一个家庭的数据 |
| | | // zfEvent.setFamilyId(myFamilyIds[0]); |
| | | // } else { |
| | | // zfEvent.setFamilyId(myFamilyId); |
| | | // } |
| | | // |
| | | // //判断是否有重复数据 |
| | | // LambdaQueryWrapper<ZfEvent> zfEventLambdaQueryWrapper = uniqueCondition(zfEvent); |
| | | // List<ZfEvent> list = list(zfEventLambdaQueryWrapper); |
| | | // if(list.size()>0){ |
| | | // throw new RuntimeException("请勿新增重复数据"); |
| | | // } |
| | | // |
| | | // if (save(zfEvent)) { |
| | | // return AjaxResult.success(); |
| | | // } else { |
| | | // return AjaxResult.error(); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | | ExcelUtil<ZfEvent> util = new ExcelUtil<>(ZfEvent.class); |
| | | List<ZfEvent> propertyList = null; |
| | | List<ZfEvent> dataList = null; |
| | | try { |
| | | propertyList = util.importExcel(file.getInputStream()); |
| | | dataList = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | log.info("资产列表为:{}", propertyList); |
| | | log.info("数据列表为:{}", dataList); |
| | | |
| | | for (ZfEvent zfEvent : propertyList) { |
| | | zfEventService.addData2(zfEvent); |
| | | for (ZfEvent zfEvent : dataList) { |
| | | zfEventService.addData(zfEvent); |
| | | } |
| | | |
| | | return AjaxResult.success("导入数据成功"); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public AjaxResult updateData(ZfEvent zfEvent) { |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | | //先根据id查询出数据的familyId,看看有没有权限操作 |
| | | Long dataFamilyId = getById(zfEvent.getId()).getFamilyId(); |
| | | |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_UPDATE)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | familyIdList.add(familyId); |
| | | |
| | | if (dataFamilyId!=null && !familyIdList.contains(dataFamilyId)) { |
| | | throw new RuntimeException("你没有权限操作此家庭的数据"); |
| | | } |
| | | |
| | | if(updateById(zfEvent)){ |
| | | return AjaxResult.success(); |
| | | }else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult deleteData(Long[] ids) { |
| | | List<ZfEvent> dataList = zfEventService.listByIds(Arrays.asList(ids)); |
| | | |
| | | ZInfoUser myself = zInfoUserService.getMyself(); |
| | | Long familyId = myself.getFamilyId(); |
| | | |
| | | List<ZAuthority> authority = zAuthorityService.getAuthority(); |
| | | List<Long> familyIdList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(EVENT_LIST_REMOVE)).map(ZAuthority::getFid).collect(Collectors.toList()); |
| | | familyIdList.add(familyId); |
| | | |
| | | for (ZfEvent data : dataList) { |
| | | if (!familyIdList.contains(data.getFamilyId())){ |
| | | throw new RuntimeException("你没有权限操作此家庭的数据"); |
| | | } |
| | | } |
| | | |
| | | if (zfEventService.removeByIds(Arrays.asList(ids))) { |
| | | return AjaxResult.success(); |
| | | }else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |