多单位版国产化地质资料管理系统
zhai
2025-09-17 7a8a84577894b766a95c6cbfa5ac7b51e54ac242
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
package com.zbooksoft.gdmis.controller;
 
import com.alibaba.fastjson.JSONObject;
import com.ruili.wcp.common.CustomConfigUtil;
import com.ruili.wcp.common.StringUtil;
import com.ruili.wcp.common.excel.PoiUtil;
import com.ruili.wcp.configsettting.SystemConfig;
import com.ruili.wcp.data.entity.config.Module;
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.common.*;
import com.zbooksoft.gdmis.data.entity.CatYswjxx;
import com.zbooksoft.gdmis.data.entity.PackingManage;
import com.zbooksoft.gdmis.service.CatCheckService;
import com.zbooksoft.gdmis.service.CatYswjxxService;
import com.zbooksoft.gdmis.service.PackingManageService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import static com.zbooksoft.gdmis.common.ZipUtil.copyFile;
import static com.zbooksoft.gdmis.common.ZipUtil.zipFile;
 
 
/**
 * @author 15280
 */
@Controller
@RequestMapping("/catYswjxx")
public class CatYswjxxController {
 
    @Autowired
    ViewService viewService;
    @Autowired
    PackingManageService packingManageService;
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    CatYswjxxService catYswjxxService;
    @Autowired
    CustomConfigUtil customConfigUtil;
 
    @Autowired
    ModuleService moduleService;
 
    @Autowired
    IFormData iform;
 
