用户创建作品createUserWork接口实现。
This commit is contained in:
parent
5094efca72
commit
02eab6c935
@ -6,6 +6,7 @@ import com.ruoyi.common.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import com.ruoyi.common.exception.user.CaptchaException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||
import com.ruoyi.framework.manager.AsyncManager;
|
||||
import com.ruoyi.framework.manager.factory.AsyncFactory;
|
||||
import com.ruoyi.system.domain.BaiduCardBack;
|
||||
@ -31,6 +32,7 @@ import com.ruoyi.system.service.IUserInfoService;
|
||||
import com.ruoyi.framework.web.service.TokenService;
|
||||
import com.ruoyi.system.domain.UserInfo;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.system.service.IUserWorkService;
|
||||
import com.ruoyi.web.controller.app.baidu.GsonUtils;
|
||||
import com.ruoyi.web.controller.app.baidu.OcrIdCardBAI;
|
||||
import com.ruoyi.web.controller.common.CaptchaController;
|
||||
@ -73,6 +75,9 @@ public class AppSystemController {
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private IUserWorkService userWorkService;
|
||||
|
||||
|
||||
/**
|
||||
* 账号密码登录
|
||||
@ -565,5 +570,60 @@ public class AppSystemController {
|
||||
return error("文件上传失败");
|
||||
}
|
||||
}
|
||||
@PostMapping("createUserWork")
|
||||
public AjaxResult createUserWork(@RequestParam("workDto") String userWorkDtoString,
|
||||
@RequestParam("work") MultipartFile workImage){
|
||||
|
||||
UserWorkDto userWorkdto = GsonUtils.fromJson(userWorkDtoString, UserWorkDto.class);
|
||||
String username = SecurityUtils.getUsername();
|
||||
|
||||
String workName = userWorkdto.getWorkName();
|
||||
String workType = userWorkdto.getWorkStatus();
|
||||
String workDetail = userWorkdto.getDetail();
|
||||
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
|
||||
UserWork userWork = new UserWork();
|
||||
|
||||
userWork.setUserId(userId);
|
||||
userWork.setWorkName(workName);
|
||||
userWork.setWorkStatus(workType);
|
||||
userWork.setDetail(workDetail);
|
||||
userWork.setCoordinate("0000");
|
||||
|
||||
String localPath = RuoYiConfig.getProfile();
|
||||
if (workImage.isEmpty()) {
|
||||
return error("文件为空");
|
||||
}
|
||||
// 验证文件类型(可选,这里只允许jpg,jpeg和png格式)
|
||||
String fileType = workImage.getContentType().split("/")[1].toLowerCase();
|
||||
if (!"jpg".equals(fileType) && !"jpeg".equals(fileType) && !"png".equals(fileType)) {
|
||||
return error("只支持jpg、jpeg和png格式的图片");
|
||||
}
|
||||
String uuid = IdUtils.simpleUUID();
|
||||
// System.out.println(uuid);
|
||||
|
||||
|
||||
String filePath = localPath + "/work";
|
||||
try {
|
||||
// 保存文件到服务器
|
||||
workImage.transferTo(new File(filePath, username+uuid+".jpg"));
|
||||
userWork.setWorkAddress(filePath+"/"+username+uuid+".jpg");
|
||||
boolean flag = userWorkService.insertUserWork(userWork) > 0;
|
||||
|
||||
if(flag){
|
||||
|
||||
return success("保存作品成功");// 可以返回文件的相对路径或URL给前端
|
||||
}
|
||||
else{
|
||||
return error("保存作品失败");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return error("作品文件上传失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,8 +1,35 @@
|
||||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
public class UserWorkDto {
|
||||
private String workName;
|
||||
private String workname;
|
||||
private String detail;
|
||||
private String workType;
|
||||
private String workstatus;
|
||||
|
||||
public String getWorkName()
|
||||
{
|
||||
return workname;
|
||||
}
|
||||
|
||||
public void setWorkName(String workname)
|
||||
{
|
||||
this.workname = workname;
|
||||
}
|
||||
|
||||
public String getDetail()
|
||||
{
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail)
|
||||
{
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public String getWorkStatus(){
|
||||
return workstatus;
|
||||
}
|
||||
public void setWorkStatus(String workstatus){
|
||||
this.workstatus = workstatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user