Commit 5048bce2fd3df8efaccbd3e393b779c165a97d66

Authored by guzijian
1 parent 7b49ec2f

fix:

ruoyi-admin/src/main/java/com/ruoyi/common/SignInEnum.java
... ... @@ -2,6 +2,10 @@ package com.ruoyi.common;
2 2  
3 3 public interface SignInEnum {
4 4 /**
  5 + * 导出图片
  6 + */
  7 + Integer EXPORT = 1;
  8 + /**
5 9 * 签到
6 10 */
7 11 Integer SIGN_IN = 1;
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
1 1 package com.ruoyi.driver.controller;
2 2  
3   -import java.nio.file.Paths;
4 3 import java.util.List;
5 4 import javax.servlet.http.HttpServletResponse;
6 5  
7   -import com.ruoyi.common.config.RuoYiConfig;
8   -import com.ruoyi.common.utils.file.FileUploadUtils;
9   -import com.ruoyi.common.utils.file.FileUtils;
10   -import com.ruoyi.common.utils.file.MimeTypeUtils;
11   -import com.ruoyi.framework.config.ServerConfig;
12   -import com.ruoyi.pojo.response.ResponseScheduling;
13 6 import io.swagger.annotations.Api;
  7 +import io.swagger.annotations.ApiModelProperty;
14 8 import io.swagger.annotations.ApiOperation;
15 9 import io.swagger.annotations.ApiParam;
16   -import org.springframework.security.access.prepost.PreAuthorize;
17 10 import org.springframework.beans.factory.annotation.Autowired;
18 11 import org.springframework.web.bind.annotation.*;
19 12 import com.ruoyi.common.annotation.Log;
... ... @@ -150,5 +143,13 @@ public class DriverController extends BaseController {
150 143 return AjaxResult.error(e.getMessage());
151 144 }
152 145 }
  146 + /**
  147 + * 头像下载 根据 工号
  148 + */
  149 + @ApiModelProperty("头像下载")
  150 + @GetMapping("/download/{jobCode}")
  151 + public void downLoadHeadImage(@PathVariable("jobCode")String jobCode,HttpServletResponse response){
  152 + driverService.downloadHeadImage(jobCode,response);
  153 + }
153 154  
154 155 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/mapper/DriverMapper.java
... ... @@ -92,4 +92,6 @@ public interface DriverMapper
92 92 * @return
93 93 */
94 94 Integer jobCodeIsEmpty(@Param("jobCode") String jobCode);
  95 +
  96 + String getDriverInfoByJobCode(@Param("jobCode") String jobCode);
95 97 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/IDriverService.java
... ... @@ -2,7 +2,6 @@ package com.ruoyi.driver.service;
2 2  
3 3 import java.io.IOException;
4 4 import java.util.List;
5   -import java.util.Map;
6 5  
7 6 import com.ruoyi.common.core.domain.AjaxResult;
8 7 import com.ruoyi.common.exception.file.InvalidExtensionException;
... ... @@ -10,6 +9,8 @@ import com.ruoyi.driver.domain.Driver;
10 9 import com.ruoyi.pojo.response.ResponseScheduling;
11 10 import org.springframework.web.multipart.MultipartFile;
12 11  
  12 +import javax.servlet.http.HttpServletResponse;
  13 +
