Quellcode durchsuchen

资料费excel批量导入限制禁止重复申请

梁世豪 vor 3 Tagen
Ursprung
Commit
c9c6281667

+ 59 - 10
src/main/java/com/liang/common/fileupload/controller/FileUploadController.java

@@ -5,10 +5,7 @@ import com.liang.common.base.BaseResult;
5 5
 import com.liang.common.utils.ExcelPoiUtil;
6 6
 import com.liang.common.utils.FileNameValidator;
7 7
 import com.liang.entity.*;
8
-import com.liang.service.BaseCompanyService;
9
-import com.liang.service.BasePersonService;
10
-import com.liang.service.PrjGwtaskService;
11
-import com.liang.service.PrjProjectroleService;
8
+import com.liang.service.*;
12 9
 import io.swagger.annotations.Api;
13 10
 import org.apache.poi.openxml4j.opc.OPCPackage;
14 11
 import org.apache.poi.xwpf.usermodel.*;
@@ -45,6 +42,8 @@ public class FileUploadController extends BaseController {
45 42
     private BaseCompanyService baseCompanyService;
46 43
     @Resource
47 44
     private PrjGwtaskService prjGwtaskService;
45
+    @Resource
46
+    private StaSourceFeeService staSourceFeeService;
48 47
 
49 48
     @PostMapping("/upload")
50 49
     @ResponseBody
@@ -182,14 +181,64 @@ public class FileUploadController extends BaseController {
182 181
             //资料费批量导入
183 182
             if(fileType.equals("zlfFile")){
184 183
                 List<StaSourceFee> list = ExcelPoiUtil.zlfImport(file);
185
-                if (list.size()>0){
186
-                    xlsMap.put("code",0);
184
+                //添加判断条件,同一部门一本书籍只能申请一次,不可重复申请
185
+                String deptName = getSysUserInfo().getDeptName();
186
+                //获取该部门下已申请的书籍
187
+                List<StaSourceFee> TsmcList = staSourceFeeService.searchSourceTsmcByDeptName(deptName);
188
+                Set<String> tsmcSet = new HashSet<>();
189
+                Set<String> tsmcSet2 = new HashSet<>();
190
+                //用于存储部门已申请重复数据
191
+                List<String> filteredList = new ArrayList<>();
192
+                //用于自我查重重复数据
193
+                List<String> filtered2List = new ArrayList<>();
194
+                for (StaSourceFee fee : list) {
195
+                    tsmcSet.add(fee.getTsmc());
196
+                }
197
+                //自我查重
198
+                for (StaSourceFee fee : list) {
199
+                    String bookName = fee.getTsmc();
200
+                    if (!tsmcSet2.add(bookName)) {// 如果添加失败,说明是重复的
201
+                        filtered2List.add(bookName);
202
+                    }
203
+                }
204
+                // 查找第二个列表中与集合中的 tsmc 重复的值
205
+                for (StaSourceFee fee : TsmcList) {
206
+                    if (tsmcSet.contains(fee.getTsmc())) {
207
+                        filteredList.add(fee.getTsmc());
208
+                    }
209
+                }
210
+                if (filteredList.size()>0||filtered2List.size()>0){
211
+                    xlsMap.put("code",10);
212
+                    xlsMap.put("fileType",fileType);
213
+                    StringBuilder messageBuilder = new StringBuilder();
214
+                    if (filteredList.size()>0){
215
+                    messageBuilder.append(deptName + "在资料费中已申请过:");
216
+                    for (int i = 0; i < filteredList.size(); i++) {
217
+                        String bookName = filteredList.get(i);
218
+                        messageBuilder.append(bookName);
219
+                        if (i < filteredList.size() - 1) {
220
+                            messageBuilder.append(", ");
221
+                        }
222
+                        }
223
+                    }
224
+                    if (filtered2List.size()>0){
225
+                        messageBuilder.append("表格中申请出现重复资料:");
226
+                        for (int i = 0; i < filtered2List.size(); i++) {
227
+                            String bookName = filtered2List.get(i);
228
+                            messageBuilder.append(bookName);
229
+                            if (i < filtered2List.size() - 1) {
230
+                                messageBuilder.append(", ");
231
+                            }
232
+                        }
233
+                    }
234
+                    String message = messageBuilder.toString();
235
+                    return BaseResult.failure(message);
187 236
                 }else {
188
-                    xlsMap.put("code", 10);
237
+                    xlsMap.put("code", 0);
238
+                    xlsMap.put("list",list);
239
+                    xlsMap.put("fileType",fileType);
240
+                    return BaseResult.success("资料费导入成功!", xlsMap);
189 241
                 }
190
-                xlsMap.put("list",list);
191
-                xlsMap.put("fileType",fileType);
192
-                return BaseResult.success("资料费导入成功!", xlsMap);
193 242
             }
194 243
             //印刷费批量导入
195 244
             if(fileType.equals("ysfFile")){