Commit 001d2d5b2dc79a9be18acd747932e781bce603b7

Authored by guzijian
1 parent 8f878e38

fix: 修改驾驶员上传图片接口逻辑

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;
3 4 import java.util.List;
4 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 12 import com.ruoyi.pojo.response.ResponseScheduling;
7 13 import io.swagger.annotations.Api;
8 14 import io.swagger.annotations.ApiOperation;
... ... @@ -18,6 +24,7 @@ import com.ruoyi.driver.domain.Driver;
18 24 import com.ruoyi.driver.service.IDriverService;
19 25 import com.ruoyi.common.utils.poi.ExcelUtil;
20 26 import com.ruoyi.common.core.page.TableDataInfo;
  27 +import org.springframework.web.multipart.MultipartFile;
21 28  
22 29 /**
23 30 * 驾驶员信息Controller
... ... @@ -32,6 +39,9 @@ public class DriverController extends BaseController {
32 39 @Autowired
33 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 132 /**
123 133 * 校验工号
124 134 *
125   - * @param jobCode
  135 + * @param driver
126 136 * @return
127 137 */
128 138 @GetMapping("/check")
... ... @@ -131,6 +141,32 @@ public class DriverController extends BaseController {
131 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 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 108 @Excel(name = "RFID 人卡ID号", readConverterExp = "1=0进制")
109 109 @JsonIgnoreProperties(ignoreUnknown = true)
110 110 private String idRfid;
111   -
112 111 /**
113 112 * RFID 标签号
114 113 */
115 114 @Excel(name = "RFID 标签号")
116 115 @JsonIgnoreProperties(ignoreUnknown = true)
117 116 private String tagRfid;
118   -
119 117 /**
120 118 * 线路名称
121 119 */
122 120 @Excel(name = "线路名称")
123 121 @JsonIgnoreProperties(ignoreUnknown = true)
124 122 private String lineName;
125   -
126 123 /**
127 124 * 线路编码
128 125 */
129 126 @Excel(name = "线路编码")
130 127 @JsonIgnoreProperties(ignoreUnknown = true)
131 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 42 remark,
43 43 line_name,
44 44 line_code,
45   - sign_in
  45 + face_sign_in,
  46 + image
46 47 from driver
47 48 </sql>
48 49 <sql id="insertDriverVo">
49 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 52 </sql>
52 53  
53 54 <select id="selectDriverList" parameterType="Driver" resultMap="DriverResult">
... ... @@ -72,6 +73,7 @@
72 73 <if test="tagRfid != null and tagRfid != ''">and tag_rfid = #{tagRfid}</if>
73 74 <if test="lineName != null and lineName != ''">and line_name like concat('%', #{lineName}, '%')</if>
74 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 77 </where>
76 78 </select>
77 79  
... ... @@ -127,6 +129,8 @@
127 129 <if test="remark != null">remark,</if>
128 130 <if test="lineName != null">line_name,</if>
129 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 134 </trim>
131 135 <trim prefix="values (" suffix=")" suffixOverrides=",">
132 136 <if test="jobCode != null and jobCode != ''">#{jobCode},</if>
... ... @@ -145,6 +149,8 @@
145 149 <if test="remark != null">#{remark},</if>
146 150 <if test="lineName != null">#{lineName},</if>
147 151 <if test="lineCode != null">#{lineCode},</if>
  152 + <if test="faceSignIn != null">#{faceSignIn},</if>
  153 + <if test="image != null">#{image}</if>
148 154 </trim>
149 155 </insert>
150 156  
... ... @@ -167,7 +173,8 @@
167 173 <if test="remark != null">remark = #{remark},</if>
168 174 <if test="lineName != null">line_name = #{lineName},</if>
169 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 178 </trim>
172 179 where id = #{id}
173 180 </update>
... ... @@ -253,7 +260,8 @@
253 260 #{item.remark,jdbcType=VARCHAR},
254 261 #{item.lineName,jdbcType=VARCHAR},
255 262 #{item.lineCode,jdbcType=VARCHAR},
256   - #{item.signIn}
  263 + #{item.faceSignIn},
  264 + #{item.image}
257 265 )
258 266 </foreach>
259 267 on duplicate key update
... ...