若依实现单表导入导出

后端:

Controller   service  serviceImpl

package com.ruoyi.project.enforceLaw.base.illegalActivities.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.enforceLaw.base.illegalActivities.domain.LawIllegalActivities;
import com.ruoyi.project.enforceLaw.base.illegalActivities.service.ILawIllegalActivitiesService;
import com.ruoyi.project.enforceLaw.lawCase.domain.LawCaseComplaint;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 违法事项库Controller
 * 
 * @author ZWL
 * @date 2024-01-03
 */
@RestController
@RequestMapping("/enforceLaw/illegalActivities")
public class LawIllegalActivitiesController extends BaseController {
    @Autowired
    private ILawIllegalActivitiesService lawIllegalActivitiesService;

    /**
     * 查询违法事项库列表
     */
//    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:list')")
    @GetMapping("/list")
    public TableDataInfo list(LawIllegalActivities lawIllegalActivities) {
        startPage();
        List list = lawIllegalActivitiesService.selectLawIllegalActivitiesList(lawIllegalActivities);
        return getDataTable(list);
    }

    /**
     * 导出违法事项库列表
     */
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:export')")
    @Log(title = "违法事项库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LawIllegalActivities lawIllegalActivities) {
        List list = lawIllegalActivitiesService.selectLawIllegalActivitiesList(lawIllegalActivities);
        ExcelUtil util = new ExcelUtil(LawIllegalActivities.class);
        util.exportExcel(response, list, "违法事项库数据");
    }

    /**
     * 导入功能实现
     * @param file
     * @param updateSupport
     * @return
     * @throws Exception
     */
    @Log(title = "用户管理", businessType = BusinessType.IMPORT)
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:import')")
    @PostMapping("/import")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil util = new ExcelUtil(LawIllegalActivities.class);
        List userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        System.out.println(userList);
        String message = lawIllegalActivitiesService.importUser(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplateActivities")
    public void importTemplateActivities(HttpServletResponse response) {
        ExcelUtil util = new ExcelUtil(LawIllegalActivities.class);
        util.importTemplateExcel(response, "模板");
    }

    /**
     * 获取违法事项库详细信息
     */
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(lawIllegalActivitiesService.selectLawIllegalActivitiesById(id));
    }

    /**
     * 新增违法事项库
     */
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:add')")
    @Log(title = "违法事项库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LawIllegalActivities lawIllegalActivities) {
        return toAjax(lawIllegalActivitiesService.insertLawIllegalActivities(lawIllegalActivities));
    }

    /**
     * 修改违法事项库
     */
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:edit')")
    @Log(title = "违法事项库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LawIllegalActivities lawIllegalActivities) {
        return toAjax(lawIllegalActivitiesService.updateLawIllegalActivities(lawIllegalActivities));
    }

    /**
     * 删除违法事项库
     */
    @PreAuthorize("@ss.hasPermi('enforceLaw:illegalActivities:remove')")
    @Log(title = "违法事项库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(lawIllegalActivitiesService.deleteLawIllegalActivitiesByIds(ids));

    }





}

package com.ruoyi.project.enforceLaw.base.illegalActivities.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanValidators;
import com.ruoyi.project.enforceLaw.base.illegalActivities.domain.LawIllegalActivities;
import com.ruoyi.project.enforceLaw.base.illegalActivities.mapper.LawIllegalActivitiesMapper;
import com.ruoyi.project.enforceLaw.base.illegalActivities.service.ILawIllegalActivitiesService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysPost;
import com.ruoyi.project.system.domain.SysRole;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

/**
 * 违法事项库Service业务层处理
 *
 * @author ZWL
 * @date 2024-01-03
 */
@Service
public class LawIllegalActivitiesServiceImpl implements ILawIllegalActivitiesService {
    @Autowired
    private LawIllegalActivitiesMapper lawIllegalActivitiesMapper;

    /**
     * 查询违法事项库
     *
     * @param id 违法事项库主键
     * @return 违法事项库
     */
    @Override
    public LawIllegalActivities selectLawIllegalActivitiesById(Integer id) {
        return lawIllegalActivitiesMapper.selectLawIllegalActivitiesById(id);
    }

    /**
     * 查询违法事项库列表
     *
     * @param lawIllegalActivities 违法事项库
     * @return 违法事项库
     */
    @Override
    public List selectLawIllegalActivitiesList(LawIllegalActivities lawIllegalActivities) {
        return lawIllegalActivitiesMapper.selectLawIllegalActivitiesList(lawIllegalActivities);
    }

    /**
     * 新增违法事项库
     *
     * @param lawIllegalActivities 违法事项库
     * @return 结果
     */
    @Override
    public int insertLawIllegalActivities(LawIllegalActivities lawIllegalActivities) {
        lawIllegalActivities.setCreateTime(DateUtils.getNowDate());
        lawIllegalActivities.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        return lawIllegalActivitiesMapper.insertLawIllegalActivities(lawIllegalActivities);
    }

    /**
     * 修改违法事项库
     *
     * @param lawIllegalActivities 违法事项库
     * @return 结果
     */
    @Override
    public int updateLawIllegalActivities(LawIllegalActivities lawIllegalActivities) {
        lawIllegalActivities.setUpdateTime(DateUtils.getNowDate());
        lawIllegalActivities.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        return lawIllegalActivitiesMapper.updateLawIllegalActivities(lawIllegalActivities);
    }

    /**
     * 批量删除违法事项库
     *
     * @param ids 需要删除的违法事项库主键
     * @return 结果
     */
    @Override
    public int deleteLawIllegalActivitiesByIds(Integer[] ids) {
        return lawIllegalActivitiesMapper.deleteLawIllegalActivitiesByIds(ids);
    }

    /**
     * 删除违法事项库信息
     *
     * @param id 违法事项库主键
     * @return 结果
     */
    @Override
    public int deleteLawIllegalActivitiesById(Integer id) {
        return lawIllegalActivitiesMapper.deleteLawIllegalActivitiesById(id);
    }

    @Override
    public String importUser(List userList, Boolean isUpdateSupport, String operName) {

        if (StringUtils.isNull(userList) || userList.size() == 0) {
            throw new ServiceException("导入数据不能为空!");
        }
        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (LawIllegalActivities illegalActivity : userList) {
            try {
                // 在这里进行具体的导入操作,例如插入数据库或更新现有数据
                // 根据需要进行相应的业务逻辑处理

                if (StringUtils.isEmpty(illegalActivity.getIllegalActivities())) {
                    illegalActivity.setIllegalActivities("");
                }

                if (StringUtils.isEmpty(illegalActivity.getTerms())) {
                    illegalActivity.setTerms("");
                }
                if (StringUtils.isEmpty(illegalActivity.getAccording())) {
                    illegalActivity.setAccording("");
                }
                if (StringUtils.isEmpty(illegalActivity.getPenalty())) {
                    illegalActivity.setPenalty("");
                }
                if (StringUtils.isEmpty(illegalActivity.getPenaltyContent())) {
                    illegalActivity.setPenaltyContent("");
                }
                if (StringUtils.isEmpty(illegalActivity.getCorrection())) {
                    illegalActivity.setCorrection("");
                }
                if (StringUtils.isEmpty(illegalActivity.getIfSimple())) {
                    illegalActivity.setIfSimple("");
                }

                if (StringUtils.isEmpty(illegalActivity.getVerify())) {
                    illegalActivity.setVerify("");
                }

                if (StringUtils.isEmpty(illegalActivity.getAdvise())) {
                    illegalActivity.setAdvise("");
                }


                // 导入成功时,增加成功计数和成功消息
                successNum++;
                insertLawIllegalActivities(illegalActivity);
                successMsg.append("导入成功:").append(illegalActivity.getIllegalActivities()).append("\n");
            } catch (Exception e) {
                // 导入失败时,增加失败计数和失败消息
                failureNum++;
                String msg = "
" + failureNum + " 导入失败:"; failureMsg.append(msg).append(e.getMessage()); } } if (failureNum > 0) { failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:"); throw new ServiceException(failureMsg.toString()); } else { successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:"); } return successMsg.toString(); } }

package com.ruoyi.project.enforceLaw.base.illegalActivities.service;

import java.util.List;
import com.ruoyi.project.enforceLaw.base.illegalActivities.domain.LawIllegalActivities;
import com.ruoyi.project.enforceLaw.lawCase.domain.LawCase;
import com.ruoyi.project.system.domain.SysUser;

/**
 * 违法事项库Service接口
 * 
 * @author ZWL
 * @date 2024-01-03
 */
public interface ILawIllegalActivitiesService 
{

    public String importUser(List list, Boolean isUpdateSupport, String operName);

    /**
     * 查询违法事项库
     * 
     * @param id 违法事项库主键
     * @return 违法事项库
     */
    public LawIllegalActivities selectLawIllegalActivitiesById(Integer id);

    /**
     * 查询违法事项库列表
     * 
     * @param lawIllegalActivities 违法事项库
     * @return 违法事项库集合
     */
    public List selectLawIllegalActivitiesList(LawIllegalActivities lawIllegalActivities);

    /**
     * 新增违法事项库
     * 
     * @param lawIllegalActivities 违法事项库
     * @return 结果
     */
    public int insertLawIllegalActivities(LawIllegalActivities lawIllegalActivities);

    /**
     * 修改违法事项库
     * 
     * @param lawIllegalActivities 违法事项库
     * @return 结果
     */
    public int updateLawIllegalActivities(LawIllegalActivities lawIllegalActivities);

    /**
     * 批量删除违法事项库
     * 
     * @param ids 需要删除的违法事项库主键集合
     * @return 结果
     */
    public int deleteLawIllegalActivitiesByIds(Integer[] ids);

    /**
     * 删除违法事项库信息
     * 
     * @param id 违法事项库主键
     * @return 结果
     */
    public int deleteLawIllegalActivitiesById(Integer id);
}

前端:

框和数据 import





  导入
  



  
    
    
将文件拖到此处,或点击上传
仅允许导入xls、xlsx格式文件。 下载用户导入模板

import {getToken} from "@/utils/auth";

// 用户导入参数
upload: {
  // 是否显示弹出层(用户导入)
  open: false,
  // 弹出层标题(用户导入)
  title: "",
  // 是否禁用上传
  isUploading: false,
  // 是否更新已经存在的用户数据
  updateSupport: 0,
  // 设置上传的请求头部
  headers: {Authorization: "Bearer " + getToken()},
  // 上传的地址
  url: process.env.VUE_APP_BASE_API + "enforceLaw/illegalActivities/import"
},
 /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("
" + response.msg + "
", "导入结果", {dangerouslyUseHTMLString: true}); this.getList(); }, // 提交上传文件 submitFileForm() { this.$refs.upload.submit(); }, initUserName() { this.form.userName = this.form.phonenumber; }, openWork(item) { this.dialogVisible = true this.workUserId = item.userId }, /** 下载模板操作 */ importTemplate() { this.download('enforceLaw/illegalActivities/importTemplateActivities', {}, `用户数据导入模版_${new Date().getTime()}.xlsx`) }, /** 导出按钮操作 */ handleExport() { this.download('enforceLaw/illegalActivities/export', { ...this.queryParams }, `illegalActivities_${new Date().getTime()}.xlsx`) } } };

你可能感兴趣的:(若依问题一览,windows)