Commit 001d2d5b2dc79a9be18acd747932e781bce603b7
1 parent
8f878e38
fix: 修改驾驶员上传图片接口逻辑
Showing
3 changed files
with
60 additions
and
12 deletions
ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
| 1 | package com.ruoyi.driver.controller; | 1 | package com.ruoyi.driver.controller; |
| 2 | 2 | ||
| 3 | +import java.nio.file.Paths; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 4 | import javax.servlet.http.HttpServletResponse; | 5 | import javax.servlet.http.HttpServletResponse; |
| 5 | 6 | ||
| 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; | ||
| 6 | import com.ruoyi.pojo.response.ResponseScheduling; | 12 | import com.ruoyi.pojo.response.ResponseScheduling; |
| 7 | import io.swagger.annotations.Api; | 13 | import io.swagger.annotations.Api; |
| 8 | import io.swagger.annotations.ApiOperation; | 14 | import io.swagger.annotations.ApiOperation; |
| @@ -18,6 +24,7 @@ import com.ruoyi.driver.domain.Driver; | @@ -18,6 +24,7 @@ import com.ruoyi.driver.domain.Driver; | ||
| 18 | import com.ruoyi.driver.service.IDriverService; | 24 | import com.ruoyi.driver.service.IDriverService; |
| 19 | import com.ruoyi.common.utils.poi.ExcelUtil; | 25 | import com.ruoyi.common.utils.poi.ExcelUtil; |
| 20 | import com.ruoyi.common.core.page.TableDataInfo; | 26 | import com.ruoyi.common.core.page.TableDataInfo; |
| 27 | +import org.springframework.web.multipart.MultipartFile; | ||
| 21 | 28 | ||
| 22 | /** | 29 | /** |
| 23 | * 驾驶员信息Controller | 30 | * 驾驶员信息Controller |
| @@ -32,6 +39,9 @@ public class DriverController extends BaseController { | @@ -32,6 +39,9 @@ public class DriverController extends BaseController { | ||
| 32 | @Autowired | 39 | @Autowired |
| 33 | private IDriverService driverService; | 40 | private IDriverService driverService; |
| 34 | 41 | ||
| 42 | + @Autowired | ||
| 43 | + private ServerConfig serverConfig; | ||
| 44 | + | ||
| 35 | /** | 45 | /** |
| 36 | * 获取驾驶员排班信息 | 46 | * 获取驾驶员排班信息 |
| 37 | */ | 47 | */ |
| @@ -122,7 +132,7 @@ public class DriverController extends BaseController { | @@ -122,7 +132,7 @@ public class DriverController extends BaseController { | ||
| 122 | /** | 132 | /** |
| 123 | * 校验工号 | 133 | * 校验工号 |
| 124 | * | 134 | * |
| 125 | - * @param jobCode | 135 | + * @param driver |
| 126 | * @return | 136 | * @return |
| 127 | */ | 137 | */ |
| 128 | @GetMapping("/check") | 138 | @GetMapping("/check") |
| @@ -131,6 +141,32 @@ public class DriverController extends BaseController { | @@ -131,6 +141,32 @@ public class DriverController extends BaseController { | ||
| 131 | return driverService.checkJobCode(driver); | 141 | return driverService.checkJobCode(driver); |
| 132 | } | 142 | } |
| 133 | 143 | ||
| 144 | + @PostMapping("/upload") | ||
| 145 | + public AjaxResult uploadImage(MultipartFile file) { | ||
| 146 | + try | ||
| 147 | + { | ||
| 148 | + // 上传文件路径 | ||
| 149 | + String baseUrl = RuoYiConfig.getUploadPath() + "/head/image"; | ||
| 150 | + // 上传并返回新文件名称 | ||
| 151 | + FileUploadUtils.assertAllowed(file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); | ||
| 152 | + String fileName = file.getOriginalFilename(); | ||
| 153 | + String absPath = FileUploadUtils.getAbsoluteFile(baseUrl, fileName).getAbsolutePath(); | ||
| 154 | + fileName = FileUploadUtils.getPathFileName(baseUrl, fileName); | ||
| 155 | + file.transferTo(Paths.get(absPath)); | ||
| 156 | + String url = serverConfig.getUrl() + fileName; | ||
| 157 | + AjaxResult ajax = AjaxResult.success(); | ||
| 158 | + ajax.put("url", url); | ||
| 159 | + ajax.put("fileName", fileName); | ||
| 160 | + ajax.put("newFileName", FileUtils.getName(fileName)); | ||
| 161 | + ajax.put("originalFilename", file.getOriginalFilename()); | ||
| 162 | + return ajax; | ||
| 163 | + } | ||
| 164 | + catch (Exception e) | ||
| 165 | + { | ||
| 166 | + return AjaxResult.error(e.getMessage()); | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + | ||
| 134 | 170 | ||
| 135 | // @ApiOperation("保存员工大头像") | 171 | // @ApiOperation("保存员工大头像") |
| 136 | } | 172 | } |
ruoyi-admin/src/main/java/com/ruoyi/driver/domain/Driver.java
| @@ -108,30 +108,34 @@ public class Driver extends BaseEntity { | @@ -108,30 +108,34 @@ public class Driver extends BaseEntity { | ||
| 108 | @Excel(name = "RFID 人卡ID号", readConverterExp = "1=0进制") | 108 | @Excel(name = "RFID 人卡ID号", readConverterExp = "1=0进制") |
| 109 | @JsonIgnoreProperties(ignoreUnknown = true) | 109 | @JsonIgnoreProperties(ignoreUnknown = true) |
| 110 | private String idRfid; | 110 | private String idRfid; |
| 111 | - | ||
| 112 | /** | 111 | /** |
| 113 | * RFID 标签号 | 112 | * RFID 标签号 |
| 114 | */ | 113 | */ |
| 115 | @Excel(name = "RFID 标签号") | 114 | @Excel(name = "RFID 标签号") |
| 116 | @JsonIgnoreProperties(ignoreUnknown = true) | 115 | @JsonIgnoreProperties(ignoreUnknown = true) |
| 117 | private String tagRfid; | 116 | private String tagRfid; |
| 118 | - | ||
| 119 | /** | 117 | /** |
| 120 | * 线路名称 | 118 | * 线路名称 |
| 121 | */ | 119 | */ |
| 122 | @Excel(name = "线路名称") | 120 | @Excel(name = "线路名称") |
| 123 | @JsonIgnoreProperties(ignoreUnknown = true) | 121 | @JsonIgnoreProperties(ignoreUnknown = true) |
| 124 | private String lineName; | 122 | private String lineName; |
| 125 | - | ||
| 126 | /** | 123 | /** |
| 127 | * 线路编码 | 124 | * 线路编码 |
| 128 | */ | 125 | */ |
| 129 | @Excel(name = "线路编码") | 126 | @Excel(name = "线路编码") |
| 130 | @JsonIgnoreProperties(ignoreUnknown = true) | 127 | @JsonIgnoreProperties(ignoreUnknown = true) |
| 131 | private String lineCode; | 128 | private String lineCode; |
| 132 | - | ||
| 133 | - @Excel(name = "人脸注册") | ||
| 134 | - @ApiModelProperty("是否人脸注册 1 注册 2 未注册") | ||
| 135 | - private Integer signIn; | 129 | + /** |
| 130 | + * 是否人脸注册 | ||
| 131 | + */ | ||
| 132 | + @Excel(name = "是否人脸注册") | ||
| 133 | + @ApiModelProperty("是否人脸注册 0 注册 1 未注册 2 注册过期") | ||
| 134 | + private Integer faceSignIn; | ||
| 135 | + /** | ||
| 136 | + * 大头像 | ||
| 137 | + */ | ||
| 138 | + @ApiModelProperty("头像") | ||
| 139 | + private String image; | ||
| 136 | 140 | ||
| 137 | } | 141 | } |
ruoyi-admin/src/main/resources/mapper/driver/DriverMapper.xml
| @@ -42,12 +42,13 @@ | @@ -42,12 +42,13 @@ | ||
| 42 | remark, | 42 | remark, |
| 43 | line_name, | 43 | line_name, |
| 44 | line_code, | 44 | line_code, |
| 45 | - sign_in | 45 | + face_sign_in, |
| 46 | + image | ||
| 46 | from driver | 47 | from driver |
| 47 | </sql> | 48 | </sql> |
| 48 | <sql id="insertDriverVo"> | 49 | <sql id="insertDriverVo"> |
| 49 | job_code | 50 | job_code |
| 50 | - , 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,sign_in | 51 | + , 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 |
| 51 | </sql> | 52 | </sql> |
| 52 | 53 | ||
| 53 | <select id="selectDriverList" parameterType="Driver" resultMap="DriverResult"> | 54 | <select id="selectDriverList" parameterType="Driver" resultMap="DriverResult"> |
| @@ -72,6 +73,7 @@ | @@ -72,6 +73,7 @@ | ||
| 72 | <if test="tagRfid != null and tagRfid != ''">and tag_rfid = #{tagRfid}</if> | 73 | <if test="tagRfid != null and tagRfid != ''">and tag_rfid = #{tagRfid}</if> |
| 73 | <if test="lineName != null and lineName != ''">and line_name like concat('%', #{lineName}, '%')</if> | 74 | <if test="lineName != null and lineName != ''">and line_name like concat('%', #{lineName}, '%')</if> |
| 74 | <if test="lineCode != null and lineCode != ''">and line_code = #{lineCode}</if> | 75 | <if test="lineCode != null and lineCode != ''">and line_code = #{lineCode}</if> |
| 76 | + <if test="faceSignIn != null and faceSignIn != ''">and face_sign_in = #{faceSignIn}</if> | ||
| 75 | </where> | 77 | </where> |
| 76 | </select> | 78 | </select> |
| 77 | 79 | ||
| @@ -127,6 +129,8 @@ | @@ -127,6 +129,8 @@ | ||
| 127 | <if test="remark != null">remark,</if> | 129 | <if test="remark != null">remark,</if> |
| 128 | <if test="lineName != null">line_name,</if> | 130 | <if test="lineName != null">line_name,</if> |
| 129 | <if test="lineCode != null">line_code,</if> | 131 | <if test="lineCode != null">line_code,</if> |
| 132 | + <if test="faceSignIn != null">face_sign_in,</if> | ||
| 133 | + <if test="image != null">image</if> | ||
| 130 | </trim> | 134 | </trim> |
| 131 | <trim prefix="values (" suffix=")" suffixOverrides=","> | 135 | <trim prefix="values (" suffix=")" suffixOverrides=","> |
| 132 | <if test="jobCode != null and jobCode != ''">#{jobCode},</if> | 136 | <if test="jobCode != null and jobCode != ''">#{jobCode},</if> |
| @@ -145,6 +149,8 @@ | @@ -145,6 +149,8 @@ | ||
| 145 | <if test="remark != null">#{remark},</if> | 149 | <if test="remark != null">#{remark},</if> |
| 146 | <if test="lineName != null">#{lineName},</if> | 150 | <if test="lineName != null">#{lineName},</if> |
| 147 | <if test="lineCode != null">#{lineCode},</if> | 151 | <if test="lineCode != null">#{lineCode},</if> |
| 152 | + <if test="faceSignIn != null">#{faceSignIn},</if> | ||
| 153 | + <if test="image != null">#{image}</if> | ||
| 148 | </trim> | 154 | </trim> |
| 149 | </insert> | 155 | </insert> |
| 150 | 156 | ||
| @@ -167,7 +173,8 @@ | @@ -167,7 +173,8 @@ | ||
| 167 | <if test="remark != null">remark = #{remark},</if> | 173 | <if test="remark != null">remark = #{remark},</if> |
| 168 | <if test="lineName != null">line_name = #{lineName},</if> | 174 | <if test="lineName != null">line_name = #{lineName},</if> |
| 169 | <if test="lineCode != null">line_code = #{lineCode},</if> | 175 | <if test="lineCode != null">line_code = #{lineCode},</if> |
| 170 | - <if test="signIn != null">sign_in = #{signIn}</if> | 176 | + <if test="faceSignIn != null">face_sign_in = #{faceSignIn},</if> |
| 177 | + <if test="image != null">image = #{image}</if> | ||
| 171 | </trim> | 178 | </trim> |
| 172 | where id = #{id} | 179 | where id = #{id} |
| 173 | </update> | 180 | </update> |
| @@ -253,7 +260,8 @@ | @@ -253,7 +260,8 @@ | ||
| 253 | #{item.remark,jdbcType=VARCHAR}, | 260 | #{item.remark,jdbcType=VARCHAR}, |
| 254 | #{item.lineName,jdbcType=VARCHAR}, | 261 | #{item.lineName,jdbcType=VARCHAR}, |
| 255 | #{item.lineCode,jdbcType=VARCHAR}, | 262 | #{item.lineCode,jdbcType=VARCHAR}, |
| 256 | - #{item.signIn} | 263 | + #{item.faceSignIn}, |
| 264 | + #{item.image} | ||
| 257 | ) | 265 | ) |
| 258 | </foreach> | 266 | </foreach> |
| 259 | on duplicate key update | 267 | on duplicate key update |