| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.read.listener.PageReadListener; |
| | | import com.ycl.handler.ImageResourceHandler; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurity; |
| | | import com.ycl.platform.domain.entity.ImageResourceSecurityDetail; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityDetailMapper; |
| | | import com.ycl.platform.mapper.ImageResourceSecurityMapper; |
| | | import com.ycl.platform.service.IImageResourceSecurityService; |
| | | import com.ycl.system.entity.SysDept; |
| | | import com.ycl.system.service.ISysDeptService; |
| | | import com.ycl.utils.DateUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * @date 2024-08-24 |
| | | */ |
| | | @Service |
| | | public class ImageResourceSecurityServiceImpl implements IImageResourceSecurityService |
| | | { |
| | | @Autowired |
| | | private ImageResourceSecurityMapper imageResourceSecurityMapper; |
| | | @RequiredArgsConstructor |
| | | public class ImageResourceSecurityServiceImpl implements IImageResourceSecurityService { |
| | | |
| | | /** |
| | | * 查询platform |
| | | * |
| | | * @param id platform主键 |
| | | * @return platform |
| | | */ |
| | | private final ImageResourceSecurityMapper imageResourceSecurityMapper; |
| | | private final ImageResourceSecurityDetailMapper imageResourceSecurityDetailMapper; |
| | | private final ISysDeptService deptService; |
| | | |
| | | @Override |
| | | public ImageResourceSecurity selectImageResourceSecurityById(Long id) |
| | | { |
| | | public ImageResourceSecurity selectImageResourceSecurityById(Long id) { |
| | | return imageResourceSecurityMapper.selectImageResourceSecurityById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询platform列表 |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return platform |
| | | */ |
| | | @Override |
| | | public List<ImageResourceSecurity> selectImageResourceSecurityList(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public List<ImageResourceSecurity> selectImageResourceSecurityList(ImageResourceSecurity imageResourceSecurity) { |
| | | return imageResourceSecurityMapper.selectImageResourceSecurityList(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 新增platform |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public int insertImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) { |
| | | imageResourceSecurity.setCreateTime(DateUtils.getNowDate()); |
| | | return imageResourceSecurityMapper.insertImageResourceSecurity(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 修改platform |
| | | * |
| | | * @param imageResourceSecurity platform |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) |
| | | { |
| | | public int updateImageResourceSecurity(ImageResourceSecurity imageResourceSecurity) { |
| | | return imageResourceSecurityMapper.updateImageResourceSecurity(imageResourceSecurity); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除platform |
| | | * |
| | | * @param ids 需要删除的platform主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteImageResourceSecurityByIds(Long[] ids) |
| | | { |
| | | public int deleteImageResourceSecurityByIds(Long[] ids) { |
| | | return imageResourceSecurityMapper.deleteImageResourceSecurityByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 删除platform信息 |
| | | * |
| | | * @param id platform主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteImageResourceSecurityById(Long id) |
| | | { |
| | | public int deleteImageResourceSecurityById(Long id) { |
| | | return imageResourceSecurityMapper.deleteImageResourceSecurityById(id); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void importTemplate(HttpServletResponse response) { |
| | | EasyExcel.write(response.getOutputStream(), ImageResourceSecurityDetail.class).sheet("模板").registerWriteHandler(new ImageResourceHandler()).doWrite(Collections.emptyList()); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public Boolean importData(MultipartFile file) { |
| | | ArrayList<ImageResourceSecurityDetail> list = new ArrayList<>(); |
| | | List<SysDept> sysDept = deptService.selectDeptList(new SysDept()); |
| | | EasyExcel.read(file.getInputStream(), ImageResourceSecurityDetail.class, new PageReadListener<ImageResourceSecurityDetail>(dataList -> { |
| | | for (ImageResourceSecurityDetail detail : dataList) { |
| | | SysDept sysDept1 = sysDept.stream().filter(dept -> dept.getDeptName().equals(detail.getDeptName())).findFirst().orElseThrow(() -> new RuntimeException(detail.getDeptName() + "不存在")); |
| | | detail.setDeptId(sysDept1.getDeptId()); |
| | | list.add(detail); |
| | | } |
| | | })).sheet().doRead(); |
| | | imageResourceSecurityDetailMapper.saveBatch(list); |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void saveBatch(ArrayList<ImageResourceSecurity> imageResourceSecurities) { |
| | | imageResourceSecurityMapper.saveBatch(imageResourceSecurities); |
| | | } |
| | | } |