Commit 782c825ad1d72624515713540b11400912ecaa9a
1 parent
5cc0a0c8
fix: 改变解码方式
Showing
5 changed files
with
70 additions
and
30 deletions
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
| @@ -71,7 +71,7 @@ public interface IDriverService | @@ -71,7 +71,7 @@ public interface IDriverService | ||
| 71 | 71 | ||
| 72 | AjaxResult getDriverSchedulingInfo(String schedulingDate,String jobCode); | 72 | AjaxResult getDriverSchedulingInfo(String schedulingDate,String jobCode); |
| 73 | 73 | ||
| 74 | - void saveDriverScheduling(Map<String, List<ResponseScheduling>> driverSchedulingMap); | 74 | + void saveDriverScheduling(List<ResponseScheduling> driverSchedulingMap); |
| 75 | 75 | ||
| 76 | AjaxResult getDriverSchedulingAll(); | 76 | AjaxResult getDriverSchedulingAll(); |
| 77 | 77 |
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
| @@ -4,9 +4,10 @@ import java.util.*; | @@ -4,9 +4,10 @@ import java.util.*; | ||
| 4 | 4 | ||
| 5 | import com.ruoyi.common.core.domain.AjaxResult; | 5 | import com.ruoyi.common.core.domain.AjaxResult; |
| 6 | import com.ruoyi.common.core.redis.RedisCache; | 6 | import com.ruoyi.common.core.redis.RedisCache; |
| 7 | -import com.ruoyi.common.utils.DateUtils; | ||
| 8 | import com.ruoyi.common.utils.SecurityUtils; | 7 | import com.ruoyi.common.utils.SecurityUtils; |
| 9 | import com.ruoyi.pojo.response.ResponseScheduling; | 8 | import com.ruoyi.pojo.response.ResponseScheduling; |
| 9 | +import com.ruoyi.utils.ConstDateUtil; | ||
| 10 | +import com.ruoyi.utils.ListUtils; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import com.ruoyi.driver.mapper.DriverMapper; | 13 | import com.ruoyi.driver.mapper.DriverMapper; |
| @@ -115,18 +116,15 @@ public class DriverServiceImpl implements IDriverService { | @@ -115,18 +116,15 @@ public class DriverServiceImpl implements IDriverService { | ||
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | @Override | 118 | @Override |
| 118 | - public void saveDriverScheduling(Map<String, List<ResponseScheduling>> driverSchedulingMap) { | ||
| 119 | - Collection<List<ResponseScheduling>> listCollection = driverSchedulingMap.values(); | ||
| 120 | - for (List<ResponseScheduling> responseSchedulings : listCollection) { | 119 | + public void saveDriverScheduling(List<ResponseScheduling> schedulings) { |
| 120 | + List<List<ResponseScheduling>> lists = ListUtils.splitList(schedulings, 1000); | ||
| 121 | + for (List<ResponseScheduling> responseSchedulings : lists) { | ||
| 121 | driverMapper.saveDriverScheduling(responseSchedulings); | 122 | driverMapper.saveDriverScheduling(responseSchedulings); |
| 122 | } | 123 | } |
| 123 | - | ||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | @Override | 126 | @Override |
| 127 | public AjaxResult getDriverSchedulingAll() { | 127 | public AjaxResult getDriverSchedulingAll() { |
| 128 | -// Set yyyyMMdd = redisCache.redisTemplate.opsForHash().keys(DateUtils.getDate("yyyyMMdd")); | ||
| 129 | -// return AjaxResult.success(yyyyMMdd); | ||
| 130 | - return AjaxResult.success(); | 128 | + return AjaxResult.success(redisCache.getHashKeys(DRIVER_SCHEDULING_PRE + ConstDateUtil.formatDate("yyyyMMdd"))); |
| 131 | } | 129 | } |
| 132 | } | 130 | } |
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
| @@ -25,6 +25,7 @@ import com.ruoyi.in.mapper.SignInMapper; | @@ -25,6 +25,7 @@ import com.ruoyi.in.mapper.SignInMapper; | ||
| 25 | import com.ruoyi.in.domain.SignIn; | 25 | import com.ruoyi.in.domain.SignIn; |
| 26 | import com.ruoyi.in.service.ISignInService; | 26 | import com.ruoyi.in.service.ISignInService; |
| 27 | import org.springframework.web.multipart.MultipartFile; | 27 | import org.springframework.web.multipart.MultipartFile; |
| 28 | +import sun.misc.BASE64Decoder; | ||
| 28 | 29 | ||
| 29 | /** | 30 | /** |
| 30 | * 签到Service业务层处理 | 31 | * 签到Service业务层处理 |
| @@ -111,15 +112,20 @@ public class SignInServiceImpl implements ISignInService { | @@ -111,15 +112,20 @@ public class SignInServiceImpl implements ISignInService { | ||
| 111 | @Override | 112 | @Override |
| 112 | public int addSignIn(SignIn signIn) throws FileUploadException, IOException { | 113 | public int addSignIn(SignIn signIn) throws FileUploadException, IOException { |
| 113 | // base64转图片 | 114 | // base64转图片 |
| 115 | + | ||
| 116 | + String base64 = signIn.getImage(); | ||
| 114 | // 图片路径 | 117 | // 图片路径 |
| 115 | String filePath = RuoYiConfig.getUploadPath(); | 118 | String filePath = RuoYiConfig.getUploadPath(); |
| 116 | // 固定jpg文件 | 119 | // 固定jpg文件 |
| 117 | - String fileName = extractFilename("jpg"); | 120 | + String fileName = ""; |
| 121 | + // 看是否带有base64前缀 有就判断文件类型 没有默认jpg | ||
| 122 | + fileName = checkImageBase64Format(signIn.getImage()); | ||
| 123 | + fileName = extractFilename(fileName); | ||
| 118 | // 获取相对路径 | 124 | // 获取相对路径 |
| 119 | String absPath = getAbsoluteFile(filePath, fileName).getAbsolutePath(); | 125 | String absPath = getAbsoluteFile(filePath, fileName).getAbsolutePath(); |
| 120 | - startUpload(absPath,signIn.getImage()); | ||
| 121 | - | ||
| 122 | - // 把上传的文件路径保存到服务器 | 126 | + // 上传文件 |
| 127 | + startUpload(absPath, base64); | ||
| 128 | + // 获取文件上传路径 | ||
| 123 | String pathFileName = getPathFileName(filePath, fileName); | 129 | String pathFileName = getPathFileName(filePath, fileName); |
| 124 | signIn.setImage(pathFileName); | 130 | signIn.setImage(pathFileName); |
| 125 | 131 | ||
| @@ -128,19 +134,17 @@ public class SignInServiceImpl implements ISignInService { | @@ -128,19 +134,17 @@ public class SignInServiceImpl implements ISignInService { | ||
| 128 | 134 | ||
| 129 | /** | 135 | /** |
| 130 | * 获取相对路径名 | 136 | * 获取相对路径名 |
| 137 | + * | ||
| 131 | * @param uploadDir | 138 | * @param uploadDir |
| 132 | * @param fileName | 139 | * @param fileName |
| 133 | * @return | 140 | * @return |
| 134 | * @throws IOException | 141 | * @throws IOException |
| 135 | */ | 142 | */ |
| 136 | - public File getAbsoluteFile(String uploadDir, String fileName) throws IOException | ||
| 137 | - { | 143 | + public File getAbsoluteFile(String uploadDir, String fileName) throws IOException { |
| 138 | File desc = new File(uploadDir + File.separator + fileName); | 144 | File desc = new File(uploadDir + File.separator + fileName); |
| 139 | 145 | ||
| 140 | - if (!desc.exists()) | ||
| 141 | - { | ||
| 142 | - if (!desc.getParentFile().exists()) | ||
| 143 | - { | 146 | + if (!desc.exists()) { |
| 147 | + if (!desc.getParentFile().exists()) { | ||
| 144 | desc.getParentFile().mkdirs(); | 148 | desc.getParentFile().mkdirs(); |
| 145 | } | 149 | } |
| 146 | } | 150 | } |
| @@ -149,35 +153,43 @@ public class SignInServiceImpl implements ISignInService { | @@ -149,35 +153,43 @@ public class SignInServiceImpl implements ISignInService { | ||
| 149 | 153 | ||
| 150 | /** | 154 | /** |
| 151 | * 获取扩展文件名 | 155 | * 获取扩展文件名 |
| 156 | + * | ||
| 152 | * @param extendFileName | 157 | * @param extendFileName |
| 153 | * @return | 158 | * @return |
| 154 | */ | 159 | */ |
| 155 | - public String extractFilename(String extendFileName) | ||
| 156 | - { | 160 | + public String extractFilename(String extendFileName) { |
| 157 | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), | 161 | return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), |
| 158 | - FilenameUtils.getBaseName(UUID.randomUUID().toString().replace("-","")), Seq.getId(Seq.uploadSeqType), extendFileName); | 162 | + FilenameUtils.getBaseName(UUID.randomUUID().toString().replace("-", "")), Seq.getId(Seq.uploadSeqType), extendFileName); |
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | /** | 165 | /** |
| 162 | - * | ||
| 163 | * @param uploadDir | 166 | * @param uploadDir |
| 164 | * @param fileName | 167 | * @param fileName |
| 165 | * @return | 168 | * @return |
| 166 | * @throws IOException | 169 | * @throws IOException |
| 167 | */ | 170 | */ |
| 168 | - public String getPathFileName(String uploadDir, String fileName) throws IOException | ||
| 169 | - { | 171 | + public String getPathFileName(String uploadDir, String fileName) throws IOException { |
| 170 | int dirLastIndex = RuoYiConfig.getProfile().length() + 1; | 172 | int dirLastIndex = RuoYiConfig.getProfile().length() + 1; |
| 171 | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); | 173 | String currentDir = StringUtils.substring(uploadDir, dirLastIndex); |
| 172 | return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; | 174 | return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; |
| 173 | } | 175 | } |
| 174 | 176 | ||
| 175 | - public void startUpload(String url,String base64) throws FileUploadException { | 177 | + public void startUpload(String url, String base64) throws FileUploadException, IOException { |
| 176 | FileOutputStream outputStream = null; | 178 | FileOutputStream outputStream = null; |
| 177 | - byte[] imageBytes = Base64.getDecoder().decode(base64); | 179 | + base64 = base64.replaceAll(" ", ""); |
| 180 | +// byte[] imageBytes = Base64.getDecoder().decode(base64); | ||
| 181 | + BASE64Decoder decoder = new BASE64Decoder(); | ||
| 182 | + byte[] photoBase64 = decoder.decodeBuffer(base64); | ||
| 183 | + for (int i = 0; i < photoBase64.length; ++i) { | ||
| 184 | + //调整异常数据 | ||
| 185 | + if (photoBase64[i] < 0) { | ||
| 186 | + photoBase64[i] += 256; | ||
| 187 | + } | ||
| 188 | + } | ||
| 178 | try { | 189 | try { |
| 179 | outputStream = new FileOutputStream(url); | 190 | outputStream = new FileOutputStream(url); |
| 180 | - outputStream.write(imageBytes); | 191 | + outputStream.write(photoBase64); |
| 192 | + outputStream.flush(); | ||
| 181 | } catch (Exception e) { | 193 | } catch (Exception e) { |
| 182 | throw new FileUploadException("文件上传异常"); | 194 | throw new FileUploadException("文件上传异常"); |
| 183 | } finally { | 195 | } finally { |
| @@ -190,4 +202,26 @@ public class SignInServiceImpl implements ISignInService { | @@ -190,4 +202,26 @@ public class SignInServiceImpl implements ISignInService { | ||
| 190 | } | 202 | } |
| 191 | } | 203 | } |
| 192 | } | 204 | } |
| 205 | + | ||
| 206 | + /** | ||
| 207 | + * 检查文件类型 | ||
| 208 | + * | ||
| 209 | + * @param base64ImgData | ||
| 210 | + * @return | ||
| 211 | + */ | ||
| 212 | + public static String checkImageBase64Format(String base64ImgData) { | ||
| 213 | + byte[] b = Base64.getDecoder().decode(base64ImgData); | ||
| 214 | + String type = ""; | ||
| 215 | + if (0x424D == ((b[0] & 0xff) << 8 | (b[1] & 0xff))) { | ||
| 216 | + type = "bmp"; | ||
| 217 | + } else if (0x8950 == ((b[0] & 0xff) << 8 | (b[1] & 0xff))) { | ||
| 218 | + type = "png"; | ||
| 219 | + } else { | ||
| 220 | + type = "jpg"; | ||
| 221 | + } | ||
| 222 | +// else if (0xFFD8 == ((b[0] & 0xff) << 8 | (b[1] & 0xff))) { | ||
| 223 | +// type = "jpg"; | ||
| 224 | +// } | ||
| 225 | + return type; | ||
| 226 | + } | ||
| 193 | } | 227 | } |
ruoyi-admin/src/main/java/com/ruoyi/job/DriverJob.java
| @@ -100,6 +100,11 @@ public class DriverJob implements InitializingBean { | @@ -100,6 +100,11 @@ public class DriverJob implements InitializingBean { | ||
| 100 | 100 | ||
| 101 | Map<String, List<ResponseScheduling>> driverSchedulingMap = new HashMap<>(); | 101 | Map<String, List<ResponseScheduling>> driverSchedulingMap = new HashMap<>(); |
| 102 | // 按照员工工号来获取排班信息 | 102 | // 按照员工工号来获取排班信息 |
| 103 | + originSchedulingList = originSchedulingList.stream() | ||
| 104 | + .map(subItem->{ | ||
| 105 | + subItem.setJobCode(subItem.getJsy().split("/")[0]); | ||
| 106 | + return subItem; | ||
| 107 | + }).collect(Collectors.toList()); | ||
| 103 | originSchedulingList.stream().forEach(item -> { | 108 | originSchedulingList.stream().forEach(item -> { |
| 104 | // 员工号为key | 109 | // 员工号为key |
| 105 | String jobCode = item.getJsy().split("/")[0]; | 110 | String jobCode = item.getJsy().split("/")[0]; |
| @@ -112,9 +117,8 @@ public class DriverJob implements InitializingBean { | @@ -112,9 +117,8 @@ public class DriverJob implements InitializingBean { | ||
| 112 | driverSchedulingMap.get(jobCode).add(item); | 117 | driverSchedulingMap.get(jobCode).add(item); |
| 113 | } | 118 | } |
| 114 | }); | 119 | }); |
| 115 | - originSchedulingList.clear(); | ||
| 116 | // 存入数据库 | 120 | // 存入数据库 |
| 117 | - DRIVER_SERVICE.saveDriverScheduling(driverSchedulingMap); | 121 | + DRIVER_SERVICE.saveDriverScheduling(originSchedulingList); |
| 118 | // 存入redis | 122 | // 存入redis |
| 119 | REDIS_CACHE.setCacheMap(DRIVER_SCHEDULING_PRE + ConstDateUtil.formatDate("yyyyMMdd"), driverSchedulingMap, 1, TimeUnit.DAYS); | 123 | REDIS_CACHE.setCacheMap(DRIVER_SCHEDULING_PRE + ConstDateUtil.formatDate("yyyyMMdd"), driverSchedulingMap, 1, TimeUnit.DAYS); |
| 120 | } | 124 | } |
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
| @@ -272,4 +272,8 @@ public class RedisCache { | @@ -272,4 +272,8 @@ public class RedisCache { | ||
| 272 | public Collection<String> keys(final String pattern) { | 272 | public Collection<String> keys(final String pattern) { |
| 273 | return redisTemplate.keys(pattern); | 273 | return redisTemplate.keys(pattern); |
| 274 | } | 274 | } |
| 275 | + | ||
| 276 | + public <T> Set<T> getHashKeys(String key){ | ||
| 277 | + return redisTemplate.opsForHash().keys(key); | ||
| 278 | + } | ||
| 275 | } | 279 | } |