Commit 7d057927fcefe595de78ec3fe170dc810c8618ab

Authored by guzijian
1 parent 7022fa14

feat: 增加注册列表显示

ruoyi-admin/src/main/java/com/ruoyi/common/global/GlobalDriverInfoCache.java
1 1 package com.ruoyi.common.global;
2 2  
3 3 import com.ruoyi.in.domain.SignIn;
  4 +import com.ruoyi.pojo.domain.SignInExpand;
  5 +import com.ruoyi.utils.ConstDateUtil;
4 6 import org.springframework.stereotype.Component;
5 7  
6 8 import java.security.Principal;
... ... @@ -12,18 +14,42 @@ import java.util.concurrent.ConcurrentHashMap;
12 14 */
13 15 @Component
14 16 public class GlobalDriverInfoCache {
15   - private final ConcurrentHashMap<String, List<SignIn>> userCurrentMap = new ConcurrentHashMap();
  17 + /**
  18 + * 上午签到汇总
  19 + */
  20 + private final ConcurrentHashMap<String, List<SignInExpand>> morningUserSignInMap = new ConcurrentHashMap();
  21 + /**
  22 + * 下午签到汇总
  23 + */
  24 + private final ConcurrentHashMap<String, List<SignInExpand>> afternoonUserSignInMap = new ConcurrentHashMap();
16 25  
17 26 /**
18   - * 驾驶员签到
  27 + * 驾驶员签到成功
  28 + *
19 29 * @param signIn
20 30 */
21   - public void putDriver(SignIn signIn) {
22   - if (Objects.isNull(userCurrentMap.get(signIn.getJobCode()))) {
23   - userCurrentMap.put(signIn.getJobCode(), new ArrayList<>(Arrays.asList(signIn)));
24   - } else {
25   - userCurrentMap.get(signIn.getJobCode()).add(signIn);
  31 + public void putDriverSignInSuccess(SignIn signIn) {
  32 + ConcurrentHashMap<String, List<SignInExpand>> userCurrentMap = null;
  33 + int hour = Integer.parseInt(ConstDateUtil.formatDate("HH"));
  34 + if (hour >= 0 && hour < 12) {
  35 + userCurrentMap = morningUserSignInMap;
  36 + if (Objects.isNull(userCurrentMap.get(signIn.getJobCode()))) {
  37 + SignInExpand signInExpand = new SignInExpand();
  38 + signInExpand.setJobCode(signIn.getJobCode());
  39 + signInExpand.setMorningSignInIds(signInExpand.getMorningSignInIds() + signIn.getId() + ",");
  40 + userCurrentMap.put(signIn.getJobCode(), new ArrayList<>(Arrays.asList(signInExpand)));
  41 + } else {
  42 + userCurrentMap.get(signIn.getJobCode()).add(null);
  43 + }
  44 + }else {
  45 + userCurrentMap = afternoonUserSignInMap;
26 46 }
  47 + /**
  48 + * 存在判断 上下午只保留一条作为正式的签到结果
  49 + * 上午签到 -》 成功 | 下午签到 -》异常,成功
  50 + * 上午签到 -》 异常,异常 | 下午签到 -》 成功
  51 + */
  52 +
27 53 }
28 54  
29 55  
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/mapper/DriverMapper.java
... ... @@ -100,4 +100,6 @@ public interface DriverMapper
100 100 Driver getDriverInfoByJobCode(@Param("jobCode")String jobCode);
101 101  
102 102 Integer insertDriverFace(@Param("deviceId") String deviceId, @Param("jobCodes")List<String> jobCodes);
  103 +
  104 + void updateDriverByComputed(@Param("count")Integer count);
103 105 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
... ... @@ -89,4 +89,6 @@ public interface IDriverService
89 89  
90 90  
91 91 AjaxResult faceRegistrationFeedback(String deviceId, List<String> jobCode);
  92 +
  93 + void updateDriverByComputed();
92 94 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
... ... @@ -4,6 +4,7 @@ import java.io.File;
4 4 import java.io.IOException;
5 5 import java.nio.file.Paths;
6 6 import java.util.*;
  7 +import java.util.stream.Collectors;
7 8  
8 9 import com.ruoyi.common.config.RuoYiConfig;
9 10 import com.ruoyi.common.core.domain.AjaxResult;
... ... @@ -12,13 +13,16 @@ import com.ruoyi.common.exception.file.InvalidExtensionException;
12 13 import com.ruoyi.common.utils.file.FileUploadUtils;
13 14 import com.ruoyi.common.utils.file.FileUtils;
14 15 import com.ruoyi.common.utils.file.MimeTypeUtils;
  16 +import com.ruoyi.equipment.mapper.EquipmentMapper;
15 17 import com.ruoyi.framework.config.ServerConfig;
16 18 import com.ruoyi.job.DriverJob;
  19 +import com.ruoyi.pojo.domain.EquipmentDriverExpand;
17 20 import com.ruoyi.pojo.response.ResponseScheduling;
18 21 import com.ruoyi.service.ThreadJobService;
19 22 import com.ruoyi.utils.ConstDateUtil;
20 23 import com.ruoyi.utils.ListUtils;
21 24 import org.apache.commons.io.FilenameUtils;
  25 +import org.apache.tomcat.util.buf.StringUtils;
22 26 import org.springframework.beans.factory.annotation.Autowired;
23 27 import org.springframework.beans.factory.annotation.Value;
24 28 import org.springframework.stereotype.Service;
... ... @@ -41,6 +45,8 @@ import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE
41 45 @Service
42 46 public class DriverServiceImpl implements IDriverService {
43 47  
  48 + @Autowired
  49 + private EquipmentMapper equipmentMapper;
44 50 @Value("${api.url.getSchedulingInfo}")
45 51 private String schedulingInfoUrl;
46 52 @Value("${api.config.password}")
... ... @@ -82,7 +88,14 @@ public class DriverServiceImpl implements IDriverService {
82 88 */
83 89 @Override
84 90 public List<Driver> selectDriverList(Driver driver) {
85   - return driverMapper.selectDriverList(driver);
  91 + List<Driver> drivers = driverMapper.selectDriverList(driver);
  92 + List<EquipmentDriverExpand> list = equipmentMapper.querySignListByJobCode(drivers);
  93 + for (Driver item : drivers) {
  94 + // 查询对应工号的注册设备号 然后用,拼接展示在前端
  95 + List<String> collect = list.stream().filter(todo -> item.getJobCode().equals(todo.getJobCode())).map(EquipmentDriverExpand::getDeviceId).collect(Collectors.toList());
  96 + item.setSignInEquipment(StringUtils.join(collect));
  97 + }
  98 + return drivers;
86 99 }
87 100  
88 101 /**
... ... @@ -242,6 +255,13 @@ public class DriverServiceImpl implements IDriverService {
242 255 return AjaxResult.success("注册成功");
243 256 }
244 257  
  258 + @Override
  259 + public void updateDriverByComputed() {
  260 + Integer count = equipmentMapper.count();
  261 + // 更新人脸认证状态
  262 + driverMapper.updateDriverByComputed(count);
  263 + }
  264 +
245 265 private File getLocationFile(String jobCode) {
246 266 String image = driverMapper.getDriverImageByJobCode(jobCode);
247 267  
... ...
ruoyi-admin/src/main/java/com/ruoyi/equipment/mapper/EquipmentMapper.java
1 1 package com.ruoyi.equipment.mapper;
2 2  
3 3 import java.util.List;
  4 +
  5 +import com.ruoyi.driver.domain.Driver;
4 6 import com.ruoyi.equipment.domain.Equipment;
  7 +import com.ruoyi.pojo.domain.EquipmentDriverExpand;
5 8 import org.apache.ibatis.annotations.Param;
6 9  
7 10 /**
... ... @@ -61,4 +64,8 @@ public interface EquipmentMapper
61 64 public int deleteEquipmentByIds(Long[] ids);
62 65  
63 66 Equipment selectEquipmentByDeviceId(@Param("deviceId") String deviceId);
  67 +
  68 + Integer count();
  69 +
  70 + List<EquipmentDriverExpand> querySignListByJobCode(@Param("drivers") List<Driver> drivers);
64 71 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
... ... @@ -144,6 +144,7 @@ public class SignInServiceImpl implements ISignInService {
144 144  
145 145 @Override
146 146 public AjaxResult addSignIn(SignIn signIn) throws IOException {
  147 + // 查询员工信息
147 148 Driver driver = driverMapper.getDriverInfoByJobCode(signIn.getJobCode());
148 149 // 查询地址
149 150 Equipment equipment = equipmentMapper.selectEquipmentByDeviceId(signIn.getDeviceId());
... ...
ruoyi-admin/src/main/java/com/ruoyi/job/DriverJob.java
... ... @@ -154,7 +154,7 @@ public class DriverJob implements InitializingBean {
154 154 ImageUrlResultResponseVo vo = JSON.parseObject(s, ImageUrlResultResponseVo.class);
155 155 result = vo.getResult();
156 156 // 可能需要重新获取token
157   - }catch (Exception e){
  157 + } catch (Exception e) {
158 158 String token = DriverJob.getToken(TOKEN_URL).getAccessToken();
159 159 header.put("x-acs-dingtalk-access-token", token);
160 160 String s = HttpUtils.doGet(url, param, header);
... ... @@ -166,7 +166,7 @@ public class DriverJob implements InitializingBean {
166 166  
167 167 /**
168 168 * 获取排班任务请求
169   - * 12小时执行一次
  169 + * 24小时执行一次
170 170 */
171 171 public void getSchedulingInfo() {
172 172 // 获取排班请求
... ... @@ -181,6 +181,13 @@ public class DriverJob implements InitializingBean {
181 181 saveSchedulingToRedis(getSchedulingInfoUrl, ConstDateUtil.formatDate("yyyyMMdd"));
182 182 }
183 183  
  184 + /**
  185 + * 计算是否全部设备完成了对应的用户人脸注册
  186 + */
  187 + public void computedFaceSignIn() {
  188 + DRIVER_SERVICE.updateDriverByComputed();
  189 + }
  190 +
184 191 public Map<String, List<ResponseScheduling>> saveSchedulingToRedis(String getSchedulingInfoUrl, String dateKey) {
185 192 List<ResponseScheduling> originSchedulingList = RESTTEMPLATE.exchange(
186 193 getSchedulingInfoUrl,
... ...
ruoyi-admin/src/main/java/com/ruoyi/pojo/domain/EquipmentDriverExpand.java 0 → 100644
  1 +package com.ruoyi.pojo.domain;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class EquipmentDriverExpand {
  7 + private String id;
  8 + /**
  9 + * 设备号
  10 + */
  11 + private String deviceId;
  12 + /**
  13 + * 工号
  14 + */
  15 + private String jobCode;
  16 +}
... ...
ruoyi-admin/src/main/java/com/ruoyi/pojo/domain/SignInExpand.java 0 → 100644
  1 +package com.ruoyi.pojo.domain;
  2 +
  3 +import lombok.Data;
  4 +import org.springframework.format.annotation.DateTimeFormat;
  5 +
  6 +import java.util.Date;
  7 +
  8 +/**
  9 + * 签到扩展表
  10 + * @author guzijian
  11 + */
  12 +@Data
  13 +public class SignInExpand {
  14 + private Integer id;
  15 + private String jobCode;
  16 + /**
  17 + * 上午签到集合 1,2
  18 + */
  19 + private String morningSignInIds;
  20 + /**
  21 + * 下午签到集合 1,2
  22 + */
  23 + private String afternoonSignInIds;
  24 + @DateTimeFormat(pattern = "yyyy-MM-dd")
  25 + private Date dated;
  26 +}
... ...
ruoyi-admin/src/main/resources/application-druid-dev.yml
... ... @@ -7,7 +7,7 @@ spring:
7 7 # 主库数据源
8 8 master:
9 9 # 测试地址
10   - url: jdbc:mysql://localhost:3306/all-in-one?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&useAffectedRows=true
  10 + url: jdbc:mysql://localhost:3306/all-in-one?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&useAffectedRows=true&allowMultiQueries=true
11 11 username: root
12 12 password: guzijian
13 13 # 从库数据源
... ...
ruoyi-admin/src/main/resources/application-druid-uat.yml
... ... @@ -7,7 +7,7 @@ spring:
7 7 # 主库数据源
8 8 master:
9 9 # 测试地址
10   - url: jdbc:mysql://1.14.107.94:3306/all-in-one?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
  10 + url: jdbc:mysql://localhost:3306/all-in-one?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&useAffectedRows=true&allowMultiQueries=true
11 11 username: root
12 12 password: guzijian
13 13 # 从库数据源
... ...
ruoyi-admin/src/main/resources/mapper/driver/DriverMapper.xml
... ... @@ -166,7 +166,8 @@
166 166 <if test="lineName != null">line_name,</if>
167 167 <if test="lineCode != null">line_code,</if>
168 168 <if test="faceSignIn != null">face_sign_in,</if>
169   - <if test="image != null">image</if>
  169 + <if test="image != null">image,</if>
  170 + <if test="updateTime != null">update_time</if>
170 171 </trim>
171 172 <trim prefix="values (" suffix=")" suffixOverrides=",">
172 173 <if test="jobCode != null and jobCode != ''">#{jobCode},</if>
... ... @@ -186,7 +187,8 @@
186 187 <if test="lineName != null">#{lineName},</if>
187 188 <if test="lineCode != null">#{lineCode},</if>
188 189 <if test="faceSignIn != null">#{faceSignIn},</if>
189   - <if test="image != null">#{image}</if>
  190 + <if test="image != null">#{image},</if>
  191 + <if test="updateTime != null">#{updateTime}</if>
190 192 </trim>
191 193 on duplicate key update
192 194 job_code = values(job_code)
... ... @@ -217,6 +219,22 @@
217 219 </trim>
218 220 where id = #{id}
219 221 </update>
  222 + <update id="updateDriverByComputed">
  223 + update driver set face_sign_in = 0
  224 + WHERE job_code in (
  225 + SELECT job_code
  226 + FROM driver_face_device_id
  227 + GROUP BY job_code
  228 + HAVING COUNT(*) = #{count}
  229 + );
  230 + update driver set face_sign_in = 2
  231 + WHERE job_code in (
  232 + SELECT job_code
  233 + FROM driver_face_device_id
  234 + GROUP BY job_code
  235 + HAVING COUNT(*) != #{count}
  236 + );
  237 + </update>
220 238 <insert id="saveDriverScheduling">
221 239 INSERT INTO driver_scheduling (
222 240 id, scheduleDate, lineName, lineCode, lpName,
... ...
ruoyi-admin/src/main/resources/mapper/equipment/EquipmentMapper.xml
... ... @@ -46,6 +46,17 @@ PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
46 46 <include refid="selectEquipmentVo"></include>
47 47 where device_id = #{deviceId}
48 48 </select>
  49 + <select id="count" resultType="java.lang.Integer">
  50 + select count(*) from equipment
  51 + where status = 1
  52 + </select>
  53 + <select id="querySignListByJobCode" resultType="com.ruoyi.pojo.domain.EquipmentDriverExpand">
  54 + select * from driver_face_device_id
  55 + where job_code in
  56 + <foreach collection="drivers" item="item" open="(" separator="," close=")">
  57 + #{item.jobCode}
  58 + </foreach>
  59 + </select>
49 60  
50 61  
51 62 <insert id="insertEquipment" parameterType="Equipment" useGeneratedKeys="true" keyProperty="id">
... ...