| | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.domain.ZHonor; |
| | | import com.ruoyi.domain.ZIdea; |
| | | import com.ruoyi.domain.ZInfoUser; |
| | | import com.ruoyi.mapper.ZIdeaMapper; |
| | | import com.ruoyi.service.ZIdeaService; |
| | | import com.ruoyi.service.ZInfoUserService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ZIdeaServiceImpl extends ServiceImpl<ZIdeaMapper, ZIdea> implements ZIdeaService { |
| | | |
| | | @Autowired |
| | | ZIdeaServiceImpl zIdeaService; |
| | | @Autowired |
| | | ZInfoUserService zInfoUserService; |
| | | private LambdaQueryWrapper<ZIdea> uniqueCondition(ZIdea zIdea) { |
| | | LambdaQueryWrapper<ZIdea> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(StringUtils.isNotEmpty(zIdea.getTitle()), ZIdea::getTitle, zIdea.getTitle()) |
| | | .eq(StringUtils.isNotEmpty(zIdea.getCause()), ZIdea::getCause, zIdea.getCause()) |
| | | .eq(StringUtils.isNotEmpty(zIdea.getBeneficiary()), ZIdea::getBeneficiary, zIdea.getBeneficiary()) |
| | | .eq(StringUtils.isNotEmpty(zIdea.getHeir()), ZIdea::getHeir, zIdea.getHeir()) |
| | | .eq(StringUtils.isNotEmpty(zIdea.getDifficulty()), ZIdea::getDifficulty, zIdea.getDifficulty()) |
| | | .eq(zIdea.getHappenTime() != null, ZIdea::getHappenTime, zIdea.getHappenTime()) |
| | | .eq(zIdea.getIsEffective() != null, ZIdea::getIsEffective, zIdea.getIsEffective()) |
| | | .eq(StringUtils.isNotEmpty(zIdea.getRemark()), ZIdea::getRemark, zIdea.getRemark()) |
| | | .eq(zIdea.getUid() != null, ZIdea::getUid, zIdea.getUid()); |
| | | return lqw; |
| | | } |
| | | |
| | | private LambdaQueryWrapper<ZIdea> buildCondition(ZIdea zIdea, Long userId) { |
| | | LambdaQueryWrapper<ZIdea> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(userId != null, ZIdea::getUid, userId) |
| | | .like(StringUtils.isNotEmpty(zIdea.getTitle()), ZIdea::getTitle, zIdea.getTitle()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getBeneficiary()), ZIdea::getBeneficiary, zIdea.getBeneficiary()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getHeir()), ZIdea::getHeir, zIdea.getHeir()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getDifficulty()), ZIdea::getDifficulty, zIdea.getDifficulty()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getCause()), ZIdea::getCause, zIdea.getCause()) |
| | | .like(zIdea.getIsEffective()!=null, ZIdea::getIsEffective, zIdea.getIsEffective()) |
| | | .between(zIdea.getHappenStartTime() != null && zIdea.getHappenEndTime() != null, ZIdea::getHappenTime, zIdea.getHappenStartTime(), zIdea.getHappenEndTime()) |
| | | .orderByDesc(ZIdea::getCreateTime); |
| | | return lqw; |
| | | } |
| | | private LambdaQueryWrapper<ZIdea> buildConditionSec(ZIdea zIdea, List<Long> userIds){ |
| | | LambdaQueryWrapper<ZIdea> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.in(ZIdea::getUid, userIds) |
| | | .like(StringUtils.isNotEmpty(zIdea.getTitle()), ZIdea::getTitle, zIdea.getTitle()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getBeneficiary()), ZIdea::getBeneficiary, zIdea.getBeneficiary()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getHeir()), ZIdea::getHeir, zIdea.getHeir()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getDifficulty()), ZIdea::getDifficulty, zIdea.getDifficulty()) |
| | | .like(StringUtils.isNotEmpty(zIdea.getCause()), ZIdea::getCause, zIdea.getCause()) |
| | | .like(zIdea.getIsEffective()!=null, ZIdea::getIsEffective, zIdea.getIsEffective()) |
| | | .between(zIdea.getHappenStartTime() != null && zIdea.getHappenEndTime() != null, ZIdea::getHappenTime, zIdea.getHappenStartTime(), zIdea.getHappenEndTime()) |
| | | .orderByDesc(ZIdea::getCreateTime); |
| | | return lqw; |
| | | } |
| | | /** |
| | | * 分页查找 |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDataList(ZIdea zIdea, Integer pageNum, Integer pageSize) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | // LambdaQueryWrapper<ZIdea> lqw = buildCondition(zIdea, userId); |
| | | //根据userId查询到infouser的uaid |
| | | ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId); |
| | | //拿到所有的sysid |
| | | List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<ZIdea> lqw; |
| | | if(!fms.isEmpty()) |
| | | lqw = buildConditionSec(zIdea, fms); |
| | | else |
| | | lqw = buildCondition(zIdea, userId); |
| | | Page<ZIdea> pageBean = new Page<>(pageNum, pageSize); |
| | | Page<ZIdea> pageResult = page(pageBean, lqw); |
| | | |
| | | List<ZIdea> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords); |
| | | return AjaxResult.success(data); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<ZIdea> selectByIds(Long[] ids) { |
| | | List<ZIdea> list = new ArrayList<>(); |
| | | if (ids.length != 0) |
| | | list = listByIds(Arrays.asList(ids)); |
| | | else |
| | | list = list(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult mySave(ZIdea zIdea) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | zIdea.setUid(userId); |
| | | |
| | | //检查是否有重复数据插入 |
| | | LambdaQueryWrapper<ZIdea> lqw = uniqueCondition(zIdea); |
| | | List<ZIdea> list = list(lqw); |
| | | if (list.size() > 0) { |
| | | throw new RuntimeException("请勿新增重复数据"); |
| | | } |
| | | |
| | | if (save(zIdea)) { |
| | | return AjaxResult.success(); |
| | | } else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ZIdea> selectByCondition() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | ZIdea zIdea = new ZIdea(); |
| | | LambdaQueryWrapper<ZIdea> lqw = buildCondition(zIdea, userId); |
| | | return list(lqw); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | | |
| | | ExcelUtil<ZIdea> util = new ExcelUtil<>(ZIdea.class); |
| | | List<ZIdea> dataList = null; |
| | | try { |
| | | dataList = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("没有按照规则导入数据"); |
| | | } |
| | | |
| | | assert dataList != null; |
| | | |
| | | for (ZIdea zIdea : dataList) { |
| | | zIdeaService.mySave(zIdea); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | |
| | | } |