13 14 /**
14 15 * 驾驶员信息Service接口
15 16 *
... ... @@ -81,4 +82,7 @@ public interface IDriverService
81 82 AjaxResult checkJobCode(Driver jobCode);
82 83  
83 84 AjaxResult uploadImage(MultipartFile file) throws InvalidExtensionException, IOException;
  85 +
  86 + void downloadHeadImage(String jobCode, HttpServletResponse response);
  87 +
84 88 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/driver/service/impl/DriverServiceImpl.java
1 1 package com.ruoyi.driver.service.impl;
2 2  
  3 +import java.io.File;
  4 +import java.io.FileInputStream;
3 5 import java.io.IOException;
4 6 import java.nio.file.Paths;
5 7 import java.util.*;
... ... @@ -13,16 +15,22 @@ import com.ruoyi.common.utils.file.FileUploadUtils;
13 15 import com.ruoyi.common.utils.file.FileUtils;
14 16 import com.ruoyi.common.utils.file.MimeTypeUtils;
15 17 import com.ruoyi.framework.config.ServerConfig;
  18 +import com.ruoyi.job.DriverJob;
16 19 import com.ruoyi.pojo.response.ResponseScheduling;
17 20 import com.ruoyi.utils.ConstDateUtil;
18 21 import com.ruoyi.utils.ListUtils;
  22 +import org.apache.commons.io.FilenameUtils;
19 23 import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.beans.factory.annotation.Value;
20 25 import org.springframework.stereotype.Service;
21 26 import com.ruoyi.driver.mapper.DriverMapper;
22 27 import com.ruoyi.driver.domain.Driver;
23 28 import com.ruoyi.driver.service.IDriverService;
24 29 import org.springframework.web.multipart.MultipartFile;
25 30  
  31 +import javax.servlet.ServletOutputStream;
  32 +import javax.servlet.http.HttpServletResponse;
  33 +
26 34 import static com.ruoyi.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE;
27 35  
28 36 /**
... ... @@ -34,6 +42,14 @@ import static com.ruoyi.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE;
34 42 @Service
35 43 public class DriverServiceImpl implements IDriverService {
36 44  
  45 + @Value("${api.url.getSchedulingInfo}")
  46 + private String schedulingInfoUrl;
  47 + @Value("${api.config.password}")
  48 + private String password;
  49 + @Value("${api.config.nonce}")
  50 + private String nonce;
  51 + @Autowired
  52 + private DriverJob driverJob;
37 53  
38 54 @Autowired
39 55 private ServerConfig serverConfig;
... ... @@ -127,9 +143,19 @@ public class DriverServiceImpl implements IDriverService {
127 143 if (cacheMapValue != null && cacheMapValue.size() > 0) {
128 144 return AjaxResult.success(cacheMapValue);
129 145 }
  146 + // 没有再次请求地址获取值
  147 + long timestamp = System.currentTimeMillis();
  148 + // 请求资源地址格式化
  149 + String getSchedulingInfoUrl = null;
  150 + try {
  151 + getSchedulingInfoUrl = String.format(schedulingInfoUrl, "99", schedulingDate, timestamp, nonce, password, driverJob.getSHA1(driverJob.getStringStringMap(String.valueOf(timestamp))));
  152 + } catch (Exception e) {
  153 + throw new RuntimeException(e);
  154 + }
  155 + Map<String, List<ResponseScheduling>> scheduling = driverJob.saveSchedulingToRedis(getSchedulingInfoUrl, Collections.emptyList(), schedulingDate);
130 156 // 数据库中读取所有接收到的排班信息
131   - List<ResponseScheduling> responseSchedulings = driverMapper.getDriverSchedulingList(schedulingDate, jobCode);
132   - return AjaxResult.success(responseSchedulings);
  157 +// List<ResponseScheduling> responseSchedulings = driverMapper.getDriverSchedulingList(schedulingDate, jobCode);
  158 + return AjaxResult.success(scheduling.get(jobCode));
133 159 }
134 160  
135 161 @Override
... ... @@ -164,7 +190,8 @@ public class DriverServiceImpl implements IDriverService {
164 190 String baseUrl = RuoYiConfig.getUploadPath() + "/head/image";
165 191 // 上传并返回新文件名称
166 192 FileUploadUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION);
167   - String fileName = file.getOriginalFilename();
  193 + // 后期可以通过请求头拿到对应的工号
  194 + String fileName = FilenameUtils.getBaseName(file.getOriginalFilename()) + "." + FileUploadUtils.getExtension(file);
168 195 String absPath = FileUploadUtils.getAbsoluteFile(baseUrl, fileName).getAbsolutePath();
169 196 fileName = FileUploadUtils.getPathFileName(baseUrl, fileName);
170 197 file.transferTo(Paths.get(absPath));
... ... @@ -176,4 +203,34 @@ public class DriverServiceImpl implements IDriverService {
176 203 ajax.put("originalFilename", file.getOriginalFilename());
177 204 return ajax;
178 205 }
  206 +
  207 + @Override
  208 + public void downloadHeadImage(String jobCode, HttpServletResponse response) {
  209 + File file = getLocationFile(jobCode);
  210 + ServletOutputStream ops = null;
  211 + try {
  212 + if (file.exists()) {
  213 + byte[] bytes = com.alibaba.excel.util.FileUtils.readFileToByteArray(file);
  214 + ops = response.getOutputStream();
  215 + ops.write(bytes);
  216 + ops.flush();
  217 + }
  218 + } catch (Exception e) {
  219 + throw new RuntimeException("download fail cause:" + e.getMessage());
  220 + } finally {
  221 + try {
  222 + if (ops != null) {
  223 + ops.close();
  224 + }
  225 + } catch (IOException e) {
  226 + throw new RuntimeException(e);
  227 + }
  228 + }
  229 + }
  230 +
  231 + private File getLocationFile(String jobCode) {
  232 + String image = driverMapper.getDriverInfoByJobCode(jobCode);
  233 +
  234 + return new File(RuoYiConfig.getProfile() + File.separator + image.replace("/profile", ""));
  235 + }
179 236 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/job/DriverJob.java
... ... @@ -76,7 +76,7 @@ public class DriverJob implements InitializingBean {
76 76 // 格式化请求
77 77 String getSchedulingInfoUrl = String.format(GET_SCHEDULING_INFO_URL, "99", ConstDateUtil.formatDate("yyyyMMdd"), timestamp, NONCE, PASSWORD, getSHA1(getStringStringMap(String.valueOf(timestamp))));
78 78 // 获取排班信息并存入redis
79   - saveSchedulingToRedis(getSchedulingInfoUrl, drivers);
  79 + saveSchedulingToRedis(getSchedulingInfoUrl, drivers,ConstDateUtil.formatDate("yyyyMMdd"));
80 80 // 分片插入
81 81 List<List<Driver>> splitList = ListUtils.splitList(drivers, 1000);
82 82 System.out.println("开始更新数据-----");
... ... @@ -95,10 +95,10 @@ public class DriverJob implements InitializingBean {
95 95 */
96 96 public void importImages(){
97 97 // TODO 获取用户列表 通过用户列表的jobCode来匹配对应的用户图像信息并保存到服务器
98   -
  98 +
99 99 }
100 100  
101   - private static void saveSchedulingToRedis(String getSchedulingInfoUrl, List<Driver> drivers) {
  101 + public Map<String, List<ResponseScheduling>> saveSchedulingToRedis(String getSchedulingInfoUrl, List<Driver> drivers,String dateKey) {
102 102 List<ResponseScheduling> originSchedulingList = RESTTEMPLATE.exchange(
103 103 getSchedulingInfoUrl,
104 104 HttpMethod.GET,
... ... @@ -113,6 +113,7 @@ public class DriverJob implements InitializingBean {
113 113 subItem.setJobCode(subItem.getJsy().split("/")[0]);
114 114 return subItem;
115 115 }).collect(Collectors.toList());
  116 + // 以员工号为key存入排班集合
116 117 originSchedulingList.stream().forEach(item -> {
117 118 // 员工号为key
118 119 String jobCode = item.getJsy().split("/")[0];
... ... @@ -126,12 +127,13 @@ public class DriverJob implements InitializingBean {
126 127 }
127 128 });
128 129 // 存入数据库
129   - DRIVER_SERVICE.saveDriverScheduling(originSchedulingList);
  130 +// DRIVER_SERVICE.saveDriverScheduling(originSchedulingList);
130 131 // 存入redis
131   - REDIS_CACHE.setCacheMap(DRIVER_SCHEDULING_PRE + ConstDateUtil.formatDate("yyyyMMdd"), driverSchedulingMap, 1, TimeUnit.DAYS);
  132 + REDIS_CACHE.setCacheMap(DRIVER_SCHEDULING_PRE + dateKey, driverSchedulingMap, 1, TimeUnit.DAYS);
  133 + return driverSchedulingMap;
132 134 }
133 135  
134   - private static List<Driver> getDrivers(String format, String timestamp) throws Exception {
  136 + private List<Driver> getDrivers(String format, String timestamp) throws Exception {
135 137 Map<String, String> configMap = getStringStringMap(timestamp);
136 138 String sign = getSHA1(configMap);
137 139 String url = format
... ... @@ -152,7 +154,7 @@ public class DriverJob implements InitializingBean {
152 154 return drivers;
153 155 }
154 156  
155   - private static Map<String, String> getStringStringMap(String timestamp) {
  157 + public Map<String, String> getStringStringMap(String timestamp) {
156 158 Map<String, String> configMap = new HashMap<>(5);
157 159 configMap.put("timestamp", String.valueOf(timestamp));
158 160 configMap.put("nonce", NONCE);
... ... @@ -168,7 +170,7 @@ public class DriverJob implements InitializingBean {
168 170 * @return
169 171 * @throws Exception
170 172 */
171   - public static String getSHA1(Map<String, String> map) throws Exception {
  173 + public String getSHA1(Map<String, String> map) throws Exception {
172 174 try {
173 175 String[] array = new String[map.size()];
174 176 map.values().toArray(array);
... ...
ruoyi-admin/src/main/java/com/ruoyi/pojo/request/ReportViewRequestVo.java
... ... @@ -42,4 +42,7 @@ public class ReportViewRequestVo {
42 42 @ApiModelProperty("姓名")
43 43 String name;
44 44  
  45 + @ApiModelProperty("是否导出图片")
  46 + Integer exportFlag;
  47 +
45 48 }
... ...
ruoyi-admin/src/main/java/com/ruoyi/service/ReportService.java
... ... @@ -18,6 +18,7 @@ import java.util.stream.Collectors;
18 18  
19 19 import static com.ruoyi.common.ErrorTypeProperties.EQUIPMENT_ERROR;
20 20 import static com.ruoyi.common.ErrorTypeProperties.SIGN_IN_ERROR;
  21 +import static com.ruoyi.common.SignInEnum.EXPORT;
21 22  
22 23 /**
23 24 * @author 20412
... ... @@ -38,7 +39,12 @@ public class ReportService {
38 39 * 查询报表信息
39 40 */
40 41 public List<ReportViewResponseVo> getReportScrollViewTable(ReportViewRequestVo requestVo) {
41   - return signInMapper.getReportScrollViewTable(requestVo);
  42 + List<ReportViewResponseVo> reportScrollViewTable = signInMapper.getReportScrollViewTable(requestVo);
  43 + // 不导出图片清空路径信息
  44 + if (!EXPORT.equals(requestVo.getExportFlag())){
  45 + reportScrollViewTable = reportScrollViewTable.stream().map(item->{item.setImage("");return item;}).collect(Collectors.toList());
  46 + }
  47 + return reportScrollViewTable;
42 48 }
43 49  
44 50 public List<ReportErrorResponseVo> getErrorReportList(ReportErrorRequestVo request) {
... ...
ruoyi-admin/src/main/java/com/ruoyi/utils/ConstDateUtil.java
... ... @@ -8,9 +8,4 @@ public class ConstDateUtil {
8 8 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(str);
9 9 return simpleDateFormat.format(new Date());
10 10 }
11   -
12   - public static void main(String[] args) {
13   - String formatDate = formatDate("yyyyMMdd");
14   - System.out.println(formatDate);
15   - }
16 11 }
... ...
ruoyi-admin/src/main/resources/mapper/driver/DriverMapper.xml
... ... @@ -109,6 +109,10 @@
109 109 from driver
110 110 where job_code = #{jobCode}
111 111 </select>
  112 + <select id="getDriverInfoByJobCode" resultType="String">
  113 + select image from driver
  114 + where job_code = #{jobCode}
  115 + </select>
112 116  
113 117 <insert id="insertDriver" parameterType="Driver" useGeneratedKeys="true" keyProperty="id">
114 118 insert into driver
... ...