Procházet zdrojové kódy

Merge remote-tracking branch 'origin/master'

梁世豪 před 5 měsíci
rodič
revize
41800ad2d7

+ 63 - 0
src/main/java/com/liang/common/utils/DateUtil.java

@@ -0,0 +1,63 @@
1
+package com.liang.common.utils;
2
+
3
+import java.time.LocalDate;
4
+import java.time.format.DateTimeFormatter;
5
+import java.time.temporal.ChronoUnit;
6
+import java.util.Locale;
7
+
8
+/**
9
+ * @Author ly
10
+ * @Date 2024/6/30 17:44
11
+ * @Version 1.0
12
+ */
13
+public class DateUtil {
14
+    public String convertDate(String inputDate) {
15
+        if (inputDate == null || inputDate.isEmpty()) {
16
+            return "";
17
+        }
18
+        // 定义输入格式的日期时间格式化器
19
+        DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("dd-LLL-yyyy", Locale.CHINESE);
20
+
21
+        // 将字符串解析为 LocalDate 对象
22
+        LocalDate date = LocalDate.parse(inputDate, inputFormatter);
23
+
24
+        // 定义输出格式的日期时间格式化器
25
+        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
26
+
27
+        // 格式化日期为所需的输出格式
28
+        String formattedDate = date.format(outputFormatter);
29
+
30
+        return formattedDate;
31
+    }
32
+    /**
33
+     * 判断两个给定日期是否相差少于三个月
34
+     * @param startDate 开始日期
35
+     * @param endDate 结束日期
36
+     * @return 如果 startDate 和 endDate 相差少于三个月返回 true,否则返回 false
37
+     */
38
+    public boolean isWithinThreeMonths(LocalDate startDate, LocalDate endDate) {
39
+        // 计算 startDate 和 endDate 之间的月份差距
40
+        long monthsApart = ChronoUnit.MONTHS.between(startDate, endDate);
41
+
42
+        // 判断绝对差距是否小于三个月
43
+        return Math.abs(monthsApart) < 3;
44
+    }
45
+    public  boolean areDatesWithinThreeMonths(String startDateStr, String endDateStr) {
46
+        if (startDateStr.isEmpty() || endDateStr.isEmpty() ){
47
+            return false;
48
+        }
49
+        // 将字符串日期转换为 LocalDate 对象
50
+        LocalDate startDate = LocalDate.parse(startDateStr, DateTimeFormatter.ISO_DATE);
51
+        LocalDate endDate = LocalDate.parse(endDateStr, DateTimeFormatter.ISO_DATE);
52
+
53
+        // 使用已有方法检查
54
+        return areDatesWithinThreeMonths(startDate, endDate);
55
+    }
56
+    public  boolean areDatesWithinThreeMonths(LocalDate startDate, LocalDate endDate) {
57
+        // 计算 startDate 和 endDate 之间的月份差距
58
+        long monthsApart = ChronoUnit.MONTHS.between(startDate, endDate);
59
+
60
+        // 判断绝对差距是否小于三个月
61
+        return Math.abs(monthsApart) < 3;
62
+    }
63
+}

+ 145 - 4
src/main/java/com/liang/controller/LsUserController.java

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
4 4
 import com.github.pagehelper.PageInfo;
5 5
 import com.liang.common.JsonTool;
6 6
 import com.liang.common.base.BaseResult;
7
+import com.liang.common.utils.DateUtil;
7 8
 import com.liang.entity.BasePerson;
8 9
 import com.liang.entity.SysLsUserEntity;
9 10
 
@@ -12,20 +13,36 @@ import com.liang.service.BaseEducationService;
12 13
 import com.liang.service.LsUserService;
13 14
 import io.swagger.annotations.ApiOperation;
14 15
 import io.swagger.models.auth.In;
16
+import org.apache.commons.io.FilenameUtils;
15 17
 import org.apache.ibatis.annotations.Delete;
