| | |
| | | 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.ZAbroad; |
| | | import com.ruoyi.domain.ZHonor; |
| | | import com.ruoyi.domain.ZfCollection; |
| | | import com.ruoyi.mapper.ZHonorMapper; |
| | | import com.ruoyi.service.ZHonorService; |
| | | 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.HashMap; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class ZHonorServiceImpl extends ServiceImpl<ZHonorMapper, ZHonor> implements ZHonorService { |
| | | |
| | | @Autowired |
| | | ZHonorServiceImpl zHonorService; |
| | | |
| | | private LambdaQueryWrapper<ZHonor> uniqueCondition(ZHonor zHonor){ |
| | | LambdaQueryWrapper<ZHonor> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(StringUtils.isNotEmpty(zHonor.getName()),ZHonor::getName,zHonor.getName()) |
| | | .eq(zHonor.getType()!=null,ZHonor::getType,zHonor.getType()) |
| | | .eq(StringUtils.isNotEmpty(zHonor.getIdNo()),ZHonor::getIdNo,zHonor.getIdNo()) |
| | | .eq(StringUtils.isNotEmpty(zHonor.getGrade()),ZHonor::getGrade,zHonor.getGrade()) |
| | | .eq(zHonor.getValidityDate()!=null,ZHonor::getValidityDate,zHonor.getValidityDate()) |
| | | .eq(zHonor.getGetDate()!=null,ZHonor::getGetDate,zHonor.getGetDate()) |
| | | .eq(StringUtils.isNotEmpty(zHonor.getLocation()),ZHonor::getLocation,zHonor.getLocation()) |
| | | .eq(StringUtils.isNotEmpty(zHonor.getRemark()),ZHonor::getRemark,zHonor.getRemark()) |
| | | .eq(zHonor.getUserId()!=null,ZHonor::getUserId,zHonor.getUserId()); |
| | | return lqw; |
| | | } |
| | | |
| | | private LambdaQueryWrapper<ZHonor> buildCondition(ZHonor zHonor,Long userId){ |
| | | LambdaQueryWrapper<ZHonor> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(StringUtils.isNotEmpty(zHonor.getName()),ZHonor::getName,zHonor.getName()) |
| | | .eq(ZHonor::getUserId,userId) |
| | | .like(zHonor.getType()!=null,ZHonor::getType,zHonor.getType()) |
| | | .like(StringUtils.isNotEmpty(zHonor.getIdNo()),ZHonor::getIdNo,zHonor.getIdNo()) |
| | | .like(StringUtils.isNotEmpty(zHonor.getGrade()),ZHonor::getGrade,zHonor.getGrade()) |
| | | .like(StringUtils.isNotEmpty(zHonor.getLocation()),ZHonor::getLocation,zHonor.getLocation()) |
| | | .like(StringUtils.isNotEmpty(zHonor.getRemark()),ZHonor::getRemark,zHonor.getRemark()) |
| | | .orderByDesc(ZHonor::getCreateTime); |
| | | return lqw; |
| | | } |
| | | |
| | | /** |
| | | * 分页查找 |
| | | */ |
| | | @Override |
| | | public AjaxResult selectDataList(ZHonor zHonor,Integer pageNum,Integer pageSize) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZHonor> lqw = buildCondition(zHonor, userId); |
| | | |
| | | Page<ZHonor> pageBean = new Page<>(pageNum, pageSize); |
| | | Page<ZHonor> pageResult = page(pageBean, lqw); |
| | | |
| | | List<ZHonor> beanRecords = pageResult.getRecords();//得到查询出来的数据 |
| | | |
| | | HashMap<String, Object> data = MapUtils.getResult(pageResult, beanRecords); |
| | | return AjaxResult.success(data); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public List<ZHonor> selectCondition(ZHonor zHonor) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | LambdaQueryWrapper<ZHonor> lqw = buildCondition(zHonor, userId); |
| | | return list(lqw); |
| | | } |
| | | |
| | | @Override |
| | | public AjaxResult mySave(ZHonor zHonor) { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | zHonor.setUserId(userId); |
| | | |
| | | //检查是否有重复数据插入 |
| | | LambdaQueryWrapper<ZHonor> lqw = uniqueCondition(zHonor); |
| | | List<ZHonor> list = list(lqw); |
| | | if(list.size()>0){ |
| | | throw new RuntimeException("请勿新增重复数据"); |
| | | } |
| | | |
| | | if (save(zHonor)) { |
| | | return AjaxResult.success(); |
| | | }else { |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public AjaxResult importExcel(MultipartFile file) { |
| | | |
| | | ExcelUtil<ZHonor> util = new ExcelUtil<>(ZHonor.class); |
| | | List<ZHonor> dataList = null; |
| | | try { |
| | | dataList = util.importExcel(file.getInputStream()); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("没有按照规则导入数据"); |
| | | } |
| | | |
| | | assert dataList != null; |
| | | |
| | | for (ZHonor zHonor : dataList) { |
| | | zHonorService.mySave(zHonor); |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |