Commit 60f20ca23689cd4a4a01f271bbd39c73346a1bf5

Authored by guzijian
1 parent ade1de37

fix: 新增注册反馈接口

ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
... ... @@ -109,16 +109,7 @@ public class DriverController extends BaseController {
109 109 return toAjax(driverService.insertDriver(driver));
110 110 }
111 111  
112   - /**
113   - * 人脸注册
114   - * @param driver
115   - * @return
116   - */
117   - @PostMapping("/addDriver")
118   - @ApiOperation("新增驾驶员信息(酒精一体机)")
119   - public AjaxResult addDriver(@ApiParam @RequestBody Driver driver) {
120   - return toAjax(driverService.addDriver(driver));
121   - }
  112 +
122 113  
123 114 /**
124 115 * 修改驾驶员信息
... ... @@ -174,4 +165,13 @@ public class DriverController extends BaseController {
174 165 driverService.downloadHeadImage(jobCode, response);
175 166 }
176 167  
  168 + /**
  169 + * 人脸注册状态
  170 + */
  171 + @ApiOperation("注册反馈")
  172 + @GetMapping("/faceSignIn")
  173 + public AjaxResult faceRegistrationFeedback(@RequestParam("deviceId") String deviceId,@RequestParam("jobCode")List<String> jobCode){
  174 + return driverService.faceRegistrationFeedback(deviceId,jobCode);
  175 + }
  176 +
177 177 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/domain/Driver.java
... ... @@ -145,4 +145,7 @@ public class Driver extends BaseEntity {
145 145 @ApiModelProperty("更新时间")
146 146 private Date update_time;
147 147  
  148 + @ApiModelProperty("注册设备列表")
  149 + private String signInEquipment;
  150 +
148 151 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/mapper/DriverMapper.java
... ... @@ -93,7 +93,11 @@ public interface DriverMapper
93 93 */
94 94 Integer jobCodeIsEmpty(@Param("jobCode") String jobCode);
95 95  
96   - String getDriverInfoByJobCode(@Param("jobCode") String jobCode);
  96 + String getDriverImageByJobCode(@Param("jobCode") String jobCode);
97 97  
98 98 List<Driver> getDrivers(Driver driver);
  99 +
  100 + Driver getDriverInfoByJobCode(@Param("jobCode")String jobCode);
  101 +
  102 + Integer insertDriverFace(@Param("deviceId") String deviceId, @Param("jobCodes")List<String> jobCodes);
99 103 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
... ... @@ -87,5 +87,6 @@ public interface IDriverService
87 87  
88 88 List<Driver> getDrivers(Driver driver);
89 89  
90   - int addDriver(Driver driver);
  90 +
  91 + AjaxResult faceRegistrationFeedback(String deviceId, List<String> jobCode);
91 92 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
... ... @@ -15,6 +15,7 @@ import com.ruoyi.common.utils.file.MimeTypeUtils;
15 15 import com.ruoyi.framework.config.ServerConfig;
16 16 import com.ruoyi.job.DriverJob;
17 17 import com.ruoyi.pojo.response.ResponseScheduling;
  18 +import com.ruoyi.service.ThreadJobService;
18 19 import com.ruoyi.utils.ConstDateUtil;
19 20 import com.ruoyi.utils.ListUtils;
20 21 import org.apache.commons.io.FilenameUtils;
... ... @@ -55,6 +56,9 @@ public class DriverServiceImpl implements IDriverService {
55 56 private DriverMapper driverMapper;
56 57  
57 58 @Autowired
  59 + private ThreadJobService threadJobService;
  60 +
  61 + @Autowired
58 62 private RedisCache redisCache;
59 63  
60 64 /**
... ... @@ -233,14 +237,16 @@ public class DriverServiceImpl implements IDriverService {
233 237 return drivers;
234 238 }
235 239  
  240 +
  241 +
236 242 @Override
237   - public int addDriver(Driver driver) {
238   - // TODO 人脸注册
239   - return 0;
  243 + public AjaxResult faceRegistrationFeedback(String deviceId, List<String> jobCodes) {
  244 + threadJobService.asyncUpdateDriver(deviceId,jobCodes);
  245 + return AjaxResult.success("注册成功");
240 246 }
241 247  
242 248 private File getLocationFile(String jobCode) {
243   - String image = driverMapper.getDriverInfoByJobCode(jobCode);
  249 + String image = driverMapper.getDriverImageByJobCode(jobCode);
244 250  
245 251 return new File(RuoYiConfig.getProfile() + File.separator + image.replace("/profile", ""));
246 252 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
... ... @@ -89,9 +89,9 @@ public class SignInServiceImpl implements ISignInService {
89 89 if (signIn.getType() == null) {
90 90 signIn.setType(SignInEnum.SIGN_IN);
91 91 }
92   - if (ALCOHOL_FLAG_YES.equals(signIn.getAlcoholFlag())){
  92 + if (ALCOHOL_FLAG_YES.equals(signIn.getAlcoholFlag())) {
93 93 signIn.setStatus(signIn.getAlcoholIntake().compareTo(new BigDecimal(20)) < 0 ? SIGN_IN_SUCCESS : SIGN_IN_FAIL);
94   - signIn.setRemark(signIn.getStatus().equals(SIGN_IN_FAIL)? "酒精测试不通过超标:" + signIn.getAlcoholIntake().floatValue() + "%" : "");
  94 + signIn.setRemark(signIn.getStatus().equals(SIGN_IN_FAIL) ? "酒精测试不通过超标:" + signIn.getAlcoholIntake().floatValue() + "%" : "");
95 95 }
96 96 return signInMapper.insertSignIn(signIn);
97 97 }
... ... @@ -131,7 +131,7 @@ public class SignInServiceImpl implements ISignInService {
131 131 }
132 132  
133 133 @Override
134   - public AjaxResult addSignIn(SignIn signIn) throws IOException {
  134 + public AjaxResult addSignIn(SignIn signIn) throws IOException {
135 135 // 签到检查
136 136 checkSignIn(signIn);
137 137 // base64转图片
... ... @@ -140,33 +140,35 @@ public class SignInServiceImpl implements ISignInService {
140 140 uploadImage(signIn);
141 141 signInMapper.insertSignIn(signIn);
142 142 // TODO 驾驶人员二次签到酒精测试异常
143   - if (true){
  143 + if (true) {
144 144 Integer count = redisCache.getCacheMapValue(ConstDateUtil.formatDate("yyyyMMdd") + REDIS_SIGN_IN, signIn.getJobCode());
145   - if (Objects.isNull(count)){
146   - redisCache.setCacheMapValue(ConstDateUtil.formatDate("yyyyMMdd") + REDIS_SIGN_IN, signIn.getJobCode(),0);
  145 + if (Objects.isNull(count)) {
  146 + redisCache.setCacheMapValue(ConstDateUtil.formatDate("yyyyMMdd") + REDIS_SIGN_IN, signIn.getJobCode(), 0);
  147 + } else {
  148 + count = redisCache.increment(ConstDateUtil.formatDate("yyyyMMdd") + REDIS_SIGN_IN, signIn.getJobCode(), 1);
147 149 }
148   - count = redisCache.increment(ConstDateUtil.formatDate("yyyyMMdd") + REDIS_SIGN_IN, signIn.getJobCode(), 1);
149   - if (count.equals(2) || count.compareTo(2) == 1){
150   -
  150 + if (count.compareTo(2) >= 0) {
  151 + // TODO
  152 + return SIGN_IN_SUCCESS.equals(signIn.getStatus()) ? AjaxResult.success(SIGN_IN_SUCCESS_STRING) : AjaxResult.error(SIGN_IN_ERROR + signIn.getRemark() + ",酒精测试不通过两次请更换车辆驾驶员");
151 153 }
152 154 }
153 155  
154 156  
155   - return SIGN_IN_SUCCESS.equals(signIn.getStatus()) ? AjaxResult.success(SIGN_IN_SUCCESS_STRING): AjaxResult.error(SIGN_IN_ERROR + signIn.getRemark());
  157 + return SIGN_IN_SUCCESS.equals(signIn.getStatus()) ? AjaxResult.success(SIGN_IN_SUCCESS_STRING) : AjaxResult.error(SIGN_IN_ERROR + signIn.getRemark());
156 158 }
157 159  
158 160 private void checkSignIn(SignIn signIn) {
159 161 // TODO 更具工号获取人员信息
160 162 Driver driver = getDriverInfoByJobCode(signIn.getJobCode());
161   - if (Objects.isNull(driver)){
  163 + if (Objects.isNull(driver)) {
162 164 signIn.setStatus(SIGN_IN_SUCCESS);
163 165 return;
164 166 }
165 167 // TODO 排班校验 非司售未作
166   - checkWorkDay(signIn,driver.getPersonnelType());
  168 + checkWorkDay(signIn, driver.getPersonnelType());
167 169  
168 170 // 酒精测试校验 TODO 判断人员类型
169   - if (ALCOHOL_FLAG_YES.equals(signIn.getAlcoholFlag())){
  171 + if (ALCOHOL_FLAG_YES.equals(signIn.getAlcoholFlag())) {
170 172 signIn.setStatus(signIn.getAlcoholIntake().compareTo(new BigDecimal(20)) < 0 ? SIGN_IN_SUCCESS : SIGN_IN_FAIL);
171 173 signIn.setRemark(signIn.getStatus().equals(SIGN_IN_FAIL) ? ALCOHOL_SIGN_IN_ERROR : "");
172 174 }
... ... @@ -178,11 +180,11 @@ public class SignInServiceImpl implements ISignInService {
178 180  
179 181 private void checkWorkDay(SignIn signIn, String personnelType) {
180 182 List<ResponseScheduling> jobs = null;
181   - switch (personnelType){
  183 + switch (personnelType) {
182 184 case "0":
183 185 // 查询工号对应的排班 司售人员
184   - jobs = redisCache.getCacheMapValue(ConstDateUtil.formatDate("yyyyMMdd"),signIn.getJobCode());
185   - if (Objects.isNull(jobs)|| jobs.size() == 0){
  186 + jobs = redisCache.getCacheMapValue(ConstDateUtil.formatDate("yyyyMMdd"), signIn.getJobCode());
  187 + if (Objects.isNull(jobs) || jobs.size() == 0) {
186 188 signIn.setStatus(SIGN_IN_FAIL);
187 189 signIn.setRemark(WORK_DAY_ERROR);
188 190 }
... ... @@ -194,7 +196,7 @@ public class SignInServiceImpl implements ISignInService {
194 196 }
195 197  
196 198 // 超时校验司售人员
197   - checkTimeOut(signIn,jobs);
  199 + checkTimeOut(signIn, jobs);
198 200 // TODO 非司售人员
199 201  
200 202 }
... ... @@ -231,7 +233,7 @@ public class SignInServiceImpl implements ISignInService {
231 233 String pathFileName = getPathFileName(filePath, fileName);
232 234 signIn.setImage(pathFileName);
233 235 // 异步上传文件
234   - threadJobConfig.startUpload(absPath,base64);
  236 + threadJobConfig.asyncStartUpload(absPath, base64);
235 237 }
236 238  
237 239 /**
... ...
ruoyi-admin/src/main/java/com/ruoyi/service/ThreadJobService.java
... ... @@ -8,7 +8,7 @@ import com.ruoyi.common.utils.DateUtils;
8 8 import com.ruoyi.common.utils.StringUtils;
9 9 import com.ruoyi.common.utils.uuid.Seq;
10 10 import com.ruoyi.common.utils.uuid.UUID;
11   -import com.ruoyi.in.mapper.SignInMapper;
  11 +import com.ruoyi.driver.mapper.DriverMapper;
12 12 import lombok.extern.slf4j.Slf4j;
13 13 import org.apache.commons.io.FilenameUtils;
14 14 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -21,6 +21,7 @@ import java.io.File;
21 21 import java.io.FileOutputStream;
22 22 import java.io.IOException;
23 23 import java.util.Base64;
  24 +import java.util.List;
24 25 import java.util.Objects;
25 26  
26 27  
... ... @@ -34,6 +35,10 @@ import java.util.Objects;
34 35 @Slf4j
35 36 public class ThreadJobService {
36 37  
  38 + @Autowired
  39 + private DriverMapper driverMapper;
  40 +
  41 +
37 42  
38 43 /**
39 44 * 异步上传图片
... ... @@ -44,10 +49,9 @@ public class ThreadJobService {
44 49 * @throws IOException
45 50 */
46 51 @Async
47   - public void startUpload(String url, String base64) {
  52 + public void asyncStartUpload(String url, String base64) {
48 53 FileOutputStream outputStream = null;
49 54 base64 = base64.replaceAll(" ", "");
50   -// byte[] imageBytes = Base64.getDecoder().decode(base64);
51 55 BASE64Decoder decoder = new BASE64Decoder();
52 56 try {
53 57 byte[] photoBase64 = decoder.decodeBuffer(base64);
... ... @@ -72,6 +76,14 @@ public class ThreadJobService {
72 76 }
73 77 }
74 78 }
  79 + @Async
  80 + public void asyncUpdateDriver(String deviceId, List<String> jobCodes){
  81 + // 获取员工信息
  82 + // 加锁
  83 + // 同步锁实现
  84 + Integer result = driverMapper.insertDriverFace(deviceId, jobCodes);
  85 + log.info("注册设备与员工关联完毕:{}",result);
  86 + }
75 87  
76 88 /**
77 89 * 检查文件类型
... ... @@ -137,4 +149,6 @@ public class ThreadJobService {
137 149 return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
138 150 }
139 151  
  152 +
  153 +
140 154 }
... ...
ruoyi-admin/src/main/resources/mapper/driver/DriverMapper.xml
... ... @@ -45,12 +45,13 @@
45 45 line_code,
46 46 face_sign_in,
47 47 image,
48   - update_time
  48 + update_time,
  49 + sign_in_equipment
49 50 from driver
50 51 </sql>
51 52 <sql id="insertDriverVo">
52 53 job_code
53   - , company_code, branche_company_code, personnel_name, papers_code, ic_card_code, personnel_type, posts, card, telphone, ic_rfid, id_rfid, tag_rfid, remark, line_name, line_code,face_sign_in,image,update_time
  54 + , company_code, branche_company_code, personnel_name, papers_code, ic_card_code, personnel_type, posts, card, telphone, ic_rfid, id_rfid, tag_rfid, remark, line_name, line_code,face_sign_in,image,update_time,sign_in_equipment
54 55 </sql>
55 56  
56 57 <select id="selectDriverList" parameterType="Driver" resultMap="DriverResult">
... ... @@ -111,7 +112,7 @@
111 112 from driver
112 113 where job_code = #{jobCode}
113 114 </select>
114   - <select id="getDriverInfoByJobCode" resultType="String">
  115 + <select id="getDriverImageByJobCode" resultType="String">
115 116 select image from driver
116 117 where job_code = #{jobCode}
117 118 </select>
... ... @@ -140,6 +141,10 @@
140 141 <if test="faceSignIn != null and faceSignIn != ''">and face_sign_in = #{faceSignIn}</if>
141 142 </where>
142 143 </select>
  144 + <select id="getDriverInfoByJobCode" resultType="com.ruoyi.driver.domain.Driver">
  145 + <include refid="selectDriverVo"></include>
  146 + where job_code = #{jobCode}
  147 + </select>
143 148  
144 149 <insert id="insertDriver" parameterType="Driver" useGeneratedKeys="true" keyProperty="id">
145 150 insert into driver
... ... @@ -206,6 +211,7 @@
206 211 <if test="lineCode != null">line_code = #{lineCode},</if>
207 212 <if test="faceSignIn != null">face_sign_in = #{faceSignIn},</if>
208 213 <if test="image != null">image = #{image}</if>
  214 + <if test="signInEquipment != null">sign_in_equipment = #{signInEquipment}</if>
209 215 </trim>
210 216 where id = #{id}
211 217 </update>
... ... @@ -293,11 +299,24 @@
293 299 #{item.lineCode,jdbcType=VARCHAR},
294 300 #{item.faceSignIn},
295 301 #{item.image},
296   - #{item.updateTime}
  302 + #{item.updateTime},
  303 + #{item.signInEquipment}
  304 + )
  305 + </foreach>
  306 + on duplicate key update
  307 + job_code = values(job_code)
  308 + </insert>
  309 + <insert id="insertDriverFace" useGeneratedKeys="true" keyProperty="id">
  310 + INSERT INTO driver_face_device_id ( job_code,device_id )
  311 + values
  312 + <foreach collection="jobCodes" item="item" index="index" separator=",">
  313 + (
  314 + #{item},#{deviceId}
297 315 )
298 316 </foreach>
299 317 on duplicate key update
300 318 job_code = values(job_code)
  319 + device_id = values(device_id)
301 320 </insert>
302 321  
303 322 </mapper>
304 323 \ No newline at end of file
... ...