18
+import org.apache.poi.ss.usermodel.Cell;
19
+import org.apache.poi.ss.usermodel.Row;
20
+import org.apache.poi.ss.usermodel.Sheet;
21
+import org.apache.poi.ss.usermodel.Workbook;
22
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
16 23
 import org.springframework.beans.factory.annotation.Autowired;
24
+import org.springframework.core.io.ClassPathResource;
25
+import org.springframework.http.HttpHeaders;
26
+import org.springframework.http.HttpStatus;
27
+import org.springframework.http.MediaType;
17 28
 import org.springframework.http.ResponseEntity;
18 29
 import org.springframework.stereotype.Controller;
19 30
 import org.springframework.ui.Model;
20 31
 import org.springframework.web.bind.annotation.*;
32
+import org.springframework.web.multipart.MultipartFile;
33
+import org.springframework.web.multipart.MultipartHttpServletRequest;
21 34
 
22 35
 import javax.annotation.Resource;
23 36
 import javax.xml.transform.Result;
37
+import java.io.IOException;
38
+import java.io.InputStream;
39
+import java.nio.file.Path;
40
+import java.nio.file.Paths;
41
+import java.text.DateFormat;
24 42
 import java.text.SimpleDateFormat;
25
-import java.util.Date;
26
-import java.util.HashMap;
27
-import java.util.List;
28
-import java.util.Map;
43
+import java.time.LocalDate;
44
+import java.time.format.DateTimeFormatter;
45
+import java.util.*;
29 46
 
30 47
 import static com.liang.common.base.BaseController.RESULT_ROWS;
31 48
 import static com.liang.common.base.BaseController.RESULT_TOTAL;
