| | |
| | | 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.ZYearInfo; |
| | | import com.ruoyi.domain.ZYearInfo; |
| | | import com.ruoyi.mapper.ZYearInfoMapper; |
| | | import com.ruoyi.service.ZYearInfoService; |
| | | 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; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ZYearInfoServiceImpl extends ServiceImpl<ZYearInfoMapper, ZYearInfo> implements ZYearInfoService { |
| | | |
| | | @Autowired |
| | | ZYearInfoServiceImpl zYearInfoService; |
| | | |
| | | private LambdaQueryWrapper<ZYearInfo> uniqueCondition(ZYearInfo zYearInfo) { |
| | | LambdaQueryWrapper<ZYearInfo> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(StringUtils.isNotEmpty(zYearInfo.getType()), ZYearInfo::getType, zYearInfo.getType()) |
| | | .eq(StringUtils.isNotEmpty(zYearInfo.getHospital()), ZYearInfo::getHospital, zYearInfo.getHospital()) |
| | | .eq(StringUtils.isNotEmpty(zYearInfo.getTitle()), ZYearInfo::getTitle, zYearInfo.getTitle()) |
| | | .eq(zYearInfo.getCheckTime() != null, ZYearInfo::getCheckTime, zYearInfo.getCheckTime()) |
| | | .eq(StringUtils.isNotEmpty(zYearInfo.getNotice()), ZYearInfo::getNotice, zYearInfo.getNotice()) |
| | | .eq(StringUtils.isNotEmpty(zYearInfo.getRemark()), ZYearInfo::getRemark, zYearInfo.getRemark()) |
| | | .eq(zYearInfo.getUid() != null, ZYearInfo::getUid, zYearInfo.getUid()); |
| | | return lqw; |
| | | } |
| | | |
| | | private LambdaQueryWrapper<ZYearInfo> buildCondition(ZYearInfo zYearInfo, Long userId) { |
| | | LambdaQueryWrapper<ZYearInfo> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(userId != null, ZYearInfo::getUid, userId) |
| | | .like(StringUtils.isNotEmpty(zYearInfo.getType()), ZYearInfo::getType, zYearInfo.getType()) |
| | | .like(StringUtils.isNotEmpty(zYearInfo.getHospital()), ZYearInfo::getHospital, zYearInfo.getHospital()) |
| | | .like(StringUtils.isNotEmpty(zYearInfo.getTitle()), ZYearInfo::getTitle, zYearInfo.getTitle()) |
| | | .like(StringUtils.isNotEmpty(zYearInfo.getNotice()),ZYearInfo::getNotice,zYearInfo.getNotice()) |
| | | .like(StringUtils.isNotEmpty(zYearInfo.getRemark()),ZYearInfo::getRemark,zYearInfo.getRemark()) |
| | | .between(zYearInfo.getHappenStartTime() != null && zYearInfo.getHappenEndTime() != null, ZYearInfo::getCheckTime, zYearInfo.getHappenStartTime(), zYearInfo.getHappenEndTime()) |
| | | .orderByDesc(ZYearInfo::getCreateTime); |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | | * 分页查找 |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDataList(ZYearInfo zYearInfo, Integer pageNum, Integer pageSize) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZYearInfo> lqw = buildCondition(zYearInfo, userId); |
| | | |
| | | Page<ZYearInfo> pageBean = new Page<>(pageNum, pageSize); |
| | | Page<ZYearInfo> pageResult = page(pageBean, lqw); |
| | | |
| | | List<ZYearInfo> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords); |
| | | return AjaxResult.success(data); |
| | | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<ZYearInfo> selectByIds(Long[] ids) { |
| | | List<ZYearInfo> list = new ArrayList<>(); |
| | | if (ids.length != 0) |
| | | list = listByIds(Arrays.asList(ids)); |
| | | else |
| | | list = list(); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult mySave(ZYearInfo zYearInfo) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | zYearInfo.setUid(userId); |
| | | |
| | | //检查是否有重复数据插入 |
| | | LambdaQueryWrapper<ZYearInfo> lqw = uniqueCondition(zYearInfo); |
| | | List<ZYearInfo> list = list(lqw); |
| | | if (list.size() > 0) { |
| | | throw new RuntimeException("请勿新增重复数据"); |
| | | } |
| | | |
| | | if (save(zYearInfo)) { |
| | | return AjaxResult.success(); |
| | | } else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | | |
| | | ExcelUtil<ZYearInfo> util = new ExcelUtil<>(ZYearInfo.class); |
| | | List<ZYearInfo> dataList = null; |
| | | try { |
| | | dataList = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("没有按照规则导入数据"); |
| | | } |
| | | |
| | | assert dataList != null; |
| | | |
| | | for (ZYearInfo zYearInfo : dataList) { |
| | | zYearInfoService.mySave(zYearInfo); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | } |