mitao
2024-05-16 4965b67d9e2a8e99894bd40aff7c88d695ec4040
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.ruoyi.common.core.utils;
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
 
import java.io.IOException;
import java.util.List;
 
/**
 * 导出返回信息
 */
@Slf4j
public class ImportExcelUtil {
 
    /**
     * @param errorLines   错误行数
     * @param successLines 成功行数
     * @param errorMessage 错误信息
     * @return
     * @throws IOException
     */
    public static R<String > importReturnMsg(int errorLines, int successLines, List<String> errorMessage) throws IOException {
        if (errorLines == 0) {
            return R.ok("共" + successLines + "行数据全部导入成功!");
        } else {
            JSONObject result = new JSONObject(5);
            int totalCount = successLines + errorLines;
            result.put("totalCount", totalCount);
            result.put("errorCount", errorLines);
            result.put("errorMessage", errorMessage);
            result.put("successCount", successLines);
            result.put("msg", "总上传行数:" + totalCount + ",已导入行数:" + successLines + ",错误行数:" + errorLines);
            return R.ok(JSON.toJSONString(result));
        }
    }
 
}