@@ -44,6 +61,10 @@ public class LsUserController {
44 61
     @Resource
45 62
     private BaseEducationService baseEducationService;
46 63
 
64
+    // 允许的表格文件扩展名列表
65
+    private final List<String> allowedExtensions = Arrays.asList("xls", "xlsx", "csv");
66
+
67
+
47 68
     @ApiOperation(value = "页面初始化", notes = "页面初始化")
48 69
     @RequestMapping(value = "/init", method = RequestMethod.GET)
49 70
     public String init( Model model) {
@@ -206,5 +227,125 @@ public class LsUserController {
206 227
         return BaseResult.failure("该人员不存在");
207 228
     }
208 229
 
230
+    @PostMapping("/file")
231
+    @ResponseBody
232
+    public BaseResult handleFileUpload(@RequestParam("file") MultipartFile file) {
233
+        if (file.isEmpty()){
234
+            return BaseResult.failure("上传文件异常,上传失败!");
235
+        }
236
+        List<SysLsUserEntity> lists = new ArrayList<>();
237
+        Integer h = 0;
238
+        try{
239
+            // 验证文件类型
240
+
241
+            DateUtil dateUtil = new DateUtil();
242
+            String fileExtension = FilenameUtils.getExtension(file.getOriginalFilename());
243
+            if (!allowedExtensions.contains(fileExtension.toLowerCase())) {
244
+                return BaseResult.failure("只允许上传 Excel文件");
245
+            }
246
+            // 开始解析这个文件
247
+            List<List<String>> spreadsheetData = parseSpreadsheet(file.getInputStream(), fileExtension);
248
+            System.out.println(spreadsheetData);
249
+            spreadsheetData.remove(0);
250
+            List<SysLsUserEntity> list = new ArrayList<>();
251
+            for (List<String> row : spreadsheetData) {
252
+                SysLsUserEntity employee = new SysLsUserEntity();
253
+                // 设置员工信息
254
+                employee.setXm(row.get(0));
255
+                employee.setXb(row.get(1));
256
+                employee.setPhone(row.get(2));
257
+                employee.setSfzh(row.get(3));
258
+                employee.setXl(row.get(4));
259
+                employee.setByxy(row.get(5));
260
+                employee.setZy(row.get(6));
261
+                employee.setQpsj(dateUtil.convertDate(row.get(7)));
262
+                employee.setDqsj(dateUtil.convertDate(row.get(8)));
263
+                employee.setGznr(row.get(9));
264
+                // 将对象添加到列表中
265
+                list.add(employee);
266
+            }
267
+            System.out.println(list);
268
+
269
+            for(int i = 0; i<list.size();i++){
270
+                SysLsUserEntity sysLsUserEntity = new SysLsUserEntity();
271
+                // 校验合同起始时间和到期时间是否在三个月 内
272
+                if (dateUtil.areDatesWithinThreeMonths(list.get(i).getDqsj(), list.get(i).getQpsj()) !=true) {
273
+                    sysLsUserEntity.setXm(list.get(i).getXm());
274
+                    // xmfzr 这个字段存储未能存储原因
275
+                    sysLsUserEntity.setXmfzr("聘用日期不能大于三个月");
276
+                    sysLsUserEntity.setSfzh(list.get(i).getSfzh());
277
+                    sysLsUserEntity.setDqsj(list.get(i).getDqsj());
278
+                    sysLsUserEntity.setQpsj(list.get(i).getQpsj());
279
+                    if (list.get(i).getXm().isEmpty() && list.get(i).getSfzh().isEmpty()){
280
+                        continue;
281
+                    }
282
+                    lists.add(sysLsUserEntity);
283
+                    continue;
284
+                }
285
+                // 校验当前传入的 身份证号 是否在数据库中存在
286
+                if (lsUserService.jy(list.get(i).getSfzh()) != true){
287
+                    sysLsUserEntity.setXm(list.get(i).getXm());
288
+                    sysLsUserEntity.setSfzh(list.get(i).getSfzh());
289
+                    sysLsUserEntity.setDqsj(list.get(i).getDqsj());
290
+                    sysLsUserEntity.setQpsj(list.get(i).getQpsj());
291
+                    // xmfzr 这个字段存储未能存储原因
292
+                    sysLsUserEntity.setXmfzr("该人员身份证已存在");
293
+                    if (list.get(i).getXm().isEmpty() && list.get(i).getSfzh().isEmpty()){
294
+                        continue;
295
+                    }
296
+                    lists.add(sysLsUserEntity);
297
+
298
+                    continue;
299
+                }
300
+               Integer mum = lsUserService.saveOperLog(list.get(i));
301
+               if (mum > 0){
302
+                   h++;
303
+                   continue;
304
+               }
305
+            }
306
+        }catch (Exception a){
307
+            a.printStackTrace();
308
+        }
309
+
310
+        // 获取文件名后缀
311
+        if (h == 0){
312
+            return BaseResult.failure(43,"成员录入失败,人员已存在!");
313
+        }
314
+        return BaseResult.success("成员录入成功",lists);
315
+    }
316
+    private List<List<String>> parseSpreadsheet(InputStream inputStream, String fileExtension) throws IOException {
317
+        Workbook workbook = null;
318
+        if (fileExtension.equalsIgnoreCase("xlsx")) {
319
+            workbook = new XSSFWorkbook(inputStream);
320
+        } else if (fileExtension.equalsIgnoreCase("xls")) {
321
+            throw new IOException("上传的Excel文件格式不支持,请上传xlsx格式文件。");
322
+        } else if (fileExtension.equalsIgnoreCase("csv")) {
323
+            throw new IOException("上传的文件是CSV格式,当前不支持解析,请上传Excel文件。");
324
+        }
325
+
326
+        List<List<String>> spreadsheetData = new ArrayList<>();
327
+        if (workbook != null) {
328
+            Sheet sheet = workbook.getSheetAt(0);
329
+            Iterator<Row> iterator = sheet.iterator();
330
+
331
+            while (iterator.hasNext()) {
332
+                Row currentRow = iterator.next();
333
+                Iterator<Cell> cellIterator = currentRow.iterator();
334
+
335
+                List<String> rowData = new ArrayList<>();
336
+                while (cellIterator.hasNext()) {
337
+                    Cell currentCell = cellIterator.next();
338
+                    rowData.add(currentCell.toString());
339
+                }
340
+
341
+                spreadsheetData.add(rowData);
342
+            }
343
+
344
+            workbook.close();
345
+        }
346
+
347
+        return spreadsheetData;
348
+    }
349
+
209 350
 
210 351
 }

+ 8 - 2
src/main/java/com/liang/controller/StaStatisticalSummaryController.java

@@ -76,8 +76,12 @@ public class StaStatisticalSummaryController extends BaseController {
76 76
                                      @RequestParam(required = false, defaultValue = "", value = "QS") String qs,
77 77
                                      @RequestParam(required = false, defaultValue = "", value = "WC") String wc
78 78
     ) {
79
+        Map<String, String> map = new HashMap<>();
80
+        map.put("xmmc",xmmc);
81
+        map.put("qs",qs);
82
+        map.put("wc",wc);
79 83
         PageHelper.startPage(pageNum, pageSize);
80
-        List<HashMap<String, Object>> staFeasibilityreport = staStatisticalSummaryService.projectPay(xmmc, qs, wc);
84
+        List<HashMap<String, Object>> staFeasibilityreport = staStatisticalSummaryService.projectPay(map);
81 85
         PageInfo<HashMap<String, Object>> pageinfo = new PageInfo<>(staFeasibilityreport);
82 86
         List<HashMap<String, Object>> rows = pageinfo.getList();
83 87
         int total = (int) pageinfo.getTotal();
@@ -93,7 +97,9 @@ public class StaStatisticalSummaryController extends BaseController {
93 97
     @RequestMapping(value = "/getAll",method = RequestMethod.GET)
94 98
     public BaseResult getAll(){
95 99
 
96
-        List<HashMap<String, Object>> staFeasibilityreport = staStatisticalSummaryService.projectPay("", "", "");
100
+        Map<String, String> map = new HashMap<>();
101
+
102
+        List<HashMap<String, Object>> staFeasibilityreport = staStatisticalSummaryService.projectPay(map);
97 103
         return BaseResult.success(staFeasibilityreport);
98 104
     }
99 105
 

+ 1 - 1
src/main/java/com/liang/dao/PrjFeeschemeDao.java

@@ -128,6 +128,6 @@ public interface PrjFeeschemeDao {
128 128
 
129 129
     double queryByCzje(double czje);
130 130
 
131
-    double getNdFeeSchemeofDKY(Map map);
131
+    Double getNdFeeSchemeofDKY(Map map);
132 132
 }
133 133
 

+ 2 - 1
src/main/java/com/liang/dao/StaStatisticalSummaryDao.java

@@ -2,6 +2,7 @@ package com.liang.dao;
2 2
 
3 3
 import java.util.HashMap;
4 4
 import java.util.List;
5
+import java.util.Map;
5 6
 
6 7
 /**
7 8
  * 统计报表汇总表
@@ -18,5 +19,5 @@ public interface StaStatisticalSummaryDao {
18 19
      */
19 20
     List<HashMap<String, Object>> outPaySummary(String XMMC, String QSRQ, String JSRQ);
20 21
 
21
-    List<HashMap<String, Object>> projectPay(String XMMC, String QS, String WC);
22
+    List<HashMap<String, Object>> projectPay(Map map);
22 23
 }

+ 1 - 0
src/main/java/com/liang/service/LsUserService.java

@@ -52,4 +52,5 @@ public interface LsUserService {
52 52
 
53 53
 
54 54
     List<SysLsUserEntity> getZb(Integer zb);
55
+    boolean jy(String sfzh);
55 56
 }

+ 2 - 1
src/main/java/com/liang/service/StaStatisticalSummaryService.java

@@ -6,6 +6,7 @@ import org.springframework.data.domain.PageRequest;
6 6
 
7 7
 import java.util.HashMap;
8 8
 import java.util.List;
9
+import java.util.Map;
9 10
 
10 11
 /**
11 12
  * 经费预算(StaBudget)表服务接口
@@ -25,6 +26,6 @@ public interface StaStatisticalSummaryService {
25 26
      */
26 27
     List<HashMap<String, Object>> outPaySummary(String XMMC, String QSRQ, String JSRQ);
27 28
 
28
-    List<HashMap<String, Object>> projectPay(String xmmc, String qs, String wc);
29
+    List<HashMap<String, Object>> projectPay(Map map);
29 30
 
30 31
 }

+ 12 - 0
src/main/java/com/liang/service/impl/LsUserServiceImpl.java

@@ -15,6 +15,7 @@ import java.text.DateFormat;
15 15
 import java.text.DecimalFormat;
16 16
 import java.text.SimpleDateFormat;
17 17
 import java.util.Date;
18
+import java.util.HashMap;
18 19
 import java.util.List;
19 20
 import java.util.Map;
20 21
 
@@ -82,6 +83,17 @@ public class LsUserServiceImpl implements LsUserService {
82 83
         return this.lsUserDao.getZb(zb);
83 84
     }
84 85
 
86
+    @Override
87
+    public boolean jy(String sfzh) {
88
+        Map<String, String>map = new HashMap<>();
89
+        map.put("sfzh",sfzh);
90
+        List<SysLsUserEntity> sysLsUserEntity = lsUserDao.getUserxm(map);
91
+        if (sysLsUserEntity.size()>0){
92
+            return false;
93
+        }
94
+        return true;
95
+    }
96
+
85 97
     @Override
86 98
     public int batchDelete(List<Integer> idList) {
87 99
 

+ 3 - 2
src/main/java/com/liang/service/impl/StaStatisticalSummaryServiceImpl.java

@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
7 7
 import javax.annotation.Resource;
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
10
+import java.util.Map;
10 11
 
11 12
 @Service("staStatisticalSummaryService")
12 13
 public class StaStatisticalSummaryServiceImpl implements StaStatisticalSummaryService {
@@ -20,8 +21,8 @@ public class StaStatisticalSummaryServiceImpl implements StaStatisticalSummarySe
20 21
     }
21 22
 
22 23
     @Override
23
-    public List<HashMap<String, Object>> projectPay(String xmmc, String qs, String wc) {
24
-        return staStatisticalSummaryDao.projectPay(xmmc, qs, wc);
24
+    public List<HashMap<String, Object>> projectPay(Map map) {
25
+        return staStatisticalSummaryDao.projectPay(map);
25 26
     }
26 27
 
27 28
 }

+ 1 - 1
src/main/resources/templates/annualbudget/view_annualbudget.html

@@ -106,7 +106,7 @@
106 106
                             <label class="layui-form-label" style="width: 90px">电科院负责人</label>
107 107
                             <div class="layui-input-inline" style="width: 370px">
108 108
                                 <input type="text" id="xmfzrxm" name="xmfzrxm" class="layui-input"
109
-                                       th:value="${annualbudget.xmfzrxm}" readonly>
109
+                                       th:value="${annualbudget.dkyfzrxm}" readonly>
110 110
                             </div>
111 111
                             <label class="layui-form-label" style="width: 65px">所属部门</label>
112 112
                             <div class="layui-input-inline" style="width: 370px">

+ 59 - 24
src/main/resources/templates/lsuserinfo/list.html

@@ -67,20 +67,14 @@
67 67
                     <i class="layui-icon layui-icon-addition" style="font-size: 10px;"></i>新增
68 68
                 </button>
69 69
                 <button class="layui-btn layui-btn-sm" lay-event="export" >
70
-                    <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>全部导出
70
+                    <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>批量导出
71 71
                 </button>
72 72
                 <button class="layui-btn layui-btn-sm" lay-event="download"  style="background-color: purple">
73 73
                     <i class="layui-icon layui-icon-download-circle" style="font-size: 10px;"></i>模板下载
74 74
                 </button>
75
-            </div>
76
-            <!--文件上传的div-->
77
-            <div class="layui-upload-drag" id="excel">
78
-                <i class="layui-icon"></i>
79
-                <p>点击上传,或将文件拖拽到此处</p>
80
-                <div class="layui-hide" id="uploadDemoView">
81
-                    <hr>
82
-                    <img src="" alt="上传成功后渲染" style="max-width: 196px">
83
-                </div>
75
+                <button type="button" class="layui-btn layui-btn-sm" id="test3">
76
+                    <i class="layui-icon"></i>批量导入
77
+                </button>
84 78
             </div>
85 79
 
86 80
         </script>
@@ -109,22 +103,11 @@
109 103
 <script type="text/javascript" th:inline="javascript">
110 104
     AjaxUtil.ctx = /*[[@{/}]]*/'';
111 105
     var updateflag = 0;
112
-    layui.use(['form', 'table'], function () {
106
+    layui.use(['form', 'table','upload'], function () {
113 107
         var form = layui.form,
114 108
             table = layui.table,
115 109
             layer = layui.layer,
116
-            upload = layui.upload;
117
-        upload.render({
118
-            elem: '#excel',
119
-            url:AjaxUtil.ctx +'',
120
-            accept:'file',
121
-            done: function (res) {
122
-                layer.msg(res.msg);
123
-                console.log(res);
124
-                
125
-            }
126
-        });
127
-
110
+         upload = layui.upload;
128 111
         var currTable = table.render({
129 112
             elem: '#currentTableId',
130 113
             url: AjaxUtil.ctx + 'lsUser/all',
@@ -170,7 +153,59 @@
170 153
                 console.log(JSON.stringify(permissionSet));
171 154
             }
172 155
         });
156
+        //指定允许上传的文件类型
157
+        upload.render({
158
+            elem: '#test3'
159
+            , url: AjaxUtil.ctx + 'lsUser/file'
160
+            , method: 'post'
161
+            , accept: 'file' //普通文件
162
+            , done: function (res) {
163
+                console.log(res);
164
+                console.log(res.code);
165
+                if (res.code === 43) {
166
+                    layer.msg(res.message);
167
+                }else {
168
+                    if (res.data && Array.isArray(res.data) && res.data.length > 0) {
169
+                        // 安全访问数组元素或对象属性
170
+                        layer.msg(res.message);
171
+                        table.reload('currentTableId');
172
+                    }
173
+                    console.log(res);
174
+                    // 将 JSON 数据转换成 HTML 表格格式
175
+                    var tableHtml = '<table class="layui-table"><thead><tr>' +
176
+                        '<th>姓名</th>' +
177
+                        '<th>身份证号</th>' +
178
+                        '<th>起聘时间</th>' +
179
+                        '<th>到期时间</th>' +
180
+                        '<th>原因</th>' +
181
+                        '</tr></thead><tbody>';
182
+                    for(var i = 0; i < res.data.length; i++) {
183
+                        var xm = res.data[i].xm || 'N/A';
184
+                        var sfzh = res.data[i].sfzh || 'N/A';
185
+                        var qpsj = res.data[i].qpsj || 'N/A';
186
+                        var dqsj = res.data[i].dqsj || 'N/A';
187
+                        var xmfzr = res.data[i].xmfzr || 'N/A';
173 188
 
189
+                        tableHtml += '<tr>' +
190
+                            '<td>' + xm + '</td>' +
191
+                            '<td>' + sfzh + '</td>' +
192
+                            '<td>' + qpsj + '</td>' +
193
+                            '<td>' + dqsj + '</td>' +
194
+                            '<td>' + xmfzr + '</td>' +
195
+                            '</tr>';
196
+                    };
197
+                    tableHtml += '</tbody></table>';
198
+                    layer.open({
199
+                        type: 1,
200
+                        title: '问题数据', // 弹框标题
201
+                        content: tableHtml, // 弹框内容为生成的表格 HTML
202
+                        area: ['1000px', '600px'] // 设置弹框大小
203
+                    });
204
+                    table.reload('currentTableId');
205
+                }
206
+            },
207
+
208
+    });
174 209
         // 监听搜索操作
175 210
         form.on('submit(data-search-btn)', function (data) {
176 211
             // 执行搜索重载
@@ -271,7 +306,7 @@
271 306
                 });
272 307
 
273 308
             }else if (obj.event === 'download'){
274
-                table.exportFile('currentTableId',' ','xls');
309
+                window.location.href = 'http://10.208.114.107:8082/202407/Template.xlsx';
275 310
             }
276 311
         });
277 312