| | |
| | | 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.ZInfoUser; |
| | | import com.ruoyi.domain.ZSecret; |
| | | import com.ruoyi.domain.ZfEvent; |
| | | import com.ruoyi.mapper.ZSecretMapper; |
| | | import com.ruoyi.service.ZInfoUserService; |
| | | import com.ruoyi.service.ZSecretService; |
| | | 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 javax.annotation.Resource; |
| | | 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 ZSecretServiceImpl extends ServiceImpl<ZSecretMapper, ZSecret> implements ZSecretService { |
| | | |
| | | @Autowired |
| | | ZSecretServiceImpl zSecretService; |
| | | |
| | | @Autowired |
| | | ZInfoUserService zInfoUserService; |
| | | @Resource |
| | | ZSecretMapper zSecretMapper; |
| | | |
| | | private LambdaQueryWrapper<ZSecret> uniqueCondition(ZSecret zSecret) { |
| | | LambdaQueryWrapper<ZSecret> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(StringUtils.isNotEmpty(zSecret.getType()), ZSecret::getType, zSecret.getType()) |
| | | .eq(StringUtils.isNotEmpty(zSecret.getAccNo()), ZSecret::getAccNo, zSecret.getAccNo()) |
| | | .eq(StringUtils.isNotEmpty(zSecret.getPassword()), ZSecret::getPassword, zSecret.getPassword()) |
| | | .eq(zSecret.getValidityDate() != null, ZSecret::getValidityDate, zSecret.getValidityDate()) |
| | | .eq(zSecret.getHappenTime() != null, ZSecret::getHappenTime, zSecret.getHappenTime()) |
| | | .eq(StringUtils.isNotEmpty(zSecret.getLocation()), ZSecret::getLocation, zSecret.getLocation()) |
| | | .eq(StringUtils.isNotEmpty(zSecret.getRemark()), ZSecret::getRemark, zSecret.getRemark()) |
| | | .eq(zSecret.getUserId() != null, ZSecret::getUserId, zSecret.getUserId()); |
| | | return lqw; |
| | | } |
| | | |
| | | private LambdaQueryWrapper<ZSecret> buildCondition(ZSecret zSecret, Long userId) { |
| | | LambdaQueryWrapper<ZSecret> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(userId != null, ZSecret::getUserId, userId) |
| | | .like(StringUtils.isNotEmpty(zSecret.getType()), ZSecret::getType, zSecret.getType()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getAccNo()), ZSecret::getAccNo, zSecret.getAccNo()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getRemark()), ZSecret::getRemark, zSecret.getRemark()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getLocation()), ZSecret::getLocation, zSecret.getLocation()) |
| | | .eq(zSecret.getIsFinger()!=null,ZSecret::getIsFinger,zSecret.getIsFinger()) |
| | | .eq(zSecret.getIsPrivate()!=null,ZSecret::getIsPrivate,zSecret.getIsPrivate()) |
| | | .le(zSecret.getValidityDate()!=null, ZSecret::getValidityDate, zSecret.getValidityDate()) |
| | | .eq(zSecret.getIsFace()!=null,ZSecret::getIsFace,zSecret.getIsFace()) |
| | | .between(zSecret.getHappenStartTime() != null && zSecret.getHappenEndTime() != null, ZSecret::getHappenTime, zSecret.getHappenStartTime(), zSecret.getHappenEndTime()) |
| | | .orderByDesc(ZSecret::getCreateTime); |
| | | return lqw; |
| | | } |
| | | private LambdaQueryWrapper<ZSecret> buildConditionSec(ZSecret zSecret, List<Long> userIds) { |
| | | LambdaQueryWrapper<ZSecret> lqw = new LambdaQueryWrapper<>(); |
| | | // lqw.eq(userId != null, ZSecret::getUserId, userId) |
| | | |
| | | lqw.in(ZSecret::getUserId,userIds) |
| | | |
| | | .like(StringUtils.isNotEmpty(zSecret.getType()), ZSecret::getType, zSecret.getType()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getAccNo()), ZSecret::getAccNo, zSecret.getAccNo()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getRemark()), ZSecret::getRemark, zSecret.getRemark()) |
| | | .like(StringUtils.isNotEmpty(zSecret.getLocation()), ZSecret::getLocation, zSecret.getLocation()) |
| | | .eq(zSecret.getIsFinger()!=null,ZSecret::getIsFinger,zSecret.getIsFinger()) |
| | | .eq(zSecret.getIsPrivate()!=null,ZSecret::getIsPrivate,zSecret.getIsPrivate()) |
| | | .le(zSecret.getValidityDate()!=null, ZSecret::getValidityDate, zSecret.getValidityDate()) |
| | | .eq(zSecret.getIsFace()!=null,ZSecret::getIsFace,zSecret.getIsFace()) |
| | | .between(zSecret.getHappenStartTime() != null && zSecret.getHappenEndTime() != null, ZSecret::getHappenTime, zSecret.getHappenStartTime(), zSecret.getHappenEndTime()) |
| | | .orderByDesc(ZSecret::getCreateTime); |
| | | return lqw; |
| | | } |
| | | /** |
| | | * 分页查找 |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDataList(ZSecret zSecret, Integer pageNum, Integer pageSize) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | //根据userId查询到infouser的uaid |
| | | ZInfoUser zInfoUser = zInfoUserService.getInfoBysysId(userId); |
| | | //拿到所有的sysid |
| | | List<Long> fms = zInfoUserService.findByUaidToFaid(zInfoUser.getUaid()).stream().map(ZInfoUser::getSysId).collect(Collectors.toList()); |
| | | LambdaQueryWrapper<ZSecret> lqw; |
| | | if(!fms.isEmpty()) |
| | | lqw = buildConditionSec(zSecret, fms); |
| | | else |
| | | lqw = buildCondition(zSecret, userId); |
| | | |
| | | |
| | | |
| | | |
| | | Page<ZSecret> pageBean = new Page<>(pageNum, pageSize); |
| | | Page<ZSecret> pageResult = page(pageBean, lqw); |
| | | |
| | | List<ZSecret> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords); |
| | | return AjaxResult.success(data); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<ZSecret> selectByIds(Long[] ids) { |
| | | List<ZSecret> list = new ArrayList<>(); |
| | | if (ids.length != 0) |
| | | list = listByIds(Arrays.asList(ids)); |
| | | else |
| | | list = list(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult mySave(ZSecret zSecret) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | zSecret.setUserId(userId); |
| | | |
| | | //检查是否有重复数据插入 |
| | | LambdaQueryWrapper<ZSecret> lqw = uniqueCondition(zSecret); |
| | | List<ZSecret> list = list(lqw); |
| | | if (list.size() > 0) { |
| | | throw new RuntimeException("请勿新增重复数据"); |
| | | } |
| | | |
| | | if (save(zSecret)) { |
| | | return AjaxResult.success(); |
| | | } else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ZSecret> selectByCondition() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | ZSecret zSecret = new ZSecret(); |
| | | |
| | | LambdaQueryWrapper<ZSecret> lqw = buildCondition(zSecret, userId); |
| | | return list(lqw); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult listType() { |
| | | List<String> result = zSecretMapper.listType(); |
| | | return AjaxResult.success(result); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | | |
| | | ExcelUtil<ZSecret> util = new ExcelUtil<>(ZSecret.class); |
| | | List<ZSecret> dataList = null; |
| | | try { |
| | | dataList = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("没有按照规则导入数据"); |
| | | } |
| | | |
| | | assert dataList != null; |
| | | |
| | | for (ZSecret zSecret : dataList) { |
| | | zSecretService.mySave(zSecret); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | |
| | | } |