Commit 782c825ad1d72624515713540b11400912ecaa9a

Authored by guzijian
1 parent 5cc0a0c8

fix: 改变解码方式

ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
... ... @@ -71,7 +71,7 @@ public interface IDriverService
71 71  
72 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 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 4  
5 5 import com.ruoyi.common.core.domain.AjaxResult;
6 6 import com.ruoyi.common.core.redis.RedisCache;
7   -import com.ruoyi.common.utils.DateUtils;
8 7 import com.ruoyi.common.utils.SecurityUtils;
9 8 import com.ruoyi.pojo.response.ResponseScheduling;
  9 +import com.ruoyi.utils.ConstDateUtil;
  10 +import com.ruoyi.utils.ListUtils;
10 11 import org.springframework.beans.factory.annotation.Autowired;
11 12 import org.springframework.stereotype.Service;
12 13 import com.ruoyi.driver.mapper.DriverMapper;
... ... @@ -115,18 +116,15 @@ public class DriverServiceImpl implements IDriverService {
115 116 }
116 117  
117 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 122 driverMapper.saveDriverScheduling(responseSchedulings);
122 123 }
123   -
124 124 }
125 125  
126 126 @Override
127 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 25 import com.ruoyi.in.domain.SignIn;
26 26 import com.ruoyi.in.service.ISignInService;
27 27 import org.springframework.web.multipart.MultipartFile;
  28 +import sun.misc.BASE64Decoder;
28 29  
29 30 /**
30 31 * 签到Service业务层处理
... ... @@ -111,15 +112,20 @@ public class SignInServiceImpl implements ISignInService {
111 112 @Override
112 113 public int addSignIn(SignIn signIn) throws FileUploadException, IOException {
113 114 // base64转图片
  115 +
  116 + String base64 = signIn.getImage();
114 117 // 图片路径
115 118 String filePath = RuoYiConfig.getUploadPath();
116 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 125 String absPath = getAbsoluteFile(filePath, fileName).getAbsolutePath();
120   - startUpload(absPath,signIn.getImage());
121   -
122   - // 把上传的文件路径保存到服务器
  126 + // 上传文件
  127 + startUpload(absPath, base64);
  128 + // 获取文件上传路径
123 129 String pathFileName = getPathFileName(filePath, fileName);
124 130 signIn.setImage(pathFileName);
125 131  
... ... @@ -128,19 +134,17 @@ public class SignInServiceImpl implements ISignInService {
128 134  
129 135 /**
130 136 * 获取相对路径名
  137 + *
131 138 * @param uploadDir
132 139 * @param fileName
133 140 * @return
134 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 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 148 desc.getParentFile().mkdirs();
145 149 }
146 150 }
... ... @@ -149,35 +153,43 @@ public class SignInServiceImpl implements ISignInService {
149 153  
150 154 /**
151 155 * 获取扩展文件名
  156 + *
152 157 * @param extendFileName
153 158 * @return
154 159 */
155   - public String extractFilename(String extendFileName)
156   - {
  160 + public String extractFilename(String extendFileName) {
157 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 166 * @param uploadDir
164 167 * @param fileName
165 168 * @return
166 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 172 int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
171 173 String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
172 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 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 189 try {
179 190 outputStream = new FileOutputStream(url);
180   - outputStream.write(imageBytes);
  191 + outputStream.write(photoBase64);
  192 + outputStream.flush();
181 193 } catch (Exception e) {
182 194 throw new FileUploadException("文件上传异常");
183 195 } finally {
... ... @@ -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 100  
101 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 108 originSchedulingList.stream().forEach(item -> {
104 109 // 员工号为key
105 110 String jobCode = item.getJsy().split("/")[0];
... ... @@ -112,9 +117,8 @@ public class DriverJob implements InitializingBean {
112 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 122 // 存入redis
119 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 272 public Collection<String> keys(final String pattern) {
273 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 }
... ...