From 2e64c232ab6b51b2cecf1ee96e1e9b709234f326 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期六, 21 八月 2021 16:35:14 +0800
Subject: [PATCH] 随手拍改版接口开发

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSwRotaServiceImpl.java |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSwRotaServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSwRotaServiceImpl.java
index 7ca46d7..9508c03 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSwRotaServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComSwRotaServiceImpl.java
@@ -1,5 +1,6 @@
 package com.panzhihua.service_community.service.impl;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -179,7 +180,7 @@
                     return R.fail("该值班表不存在");
                 }
                 ComSwRotaDO checkCreditCode = comSwRotaDAO.selectOne(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, comSwRotaSaveDTO.getRotaDate()));
-                if (null != checkCreditCode && comSwRotaDO.getId() != checkCreditCode.getId()) {
+                if (null != checkCreditCode && !comSwRotaDO.getId().equals(checkCreditCode.getId())) {
                     return R.fail("该值班表已存在,值班日期重复");
                 }
                 BeanUtils.copyProperties(comSwRotaSaveDTO, comSwRotaDO);
@@ -225,6 +226,9 @@
         }catch (ParseException e) {
                 e.printStackTrace();
         }
+        if (comSwRotaDO == null) {
+            return R.fail(rotaDate + "值班表不存在");
+        }
         List<ComSwRotaPersonVO> rotaPersons = new ArrayList<>();
         if (null != comSwRotaDO){
             String rotaPerson = comSwRotaDO.getRotaPerson();
@@ -252,6 +256,9 @@
         } catch (ParseException e) {
             e.printStackTrace();
         }
+        if (comSwRotaDO == null) {
+            return R.fail(rotaDate + "值班表不存在");
+        }
         List<ComSwRotaPersonVO> rotaLeaders = new ArrayList<>();
         if (null != comSwRotaDO){
             String rotaPerson = comSwRotaDO.getRotaLeader();
@@ -278,9 +285,11 @@
 
     @Override
     public R listSaveSwRotaExcelVO(List<ComSwRotaExcelVO> list, Long communityId) {
+        String[] parsePatterns = new String[]{"yyyy-MM-dd", "yyyy-M-dd", "yyyy-MM-d", "yyyy-M-d", "yyyy/MM/dd", "yyyy/M/dd", "yyyy/MM/d", "yyyy/M/d"};
         List<ComSwRotaDO> comSwRotaDOS = new ArrayList<>();
             for (ComSwRotaExcelVO comSwRotaExcelVO : list){
-                Integer count = comSwRotaDAO.selectCount(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, comSwRotaExcelVO.getRotaDate()));
+                Date date = DateUtil.parse(comSwRotaExcelVO.getRotaDate(),parsePatterns);
+                Integer count = comSwRotaDAO.selectCount(new QueryWrapper<ComSwRotaDO>().lambda().eq(ComSwRotaDO::getRotaDate, date));
                 if (count > 0) {
                     return R.fail("值班日期已存在," + comSwRotaExcelVO.getRotaDate() + "重复");
                 }
@@ -309,21 +318,22 @@
                 BeanUtils.copyProperties(comSwRotaExcelVO, comSwRotaDO);
                 comSwRotaDO.setId(Snowflake.getId());
                 comSwRotaDO.setCommunityId(communityId);
-                if (StringUtils.isNotEmpty(comSwRotaExcelVO.getRotaDate())) {
-                    String el = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)   \n" +
-                            "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ";
-                    Pattern p = Pattern.compile(el);
-                    Matcher m = p.matcher(comSwRotaExcelVO.getRotaDate());
-                    if (!m.matches()) {
-                        return R.fail(comSwRotaExcelVO.getRotaDate() + "日期格式不正确");
-                    }
-                }
-                try {
-                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-                    comSwRotaDO.setRotaDate(sdf.parse(comSwRotaExcelVO.getRotaDate()));
-                } catch (ParseException e) {
-                    e.printStackTrace();
-                }
+//                if (StringUtils.isNotEmpty(comSwRotaExcelVO.getRotaDate())) {
+//                    String el = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)   \n" +
+//                            "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) ";
+//                    Pattern p = Pattern.compile(el);
+//                    Matcher m = p.matcher(comSwRotaExcelVO.getRotaDate());
+//                    if (!m.matches()) {
+//                        return R.fail(comSwRotaExcelVO.getRotaDate() + "日期格式不正确");
+//                    }
+//                }
+//                try {
+//                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+//                    comSwRotaDO.setRotaDate(sdf.parse(comSwRotaExcelVO.getRotaDate()));
+//                } catch (ParseException e) {
+//                    e.printStackTrace();
+//                }
+                comSwRotaDO.setRotaDate(date);
                 comSwRotaDO.setRotaLeader(StringUtils.join(leaderIds, ","));
                 comSwRotaDO.setRotaPerson(StringUtils.join(personIds, ","));
                 comSwRotaDO.setLeaderName(comSwRotaExcelVO.getLeaderName().replace("、",","));

--
Gitblit v1.7.1