多单位版国产化地质资料管理系统
zs
2026-02-04 fe02f176b512a9d6a4e12437d929e04e99bb7567
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
package com.zbooksoft.gdmis.operate;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruili.wcp.common.CustomConfigUtil;
import com.ruili.wcp.common.SpringContextUtil;
import com.ruili.wcp.configsettting.SystemConfig;
import com.ruili.wcp.data.entity.config.Module;
import com.ruili.wcp.data.entity.config.View;
import com.ruili.wcp.data.entity.management.User;
import com.ruili.wcp.engine.form.IFormData;
import com.ruili.wcp.service.config.ModuleService;
import com.ruili.wcp.service.config.ViewService;
import com.ruili.wcp.web.model.AjaxResponse;
import com.ruili.wcp.web.model.ErrorInfo;
import com.zbooksoft.gdmis.config.ArchivesCustomConfig;
import com.zbooksoft.gdmis.data.entity.BorrowDetail;
import com.zbooksoft.gdmis.data.entity.CatAjjxx;
import com.zbooksoft.gdmis.data.entity.CatYswjxx;
import com.zbooksoft.gdmis.data.entity.PhysicalDetail;
import com.zbooksoft.gdmis.service.*;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
 
import java.io.File;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
 
 
/**
 * @Description:地质资料基本信息操作方法
 * @Author: zhai
 * @Date: 2024/8/15
 **/
public class CatAjjxxOperate {
    private static final Logger logger = LoggerFactory.getLogger(CatAjjxxOperate.class);
    ViewService viewService = (ViewService) SpringContextUtil.getBean("viewServiceImpl");
    BorrowDetailService borrowDetailService = (BorrowDetailService) SpringContextUtil.getBean("borrowDetailServiceImpl");
    CatAjjxxService catAjjxxService = (CatAjjxxService) SpringContextUtil.getBean("catAjjxxServiceImpl");
    PhysicalDetailService physicalDetailService = (PhysicalDetailService) SpringContextUtil.getBean("physicalDetailServiceImpl");
    ModuleService moduleService = (ModuleService) SpringContextUtil.getBean("moduleServiceImpl");
    JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate");
    IFormData iform = (IFormData) SpringContextUtil.getBean("iFormData");
    CatYswjxxService catYswjxxService = (CatYswjxxService) SpringContextUtil.getBean("catYswjxxServiceImpl");
    CustomConfigUtil customConfigUtil = (CustomConfigUtil) SpringContextUtil.getBean("customConfigUtil");
 
 
    /**
     * 发布
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse release(Long viewId, ArrayList<Long> idList) {
        try {
            LocalDateTime now = LocalDateTime.now();
 
            // 创建 DateTimeFormatter 对象,指定日期格式  blankTape
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            // 格式化日期
            String formattedDate = now.format(formatter);
            View view = viewService.getViewById(viewId);
            String strSql = "update " + view.getMainTableName() + " set fbzt = 1 ";
            jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, idList.get(i));// 下标从1开始
                }
 
                @Override
                public int getBatchSize() {
                    return idList.size();
                }
            });
            QueryWrapper<CatYswjxx> queryWrapper=new QueryWrapper<>();
            queryWrapper.in("aj_id",idList).eq("yszt",3);
//            queryWrapper.in("aj_id",idList);
            List<CatYswjxx> catYswjxxList=catYswjxxService.list(queryWrapper);
            ArchivesCustomConfig archivesCustomConfig = customConfigUtil.getConfigObj(ArchivesCustomConfig.class);
            for (CatYswjxx catYswjxx : catYswjxxList) {
                String destDir = archivesCustomConfig.getOriginalPath() + "已入库" + File.separator + catYswjxx.getWjlj().substring(archivesCustomConfig.getOriginalPath().length());
                // 源文件路径
                File sourceFile = new File(catYswjxx.getWjlj());
                // 目标文件路径
                File destFile = new File(destDir);
 
                // 确保目标目录存在
                File destParentDir = destFile.getParentFile();
                if (destParentDir != null && !destParentDir.exists()) {
                    destParentDir.mkdirs();
                }
 
                // 判断源文件是文件还是文件夹
                if (sourceFile.isDirectory()) {
                    // 如果是文件夹,复制整个文件夹及其内容
                    copyDirectory(sourceFile, destFile);
                } else {
                    // 如果是文件,直接复制
                    java.nio.file.Files.copy(sourceFile.toPath(), destFile.toPath(),
                        java.nio.file.StandardCopyOption.REPLACE_EXISTING);
                }
 
                // 删除源文件或源文件夹
                deleteDirectory(sourceFile);
 
                catYswjxx.setWjlj(destDir);
                catYswjxxService.saveOrUpdate(catYswjxx);
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 复制目录及其子目录和文件
     * @param source 源目录
     * @param target 目标目录
     * @throws IOException
     */
    private void copyDirectory(File source, File target) throws IOException {
        if (source.isDirectory()) {
            // 如果目标目录不存在,则创建
            if (!target.exists()) {
                target.mkdirs();
            }
 
            // 获取源目录下的所有文件和子目录
            String[] files = source.list();
            if (files != null) {
                for (String file : files) {
                    File srcFile = new File(source, file);
                    File destFile = new File(target, file);
                    // 递归复制
                    copyDirectory(srcFile, destFile);
                }
            }
        } else {
            // 如果是文件,直接复制
            java.nio.file.Files.copy(source.toPath(), target.toPath(),
                    java.nio.file.StandardCopyOption.REPLACE_EXISTING);
        }
    }
 
