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.Physcial;
|
import com.ruoyi.domain.ZInfoUser;
|
import com.ruoyi.domain.ZYearInfo;
|
import com.ruoyi.mapper.PhyscialMapper;
|
import com.ruoyi.service.PhyscialService;
|
import com.ruoyi.service.ZInfoUserService;
|
import lombok.extern.slf4j.Slf4j;
|
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>
|
* 服务实现类
|
* </p>
|
*
|
* @author ojq
|
* @since 2023-10-23
|
*/
|
@Service
|
@Slf4j
|
public class PhyscialServiceImpl extends ServiceImpl<PhyscialMapper, Physcial> implements PhyscialService {
|
@Autowired
|
PhyscialServiceImpl physcialService;
|
@Autowired
|
ZInfoUserService zInfoUserService;
|
private LambdaQueryWrapper<Physcial> uniqueCondition(Physcial physcial) {
|
LambdaQueryWrapper<Physcial> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(StringUtils.isNotEmpty(physcial.getReport()), Physcial::getReport, physcial.getReport())
|
.eq(physcial.getHappenTime() != null, Physcial::getHappenTime, physcial.getHappenTime())
|
.eq(physcial.getUid() != null, Physcial::getUid, physcial.getUid());
|
return lqw;
|
}
|
|
private LambdaQueryWrapper<Physcial> buildCondition(Physcial physcial, Long userId) {
|
LambdaQueryWrapper<Physcial> lqw = new LambdaQueryWrapper<>();
|
lqw.eq(userId != null, Physcial::getUid, userId)
|
.like(StringUtils.isNotEmpty(physcial.getReport()), Physcial::getReport, physcial.getReport())
|
.between(physcial.getHappenStartTime() != null && physcial.getHappenEndTime() != null, Physcial::getHappenTime, physcial.getHappenStartTime(), physcial.getHappenEndTime())
|
.orderByDesc(Physcial::getCreateTime);
|
return lqw;
|
}
|
private LambdaQueryWrapper<Physcial> buildConditionSec(Physcial physcial, List<Long> userId) {
|
LambdaQueryWrapper<Physcial> lqw = new LambdaQueryWrapper<>();
|
lqw.in(Physcial::getUid, userId)
|
.like(StringUtils.isNotEmpty(physcial.getReport()), Physcial::getReport, physcial.getReport())
|
.between(physcial.getHappenStartTime() != null && physcial.getHappenEndTime() != null, Physcial::getHappenTime, physcial.getHappenStartTime(), physcial.getHappenEndTime())
|
.orderByDesc(Physcial::getCreateTime);
|
return lqw;
|
}
|
/**
|
* 分页查找
|
*/
|
@Override
|
public AjaxResult selectDataList(Physcial physcial, 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<Physcial> lqw;
|
if(!fms.isEmpty())
|
lqw = buildConditionSec(physcial, fms);
|
else
|
lqw = buildCondition(physcial, userId);
|
Page<Physcial> pageBean = new Page<>(pageNum, pageSize);
|
Page<Physcial> pageResult = page(pageBean, lqw);
|
|
List<Physcial> beanRecords = pageResult.getRecords();//得到查询出来的数据
|
|
HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords);
|
return AjaxResult.success(data);
|
|
}
|
|
|
@Override
|
public List<Physcial> selectByIds(Long[] ids) {
|
List<Physcial> list = new ArrayList<>();
|
if (ids.length != 0)
|
list = listByIds(Arrays.asList(ids));
|
else
|
list = list();
|
return list;
|
}
|
|
@Override
|
public AjaxResult mySave(Physcial physcial) {
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
Long userId = user.getUserId();
|
physcial.setUid(userId);
|
|
//检查是否有重复数据插入
|
LambdaQueryWrapper<Physcial> lqw = uniqueCondition(physcial);
|
List<Physcial> list = list(lqw);
|
if (list.size() > 0) {
|
throw new RuntimeException("请勿新增重复数据");
|
}
|
|
if (save(physcial)) {
|
return AjaxResult.success();
|
} else {
|
return AjaxResult.error();
|
}
|
|
}
|
|
@Override
|
public List<Physcial> selectByCondition() {
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
Long userId = user.getUserId();
|
Physcial physcial = new Physcial();
|
LambdaQueryWrapper<Physcial> lqw = buildCondition(physcial, userId);
|
return list(lqw);
|
|
}
|
|
@Override
|
@Transactional
|
public AjaxResult importExcel(MultipartFile file) {
|
|
ExcelUtil<Physcial> util = new ExcelUtil<>(Physcial.class);
|
List<Physcial> dataList = null;
|
try {
|
dataList = util.importExcel(file.getInputStream());
|
} catch (Exception e) {
|
throw new RuntimeException("没有按照规则导入数据");
|
}
|
|
assert dataList != null;
|
|
for (Physcial physcial : dataList) {
|
physcialService.mySave(physcial);
|
}
|
|
return AjaxResult.success();
|
|
}
|
|
|
}
|