Commit 88c1f714852db25a44f5ee040d0105955561e260

Authored by liujun001
1 parent 9446240e

优化签到

Bsth-admin/src/main/java/com/ruoyi/in/controller/SignInController.java
... ... @@ -101,36 +101,6 @@ public class SignInController extends BaseController {
101 101 @PostMapping("/newAdd")
102 102 @ApiOperation("新增签到(设备传入)")
103 103 public AjaxResult addSignIn(@ApiParam @RequestBody @Validated SignIn signIn) throws FileUploadException, IOException {
104   -// String key = MessageFormat.format("sign:assignment:{0}", signIn.getJobCode());
105   -// if (redisCache.hasKey(key)) {
106   -// log.info(" sing method old sign :[{}]", signIn);
107   -// return signInService.addSignIn(signIn);
108   -// }
109   -//
110   -// Integer num = RandomUtils.nextInt(0, 10);
111   -// if (num < 6) {
112   -// redisCache.setCacheObject(key, num, 5, TimeUnit.MINUTES);
113   -// log.info("[{}] sing method 走新的签到方式 :[{}] ", num, signIn);
114   -// key = StringUtils.join(REDIS_SIGN_IN_DRIVER_ALCOHOL_OVERFLOW, ConstDateUtil.FAST_YYYY_MM_DD.format(new Date()), ":", signIn.getJobCode());
115   -// Integer count = redisCache.getCacheObject(key);
116   -// try {
117   -// return signInServiceV1.addsignInV1(signIn);
118   -// } catch (Exception e) {
119   -// if (Objects.isNull(count) || count < 1) {
120   -// count = 0;
121   -// } else {
122   -// count = count - 1;
123   -// }
124   -// if (redisCache.hasKey(key)) {
125   -// redisCache.setCacheObject(key, count, 1, TimeUnit.DAYS);
126   -// }
127   -// log.error("[{}] sing method 走新的签到方式,签到失败 :[{}]", num, signIn, e);
128   -// }
129   -//
130   -// }
131   -//
132   -// log.info("[{}] sing method old sign :[{}]", num, signIn);
133   -// return signInService.addSignIn(signIn);
134 104 return signInServiceV1.addsignInV1(signIn);
135 105 }
136 106  
... ...
Bsth-admin/src/main/java/com/ruoyi/in/domain/SignIn.java
... ... @@ -96,6 +96,9 @@ public class SignIn extends BaseEntity {
96 96 @ApiModelProperty("异常类型")
97 97 private Integer exType;
98 98  
  99 + @ApiModelProperty("异常类型")
  100 + private Integer exType1;
  101 +
99 102 @Override
100 103 public String toString() {
101 104 String image = this.getImage();
... ...
Bsth-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceV1Impl.java
... ... @@ -156,7 +156,9 @@ public class SignInServiceV1Impl extends ServiceImpl&lt;SignInMapperV1, SignInV1&gt; i
156 156 }
157 157  
158 158 private AjaxResult saveData(SignIn signIn, DriverScheduling scheduling, CalDriverScheduling calDriverScheduling, Driver driver, SignInV1 signInV1) {
159   -
  159 + signIn.setExType1(signIn.getExType());
  160 + Integer type = Objects.isNull(signIn.getExType()) ? 0 : signIn.getExType() > 0 ? 1 : 0;
  161 + signIn.setExType(type);
160 162 signInMapper.insertSignIn(signIn);
161 163 // 更新考勤
162 164 if (Objects.nonNull(calDriverScheduling)) {
... ... @@ -253,6 +255,7 @@ public class SignInServiceV1Impl extends ServiceImpl&lt;SignInMapperV1, SignInV1&gt; i
253 255 }
254 256  
255 257 private int switchAndChooseTime(SignIn signIn, DriverScheduling scheduling, long dateTime) {
  258 + long time = new Date().getTime();
256 259 if (Objects.equals(2, signIn.getType())) {
257 260 Date zdsj = new Date(scheduling.getZdsjT());
258 261  
... ... @@ -261,26 +264,41 @@ public class SignInServiceV1Impl extends ServiceImpl&lt;SignInMapperV1, SignInV1&gt; i
261 264 String dzsjHHMM = HHMM.format(date1);
262 265  
263 266 Calendar calendar = new GregorianCalendar();
264   - calendar.setTime(org.apache.commons.lang3.time.DateUtils.addMinutes(zdsj, 1));
  267 + calendar.setTime(org.apache.commons.lang3.time.DateUtils.addMinutes(date1, 1));
265 268 calendar.set(Calendar.SECOND, 0);
266 269 calendar.set(Calendar.MILLISECOND, 0);
267 270  
268   - Date date = Math.abs(calendar.getTime().getTime()-dateTime)>Math.abs(zdsj.getTime()-dateTime)?zdsj:calendar.getTime();
  271 + Calendar calendar1 = new GregorianCalendar();
  272 + calendar1.setTime(org.apache.commons.lang3.time.DateUtils.addMinutes(zdsj, -1));
  273 + calendar1.set(Calendar.SECOND, 0);
  274 + calendar1.set(Calendar.MILLISECOND, 999);
  275 +
269 276  
  277 + boolean flag = Math.abs(calendar.getTime().getTime() - time) > Math.abs(calendar1.getTime().getTime() - time) ? Boolean.FALSE:Boolean.TRUE;
270 278 String remark = org.apache.commons.lang3.StringUtils.join(ErrorTypeProperties.SIGN_OUT_TIMEOUT, "请在", fcsjHHMM, "到", dzsjHHMM, "之间打卡");
271   - return switchAndChooseTime(signIn, dateTime, date, 80, remark);
  279 + return switchAndChooseTime(signIn, dateTime, calendar1.getTime(), calendar.getTime(), remark,flag);
272 280 } else {
273 281 Date fcsj = new Date(scheduling.getFcsjT());
274 282  
275   - String fcsjHHMM = HHMM.format(org.apache.commons.lang3.time.DateUtils.addMinutes(fcsj, -60));
  283 + Date date1 = org.apache.commons.lang3.time.DateUtils.addMinutes(fcsj, -60);
  284 +
  285 + String fcsjHHMM = HHMM.format(date1);
276 286 String dzsjHHMM = HHMM.format(fcsj);
  287 +
277 288 Calendar calendar = new GregorianCalendar();
278 289 calendar.setTime(org.apache.commons.lang3.time.DateUtils.addMinutes(fcsj, 1));
279 290 calendar.set(Calendar.SECOND, 0);
280 291 calendar.set(Calendar.MILLISECOND, 0);
281 292  
  293 + Calendar calendar1 = new GregorianCalendar();
  294 + calendar1.setTime(org.apache.commons.lang3.time.DateUtils.addMinutes(date1, 0));
  295 + calendar1.set(Calendar.SECOND, 0);
  296 + calendar1.set(Calendar.MILLISECOND, 0);
  297 +
  298 + boolean flag = Math.abs(calendar.getTime().getTime() - time) > Math.abs(calendar1.getTime().getTime() - time) ? Boolean.FALSE:Boolean.TRUE;
282 299 String remark = org.apache.commons.lang3.StringUtils.join(ErrorTypeProperties.SIGN_IN_TIMEOUT, "请在", fcsjHHMM, "到", dzsjHHMM, "之间打卡");
283   - return switchAndChooseTime(signIn, dateTime, calendar.getTime(), -60, remark);
  300 +
  301 + return switchAndChooseTime(signIn, dateTime, calendar1.getTime(), calendar.getTime(), remark,flag);
284 302 }
285 303 }
286 304  
... ... @@ -309,39 +327,23 @@ public class SignInServiceV1Impl extends ServiceImpl&lt;SignInMapperV1, SignInV1&gt; i
309 327 * @author liujun
310 328 * @date 2024/9/20 17:14
311 329 */
312   - private int switchAndChooseTime(SignIn signIn, long dateTime, Date date, Integer value, String remark) {
313   - long time1 = date.getTime();
314   - date = org.apache.commons.lang3.time.DateUtils.addMinutes(date, value);
315   - long time = date.getTime();
316   -
317   - if (value < 0) {
318   - if (dateTime < time) {
319   - signIn.setExType(20);
320   - signIn.setRemark(remark);
321   - signIn.setStatus(2);
322   -
323   - return 1;
324   - } else if (dateTime > time1) {
325   - signIn.setExType(30);
326   - signIn.setRemark(remark);
327   - signIn.setStatus(2);
328   -
329   - return 2;
330   - }
331   - } else if (value > 0) {
332   - if (dateTime < time1) {
333   - signIn.setExType(20);
334   - signIn.setRemark(remark);
335   - signIn.setStatus(2);
336   -
337   - return 1;
338   - } else if (dateTime > time) {
339   - signIn.setExType(30);
340   - signIn.setRemark(remark);
341   - signIn.setStatus(2);
342   -
343   - return 2;
344   - }
  330 + private int switchAndChooseTime(SignIn signIn, long dateTime, Date date, Date endDate, String remark,boolean flag) {
  331 + long startTime = date.getTime();
  332 + // date = org.apache.commons.lang3.time.DateUtils.addMinutes(date, value);
  333 + long endTime = endDate.getTime();
  334 +
  335 + if(dateTime < startTime){
  336 + signIn.setExType(20);
  337 + signIn.setRemark(remark);
  338 + signIn.setStatus(2);
  339 +
  340 + return 1;
  341 + }else if(dateTime > endTime){
  342 + signIn.setExType(30);
  343 + signIn.setRemark(remark);
  344 + signIn.setStatus(2);
  345 +
  346 + return 2;
345 347 }
346 348  
347 349 signIn.setExType(0);
... ...
Bsth-admin/src/main/java/com/ruoyi/service/impl/BigViewServiceV1Impl.java
... ... @@ -188,25 +188,25 @@ public class BigViewServiceV1Impl implements BigViewServiceV1 {
188 188  
189 189 @Override
190 190 public boolean isNormal(SignIn signIn) {
191   - return Objects.nonNull(signIn) && Objects.equals(signIn.getExType(), 0);
  191 + return Objects.nonNull(signIn) && Objects.equals(signIn.getExType1(), 0);
192 192 }
193 193  
194 194  
195 195 @Override
196 196 public boolean isEarly(SignIn signIn) {
197   - return Objects.nonNull(signIn) && signIn.getExType() >= 20 && signIn.getExType() < 30;
  197 + return Objects.nonNull(signIn) && signIn.getExType1() >= 20 && signIn.getExType1() < 30;
198 198 }
199 199  
200 200  
201 201 @Override
202 202 public boolean isSignStatusWineEnum(SignIn signIn) {
203   - return Objects.nonNull(signIn) && Objects.nonNull(signIn.getExType()) && signIn.getExType() % 10 == 3;
  203 + return Objects.nonNull(signIn) && Objects.nonNull(signIn.getExType1()) && signIn.getExType1() % 10 == 3;
204 204 }
205 205  
206 206  
207 207 @Override
208 208 public boolean isSignStatusDelayEnum(SignIn signIn) {
209   - return Objects.nonNull(signIn) && Objects.nonNull(signIn.getExType()) && signIn.getExType() >= 30 && signIn.getExType() < 40;
  209 + return Objects.nonNull(signIn) && Objects.nonNull(signIn.getExType1()) && signIn.getExType1() >= 30 && signIn.getExType1() < 40;
210 210 }
211 211  
212 212 @Override
... ...
Bsth-admin/src/main/resources/mapper/in/SignInMapper.xml
... ... @@ -37,6 +37,7 @@
37 37 <result property="alcoholIntake" column="alcohol_intake"/>
38 38 <result property="remark" column="remark"/>
39 39 <result property="exType" column="ex_type"/>
  40 + <result property="exType1" column="ex_type1"/>
40 41 </resultMap>
41 42  
42 43 <sql id="selectSignInVo">
... ... @@ -54,7 +55,8 @@
54 55 update_time,
55 56 alcohol_intake,
56 57 remark,
57   - ex_type
  58 + ex_type,
  59 + ex_type1
58 60 from sign_in
59 61 </sql>
60 62  
... ... @@ -166,6 +168,7 @@
166 168 <if test="alcoholIntake != null">alcohol_intake,</if>
167 169 <if test="remark != null">remark,</if>
168 170 <if test="exType != null">ex_type,</if>
  171 + <if test="exType1 != null">ex_type1,</if>
169 172 </trim>
170 173 <trim prefix="values (" suffix=")" suffixOverrides=",">
171 174 <if test="createTime != null">#{createTime},</if>
... ... @@ -182,6 +185,7 @@
182 185 <if test="alcoholIntake != null">#{alcoholIntake},</if>
183 186 <if test="remark != null">#{remark},</if>
184 187 <if test="exType != null">#{exType},</if>
  188 + <if test="exType1 != null">#{exType1},</if>
185 189 </trim>
186 190 </insert>
187 191  
... ...