多单位版国产化地质资料管理系统
zhai
2025-11-17 378d576468f1378179a8a184e78b8aa6309edc0f
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
package com.zbooksoft.gdmis.operate;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruili.wcp.common.SpringContextUtil;
import com.ruili.wcp.common.StringUtil;
import com.ruili.wcp.data.entity.config.View;
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.data.entity.PackingManage;
import com.zbooksoft.gdmis.service.CatSmxxService;
import com.zbooksoft.gdmis.service.CatYswjxxService;
import com.zbooksoft.gdmis.service.PackingManageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
 
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * @Description:原始文件信息操作方法
 * @Author: zhai
 * @Date: 2024/8/15
 **/
public class CatYswjxxOperate {
    private static final Logger logger = LoggerFactory.getLogger(CatYswjxxOperate.class);
    CatYswjxxService catYswjxxService = (CatYswjxxService) SpringContextUtil.getBean("catYswjxxServiceImpl");
    CatSmxxService catSmxxService = (CatSmxxService) SpringContextUtil.getBean("catSmxxServiceImpl");
    PackingManageService packingManageService = (PackingManageService) SpringContextUtil.getBean("packingManageServiceImpl");
    ViewService viewService = (ViewService) SpringContextUtil.getBean("viewServiceImpl");
    JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringContextUtil.getBean("jdbcTemplate");
 
