From e5ebd02de9615e2a22694dba7e4207526054b2f8 Mon Sep 17 00:00:00 2001 From: whywhyo <1511349576@qq.com> Date: 星期二, 11 七月 2023 23:21:44 +0800 Subject: [PATCH] 123456 --- zhang-content/src/main/java/com/ruoyi/service/impl/ZYearInfoServiceImpl.java | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-) diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZYearInfoServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZYearInfoServiceImpl.java index 7b7fcd3..e924156 100644 --- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZYearInfoServiceImpl.java +++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZYearInfoServiceImpl.java @@ -1,11 +1,28 @@ 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> @@ -18,4 +35,102 @@ @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()) + .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(); + + } } -- Gitblit v1.9.1