Commit cc164197760206b55d389d415229fc03d92189be
1 parent
81c8d8d7
fix: insert bug resolve
Showing
4 changed files
with
123 additions
and
2 deletions
ruoyi-admin/src/main/java/com/ruoyi/driver/controller/DriverController.java
| @@ -44,7 +44,7 @@ public class DriverController extends BaseController { | @@ -44,7 +44,7 @@ public class DriverController extends BaseController { | ||
| 44 | */ | 44 | */ |
| 45 | @GetMapping("/{date}/{jobCode}") | 45 | @GetMapping("/{date}/{jobCode}") |
| 46 | @ApiOperation("获取驾驶员排班信息") | 46 | @ApiOperation("获取驾驶员排班信息") |
| 47 | - public AjaxResult getDriverSchedulingInfo(@PathVariable("date") String date, @PathVariable("jobCode") String jobCode) { | 47 | + public AjaxResult getDriverSchedulingInfo(@ApiParam(name = "date",value = "yyyyMMdd")@PathVariable("date") String date, @PathVariable("jobCode") String jobCode) { |
| 48 | return driverService.getDriverSchedulingInfo(date,jobCode); | 48 | return driverService.getDriverSchedulingInfo(date,jobCode); |
| 49 | } | 49 | } |
| 50 | 50 |
ruoyi-admin/src/main/java/com/ruoyi/in/controller/SignInController.java
| 1 | package com.ruoyi.in.controller; | 1 | package com.ruoyi.in.controller; |
| 2 | 2 | ||
| 3 | +import java.io.IOException; | ||
| 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.exception.file.FileUploadException; | ||
| 6 | import io.swagger.annotations.Api; | 8 | import io.swagger.annotations.Api; |
| 7 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
| 8 | import org.springframework.security.access.prepost.PreAuthorize; | 10 | import org.springframework.security.access.prepost.PreAuthorize; |
| @@ -82,13 +84,25 @@ public class SignInController extends BaseController | @@ -82,13 +84,25 @@ public class SignInController extends BaseController | ||
| 82 | // @PreAuthorize("@ss.hasPermi('in:in:add')") | 84 | // @PreAuthorize("@ss.hasPermi('in:in:add')") |
| 83 | @Log(title = "签到", businessType = BusinessType.INSERT) | 85 | @Log(title = "签到", businessType = BusinessType.INSERT) |
| 84 | @PostMapping | 86 | @PostMapping |
| 85 | - @ApiOperation("新增签到") | 87 | + @ApiOperation("新增签到(通过后台管理页面)") |
| 86 | public AjaxResult add(@RequestBody SignIn signIn) | 88 | public AjaxResult add(@RequestBody SignIn signIn) |
| 87 | { | 89 | { |
| 88 | return toAjax(signInService.insertSignIn(signIn)); | 90 | return toAjax(signInService.insertSignIn(signIn)); |
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | /** | 93 | /** |
| 94 | + * 新增签到 | ||
| 95 | + * @param signIn | ||
| 96 | + * @return | ||
| 97 | + * @throws FileUploadException | ||
| 98 | + */ | ||
| 99 | + @PostMapping("/newAdd") | ||
| 100 | + @ApiOperation("新增签到(设备传入)") | ||
| 101 | + public AjaxResult addSignIn(@RequestBody SignIn signIn) throws FileUploadException, IOException { | ||
| 102 | + return toAjax(signInService.addSignIn(signIn)); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + /** | ||
| 92 | * 修改签到 | 106 | * 修改签到 |
| 93 | */ | 107 | */ |
| 94 | // @PreAuthorize("@ss.hasPermi('in:in:edit')") | 108 | // @PreAuthorize("@ss.hasPermi('in:in:edit')") |
ruoyi-admin/src/main/java/com/ruoyi/in/service/ISignInService.java
| 1 | package com.ruoyi.in.service; | 1 | package com.ruoyi.in.service; |
| 2 | 2 | ||
| 3 | +import java.io.IOException; | ||
| 3 | import java.util.List; | 4 | import java.util.List; |
| 5 | + | ||
| 6 | +import com.ruoyi.common.exception.file.FileUploadException; | ||
| 4 | import com.ruoyi.in.domain.SignIn; | 7 | import com.ruoyi.in.domain.SignIn; |
| 5 | 8 | ||
| 6 | /** | 9 | /** |
| @@ -59,4 +62,10 @@ public interface ISignInService | @@ -59,4 +62,10 @@ public interface ISignInService | ||
| 59 | */ | 62 | */ |
| 60 | public int deleteSignInById(Long id); | 63 | public int deleteSignInById(Long id); |
| 61 | 64 | ||
| 65 | + /** | ||
| 66 | + * 设备签到 | ||
| 67 | + * @param signIn | ||
| 68 | + * @return | ||
| 69 | + */ | ||
| 70 | + int addSignIn(SignIn signIn) throws FileUploadException, IOException; | ||
| 62 | } | 71 | } |
ruoyi-admin/src/main/java/com/ruoyi/in/service/impl/SignInServiceImpl.java
| 1 | package com.ruoyi.in.service.impl; | 1 | package com.ruoyi.in.service.impl; |
| 2 | 2 | ||
| 3 | +import java.io.File; | ||
| 4 | +import java.io.FileNotFoundException; | ||
| 5 | +import java.io.FileOutputStream; | ||
| 6 | +import java.io.IOException; | ||
| 7 | +import java.util.Base64; | ||
| 3 | import java.util.List; | 8 | import java.util.List; |
| 9 | +import java.util.Objects; | ||
| 4 | 10 | ||
| 11 | +import com.ruoyi.common.config.RuoYiConfig; | ||
| 12 | +import com.ruoyi.common.constant.Constants; | ||
| 13 | +import com.ruoyi.common.exception.file.FileException; | ||
| 14 | +import com.ruoyi.common.exception.file.FileUploadException; | ||
| 5 | import com.ruoyi.common.utils.DateUtils; | 15 | import com.ruoyi.common.utils.DateUtils; |
| 6 | import com.ruoyi.common.SignInEnum; | 16 | import com.ruoyi.common.SignInEnum; |
| 17 | +import com.ruoyi.common.utils.StringUtils; | ||
| 18 | +import com.ruoyi.common.utils.file.FileUploadUtils; | ||
| 19 | +import com.ruoyi.common.utils.uuid.Seq; | ||
| 20 | +import com.ruoyi.common.utils.uuid.UUID; | ||
| 21 | +import org.apache.commons.io.FilenameUtils; | ||
| 7 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.stereotype.Service; | 23 | import org.springframework.stereotype.Service; |
| 9 | import com.ruoyi.in.mapper.SignInMapper; | 24 | import com.ruoyi.in.mapper.SignInMapper; |
| 10 | import com.ruoyi.in.domain.SignIn; | 25 | import com.ruoyi.in.domain.SignIn; |
| 11 | import com.ruoyi.in.service.ISignInService; | 26 | import com.ruoyi.in.service.ISignInService; |
| 27 | +import org.springframework.web.multipart.MultipartFile; | ||
| 12 | 28 | ||
| 13 | /** | 29 | /** |
| 14 | * 签到Service业务层处理 | 30 | * 签到Service业务层处理 |
| @@ -92,4 +108,86 @@ public class SignInServiceImpl implements ISignInService { | @@ -92,4 +108,86 @@ public class SignInServiceImpl implements ISignInService { | ||
| 92 | return signInMapper.deleteSignInById(id); | 108 | return signInMapper.deleteSignInById(id); |
| 93 | } | 109 | } |
| 94 | 110 | ||
| 111 | + @Override | ||
| 112 | + public int addSignIn(SignIn signIn) throws FileUploadException, IOException { | ||
| 113 | + // base64转图片 | ||
| 114 | + // 图片路径 | ||
| 115 | + String filePath = RuoYiConfig.getUploadPath(); | ||
| 116 | + // 固定jpg文件 | ||
| 117 | + String fileName = extractFilename("jpg"); | ||
| 118 | + // 获取相对路径 | ||
| 119 | + String absPath = getAbsoluteFile(filePath, fileName).getAbsolutePath(); | ||
| 120 | + startUpload(absPath,signIn.getImage()); | ||
| 121 | + | ||
| 122 | + // 把上传的文件路径保存到服务器 | ||
| 123 | + String pathFileName = getPathFileName(filePath, fileName); | ||
| 124 | + signIn.setImage(pathFileName); | ||
| 125 | + | ||
| 126 | + return signInMapper.insertSignIn(signIn); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * 获取相对路径名 | ||
| 131 | + * @param uploadDir | ||
| 132 | + * @param fileName | ||
| 133 | + * @return | ||
| 134 | + * @throws IOException | ||
| 135 | + */ | ||
| 136 | + public File getAbsoluteFile(String uploadDir, String fileName) throws IOException | ||
| 137 | + { | ||
| 138 | + File desc = new File(uploadDir + File.separator + fileName); | ||
| 139 | + | ||
| 140 | + if (!desc.exists()) | ||
| 141 | + { | ||
| 142 | + if (!desc.getParentFile().exists()) | ||
| 143 | + { | ||
| 144 | + desc.getParentFile().mkdirs(); | ||
| 145 | + } | ||
| 146 | + } | ||
| 147 | + return desc; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * 获取扩展文件名 | ||
| 152 | + * @param extendFileName | ||
| 153 | + * @return | ||
| 154 | + */ | ||
| 155 | + public String extractFilename(String extendFileName) | ||
| 156 | + { | ||
| 157 | + return StringUtils.format("{}/{}_{}.{}", DateUtils.datePath(), | ||
| 158 | + FilenameUtils.getBaseName(UUID.randomUUID().toString().replace("-","")), Seq.getId(Seq.uploadSeqType), extendFileName); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + /** | ||
| 162 | + * | ||
| 163 | + * @param uploadDir | ||
| 164 | + * @param fileName | ||
| 165 | + * @return | ||
| 166 | + * @throws IOException | ||
| 167 | + */ | ||
| 168 | + public String getPathFileName(String uploadDir, String fileName) throws IOException | ||
| 169 | + { | ||
| 170 | + int dirLastIndex = RuoYiConfig.getProfile().length() + 1; | ||
| 171 | + String currentDir = StringUtils.substring(uploadDir, dirLastIndex); | ||
| 172 | + return Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + public void startUpload(String url,String base64) throws FileUploadException { | ||
| 176 | + FileOutputStream outputStream = null; | ||
| 177 | + byte[] imageBytes = Base64.getDecoder().decode(base64); | ||
| 178 | + try { | ||
| 179 | + outputStream = new FileOutputStream(url); | ||
| 180 | + outputStream.write(imageBytes); | ||
| 181 | + } catch (Exception e) { | ||
| 182 | + throw new FileUploadException("文件上传异常"); | ||
| 183 | + } finally { | ||
| 184 | + try { | ||
| 185 | + if (!Objects.isNull(outputStream)) { | ||
| 186 | + outputStream.close(); | ||
| 187 | + } | ||
| 188 | + } catch (IOException e) { | ||
| 189 | + throw new RuntimeException(e); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + } | ||
| 95 | } | 193 | } |