Browse Source

判断是否是工作日,非工作日不锁定工时

seyason 2 years ago
parent
commit
b3d2bf2bdf

+ 23 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/AuthRedirectController.java

@@ -2,14 +2,12 @@ package com.management.platform.controller;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.management.platform.entity.Company;
-import com.management.platform.entity.Project;
-import com.management.platform.entity.SysConfig;
-import com.management.platform.entity.User;
+import com.management.platform.entity.*;
 import com.management.platform.entity.vo.UserVO;
 import com.management.platform.mapper.CompanyMapper;
 import com.management.platform.mapper.SysConfigMapper;
 import com.management.platform.mapper.UserMapper;
+import com.management.platform.mapper.WxCorpInfoMapper;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.UserAgentUtils;
@@ -54,6 +52,8 @@ public class AuthRedirectController {
     RestTemplate restTemplate;
     @Resource
     UserMapper userMapper;
+    @Resource
+    WxCorpInfoMapper wxCorpInfoMapper;
 
     @RequestMapping("/corpWXAuth")
     public ModelAndView auth(String code, String state) {
@@ -70,6 +70,8 @@ public class AuthRedirectController {
         System.out.println("企微身份:"+obj.toString());
         String wxUserId = obj.getString("UserId");
         String openUserId = obj.getString("open_userid");
+        String corpId = obj.getString("CorpId");
+
         System.out.println("wxUserId="+wxUserId+", openUserId="+openUserId);
         List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", openUserId));
         if (userList.size() > 0) {
@@ -83,6 +85,23 @@ public class AuthRedirectController {
                 //reqParam.put("errorMsg", "您的账号已停用,无法登录");
                 reqParam.put("errorMsg", MessageUtils.message("user.inactive"));
             }
+        } else {
+            //使用UserId比对,之前有的老用户存的是UserId
+            WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
+            if (wxCorpInfo == null) {
+                reqParam.put("errorMsg", MessageUtils.message("user.accountNoExist"));
+            } else {
+                User curUser = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_userid", wxUserId));
+                if (curUser == null) {
+                    reqParam.put("errorMsg", MessageUtils.message("user.accountNoExist"));
+                } else if (curUser.getIsActive() == 1) {
+                    reqParam.put("userId", curUser.getId());
+                } else {
+                    //提示账号已停用
+                    //reqParam.put("errorMsg", "您的账号已停用,无法登录");
+                    reqParam.put("errorMsg", MessageUtils.message("user.inactive"));
+                }
+            }
         }
         reqParam.put("hasTriedAutoLogin", 1);
         String redirecUrl = null;

+ 17 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ReportController.java

@@ -1270,6 +1270,23 @@ public class ReportController {
         return reportService.exportUserDailyWorkTime(request, startDate, endDate);
     }
 
+    @RequestMapping("/isWorkDay")
+    public HttpRespMsg isWorkDay(String date) {
+        HttpRespMsg msg = new HttpRespMsg();
+        String token = request.getHeader("TOKEN");
+        if (token == null) {
+            //
+            //msg.setError("请求非法");
+            msg.setError(MessageUtils.message("request.illegal"));
+            System.err.println("==有非法请求===" + date);
+        } else {
+            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate lDate = LocalDate.parse(date, dtf);
+            msg.data = WorkDayCalculateUtils.isWorkDay(lDate);
+        }
+        return msg;
+    }
+
     /**
      * 计算给定时间段内的工作日数量
      * @param startDate 开始日期

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -652,6 +652,11 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
             if (company.getPackageProject() == 1) {
                 timeBasecostList = projectBasecostSettingMapper.selectList(new QueryWrapper<ProjectBasecostSetting>().eq("company_id", companyId).eq("alarm_type", 1));
             }
+            //当天是否是工作日
+            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate lDate = LocalDate.parse(date, dtf);
+            boolean isWorkDay = companyId == 817 ? WorkDayCalculateUtils.isWorkDayExceptSaturday(lDate) : WorkDayCalculateUtils.isWorkDay(lDate);
+            resultMap.put("isWorkDay", isWorkDay);
 
             resultMap.put("timeBasecostList",timeBasecostList);
 

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/WxCorpInfoServiceImpl.java

@@ -208,6 +208,7 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
             JSONObject reqParam = new JSONObject();
             reqParam.put("touser", corpUserid);
             reqParam.put("msgtype", "text");
+            reqParam.put("enable_id_trans", 1);
             reqParam.put("agentid", corpInfo.getAgentid());
             JSONObject contentJson = new JSONObject();
             contentJson.put("content", msg);
@@ -219,7 +220,6 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
             if (responseEntity.getStatusCode() == HttpStatus.OK) {
                 String resp = responseEntity.getBody();
                 log.info("发送企业微信消息返回结果==" + resp);
-                System.out.println("发送企业微信消息返回结果==" + resp);
                 JSONObject json = JSONObject.parseObject(resp);
                 if (json.getIntValue("errcode") == 0) {
                     //发送成功

+ 41 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/WorkDayCalculateUtils.java

@@ -167,6 +167,47 @@ public class WorkDayCalculateUtils {
         }
         return false;
     }
+    //一周6天工作制,周六也算工作日
+    public static boolean isWorkDayExceptSaturday(LocalDate date) {
+        int year = date.getYear();
+        try {
+            String dateStr = dateTimeFormatter.format(date);
+            Date d = simpleDateFormat.parse(dateStr);
+            boolean isWeekend = date.getDayOfWeek() == DayOfWeek.SUNDAY;
+            if (isWeekend) {
+                //判断周末是否是特殊工作日
+                HashMap<String, String[]> map = YEAR_DEFINE.get(year + "");
+                if (map == null) {
+                    //特殊日期年份尚未录入,周末不算是工作日
+                    return false;
+                }
+                String[] list = map.get(KEY_SPECIAL_WORK_DAYS);
+                if (isInArray(dateStr, list)) {
+                    //存在特殊工作日
+                    return true;
+                } else {
+                    return false;
+                }
+            } else {
+                //判断常规周一到周六,是否是特殊节假日
+                HashMap<String, String[]> map = YEAR_DEFINE.get(year+"");
+                if (map == null) {
+                    //特殊日期年份尚未录入,工作日正常上班
+                    return true;
+                }
+                String[] list = map.get(KEY_SPECIAL_REST_DAYS);
+                if (isInArray(dateStr, list)) {
+                    return false;
+                } else {
+                    return true;
+                }
+            }
+        } catch (ParseException e) {
+            e.printStackTrace();
+            System.out.println(e.getMessage());
+        }
+        return true;
+    }
 
     public static boolean isWorkDay(LocalDate date) {
         int year = date.getYear();

+ 2 - 0
fhKeeper/formulahousekeeper/timesheet/src/views/workReport/daily.vue

@@ -4076,6 +4076,8 @@
                         this.jsTime = quanbu
                         var list = res.data;
                         this.report = list;
+                        //从后端接口的数据设置是否是周末,后端会判断节假日以及中航工业一周6天工作日的情况
+                        this.isWeekend = !this.report.isWorkDay;
                         
                         this.canCancelInDialog = false
                         if(list.report.length != 0) {