    /**
     * 删除目录及其子目录和文件
     * @param directory 要删除的目录
     */
    private void deleteDirectory(File directory) {
        if (directory.isDirectory()) {
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : files) {
                    deleteDirectory(file);
                }
            }
        }
        directory.delete();
    }
 
    /**
     * 取消发布
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse cancelRelease(Long viewId, ArrayList<Long> idList) {
        try {
            int state = 0;
            String columnName = "fbzt";
//            updateState(viewId, idList, state, columnName);
            QueryWrapper<CatAjjxx> fileQueryWrapper = new QueryWrapper<>();
            fileQueryWrapper.in("id",idList);
            List<CatAjjxx> catAjjxxList=catAjjxxService.list(fileQueryWrapper);
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
 
    /**
     * 取消发布
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse warehousing(Long viewId, ArrayList<Long> idList) {
        try {
            int state = 1;
            String columnName = "zlzt";
            updateState(viewId, idList, state, columnName);
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    public void updateState(Long viewId, ArrayList<Long> idList, Integer state, String columnName) {
        View view = viewService.getViewById(viewId);
        String strSql = "update " + view.getMainTableName() + " set " + columnName + " = " + state;
//        jdbcTemplate.batchUpdate(strSql + " where " + view.getIdField() + "=?", new BatchPreparedStatementSetter() {
//            @Override
//            public void setValues(PreparedStatement ps, int i) throws SQLException {
//                ps.setLong(1, idList.get(i));// 下标从1开始
//            }
//
//            @Override
//            public int getBatchSize() {
//                return idList.size();
//            }
//        });
 
    }
 
 
    /**
     * 添加档案利用
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse addUtilization(Long viewId, ArrayList<Long> idList) {
        try {
            View view = viewService.getViewById(viewId);
            AjaxResponse ajaxResponse = addUtilizationByModuleId(view.getModuleId(), idList);
            return ajaxResponse;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 添加档案利用
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse addUtilizationAll(Long viewId, ArrayList<Long> idList) {
        try {
 
            AjaxResponse ajaxResponse = addUtilizationByAll(idList);
            return ajaxResponse;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 通过moduleid添加档案利用
     */
    public AjaxResponse addUtilizationByModuleId(Long moduleId, List<Long> idList) {
        try {
 
            Module module = moduleService.getByIdModule(moduleId);
            QueryWrapper<Module> moduleQueryWrapper = new QueryWrapper<>();
            moduleQueryWrapper.eq("module_id", module.getParentId());
            moduleQueryWrapper.ne("parent_id", 0);
            List<Module> moduleList = moduleService.list(moduleQueryWrapper);
 
            AjaxResponse ajaxResponse = new AjaxResponse(true);
 
            Map<String, Object> resultMap = new HashMap<String, Object>();
            if (moduleList.size() == 0) {
                // 案卷级利用
                resultMap = addUtilizationForFile(idList);
            } else if (moduleList.size() > 0) {
                // 文件级利用,需要反查案卷级信息
                resultMap = addUtilizationForItem(module, idList);
            }
 
//            String unit = resultMap.get("unit").toString().equals("卷") ? "0" : "1";
            String unit = "0";
            if (resultMap != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("top.layer.open({");
                sb.append("   title : '提示',");
                sb.append("   type : 2,");
                sb.append("   area : [ '700px', '220px' ],");
                sb.append("   fixed : true, ");
                sb.append("   content : 'common/commonTips?addNum=" + resultMap.get("addNum") + "&type=借阅&repeatNum=" + resultMap.get("repeatNum") + "&existFileNum=" + resultMap.get("existFileNum") + "&existItemNum=" + resultMap.get("existItemNum") + "&urlPath=borrow'");
                sb.append("});");
 
                Map<String, String> result = new HashMap<String, String>();
                result.put("jsExpression", sb.toString());
                result.put("totalNum", resultMap.get("existFileNum").toString());
                ajaxResponse.setResult(result);
            }
            return ajaxResponse;
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            return new AjaxResponse(new ErrorInfo(ex.getMessage()), false);
        }
    }
 
    /**
     * 通过moduleid添加档案利用
     */
    public AjaxResponse addUtilizationByAll(List<Long> idList) {
        try {
 
            String strSql = "select  *  from view_all_utlization where id = " + idList.get(0);
            Map<String, Object> map = jdbcTemplate.queryForMap(strSql);
            Long moduleId = Long.parseLong(map.get("module_id").toString());
            Module module = moduleService.getByIdModule(moduleId);
            QueryWrapper<Module> moduleQueryWrapper = new QueryWrapper<>();
            moduleQueryWrapper.eq("module_id", module.getParentId());
            moduleQueryWrapper.ne("parent_id", 0);
            List<Module> moduleList = moduleService.list(moduleQueryWrapper);
 
            AjaxResponse ajaxResponse = new AjaxResponse(true);
 
            Map<String, Object> resultMap = new HashMap<String, Object>();
            if (moduleList.size() == 0) {
                // 案卷级利用
                resultMap = addUtilizationForFile(idList);
            } else if (moduleList.size() > 0) {
                // 文件级利用,需要反查案卷级信息
                resultMap = addUtilizationForItem(module, idList);
            }
 
//            String unit = resultMap.get("unit").toString().equals("卷") ? "0" : "1";
            String unit = "0";
            if (resultMap != null) {
                StringBuilder sb = new StringBuilder();
                sb.append("top.layer.open({");
                sb.append("   title : '提示',");
                sb.append("   type : 2,");
                sb.append("   area : [ '700px', '220px' ],");
                sb.append("   fixed : true, ");
                sb.append("   content : 'common/commonTips?addNum=" + resultMap.get("addNum") + "&type=借阅&repeatNum=" + resultMap.get("repeatNum") + "&existFileNum=" + resultMap.get("existFileNum") + "&existItemNum=" + resultMap.get("existItemNum") + "&urlPath=borrow'");
                sb.append("});");
 
                Map<String, String> result = new HashMap<String, String>();
                result.put("jsExpression", sb.toString());
                result.put("totalNum", resultMap.get("existFileNum").toString());
                ajaxResponse.setResult(result);
            }
            return ajaxResponse;
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            return new AjaxResponse(new ErrorInfo(ex.getMessage()), false);
        }
    }
 
    public Map<String, Object> addUtilizationForFile(List<Long> idList) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
 
        Map<String, Object> resultMap = new HashMap<>();
        int addNum = 0;
        int repeatNum = 0;
        int existItemNum = 0;
 
        for (int i = 0; i < idList.size(); i++) {
            Long keyId = idList.get(i);
            QueryWrapper<BorrowDetail> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("form_id", 0);
            queryWrapper.eq("create_user_id", user.getUserId());
            int itemCount = borrowDetailService.count(queryWrapper);
            existItemNum += itemCount;
            queryWrapper.eq("file_id", keyId);
            List<BorrowDetail> borrowDetailList = borrowDetailService.list(queryWrapper);
            if (borrowDetailList.size() == 0) {
                CatAjjxx catAjjxx = catAjjxxService.getById(keyId);
                Integer cgwjxxCount = borrowDetailService.setCgwjxx(catAjjxx);
                Integer yswjxxCount = borrowDetailService.setYswjxx(catAjjxx);
                addNum++;
                existItemNum += cgwjxxCount + yswjxxCount;
            } else {
                repeatNum++;
            }
        }
        String strSql = "select distinct file_id from UTL_BORROW_DETAIL  where form_id=0 and create_user_id=" + user.getUserId();
        List<Map<String, Object>> parentMapList = jdbcTemplate.queryForList(strSql);
        resultMap.put("existFileNum", parentMapList.size());
        resultMap.put("existItemNum", existItemNum);
        resultMap.put("addNum", addNum);
        resultMap.put("repeatNum", repeatNum);
 
        return resultMap;
    }
 
    public Map<String, Object> addUtilizationForItem(Module module, List<Long> idList) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
 
        int addNum = 0;
        int repeatNum = 0;
        int existItemNum = 0;
 
        Map<String, Object> resultMap = new HashMap<>();
        for (int i = 0; i < idList.size(); i++) {
            Long keyId = idList.get(i);
            QueryWrapper<BorrowDetail> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("form_id", 0);
            queryWrapper.eq("create_user_id", user.getUserId());
            int itemCount = borrowDetailService.count(queryWrapper);
            existItemNum += itemCount;
            queryWrapper.eq("item_id", keyId);
            List<BorrowDetail> borrowDetailList = borrowDetailService.list(queryWrapper);
            if (borrowDetailList.size() == 0) {
                String mainTableName = module.getMainTableName();
                if (mainTableName.equals("CAT_ITEM_CGWJXX")) {
                    Integer cgwjxxCount = borrowDetailService.setCgwjxxByIds(idList);
                    existItemNum += cgwjxxCount;
                } else if (mainTableName.equals("CAT_ITEM_YSWJXX")) {
                    Integer cgwjxxCount = borrowDetailService.setYswjxxByIds(idList);
                    existItemNum += cgwjxxCount;
                }
            }
        }
 
        resultMap.put("addNum", 1);
        resultMap.put("repeatNum", 0);
        resultMap.put("existItemNum", existItemNum);
        String strSql = "select distinct file_id from UTL_BORROW_DETAIL  where form_id=0 and create_user_id=" + user.getUserId();
        List<Map<String, Object>> parentMapList = jdbcTemplate.queryForList(strSql);
        resultMap.put("existFileNum", parentMapList.size());
        return resultMap;
    }
 
 
 
    //添加实物样品
    public Map<String, Object> addPhysicalForItem( Long viewId, ArrayList<Long> idList) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute("user");
 
        int addNum = 0;
        int repeatNum = 0;
        int existItemNum = 0;
 
        Map<String, Object> resultMap = new HashMap<>();
        for (int i = 0; i < idList.size(); i++) {
            Long keyId = idList.get(i);
            QueryWrapper<PhysicalDetail> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("form_id", 0);
            queryWrapper.eq("create_user_id", user.getUserId());
            int itemCount = physicalDetailService.count(queryWrapper);
            existItemNum += itemCount;
            queryWrapper.eq("item_id", keyId);
            List<PhysicalDetail> physicalDetailList = physicalDetailService.list(queryWrapper);
            if (physicalDetailList.size() == 0) {
                Integer cgwjxxCount = physicalDetailService.setCgwjxxByIds(idList);
                existItemNum += cgwjxxCount;
            }
        }
 
        resultMap.put("addNum", 1);
        resultMap.put("repeatNum", 0);
        resultMap.put("existItemNum", existItemNum);
        String strSql = "select distinct file_id from UTL_PHYSICAL_DETAIL  where form_id=0 and create_user_id=" + user.getUserId();
        List<Map<String, Object>> parentMapList = jdbcTemplate.queryForList(strSql);
        resultMap.put("existFileNum", parentMapList.size());
        return resultMap;
    }
 
    /**
     * 添加成果
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse addCg(Long viewId, ArrayList<Long> idList) {
        try {
            String cgSql = "select NVL(max(BGBH), 0) BGBH FROM CAT_ITEM_CGWJXX";
            Map<String, Object> stringMap = jdbcTemplate.queryForMap(cgSql);
            int maxDH = Integer.parseInt(stringMap.get("BGBH").toString());
            for (int i = 0; i < idList.size(); i++) {
                int newDH = maxDH + 1 + i;
                String newDhString = String.format("%04d", newDH);
                String sql = "select * from CAT_ITEM_YSWJXX where id = " + idList.get(i);
                Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
 
                stringObjectMap.put("BGBH", newDhString);
                LocalDateTime currentDate = LocalDateTime.now();
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                String formattedDate = currentDate.format(formatter);
                stringObjectMap.put("CREATE_TIME", formattedDate);
                stringObjectMap.put("MODIFY_TIME", formattedDate);
                stringObjectMap.put("CDDZWJLJ", stringObjectMap.get("WJLJ"));
                stringObjectMap.put("CDDZWJLJ", stringObjectMap.get("WJLJ"));
                iform.insert(1823017354756390913L, stringObjectMap);
            }
 
            return null;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 取消发布
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse createArchiveCode(Long viewId, ArrayList<Long> idList) {
        try {
            String sql = "select NVL(max(DH), 0) DH FROM CAT_FILE_AJJXX";
            Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
            int maxDH = Integer.parseInt(stringObjectMap.get("DH").toString());
            for (int i = 0; i < idList.size(); i++) {
                int newDH = maxDH + 1 + i;
                String newDhString = String.format("%04d", newDH);
                String updateSql = "update CAT_FILE_AJJXX set DH = '" + newDhString + "' where ID = " + idList.get(i);
                jdbcTemplate.update(updateSql);
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
}