    @Autowired
    CatCheckService catCheckService;
    private static final Logger logger = LoggerFactory.getLogger(CatYswjxxController.class);
 
 
    /**
     * 文件拆分
     *
     * @return
     */
    @RequestMapping({"/split"})
    @ResponseBody
    @RequiresUser
    public Object split(Long moduleId, Long viewId, Long id, @RequestBody JSONObject jsonData) {
        try {
            //获取拆几份
            String count = StringUtil.nullToEmpty(jsonData.getString("returnOpinion")).trim();
            if (jsonData.containsKey("ids")) {
                ArrayList<String> ids = (ArrayList<String>) jsonData.get("ids");
                for (String longId : ids) {
                    Module module = moduleService.getByIdModule(moduleId);
                    String mainTableName = module.getMainTableName();
                    String selectSql = "select * from " + mainTableName + " where ID = " + longId;
                    Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
                    addPacking(map, count);
                }
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 文件拆分
     *
     * @return
     */
    @RequestMapping({"/addCg"})
    @ResponseBody
    @RequiresUser
    public Object addCg(Long moduleId, Long viewId, Long id, @RequestBody JSONObject jsonData) {
        try {
            //获取拆几份
            String count = StringUtil.nullToEmpty(jsonData.getString("returnOpinion")).trim();
            if (jsonData.containsKey("ids")) {
 
                ArrayList<String> ids = (ArrayList<String>) jsonData.get("ids");
                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());
                int newDH = maxDH + 1;
                for (int i = 0; i < ids.size(); i++) {
                    String newDhString = String.format("%04d", newDH);
                    String sql = "select * from CAT_ITEM_YSWJXX where id = " + ids.get(i);
                    Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
                    String sl = stringObjectMap.get("SL") == null ? "0" : stringObjectMap.get("SL").toString();
                    Integer slInt = Integer.parseInt(sl) - Integer.parseInt(count);
                    if (slInt < 0) {
                        slInt = 0;
                    }
                    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("SL", count);
                    String jnxh = stringObjectMap.get("JNXH") == null ? "" : stringObjectMap.get("JNXH").toString();
                    String newDh = newDhString + "-" + jnxh;
                    stringObjectMap.put("DH", newDh);
                    iform.insert(1823017354756390913L, stringObjectMap);
 
                    String updateSql = "update CAT_ITEM_YSWJXX set SL = '" + slInt + "' where ID = " + ids.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);
        }
    }
 
    /**
     * 添加临时位置
     *
     * @return
     */
    @RequestMapping({"/addTemp"})
    @ResponseBody
    @RequiresUser
    public Object addTemp(Long moduleId, Long viewId, Long id, @RequestBody JSONObject jsonData) {
        try {
            //获取拆几份
            String count = StringUtil.nullToEmpty(jsonData.getString("returnOpinion")).trim();
            if (jsonData.containsKey("ids")) {
                ArrayList<String> ids = (ArrayList<String>) jsonData.get("ids");
                for (String longId : ids) {
                    Module module = moduleService.getByIdModule(moduleId);
                    String mainTableName = module.getMainTableName();
                    String updateSql = "update " + mainTableName + " set HH = '" + count + "' where ID = " + longId;
                    int update = jdbcTemplate.update(updateSql);
                }
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    /**
     * 文件装盒
     *
     * @return
     */
    @RequestMapping({"/packagingBox"})
    @ResponseBody
    @RequiresUser
    public Object packagingBox(Long moduleId, Long viewId, Long id, @RequestBody JSONObject jsonData) {
        try {
            //获取拆几份
            String count = StringUtil.nullToEmpty(jsonData.getString("returnOpinion")).trim();
            if (jsonData.containsKey("ids")) {
                ArrayList<String> ids = (ArrayList<String>) jsonData.get("ids");
                for (String longId : ids) {
                    Module module = moduleService.getByIdModule(moduleId);
                    String mainTableName = module.getMainTableName();
                    String selectSql = "select * from " + mainTableName + " where ID = " + longId;
                    Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
                    addPacking(map, count);
                }
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
    private void addPacking(Map<String, Object> map, String count) {
        String num = "";
        int i = Integer.parseInt(count);
        String id = StringUtil.nullToEmpty(map.get("ID")).trim();
        String dh = StringUtil.nullToEmpty(map.get("DH")).trim();
        packingManageService.removeByItemId(Long.parseLong(id));
 
        if (dh != null && !dh.equals("")) {
            num = dh;
        }
        String ajId = StringUtil.nullToEmpty(map.get("AJ_ID")).trim();
        for (int j = 0; j <= i; j++) {
            PackingManage packingManage = new PackingManage();
            if (j == 0) {
                packingManage.setItemNum(num);
            } else {
                packingManage.setItemNum(num + "-" + j);
            }
            packingManage.setItemId(id);
            packingManage.setAjId(ajId);
            packingManage.setType(0);
            packingManage.setCreateTime(new java.util.Date());
            packingManageService.saveOrUpdate(packingManage);
        }
    }
 
 
    /**
     * 全部打包
     *
     * @return
     */
    @RequestMapping("/extractFile")
    @RequiresUser
    public void extractFile(HttpServletRequest request, HttpServletResponse response, String ids) {
        try {
            String filePath = "";
            String generatePath = "";
            Subject currentUser = SecurityUtils.getSubject();
            Session session = currentUser.getSession();
            User user = (User) session.getAttribute("user");
            String userName = user.getUserName();
            String timestamp = Long.toString(System.currentTimeMillis());
 
            try {
                //1193266555786362880,1193266555916386304,1193266556004466688,1193266556105129984,1193266556193210368,1193266556277096448,1193266556377759744,1193266556474228736,1193266556545531904 变成list
                String[] idList = ids.split(",");
 
                // 读取文件存放路径
                SystemConfig config = SystemConfig.getInstance();
                filePath = config.getAttachUploadPath() + "dataPack" + File.separator + userName + "_" + timestamp + File.separator;
//                for (int i = 0; i < idList.length; i++) {
                for (int i = 0; i < idList.length; i++) {
                    String wjljSql = "SELECT WJLJ,WJTM FROM CAT_ITEM_YSWJXX WHERE  ID  = " + idList[i];
                    List<Map<String, Object>> wjljList = jdbcTemplate.queryForList(wjljSql);
                    if (wjljList.size() > 0) {
                        String newSavePath = filePath;
                        if (wjljList.get(0).get("WJLJ") != null) {
                            String cddzwjlj = wjljList.get(0).get("WJLJ").toString();
                            String wjm = wjljList.get(0).get("WJTM").toString();
                            File file = new File(cddzwjlj);
                            String name = file.getName();
                            if (name.contains(".pdf") || name.contains(".PDF")) {
                                String parent = file.getParent();
                                String newName = "tmp_" + name;
                                String newCddzwjlj = parent + File.separator + newName;
                                PdfUtil.addBlankPageAtBeginning(cddzwjlj, newCddzwjlj, wjm);
                                cddzwjlj = newCddzwjlj;
                            }
                            copyFile(cddzwjlj, newSavePath + File.separator + name);
                        }
 
                    }
                }
                // 压缩文件
                generatePath = zipFile(new File(filePath), "rar");
            } catch (Exception ex) {
                logger.error(ex.getMessage(), ex);
            }
            File file = new File(generatePath);
            InputStream inStream;
            try {
                inStream = new FileInputStream(generatePath);// 文件的存放路径
                response.reset();
                // 设置输出的格式
                String userAgent = request.getHeader("User-Agent");
                // 根据获取的浏览器进行编码
                String encodeFilename = PoiUtil.encodeDownloadFilename(file.getName(), userAgent);
                response.setHeader("content-disposition", "filename=" + encodeFilename);
                // 文件后缀
                response.setContentType("application/vnd.ms-excel;charset=UTF-8");
                // 循环取出流中的数据
                byte[] b = new byte[100];
                int len;
                while ((len = inStream.read(b)) > 0) response.getOutputStream().write(b, 0, len);
                inStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                file.delete();
            }
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
    }
 
//    /**
//     * 添加到成果资料
//     *
//     * @return
//     */
//    @RequestMapping({"/addCg"})
//    @ResponseBody
//    @RequiresUser
//    public Object addCg(Long moduleId, Long viewId, Long id, @RequestBody JSONObject jsonData) {
//        try {
//            //获取拆几份
//            String count = StringUtil.nullToEmpty(jsonData.getString("returnOpinion")).trim();
//            if (jsonData.containsKey("ids")) {
//                ArrayList<String> ids = (ArrayList<String>) jsonData.get("ids");
//                for (String longId : ids) {
//                    Module module = moduleService.getByIdModule(moduleId);
//                    String mainTableName = module.getMainTableName();
//                    String selectSql = "select * from " + mainTableName + " where ID = " + longId;
//                    Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
//                    addPacking(map, count);
//                }
//            }
//            return new AjaxResponse(true);
//        } catch (Exception e) {
//            logger.error(e.getMessage(), e);
//            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
//        }
//    }
 
    /**
     * 导入页面
     *
     * @param type 0:从转孔基本信息进入 1:从钻孔图幅进入
     */
    @RequestMapping({"/updateFileTypeIndex"})
    @RequiresUser
    public ModelAndView importIndex(Integer type) {
        ModelAndView mv = new ModelAndView("gh/catAjjxx/updateFileTypeIndex");
        return mv;
    }
 
    /**
     * @param type 0 是成果 1 是原始
     * @return
     */
    @RequestMapping({"/printLabelIndex"})
    @RequiresUser
    public ModelAndView printLabelIndex(Integer type) {
        ModelAndView mv = new ModelAndView("gh/catAjjxx/printLabelIndex");
        mv.addObject("type", type);
        return mv;
    }
 
    /**
     * @param fileType 打印类型 0是盒子 1是文件
     * @param type     资料类型 0成果报告 1原始资料
     * @param idList
     * @return
     */
    @RequestMapping(value = "/printLabel")
    @ResponseBody
    @RequiresUser
    public Object printLabel(String fileType, Integer type, @RequestBody List<Long> idList) {
        try {
            //打印盒子
            if ("盒子".equals(fileType)) {
                if (type == 0) {
 
                }
                if (type == 1) {
 
                    UsbSyncExampleWindows usbSyncExampleWindows = new UsbSyncExampleWindows();
                    usbSyncExampleWindows.printFileLabel(idList);
//                    ZT411RFIDPrintService zt411RFIDPrintService = new ZT411RFIDPrintService();
//                    zt411RFIDPrintService.printRFIDLabel(idList);
                }
            }
            //打印文件
            if ("文件".equals(fileType)) {
                if (type == 0) {
                    UsbSyncExampleWindowsItemCg usbSyncExampleWindowsItemCg = new UsbSyncExampleWindowsItemCg();
                    usbSyncExampleWindowsItemCg.printItemLabelCg(idList);
                }
                if (type == 1) {
                    UsbSyncExampleWindowsItem usbSyncExampleWindowsItem = new UsbSyncExampleWindowsItem();
                    usbSyncExampleWindowsItem.printItemLabel(idList);
                }
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
 
    /**
     * 获取文件类型
     *
     * @return
     */
    @RequestMapping(value = "/getFileType")
    @ResponseBody
    @RequiresUser
    public List<Map<String, Object>> getFileType() {
        String sql = "SELECT param_name , param_value  FROM sys_keyword_param where  keyword_id = 1830441538759495681";
        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql);
        return mapList;
    }
 
    /**
     * 获取文件类型
     *
     * @return
     */
    @RequestMapping(value = "/updateFileType")
    @ResponseBody
    @RequiresUser
    public Object updateFileType(String fileType, @RequestBody ArrayList<Long> idList) {
        int newXh = 0;
        CatYswjxx yswjxx = catYswjxxService.getById(idList.get(0));
        String maxFileType = catYswjxxService.getMaxFileType(yswjxx.getAjId(), fileType);
        if (maxFileType != null) {
            newXh = Integer.parseInt(maxFileType);
        }
        try {
            for (Long id : idList) {
                //JNXH
                CatYswjxx catYswjxx = catYswjxxService.getById(id);
                newXh = newXh + 1;
                catYswjxx.setXh(Integer.toString(newXh));
                String substring = fileType.substring(fileType.indexOf("/") + 1);
                String newXhFormatted = String.format("%04d", newXh);
                String newJnxh = substring + newXhFormatted;
                catYswjxx.setJnxh(newJnxh);
                catYswjxx.setWjlx(fileType);
                catYswjxxService.updateById(catYswjxx);
            }
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
 
}