    /**
     * 退回待著录
     *
     * @param viewId
     * @param idList
     * @return
     */
    public AjaxResponse submitCheck(Long viewId, ArrayList<Long> idList) {
 
        View view = viewService.getViewById(viewId);
        int state = 2;
        String strSql = "update " + view.getMainTableName() + " set yszt = " + state;
        try {
            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();
                }
            });
 
            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 revocationCheck(Long viewId, ArrayList<Long> idList) {
 
        View view = viewService.getViewById(viewId);
        int state = 0;
        String strSql = "update " + view.getMainTableName() + " set yszt = " + state;
        try {
            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();
                }
            });
 
            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 isBorrow(Long viewId, ArrayList<Long> idList) {
        //纸质借阅状态,0可外借,1不可借出
        View view = viewService.getViewById(viewId);
        int state = 1;
        String strSql = "update " + view.getMainTableName() + " set JYZT = " + state;
        try {
            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();
                }
            });
 
            return new AjaxResponse(true);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new AjaxResponse(new ErrorInfo(e.getMessage()), false);
        }
    }
 
 
    /**
     * 原始文件装盒
     *
     * @return
     */
    public AjaxResponse packagingBoxYs(Long viewId, ArrayList<Long> idList) {
        try {
            String box = "0001";
            String maxBoxSql = "select max(box_number) from BUS_PACKING_MANAGE WHERE TYPE = 1";
            String boxNum = jdbcTemplate.queryForObject(maxBoxSql, String.class);
            if (boxNum != null || "".equals(boxNum)) {
                int num = Integer.parseInt(boxNum);
                num += 1;
                DecimalFormat df = new DecimalFormat("0000");
                box = df.format(num);
            }
            int newPage = 0;
            View view = viewService.getViewById(viewId);
            String mainTableName = view.getMainTableName();
            for (int i = 0; i < idList.size(); i++) {
                String selectSql = "select * from " + mainTableName + " where id = " + idList.get(i);
                Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
                String itemNum = StringUtil.nullToEmpty(map.get("DH")).trim();
                String id = StringUtil.nullToEmpty(map.get("ID")).trim();
                String ajId = StringUtil.nullToEmpty(map.get("AJ_ID")).trim();
                QueryWrapper<PackingManage> packingManageQueryWrapper = new QueryWrapper<>();
                packingManageQueryWrapper.eq("item_id", idList.get(i));
                PackingManage packingManage = new PackingManage();
                List<PackingManage> packingManageList = packingManageService.list(packingManageQueryWrapper);
                if (packingManageList.size() > 0) {
                    packingManage = packingManageList.get(0);
                }
                packingManage.setItemNum(itemNum);
                packingManage.setItemId(id);
                packingManage.setAjId(ajId);
                packingManage.setCreateTime(new java.util.Date());
                packingManage.setType(1);
                String zzys = map.get("ZZYS") == null ? "0" : map.get("ZZYS").toString();
                if (newPage + Integer.parseInt(zzys) > 500) {
                    int num = Integer.parseInt(box);
                    num += 1;
                    DecimalFormat df = new DecimalFormat("0000");
                    String newBox = df.format(num);
                    box = newBox;
                    newPage = Integer.parseInt(zzys);
                } else {
                    newPage = newPage + Integer.parseInt(zzys);
                }
                packingManage.setBoxNumber(box);
                packingManageService.saveOrUpdate(packingManage);
                String updateSql = "update " + mainTableName + " set HH = '" + box + "' 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);
        }
    }
 
    /**
     * 文件装盒
     *
     * @return
     */
    public AjaxResponse packagingBoxCg(Long viewId, ArrayList<Long> idList) {
        try {
            //分成果和原始  原始盒子命名规则最大号,成果文件报告号
            //解析纸张大小, 获取最大盒子号,进行装盒 500页
            String box = "01";
            int newPage = 0;
            View view = viewService.getViewById(viewId);
            String mainTableName = view.getMainTableName();
            String selectSqlOne = "select * from " + mainTableName + " where id = " + idList.get(0);
            Map<String, Object> mapList = jdbcTemplate.queryForMap(selectSqlOne);
            String sl = mapList.get("SL") == null ? "0" : mapList.get("SL").toString();
            for (int i = 1; i <= Integer.parseInt(sl); i++) {
                DecimalFormat df = new DecimalFormat("00");
                String cover = df.format(i);
                for (int j = 0; j < idList.size(); j++) {
                    String selectSql = "select * from " + mainTableName + " where id = " + idList.get(j);
                    Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
                    String zzys = map.get("ZZYS") == null ? "0" : map.get("ZZYS").toString();
 
                    String id = StringUtil.nullToEmpty(map.get("ID")).trim();
                    String dh = StringUtil.nullToEmpty(map.get("DH")).trim();
                    String bgbh = StringUtil.nullToEmpty(map.get("BGBH")).trim();
                    String ajId = StringUtil.nullToEmpty(map.get("AJ_ID")).trim();
 
 
                    PackingManage packingManage = new PackingManage();
                    packingManage.setItemNum(dh + "-" + i);
                    packingManage.setItemId(id);
                    packingManage.setAjId(ajId);
                    packingManage.setType(0);
                    packingManage.setCreateTime(new java.util.Date());
 
                    //计算盒号
                    if (newPage + Integer.parseInt(zzys) > 500) {
                        int num = Integer.parseInt(box);
                        num += 1;
                        String newBox = df.format(num);
                        box = newBox;
                        newPage = Integer.parseInt(zzys);
                        packingManage.setBoxNumber(bgbh + "-" + cover + "-" + newBox);
                    } else {
                        newPage = newPage + Integer.parseInt(zzys);
                        packingManage.setBoxNumber(bgbh + "-" + cover + "-" + box);
                    }
                    packingManageService.saveOrUpdate(packingManage);
                }
 
            }
 
//            for (int i = 0; i < idList.size(); i++) {
//                String selectSql = "select * from " + mainTableName + " where id = " + idList.get(i);
//                Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
//                String zzys = map.get("ZZYS") == null ? "0" : map.get("ZZYS").toString();
//                String dh = map.get("DH") == null ? "0" : map.get("DH").toString();
//                if (newPage + Integer.parseInt(zzys) > 500) {
//                    int num = Integer.parseInt(box);
//                    num += 1;
//                    DecimalFormat df = new DecimalFormat("0000");
//                    String newBox = df.format(num);
//                    box = newBox;
//                    newPage = Integer.parseInt(zzys);
//                } else {
//                    newPage = newPage + Integer.parseInt(zzys);
//                }
//                String updateSql = "update " + mainTableName + " set HH = '" + box + "' where id = " + idList.get(i);
//                jdbcTemplate.update(updateSql);
//
//
//                //查询拆分了几份
//                QueryWrapper<PackingManage> packingManageQueryWrapper = new QueryWrapper<>();
//                packingManageQueryWrapper.eq("item_id", idList.get(i));
//                List<PackingManage> packingManageList = packingManageService.list(packingManageQueryWrapper);
//                for (int j = 0; j < packingManageList.size(); j++) {
//                    PackingManage packingManage = packingManageList.get(j);
//                    if (newPage + Integer.parseInt(zzys) > 500) {
//                        int num = Integer.parseInt(box);
//                        num += 1;
//                        DecimalFormat df = new DecimalFormat("00");
//                        String newBox = df.format(num);
//                        box = newBox;
//                        newPage = Integer.parseInt(zzys);
//                        packingManage.setBoxNumber(dh + "-" + newBox);
//                    } else {
//                        newPage = newPage + Integer.parseInt(zzys);
//                        packingManage.setBoxNumber(dh + "-" + box);
//                    }
//                    if (j == 0) {
//                        String updateSql = "update " + mainTableName + " set HH = '" + dh + "-" + box + "' where id = " + idList.get(i);
//                        jdbcTemplate.update(updateSql);
//                    }
//                    packingManageService.saveOrUpdate(packingManage);
//                }
//            }
            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 createArchiveCode(Long viewId, ArrayList<Long> idList) {
        try {
            Long aLong = idList.get(0);
            String selectSql = "select AJ_ID from CAT_ITEM_YSWJXX  where id = " + aLong;
            Map<String, Object> map = jdbcTemplate.queryForMap(selectSql);
            Long ajId = map.get("AJ_ID") == null ? 0 : Long.parseLong(map.get("AJ_ID").toString());
            String sql = "select  DH FROM CAT_FILE_AJJXX where  id = " + ajId;
            Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(sql);
            String maxDH = stringObjectMap.get("DH") == null ? "" : stringObjectMap.get("DH").toString();
            for (int i = 0; i < idList.size(); i++) {
                String sqlSelect = "select JNXH from CAT_ITEM_YSWJXX where id = " + idList.get(i);
                Map<String, Object> stringObjectMap1 = jdbcTemplate.queryForMap(sqlSelect);
                String jnxh = stringObjectMap1.get("JNXH") == null ? "" : stringObjectMap1.get("JNXH").toString();
                String dh = maxDH + "-" + jnxh;
                String updateSql = "update CAT_ITEM_YSWJXX set DH = '" + dh + "' 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);
        }
    }
 
}