Jelajahi Sumber

修复打卡接口

Administrator 2 tahun lalu
induk
melakukan
932ff3b0f1

+ 17 - 21
ruoyi-admin/src/main/java/com/ruoyi/web/controller/kaoqin/KaoQinController.java

@@ -4,6 +4,7 @@ import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDictData;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.system.domain.KaoqinConfig;
 import com.ruoyi.system.domain.KaoqinRecord;
 import com.ruoyi.system.domain.PlatPunch;
@@ -11,10 +12,7 @@ import com.ruoyi.system.service.IKaoqinConfigService;
 import com.ruoyi.system.service.IKaoqinRecordService;
 import com.ruoyi.system.service.ISysDictDataService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -93,13 +91,11 @@ public class KaoQinController extends BaseController {
         List<SysDictData> sysDictData = dictDataService.selectDictDataList(dictData);
         Map<String, Long> map = new HashMap();
         for (SysDictData sysDictDatum : sysDictData) {
-            //获取异常名称
-            String dictLabel = sysDictDatum.getDictLabel();
             //获取异常的值
             String dictValue = sysDictDatum.getDictValue();
             if (!"1".equals(dictValue)) {
                 Long aLong = 0L;
-                map.put(dictLabel, aLong);
+                map.put(dictValue, aLong);
             }
         }
         for (KaoqinRecord kaoQinRecord : kaoQinRecords) {
@@ -107,19 +103,19 @@ public class KaoQinController extends BaseController {
             String kaTypeAmOut = kaoQinRecord.getKaTypeAmOut();
             String kaTypePmIn = kaoQinRecord.getKaTypePmIn();
             String kaTypePmOut = kaoQinRecord.getKaTypePmOut();
-            if (!"1".equals(kaTypeAmIn)) {
+            if (!"1".equals(kaTypeAmIn) && StringUtils.isNotBlank(kaTypeAmIn)) {
                 Long aLong = map.get(kaTypeAmIn);
                 map.put(kaTypeAmIn, aLong + 1);
                 count = count + 1;
-            }  if (!"1".equals(kaTypeAmOut)) {
+            }  if (!"1".equals(kaTypeAmOut) && StringUtils.isNotBlank(kaTypeAmOut)) {
                 Long aLong = map.get(kaTypeAmOut);
                 map.put(kaTypeAmOut, aLong + 1);
                 count = count + 1;
-            }  if (!"1".equals(kaTypePmIn)) {
+            }  if (!"1".equals(kaTypePmIn) && StringUtils.isNotBlank(kaTypePmIn)) {
                 Long aLong = map.get(kaTypePmIn);
                 map.put(kaTypePmIn, aLong + 1);
                 count = count + 1;
-            }  if (!"1".equals(kaTypePmOut)) {
+            }  if (!"1".equals(kaTypePmOut) && StringUtils.isNotBlank(kaTypePmOut)) {
                 Long aLong = map.get(kaTypePmOut);
                 map.put(kaTypePmOut, aLong + 1);
                 count = count + 1;
@@ -151,19 +147,19 @@ public class KaoQinController extends BaseController {
                     String kaTypeAmOut = record.getKaTypeAmOut();
                     String kaTypePmIn = record.getKaTypePmIn();
                     String kaTypePmOut = record.getKaTypePmOut();
-                    if (!"1".equals(kaTypeAmIn)) {
+                    if (!"1".equals(kaTypeAmIn) && StringUtils.isNotBlank(kaTypeAmIn)) {
                         abnormal = kaTypeAmIn + ",";
                         flag = false;
                     }
-                    if (!"1".equals(kaTypeAmOut)) {
+                    if (!"1".equals(kaTypeAmOut) && StringUtils.isNotBlank(kaTypeAmOut)) {
                         abnormal = kaTypeAmOut + ",";
                         flag = false;
                     }
-                    if (!"1".equals(kaTypePmIn)) {
+                    if (!"1".equals(kaTypePmIn) && StringUtils.isNotBlank(kaTypePmIn)) {
                         abnormal = kaTypePmIn + ",";
                         flag = false;
                     }
-                    if (!"1".equals(kaTypePmOut)) {
+                    if (!"1".equals(kaTypePmOut) && StringUtils.isNotBlank(kaTypePmOut)) {
                         abnormal = kaTypePmOut + ",";
                         flag = false;
                     }
@@ -193,10 +189,10 @@ public class KaoQinController extends BaseController {
      * @return
      */
     @PostMapping("/clockRecord")
-    public AjaxResult clockRecord(KaoqinRecord kaoqinRecord) {
+    public AjaxResult clockRecord(@RequestBody KaoqinRecord kaoqinRecord) {
         //定义返回值
         List list = new ArrayList();
-        //根据部门祖籍列表查询考勤数据
+        //根据部门id查询考勤数据
         List<KaoqinRecord> kaoqinRecords = kaoqinRecordService.selectKaoqinRecordList(kaoqinRecord);
         if (kaoqinRecords != null) {
             //根据userId进行分组
@@ -234,22 +230,22 @@ public class KaoQinController extends BaseController {
                         String kaTypeAmOut = kaoQinRecord.getKaTypeAmOut();
                         String kaTypePmIn = kaoQinRecord.getKaTypePmIn();
                         String kaTypePmOut = kaoQinRecord.getKaTypePmOut();
-                        if (!"1".equals(kaTypeAmIn)) {
+                        if (!"1".equals(kaTypeAmIn) && StringUtils.isNotBlank(kaTypeAmIn)) {
                             //获取异常的名称
                             String dictLabel = map.get(kaTypeAmIn);
                             Integer num = (Integer) userMap.get(dictLabel);
                             userMap.put(dictLabel, num + 1);
-                        }  if (!"1".equals(kaTypeAmOut)) {
+                        }  if (!"1".equals(kaTypeAmOut) && StringUtils.isNotBlank(kaTypeAmOut)) {
                             String dictLabel = map.get(kaTypeAmOut);
                             //获取异常的名称
                             Integer num = (Integer) userMap.get(dictLabel);
                             userMap.put(dictLabel, num + 1);
-                        }  if (!"1".equals(kaTypePmIn)) {
+                        }  if (!"1".equals(kaTypePmIn) && StringUtils.isNotBlank(kaTypePmIn)) {
                             String dictLabel = map.get(kaTypePmIn);
                             //获取异常的名称
                             Integer num = (Integer) userMap.get(dictLabel);
                             userMap.put(dictLabel, num + 1);
-                        }  if (!"1".equals(kaTypePmOut)) {
+                        }  if (!"1".equals(kaTypePmOut) && StringUtils.isNotBlank(kaTypePmOut)) {
                             String dictLabel = map.get(kaTypePmOut);
                             //获取异常的名称
                             Integer num = (Integer) userMap.get(dictLabel);

+ 9 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/sms/SendSmsController.java

@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
 import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
 import com.aliyun.tea.TeaException;
 import com.aliyun.teautil.models.RuntimeOptions;
+import com.ruoyi.common.annotation.RateLimiter;
 import com.ruoyi.common.constant.CacheConstants;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.redis.RedisCache;
@@ -48,7 +49,6 @@ public class SendSmsController extends BaseController
 
     @Autowired
     private RedisCache redisCache;
-
     /**
      * 查询短信日志列表
      */
@@ -122,6 +122,7 @@ public class SendSmsController extends BaseController
      * 单独发送短信的接口
      */
     @PostMapping("/sendSmsOnly")
+    @RateLimiter(count = 50, time = 60)
     public AjaxResult sendSms(@RequestBody SendSms sendSms) {
         String phone = sendSms.getPhone();
         if (StringUtils.isBlank(phone)) {
@@ -132,23 +133,27 @@ public class SendSmsController extends BaseController
             com.aliyun.dysmsapi20170525.Client client = SendSmsUtils.createClient();
             //获取用户验证码
             String verifyKey = CacheConstants.SMS_CODE_KEY + sendSms.getPhone();
-            String smsCode = "{\"code\":"+redisCache.getCacheObject(verifyKey)+"}";
+            String codeYan = SendSmsUtils.getCode(4);
+            String smsCode = "{\"code\":\"+codeYan+\"}";
             com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
                     //手机号码
                     .setPhoneNumbers(phone)
                     //短信签名名称。潜山市数据资源局
-                    .setSignName("安徽博曼网络科技有限公司")
+                    .setSignName("中新云")
                     //短信模板CODE
                     .setTemplateCode("SMS_232893584")
                     //短信模板变量对应的实际值{"name": code}
                     .setTemplateParam(smsCode);
             try {
+                sendSms.setContent("【中新云】您的验证码"+smsCode+",该验证码10分钟内有效,请勿泄漏于他人!");
                 // 复制代码运行请自行打印 API 的返回值
                 SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
                 String code = sendSmsResponse.getBody().code;
                 if ("OK".equals(code)) {
                     sendSms.setStatus("发送成功");
+
                     sendSmsService.insertSendSms(sendSms);
+                    redisCache.setCacheObject(verifyKey, codeYan, Constants.SMS_EXPIRATION, TimeUnit.MINUTES);
                     return AjaxResult.success("发送成功");
                 } else {
                     sendSms.setStatus("发送失败");
@@ -174,9 +179,8 @@ public class SendSmsController extends BaseController
      */
     @PostMapping("/getCode")
     public AjaxResult getCode(@RequestBody SendSms sendSms) {
-        String code = SendSmsUtils.getCode(4);
         String verifyKey = CacheConstants.SMS_CODE_KEY + sendSms.getPhone();
-        redisCache.setCacheObject(verifyKey, code, Constants.SMS_EXPIRATION, TimeUnit.MINUTES);
+        String code = redisCache.getCacheObject(verifyKey);
         return AjaxResult.success("获取成功",code);
     }
 }

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/utils/SendSmsUtils.java

@@ -16,7 +16,7 @@ public class SendSmsUtils {
 
     //生成X位验证码
     public static String getCode(Integer num) {
-        String[] codes = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
+        String[] codes = { "1", "2", "3", "4", "5", "6", "7", "8", "9"};
         StringBuilder code = new StringBuilder();
         for (int i = 0; i < num; i++) {
             int j = (int) (Math.random() * 10);

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/register", "/captchaImage","/index/**","/sms/sendSmsOnly").permitAll()
+                .antMatchers("/login", "/register", "/captchaImage","/index/**","/sms/sendSmsOnly","/sms/getCode").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

+ 13 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/KaoqinRecord.java

@@ -123,6 +123,11 @@ public class KaoqinRecord extends BaseEntity
     /** 打卡类别-下午下班 1正常 2:迟到 3:外勤 4:早退 */
     @Excel(name = "打卡类别-下午下班 1正常 2:迟到 3:外勤 4:早退")
     private String kaTypePmOut;
+
+    /**
+     * 考勤详情里面来查询打卡类别的字段
+     */
+    private String kaType;
     /**
      * 上午上班-图片
      */
@@ -160,6 +165,14 @@ public class KaoqinRecord extends BaseEntity
     @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
     private String remarkPmOut;
 
+    public String getKaType() {
+        return kaType;
+    }
+
+    public void setKaType(String kaType) {
+        this.kaType = kaType;
+    }
+
     public String getKaAmInPhoto() {
         return kaAmInPhoto;
     }

+ 3 - 3
ruoyi-system/src/main/resources/mapper/system/KaoqinRecordMapper.xml

@@ -55,9 +55,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>  
             <if test="userId != null "> and user_id = #{userId}</if>
             <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
-            <if test="deptId != null "> and dept_id = #{deptId}</if>
             <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
-            <if test="ancestors != null  and ancestors != ''"> and find_in_set(#{deptId}, ancestors)</if>
+            <if test="deptId != null  and deptId != ''"> and find_in_set(#{deptId}, ancestors)</if>
             <if test="kaYear != null  and kaYear != ''"> and ka_year = #{kaYear}</if>
             <if test="kaMonth != null  and kaMonth != ''"> and ka_month = #{kaMonth}</if>
             <if test="kaDay != null  and kaDay != ''"> and ka_day = #{kaDay}</if>
@@ -78,6 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="kaTypeAmOut != null  and kaTypeAmOut != ''"> and ka_type_am_out = #{kaTypeAmOut}</if>
             <if test="kaTypePmIn != null  and kaTypePmIn != ''"> and ka_type_pm_in = #{kaTypePmIn}</if>
             <if test="kaTypePmOut != null  and kaTypePmOut != ''"> and ka_type_pm_out = #{kaTypePmOut}</if>
+            <if test="kaType != null  and kaType != ''"> and (ka_type_am_in = #{kaType} or ka_type_am_out = #{kaType} or ka_type_pm_in = #{kaType} or ka_type_pm_out = #{kaType})</if>
             <if test="kaStatus != null  and kaStatus != ''"> and ka_status = #{kaStatus}</if>
             <if test="remarkAmIn != null  and remarkAmIn != ''"> and remark_am_in = #{remarkAmIn}</if>
             <if test="remarkAmOut != null  and remarkAmOut != ''"> and remark_am_out = #{remarkAmOut}</if>
@@ -123,7 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="kaAmOutPhoto != null">ka_am_out_photo,</if>
             <if test="kaPmInPhoto != null">ka_pm_in_photo,</if>
             <if test="kaPmOutPhoto != null">ka_pm_out_photo,</if>
-            <if test="kaStatus != null">ka_status,</if>
+            <if test="kaStatus != null and kaStatus != ''">ka_status,</if>
             <if test="createBy != null">create_by,</if>
             <if test="createTime != null">create_time,</if>
             <if test="updateBy != null">update_by,</if>

+ 92 - 0
ruoyi-system/src/main/resources/mapper/system/SendSmsMapper.xml

@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.system.mapper.SendSmsMapper">
+    
+    <resultMap type="SendSms" id="SendSmsResult">
+        <result property="id"    column="id"    />
+        <result property="phone"    column="phone"    />
+        <result property="status"    column="status"    />
+        <result property="content"    column="content"    />
+        <result property="modifyDate"    column="modify_date"    />
+        <result property="createBy"    column="create_by"    />
+        <result property="createTime"    column="create_time"    />
+        <result property="updateBy"    column="update_by"    />
+        <result property="updateTime"    column="update_time"    />
+        <result property="isDel"    column="is_del"    />
+    </resultMap>
+
+    <sql id="selectSendSmsVo">
+        select id, phone, status, content, modify_date, create_by, create_time, update_by, update_time, is_del from send_sms
+    </sql>
+
+    <select id="selectSendSmsList" parameterType="SendSms" resultMap="SendSmsResult">
+        <include refid="selectSendSmsVo"/>
+        <where>  
+            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
+            <if test="status != null  and status != ''"> and status = #{status}</if>
+            <if test="content != null  and content != ''"> and content = #{content}</if>
+            <if test="modifyDate != null  and modifyDate != ''"> and modify_date = #{modifyDate}</if>
+            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
+        </where>
+    </select>
+    
+    <select id="selectSendSmsById" parameterType="Long" resultMap="SendSmsResult">
+        <include refid="selectSendSmsVo"/>
+        where id = #{id}
+    </select>
+        
+    <insert id="insertSendSms" parameterType="SendSms" useGeneratedKeys="true" keyProperty="id">
+        insert into send_sms
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="phone != null">phone,</if>
+            <if test="status != null">status,</if>
+            <if test="content != null">content,</if>
+            <if test="modifyDate != null">modify_date,</if>
+            <if test="createBy != null">create_by,</if>
+            <if test="createTime != null">create_time,</if>
+            <if test="updateBy != null">update_by,</if>
+            <if test="updateTime != null">update_time,</if>
+            <if test="isDel != null and isDel != ''">is_del,</if>
+         </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="phone != null">#{phone},</if>
+            <if test="status != null">#{status},</if>
+            <if test="content != null">#{content},</if>
+            <if test="modifyDate != null">#{modifyDate},</if>
+            <if test="createBy != null">#{createBy},</if>
+            <if test="createTime != null">#{createTime},</if>
+            <if test="updateBy != null">#{updateBy},</if>
+            <if test="updateTime != null">#{updateTime},</if>
+            <if test="isDel != null and isDel != ''">#{isDel},</if>
+         </trim>
+    </insert>
+
+    <update id="updateSendSms" parameterType="SendSms">
+        update send_sms
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="phone != null">phone = #{phone},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="content != null">content = #{content},</if>
+            <if test="modifyDate != null">modify_date = #{modifyDate},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="createTime != null">create_time = #{createTime},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="isDel != null and isDel != ''">is_del = #{isDel},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteSendSmsById" parameterType="Long">
+        delete from send_sms where id = #{id}
+    </delete>
+
+    <delete id="deleteSendSmsByIds" parameterType="String">
+        delete from send_sms where id in 
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+</mapper>