Browse Source

[update]:物料信息增加上传图片功能;增加上传方法公共类;修改了bootstrap.min.css中的 input-file;增加vue引入、element-ui引入

erp、
youjianchi 1 year ago
parent
commit
3b3a386a05
  1. 21
      ruoyi-admin/src/main/java/com/ruoyi/common/service/ICommonService.java
  2. 141
      ruoyi-admin/src/main/java/com/ruoyi/common/service/impl/CommonServiceImpl.java
  3. 40
      ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpMaterial.java
  4. 60
      ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpMaterialServiceImpl.java
  5. 48
      ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysAttachFileController.java
  6. 97
      ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysAttach.java
  7. 138
      ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysAttachFile.java
  8. 67
      ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysAttachFileMapper.java
  9. 62
      ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysAttachMapper.java
  10. 68
      ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysAttachFileService.java
  11. 63
      ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysAttachService.java
  12. 130
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysAttachFileServiceImpl.java
  13. 103
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysAttachServiceImpl.java
  14. 37
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
  15. 56
      ruoyi-admin/src/main/resources/mapper/erp/ErpMaterialMapper.xml
  16. 117
      ruoyi-admin/src/main/resources/mapper/system/SysAttachFileMapper.xml
  17. 91
      ruoyi-admin/src/main/resources/mapper/system/SysAttachMapper.xml
  18. 1
      ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/element-ui.css
  19. 1
      ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/element-ui.js
  20. BIN
      ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/fonts/element-icons.ttf
  21. BIN
      ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/fonts/element-icons.woff
  22. 11914
      ruoyi-admin/src/main/resources/static/ajax/libs/vue/vue.js
  23. 2
      ruoyi-admin/src/main/resources/static/css/bootstrap.min.css
  24. 79
      ruoyi-admin/src/main/resources/templates/erp/material/add.html
  25. 127
      ruoyi-admin/src/main/resources/templates/erp/material/edit.html
  26. 7
      ruoyi-admin/src/main/resources/templates/erp/material/material.html
  27. 5
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java
  28. 18
      ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java

21
ruoyi-admin/src/main/java/com/ruoyi/common/service/ICommonService.java

@ -0,0 +1,21 @@
package com.ruoyi.common.service;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Description 公共服务
* @Author youjianchi
* @Date 2023/11/13 14:23
*/
public interface ICommonService {
AjaxResult uploadFile(MultipartFile file,String sourceType,String sourceSubType,Long attachId) throws Exception;
AjaxResult uploadSingleFile(MultipartFile file);
AjaxResult delete(Long id);
void deleteByIds(List<String> ids);
}

141
ruoyi-admin/src/main/java/com/ruoyi/common/service/impl/CommonServiceImpl.java

@ -0,0 +1,141 @@
package com.ruoyi.common.service.impl;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.config.ServerConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.service.ICommonService;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.system.domain.SysAttach;
import com.ruoyi.system.domain.SysAttachFile;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.List;
/**
* @Description 公共服务实现
* @Author youjianchi
* @Date 2023/11/13 14:25
*/
@Service
public class CommonServiceImpl implements ICommonService {
@Autowired
private ServerConfig serverConfig;
@Autowired
private ISysAttachService attachService;
@Autowired
private ISysAttachFileService attachFileService;
private static final String FILE_DELIMETER = ",";
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult uploadFile(MultipartFile file, String sourceType, String sourceSubType,Long attachId) throws Exception {
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = null;
try {
fileName = FileUploadUtils.upload(filePath, file);
} catch (Exception e) {
throw new Exception("文件上传失败");
}
String url = serverConfig.getUrl() + fileName;
String originalFilename = file.getOriginalFilename();
String fileExt = originalFilename.substring(originalFilename.lastIndexOf(".")+1);
Long fileSize = file.getSize();
if(attachId==null){
SysAttach attach = new SysAttach();
attach.setCreateBy("admin");
attach.setCreateTime(new Date());
attach.setSourceType(sourceType);
attach.setSourceSubType(sourceSubType);
attachService.insertSysAttach(attach);
attachId = attach.getId();
}
SysAttachFile sysAttachFile = new SysAttachFile();
sysAttachFile.setAttachId(attachId);
sysAttachFile.setName(originalFilename);
sysAttachFile.setUrl(url);
sysAttachFile.setSize(fileSize);
sysAttachFile.setExt(fileExt);
attachFileService.insertSysAttachFile(sysAttachFile);
Long fileId = sysAttachFile.getId();
AjaxResult ajax = AjaxResult.success();
ajax.put("attachId", attachId);
ajax.put("fileId", fileId);
ajax.put("url", url);
ajax.put("fileName", fileName);
ajax.put("newFileName", FileUtils.getName(fileName));
ajax.put("originalFilename", originalFilename);
return ajax;
}
@Override
public AjaxResult uploadSingleFile(MultipartFile file) {
try
{
// 上传文件路径
String filePath = RuoYiConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName;
String originalFilename = file.getOriginalFilename();
String fileExt = originalFilename.substring(originalFilename.lastIndexOf(".")+1);
Long fileSize = file.getSize();
// 保存文件信息
SysAttachFile sysAttachFile = new SysAttachFile();
sysAttachFile.setName(originalFilename);
sysAttachFile.setUrl(url);
sysAttachFile.setSize(fileSize);
sysAttachFile.setExt(fileExt);
sysAttachFile.setPath(fileName);
attachFileService.insertSysAttachFile(sysAttachFile);
AjaxResult ajax = AjaxResult.success(sysAttachFile);
return ajax;
}
catch (Exception e)
{
return AjaxResult.error(e.getMessage());
}
}
@Override
public AjaxResult delete(Long id) {
SysAttachFile attachFile = attachFileService.selectSysAttachFileById(id);
if(attachFile!=null){
String path = attachFile.getPath();
String actualPath = RuoYiConfig.getProfile()+ path.replace("/profile","");
// 删除文件
FileUtils.deleteFile(actualPath);
// 删除文件信息
attachFileService.deleteSysAttachFileById(id);
}
return AjaxResult.success();
}
@Override
public void deleteByIds(List<String> ids) {
ids.forEach(idStr->{
Long id = Long.parseLong(idStr);
SysAttachFile attachFile = attachFileService.selectSysAttachFileById(id);
if(attachFile!=null){
String path = attachFile.getPath();
String actualPath = RuoYiConfig.getProfile()+ path.replace("/profile","");
// 删除文件
FileUtils.deleteFile(actualPath);
// 删除文件信息
attachFileService.deleteSysAttachFileById(id);
}
});
}
}

40
ruoyi-admin/src/main/java/com/ruoyi/erp/domain/ErpMaterial.java

@ -67,6 +67,14 @@ public class ErpMaterial extends BaseEntity
@Excel(name = "入库部门") @Excel(name = "入库部门")
private String warehouseDept; private String warehouseDept;
private Long photoAttachId;
private String photoUrl;
private String fileIdStr;
private String removeFileIdStr;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
@ -185,6 +193,38 @@ public class ErpMaterial extends BaseEntity
return warehouseDept; return warehouseDept;
} }
public Long getPhotoAttachId() {
return photoAttachId;
}
public void setPhotoAttachId(Long photoAttachId) {
this.photoAttachId = photoAttachId;
}
public String getPhotoUrl() {
return photoUrl;
}
public void setPhotoUrl(String photoUrl) {
this.photoUrl = photoUrl;
}
public String getFileIdStr() {
return fileIdStr;
}
public void setFileIdStr(String fileIdStr) {
this.fileIdStr = fileIdStr;
}
public String getRemoveFileIdStr() {
return removeFileIdStr;
}
public void setRemoveFileIdStr(String removeFileIdStr) {
this.removeFileIdStr = removeFileIdStr;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

60
ruoyi-admin/src/main/java/com/ruoyi/erp/service/impl/ErpMaterialServiceImpl.java

@ -1,10 +1,18 @@
package com.ruoyi.erp.service.impl; package com.ruoyi.erp.service.impl;
import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.service.ICommonService;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysAttach;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.erp.mapper.ErpMaterialMapper; import com.ruoyi.erp.mapper.ErpMaterialMapper;
@ -24,6 +32,15 @@ public class ErpMaterialServiceImpl implements IErpMaterialService
@Autowired @Autowired
private ErpMaterialMapper erpMaterialMapper; private ErpMaterialMapper erpMaterialMapper;
@Autowired
private ISysAttachService attachService;
@Autowired
private ISysAttachFileService attachFileService;
@Autowired
private ICommonService commonService;
/** /**
* 查询物料信息 * 查询物料信息
* *
@ -57,8 +74,25 @@ public class ErpMaterialServiceImpl implements IErpMaterialService
@Override @Override
public int insertErpMaterial(ErpMaterial erpMaterial) public int insertErpMaterial(ErpMaterial erpMaterial)
{ {
int result = erpMaterialMapper.insertErpMaterial(erpMaterial);
Long id = erpMaterial.getId();
String fileIdStr = erpMaterial.getFileIdStr();
if(StringUtils.isNotBlank(fileIdStr)){
// 保存附件关联
SysAttach attach = new SysAttach();
attach.setCreateBy("admin");
attach.setCreateTime(new Date());
attach.setSourceType("erpMaterial");
attach.setSourceSubType("photo");
attach.setRelId(id);
attachService.insertSysAttach(attach);
// 更新附件与文件关联
Long attachId = attach.getId();
List<String> fileIdList = Arrays.asList(fileIdStr.split(";"));
attachFileService.updateAttachIdByIdList(attachId,fileIdList);
}
erpMaterial.setCreateTime(DateUtils.getNowDate()); erpMaterial.setCreateTime(DateUtils.getNowDate());
return erpMaterialMapper.insertErpMaterial(erpMaterial); return result;
} }
/** /**
@ -70,6 +104,30 @@ public class ErpMaterialServiceImpl implements IErpMaterialService
@Override @Override
public int updateErpMaterial(ErpMaterial erpMaterial) public int updateErpMaterial(ErpMaterial erpMaterial)
{ {
String loginName = ShiroUtils.getLoginName();
Long id = erpMaterial.getId();
String fileIdStr = erpMaterial.getFileIdStr();
Long photoAttachId = erpMaterial.getPhotoAttachId();
String removeFileIdStr = erpMaterial.getRemoveFileIdStr();
if(StringUtils.isNotBlank(removeFileIdStr)){
List<String> removeFileIdList = Arrays.asList(removeFileIdStr.split(";"));
commonService.deleteByIds(removeFileIdList);
}
if(StringUtils.isNotBlank(fileIdStr)) {
List<String> fileIdList = Arrays.asList(fileIdStr.split(";"));
if (photoAttachId == null) {
SysAttach attach = new SysAttach();
attach.setCreateBy(loginName);
attach.setCreateTime(new Date());
attach.setSourceType("erpMaterial");
attach.setSourceSubType("photo");
attach.setRelId(id);
attachService.insertSysAttach(attach);
photoAttachId = attach.getId();
}
attachFileService.updateAttachIdByIdList(photoAttachId, fileIdList);
}
erpMaterial.setUpdateBy(loginName);
erpMaterial.setUpdateTime(DateUtils.getNowDate()); erpMaterial.setUpdateTime(DateUtils.getNowDate());
return erpMaterialMapper.updateErpMaterial(erpMaterial); return erpMaterialMapper.updateErpMaterial(erpMaterial);
} }

48
ruoyi-admin/src/main/java/com/ruoyi/system/controller/SysAttachFileController.java

@ -0,0 +1,48 @@
package com.ruoyi.system.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysAttachFile;
import com.ruoyi.system.service.ISysAttachFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 附件文件Controller
*
* @author ruoyi
* @date 2023-11-13
*/
@Controller
@RequestMapping("/system/attach/file")
public class SysAttachFileController extends BaseController
{
private String prefix = "system/attach/file";
@Autowired
private ISysAttachFileService sysAttachFileService;
@GetMapping( "/getListByAttachId")
@ResponseBody
public AjaxResult getListByAttachId(@RequestParam("attachId")Long attachId){
List<SysAttachFile> attachFileList = sysAttachFileService.getListByAttachId(attachId);
return AjaxResult.success(attachFileList);
}
@GetMapping( "/delFileAndAttachById")
@ResponseBody
public AjaxResult delFileAndAttachById(Long id)
{
return toAjax(sysAttachFileService.delFileAndAttachById(id));
}
@PostMapping( "/delFileAndAttachByKey")
@ResponseBody
public AjaxResult delFileAndAttachByKey(Long key)
{
return toAjax(sysAttachFileService.delFileAndAttachById(key));
}
}

97
ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysAttach.java

@ -0,0 +1,97 @@
package com.ruoyi.system.domain;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 附件业务关联对象 sys_attach
*
* @author ruoyi
* @date 2023-11-13
*/
public class SysAttach extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
private Long id;
/** 删除标志(0代表存在 2代表删除) */
private String delFlag;
/** 关联记录ID */
@Excel(name = "关联记录ID")
private Long relId;
/** 附件业务类型 */
@Excel(name = "附件业务类型")
private String sourceType;
/** 附件业务子类型 */
@Excel(name = "附件业务子类型")
private String sourceSubType;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getDelFlag()
{
return delFlag;
}
public void setRelId(Long relId)
{
this.relId = relId;
}
public Long getRelId()
{
return relId;
}
public void setSourceType(String sourceType)
{
this.sourceType = sourceType;
}
public String getSourceType()
{
return sourceType;
}
public void setSourceSubType(String sourceSubType)
{
this.sourceSubType = sourceSubType;
}
public String getSourceSubType()
{
return sourceSubType;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("relId", getRelId())
.append("sourceType", getSourceType())
.append("sourceSubType", getSourceSubType())
.toString();
}
}

138
ruoyi-admin/src/main/java/com/ruoyi/system/domain/SysAttachFile.java

@ -0,0 +1,138 @@
package com.ruoyi.system.domain;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 附件文件对象 sys_attach_file
*
* @author ruoyi
* @date 2023-11-13
*/
public class SysAttachFile extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键ID */
private Long id;
/** 删除标志(0代表存在 2代表删除) */
private String delFlag;
/** 附件业务id */
@Excel(name = "附件业务id")
private Long attachId;
/** 文件名称 */
@Excel(name = "文件名称")
private String name;
/** 文件后缀 */
@Excel(name = "文件后缀")
private String ext;
/** 文件大小 */
@Excel(name = "文件大小")
private Long size;
/** 文件url */
@Excel(name = "文件url")
private String url;
/** 文件路径 */
@Excel(name = "文件路径")
private String path;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getDelFlag()
{
return delFlag;
}
public void setAttachId(Long attachId)
{
this.attachId = attachId;
}
public Long getAttachId()
{
return attachId;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setExt(String ext)
{
this.ext = ext;
}
public String getExt()
{
return ext;
}
public void setSize(Long size)
{
this.size = size;
}
public Long getSize()
{
return size;
}
public void setUrl(String url)
{
this.url = url;
}
public String getUrl()
{
return url;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.append("attachId", getAttachId())
.append("name", getName())
.append("ext", getExt())
.append("size", getSize())
.append("url", getUrl())
.append("path", getPath())
.toString();
}
}

67
ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysAttachFileMapper.java

@ -0,0 +1,67 @@
package com.ruoyi.system.mapper;
import com.ruoyi.system.domain.SysAttachFile;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 附件文件Mapper接口
*
* @author ruoyi
* @date 2023-11-13
*/
public interface SysAttachFileMapper
{
/**
* 查询附件文件
*
* @param id 附件文件ID
* @return 附件文件
*/
public SysAttachFile selectSysAttachFileById(Long id);
/**
* 查询附件文件列表
*
* @param sysAttachFile 附件文件
* @return 附件文件集合
*/
public List<SysAttachFile> selectSysAttachFileList(SysAttachFile sysAttachFile);
/**
* 新增附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
public int insertSysAttachFile(SysAttachFile sysAttachFile);
/**
* 修改附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
public int updateSysAttachFile(SysAttachFile sysAttachFile);
/**
* 删除附件文件
*
* @param id 附件文件ID
* @return 结果
*/
public int deleteSysAttachFileById(Long id);
/**
* 批量删除附件文件
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysAttachFileByIds(String[] ids);
List<SysAttachFile> selectListByAttachId(Long attachId);
int updateAttachIdByIdList(@Param("attachId")Long attachId,@Param("idList")List<String> idList);
}

62
ruoyi-admin/src/main/java/com/ruoyi/system/mapper/SysAttachMapper.java

@ -0,0 +1,62 @@
package com.ruoyi.system.mapper;
import com.ruoyi.system.domain.SysAttach;
import java.util.List;
/**
* 附件业务关联Mapper接口
*
* @author ruoyi
* @date 2023-11-13
*/
public interface SysAttachMapper
{
/**
* 查询附件业务关联
*
* @param id 附件业务关联ID
* @return 附件业务关联
*/
public SysAttach selectSysAttachById(Long id);
/**
* 查询附件业务关联列表
*
* @param sysAttach 附件业务关联
* @return 附件业务关联集合
*/
public List<SysAttach> selectSysAttachList(SysAttach sysAttach);
/**
* 新增附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
public int insertSysAttach(SysAttach sysAttach);
/**
* 修改附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
public int updateSysAttach(SysAttach sysAttach);
/**
* 删除附件业务关联
*
* @param id 附件业务关联ID
* @return 结果
*/
public int deleteSysAttachById(Long id);
/**
* 批量删除附件业务关联
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysAttachByIds(String[] ids);
}

68
ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysAttachFileService.java

@ -0,0 +1,68 @@
package com.ruoyi.system.service;
import com.ruoyi.system.domain.SysAttachFile;
import java.util.List;
/**
* 附件文件Service接口
*
* @author ruoyi
* @date 2023-11-13
*/
public interface ISysAttachFileService
{
/**
* 查询附件文件
*
* @param id 附件文件ID
* @return 附件文件
*/
public SysAttachFile selectSysAttachFileById(Long id);
/**
* 查询附件文件列表
*
* @param sysAttachFile 附件文件
* @return 附件文件集合
*/
public List<SysAttachFile> selectSysAttachFileList(SysAttachFile sysAttachFile);
/**
* 新增附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
public int insertSysAttachFile(SysAttachFile sysAttachFile);
/**
* 修改附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
public int updateSysAttachFile(SysAttachFile sysAttachFile);
/**
* 批量删除附件文件
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysAttachFileByIds(String ids);
/**
* 删除附件文件信息
*
* @param id 附件文件ID
* @return 结果
*/
public int deleteSysAttachFileById(Long id);
List<SysAttachFile> getListByAttachId(Long attachId);
int delFileAndAttachById(Long id);
int updateAttachIdByIdList(Long attachId,List<String> idList);
}

63
ruoyi-admin/src/main/java/com/ruoyi/system/service/ISysAttachService.java

@ -0,0 +1,63 @@
package com.ruoyi.system.service;
import com.ruoyi.system.domain.SysAttach;
import java.util.List;
/**
* 附件业务关联Service接口
*
* @author ruoyi
* @date 2023-11-13
*/
public interface ISysAttachService
{
/**
* 查询附件业务关联
*
* @param id 附件业务关联ID
* @return 附件业务关联
*/
public SysAttach selectSysAttachById(Long id);
/**
* 查询附件业务关联列表
*
* @param sysAttach 附件业务关联
* @return 附件业务关联集合
*/
public List<SysAttach> selectSysAttachList(SysAttach sysAttach);
/**
* 新增附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
public int insertSysAttach(SysAttach sysAttach);
/**
* 修改附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
public int updateSysAttach(SysAttach sysAttach);
/**
* 批量删除附件业务关联
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteSysAttachByIds(String ids);
/**
* 删除附件业务关联信息
*
* @param id 附件业务关联ID
* @return 结果
*/
public int deleteSysAttachById(Long id);
}

130
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysAttachFileServiceImpl.java

@ -0,0 +1,130 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysAttachFile;
import com.ruoyi.system.mapper.SysAttachFileMapper;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 附件文件Service业务层处理
*
* @author ruoyi
* @date 2023-11-13
*/
@Service
public class SysAttachFileServiceImpl implements ISysAttachFileService
{
@Autowired
private SysAttachFileMapper sysAttachFileMapper;
@Autowired
private ISysAttachService attachService;
/**
* 查询附件文件
*
* @param id 附件文件ID
* @return 附件文件
*/
@Override
public SysAttachFile selectSysAttachFileById(Long id)
{
return sysAttachFileMapper.selectSysAttachFileById(id);
}
/**
* 查询附件文件列表
*
* @param sysAttachFile 附件文件
* @return 附件文件
*/
@Override
public List<SysAttachFile> selectSysAttachFileList(SysAttachFile sysAttachFile)
{
return sysAttachFileMapper.selectSysAttachFileList(sysAttachFile);
}
/**
* 新增附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
@Override
public int insertSysAttachFile(SysAttachFile sysAttachFile)
{
sysAttachFile.setCreateTime(DateUtils.getNowDate());
return sysAttachFileMapper.insertSysAttachFile(sysAttachFile);
}
/**
* 修改附件文件
*
* @param sysAttachFile 附件文件
* @return 结果
*/
@Override
public int updateSysAttachFile(SysAttachFile sysAttachFile)
{
sysAttachFile.setUpdateTime(DateUtils.getNowDate());
return sysAttachFileMapper.updateSysAttachFile(sysAttachFile);
}
/**
* 删除附件文件对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteSysAttachFileByIds(String ids)
{
return sysAttachFileMapper.deleteSysAttachFileByIds(Convert.toStrArray(ids));
}
/**
* 删除附件文件信息
*
* @param id 附件文件ID
* @return 结果
*/
@Override
public int deleteSysAttachFileById(Long id)
{
return sysAttachFileMapper.deleteSysAttachFileById(id);
}
@Override
public List<SysAttachFile> getListByAttachId(Long attachId) {
SysAttachFile attachFile = new SysAttachFile();
attachFile.setAttachId(attachId);
List<SysAttachFile> sysAttachFiles = selectSysAttachFileList(attachFile);
return sysAttachFiles;
}
@Override
@Transactional(rollbackFor = Exception.class)
public int delFileAndAttachById(Long id) {
SysAttachFile attachFile = sysAttachFileMapper.selectSysAttachFileById(id);
Long attachId = attachFile.getAttachId();
int i = sysAttachFileMapper.deleteSysAttachFileById(id);
List<SysAttachFile> attachFileList = sysAttachFileMapper.selectListByAttachId(attachId);
if(CollectionUtils.isEmpty(attachFileList)){
attachService.deleteSysAttachById(attachId);
}
return i;
}
@Override
public int updateAttachIdByIdList(Long attachId,List<String> idList) {
return sysAttachFileMapper.updateAttachIdByIdList(attachId,idList);
}
}

103
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysAttachServiceImpl.java

@ -0,0 +1,103 @@
package com.ruoyi.system.service.impl;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysAttach;
import com.ruoyi.system.mapper.SysAttachMapper;
import com.ruoyi.system.service.ISysAttachFileService;
import com.ruoyi.system.service.ISysAttachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 附件业务关联Service业务层处理
*
* @author ruoyi
* @date 2023-11-13
*/
@Service
public class SysAttachServiceImpl implements ISysAttachService
{
@Autowired
private SysAttachMapper sysAttachMapper;
@Autowired
private ISysAttachFileService attachFileService;
/**
* 查询附件业务关联
*
* @param id 附件业务关联ID
* @return 附件业务关联
*/
@Override
public SysAttach selectSysAttachById(Long id)
{
return sysAttachMapper.selectSysAttachById(id);
}
/**
* 查询附件业务关联列表
*
* @param sysAttach 附件业务关联
* @return 附件业务关联
*/
@Override
public List<SysAttach> selectSysAttachList(SysAttach sysAttach)
{
return sysAttachMapper.selectSysAttachList(sysAttach);
}
/**
* 新增附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
@Override
public int insertSysAttach(SysAttach sysAttach)
{
sysAttach.setCreateTime(DateUtils.getNowDate());
return sysAttachMapper.insertSysAttach(sysAttach);
}
/**
* 修改附件业务关联
*
* @param sysAttach 附件业务关联
* @return 结果
*/
@Override
public int updateSysAttach(SysAttach sysAttach)
{
sysAttach.setUpdateTime(DateUtils.getNowDate());
return sysAttachMapper.updateSysAttach(sysAttach);
}
/**
* 删除附件业务关联对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteSysAttachByIds(String ids)
{
return sysAttachMapper.deleteSysAttachByIds(Convert.toStrArray(ids));
}
/**
* 删除附件业务关联信息
*
* @param id 附件业务关联ID
* @return 结果
*/
@Override
public int deleteSysAttachById(Long id)
{
return sysAttachMapper.deleteSysAttachById(id);
}
}

37
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@ -4,6 +4,7 @@ import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.config.ServerConfig; import com.ruoyi.common.config.ServerConfig;
import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.service.ICommonService;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.file.FileUtils;
@ -12,9 +13,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -26,6 +25,7 @@ import javax.servlet.http.HttpServletResponse;
* @author ruoyi * @author ruoyi
*/ */
@Controller @Controller
@RequestMapping("/common")
public class CommonController public class CommonController
{ {
private static final Logger log = LoggerFactory.getLogger(CommonController.class); private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@ -33,13 +33,16 @@ public class CommonController
@Autowired @Autowired
private ServerConfig serverConfig; private ServerConfig serverConfig;
@Autowired
private ICommonService commonService;
/** /**
* 通用下载请求 * 通用下载请求
* *
* @param fileName 文件名称 * @param fileName 文件名称
* @param delete 是否删除 * @param delete 是否删除
*/ */
@GetMapping("common/download") @GetMapping("/download")
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
{ {
try try
@ -70,7 +73,7 @@ public class CommonController
/** /**
* 通用上传请求 * 通用上传请求
*/ */
@PostMapping("/common/upload") @PostMapping("/upload")
@ResponseBody @ResponseBody
public AjaxResult uploadFile(MultipartFile file) throws Exception public AjaxResult uploadFile(MultipartFile file) throws Exception
{ {
@ -92,10 +95,32 @@ public class CommonController
} }
} }
/**
* 通用上传请求
*/
@PostMapping("/uploadSingleFile")
@ResponseBody
public AjaxResult uploadSingleFile(@RequestParam("file") MultipartFile file) throws Exception
{
AjaxResult ajaxResult = commonService.uploadSingleFile(file);
return ajaxResult;
}
/**
* 删除文件
*/
@GetMapping("/deleteFile")
@ResponseBody
public AjaxResult deleteFile(@RequestParam(name = "id") Long id) throws Exception
{
AjaxResult ajaxResult = commonService.delete(id);
return ajaxResult;
}
/** /**
* 本地资源通用下载 * 本地资源通用下载
*/ */
@GetMapping("/common/download/resource") @GetMapping("/download/resource")
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
throws Exception throws Exception
{ {

56
ruoyi-admin/src/main/resources/mapper/erp/ErpMaterialMapper.xml

@ -23,6 +23,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="brand" column="brand" /> <result property="brand" column="brand" />
<result property="describe" column="describe" /> <result property="describe" column="describe" />
<result property="warehouseDept" column="warehouse_dept" /> <result property="warehouseDept" column="warehouse_dept" />
<result property="photoAttachId" column="photo_attach_id" />
<result property="photoUrl" column="photo_url" />
</resultMap> </resultMap>
<sql id="selectErpMaterialVo"> <sql id="selectErpMaterialVo">
@ -30,27 +32,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</sql> </sql>
<select id="selectErpMaterialList" parameterType="ErpMaterial" resultMap="ErpMaterialResult"> <select id="selectErpMaterialList" parameterType="ErpMaterial" resultMap="ErpMaterialResult">
<include refid="selectErpMaterialVo"/> select erp.id, erp.del_flag, erp.create_by, erp.create_time, erp.update_by, erp.update_time, erp.remark, erp.material_no
, erp.material_name, erp.audit_status, erp.use_status, erp.hava_product_tem, erp.material_type, erp.process_method
, erp.unit, erp.brand, erp.`describe`, erp.warehouse_dept
,file.url as photo_url
from erp_material erp
left join (
select
att.rel_id
,file.url
,min(file.create_time) as create_time
from sys_attach att
left join sys_attach_file file
on att.id = file.attach_id
where att.source_type = 'erpMaterial' and att.source_sub_type = 'photo'
group by att.rel_id
)file
on erp.id = file.rel_id
<where> <where>
<if test="createBy != null and createBy != ''"> and create_by = #{createBy}</if> <if test="createBy != null and createBy != ''"> and erp.create_by = #{createBy}</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if> <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and erp.create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
<if test="materialNo != null and materialNo != ''"> and material_no = #{materialNo}</if> <if test="materialNo != null and materialNo != ''"> and erp.material_no = #{materialNo}</if>
<if test="materialName != null and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if> <if test="materialName != null and materialName != ''"> and erp.material_name like concat('%', #{materialName}, '%')</if>
<if test="auditStatus != null and auditStatus != ''"> and audit_status = #{auditStatus}</if> <if test="auditStatus != null and auditStatus != ''"> and erp.audit_status = #{auditStatus}</if>
<if test="useStatus != null and useStatus != ''"> and use_status = #{useStatus}</if> <if test="useStatus != null and useStatus != ''"> and erp.use_status = #{useStatus}</if>
<if test="havaProductTem != null and havaProductTem != ''"> and hava_product_tem = #{havaProductTem}</if> <if test="havaProductTem != null and havaProductTem != ''"> and erp.hava_product_tem = #{havaProductTem}</if>
<if test="materialType != null and materialType != ''"> and material_type = #{materialType}</if> <if test="materialType != null and materialType != ''"> and erp.material_type = #{materialType}</if>
<if test="processMethod != null and processMethod != ''"> and process_method = #{processMethod}</if> <if test="processMethod != null and processMethod != ''"> and erp.process_method = #{processMethod}</if>
<if test="unit != null and unit != ''"> and unit = #{unit}</if> <if test="unit != null and unit != ''"> and erp.unit = #{unit}</if>
<if test="brand != null and brand != ''"> and brand = #{brand}</if> <if test="brand != null and brand != ''"> and erp.brand = #{brand}</if>
<if test="describe != null and describe != ''"> and `describe` = #{describe}</if> <if test="describe != null and describe != ''"> and erp.`describe` = #{describe}</if>
<if test="warehouseDept != null and warehouseDept != ''"> and warehouse_dept = #{warehouseDept}</if> <if test="warehouseDept != null and warehouseDept != ''"> and erp.warehouse_dept = #{warehouseDept}</if>
</where> </where>
</select> </select>
<select id="selectErpMaterialById" parameterType="Long" resultMap="ErpMaterialResult"> <select id="selectErpMaterialById" parameterType="Long" resultMap="ErpMaterialResult">
<include refid="selectErpMaterialVo"/> select erp.id, erp.del_flag, erp.create_by, erp.create_time, erp.update_by, erp.update_time, erp.remark, erp.material_no
where id = #{id} , erp.material_name, erp.audit_status, erp.use_status, erp.hava_product_tem, erp.material_type, erp.process_method
, erp.unit, erp.brand, erp.`describe`, erp.warehouse_dept
,att.id as photo_attach_id
from erp_material erp
left join sys_attach att
on erp.id = att.rel_id and att.source_type = 'erpMaterial' and att.source_sub_type = 'photo'
where erp.id = #{id}
</select> </select>
<select id="checkMaterialNoUnique" resultType="java.lang.Integer"> <select id="checkMaterialNoUnique" resultType="java.lang.Integer">

117
ruoyi-admin/src/main/resources/mapper/system/SysAttachFileMapper.xml

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysAttachFileMapper">
<resultMap type="SysAttachFile" id="SysAttachFileResult">
<result property="id" column="id" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="attachId" column="attach_id" />
<result property="name" column="name" />
<result property="ext" column="ext" />
<result property="size" column="size" />
<result property="url" column="url" />
<result property="path" column="path" />
</resultMap>
<sql id="selectSysAttachFileVo">
select id, del_flag, create_by, create_time, update_by, update_time, remark, attach_id, name, ext, size, url,path from sys_attach_file
</sql>
<select id="selectSysAttachFileList" parameterType="SysAttachFile" resultMap="SysAttachFileResult">
<include refid="selectSysAttachFileVo"/>
<where>
<if test="attachId != null "> and attach_id = #{attachId}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="ext != null and ext != ''"> and ext = #{ext}</if>
<if test="size != null "> and size = #{size}</if>
<if test="url != null and url != ''"> and url = #{url}</if>
</where>
</select>
<select id="selectSysAttachFileById" parameterType="Long" resultMap="SysAttachFileResult">
<include refid="selectSysAttachFileVo"/>
where id = #{id}
</select>
<select id="selectListByAttachId" resultMap="SysAttachFileResult">
<include refid="selectSysAttachFileVo"/>
where attach_id = #{attachId}
</select>
<insert id="insertSysAttachFile" parameterType="SysAttachFile" useGeneratedKeys="true" keyProperty="id">
insert into sys_attach_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null ">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null ">update_time,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="attachId != null ">attach_id,</if>
<if test="name != null and name != ''">name,</if>
<if test="ext != null and ext != ''">ext,</if>
<if test="size != null ">size,</if>
<if test="url != null and url != ''">url,</if>
<if test="path != null and path != ''">path,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null ">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null ">#{updateTime},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="attachId != null ">#{attachId},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="ext != null and ext != ''">#{ext},</if>
<if test="size != null ">#{size},</if>
<if test="url != null and url != ''">#{url},</if>
<if test="path != null and path != ''">#{path},</if>
</trim>
</insert>
<update id="updateSysAttachFile" parameterType="SysAttachFile">
update sys_attach_file
<trim prefix="SET" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="attachId != null ">attach_id = #{attachId},</if>
<if test="name != null and name != ''">name = #{name},</if>
<if test="ext != null and ext != ''">ext = #{ext},</if>
<if test="size != null ">size = #{size},</if>
<if test="url != null and url != ''">url = #{url},</if>
<if test="path != null and path != ''">path = #{path},</if>
</trim>
where id = #{id}
</update>
<update id="updateAttachIdByIdList">
update sys_attach_file set attach_id = #{attachId}
where id in
<foreach item="id" collection="idList" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<delete id="deleteSysAttachFileById" parameterType="Long">
delete from sys_attach_file where id = #{id}
</delete>
<delete id="deleteSysAttachFileByIds" parameterType="String">
delete from sys_attach_file where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

91
ruoyi-admin/src/main/resources/mapper/system/SysAttachMapper.xml

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.SysAttachMapper">
<resultMap type="SysAttach" id="SysAttachResult">
<result property="id" column="id" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="relId" column="rel_id" />
<result property="sourceType" column="source_type" />
<result property="sourceSubType" column="source_sub_type" />
</resultMap>
<sql id="selectSysAttachVo">
select id, del_flag, create_by, create_time, update_by, update_time, remark, rel_id, source_type, source_sub_type from sys_attach
</sql>
<select id="selectSysAttachList" parameterType="SysAttach" resultMap="SysAttachResult">
<include refid="selectSysAttachVo"/>
<where>
<if test="relId != null "> and rel_id = #{relId}</if>
<if test="sourceType != null and sourceType != ''"> and source_type = #{sourceType}</if>
<if test="sourceSubType != null and sourceSubType != ''"> and source_sub_type = #{sourceSubType}</if>
</where>
</select>
<select id="selectSysAttachById" parameterType="Long" resultMap="SysAttachResult">
<include refid="selectSysAttachVo"/>
where id = #{id}
</select>
<insert id="insertSysAttach" parameterType="SysAttach" useGeneratedKeys="true" keyProperty="id">
insert into sys_attach
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null ">create_time,</if>
<if test="updateBy != null and updateBy != ''">update_by,</if>
<if test="updateTime != null ">update_time,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="relId != null ">rel_id,</if>
<if test="sourceType != null and sourceType != ''">source_type,</if>
<if test="sourceSubType != null and sourceSubType != ''">source_sub_type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null ">#{createTime},</if>
<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
<if test="updateTime != null ">#{updateTime},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="relId != null ">#{relId},</if>
<if test="sourceType != null and sourceType != ''">#{sourceType},</if>
<if test="sourceSubType != null and sourceSubType != ''">#{sourceSubType},</if>
</trim>
</insert>
<update id="updateSysAttach" parameterType="SysAttach">
update sys_attach
<trim prefix="SET" suffixOverrides=",">
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null ">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="updateTime != null ">update_time = #{updateTime},</if>
<if test="remark != null and remark != ''">remark = #{remark},</if>
<if test="relId != null ">rel_id = #{relId},</if>
<if test="sourceType != null and sourceType != ''">source_type = #{sourceType},</if>
<if test="sourceSubType != null and sourceSubType != ''">source_sub_type = #{sourceSubType},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSysAttachById" parameterType="Long">
delete from sys_attach where id = #{id}
</delete>
<delete id="deleteSysAttachByIds" parameterType="String">
delete from sys_attach where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

1
ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/element-ui.css

File diff suppressed because one or more lines are too long

1
ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/element-ui.js

File diff suppressed because one or more lines are too long

BIN
ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/fonts/element-icons.ttf

Binary file not shown.

BIN
ruoyi-admin/src/main/resources/static/ajax/libs/element-ui/fonts/element-icons.woff

Binary file not shown.

11914
ruoyi-admin/src/main/resources/static/ajax/libs/vue/vue.js

File diff suppressed because it is too large

2
ruoyi-admin/src/main/resources/static/css/bootstrap.min.css

File diff suppressed because one or more lines are too long

79
ruoyi-admin/src/main/resources/templates/erp/material/add.html

@ -2,9 +2,10 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head> <head>
<th:block th:include="include :: header('新增物料信息')" /> <th:block th:include="include :: header('新增物料信息')" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div id="app" class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-material-add"> <form class="form-horizontal m" id="form-material-add">
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">料号:</label> <label class="col-sm-3 control-label">料号:</label>
@ -87,10 +88,84 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-2 control-label">照片:</label>
<div class="col-sm-10">
<el-upload
:action="fileUploadUrl"
:on-success="uploadSuccess"
:on-remove="uploadRemove"
:file-list="fileList"
list-type="picture"
accept=".jpg,.png"
multiple>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,第一张图片为主图</div>
</el-upload>
</div>
<input id="fileIdStr" type="text" name="fileIdStr" hidden>
</div>
</form> </form>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<script th:inline="javascript"> <script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script type="text/javascript">
new Vue({
el: '#app',
data: function() {
return {
fileList: [],
fileUploadUrl: ctx + "common/uploadSingleFile",
fileDeleteUrl: ctx + "common/deleteFile",
fileIdList:[],
}
},
methods: {
uploadSuccess(response, file, fileList) {
console.log(response);
if(response.code == web_status.SUCCESS){
var attachFileId = response.data.id;
file.attachFileId = attachFileId;
this.fileIdList.push(attachFileId);
$("#fileIdStr").val(this.fileIdList.join(";"));
$.modal.msgSuccess("上传成功");
}else{
$.modal.alertError(response.msg);
}
},
uploadRemove(file, fileList) {
console.log(file, fileList);
var attachFileId = file.attachFileId;
$.ajax({
type: "get",
url: this.fileDeleteUrl,
data: {id:attachFileId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
}
$.modal.msgSuccess("删除附件成功。");
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertError("删除附件失败。");
}
});
},
}
})
var prefix = ctx + "erp/material" var prefix = ctx + "erp/material"
$("#form-material-add").validate({ $("#form-material-add").validate({

127
ruoyi-admin/src/main/resources/templates/erp/material/edit.html

@ -2,9 +2,10 @@
<html lang="zh" xmlns:th="http://www.thymeleaf.org" > <html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head> <head>
<th:block th:include="include :: header('修改物料信息')" /> <th:block th:include="include :: header('修改物料信息')" />
<link th:href="@{/ajax/libs/element-ui/element-ui.css}" rel="stylesheet"/>
</head> </head>
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div id="app" class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-material-edit" th:object="${erpMaterial}"> <form class="form-horizontal m" id="form-material-edit" th:object="${erpMaterial}">
<input name="id" th:field="*{id}" type="hidden"> <input name="id" th:field="*{id}" type="hidden">
<div class="form-group"> <div class="form-group">
@ -88,10 +89,132 @@
</select> </select>
</div> </div>
</div> </div>
<div class="form-group">
<label class="col-sm-3 control-label">照片:</label>
<div class="col-sm-8">
<el-upload
:action="fileUploadUrl"
:on-success="uploadSuccess"
:on-remove="uploadRemove"
:file-list="fileList"
list-type="picture"
accept=".jpg,.png"
multiple>
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,第一张图片为主图</div>
</el-upload>
</div>
<input id="photoAttachId" name = "photoAttachId" hidden th:field="*{photoAttachId}">
<input id="fileIdStr" type="text" name="fileIdStr" th:field="*{fileIdStr}" hidden>
<input id="removeFileIdStr" type="text" name="removeFileIdStr" hidden>
</div>
</form> </form>
</div> </div>
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<script th:inline="javascript"> <script th:src="@{/ajax/libs/vue/vue.js}"></script>
<script th:src="@{/ajax/libs/element-ui/element-ui.js}"></script>
<script type="text/javascript">
new Vue({
el: '#app',
data: function() {
return {
fileList: [],
fileUploadUrl: ctx + "common/uploadSingleFile",
fileDeleteUrl: ctx + "common/deleteFile",
getListByAttachIdUrl: ctx + "system/attach/file/getListByAttachId",
fileIdList:[],
removeFileIdList:[],
}
},
mounted() {
var that = this;
// 页面渲染完成,可以执行需要的操作
console.log('页面已渲染完成');
console.log($("#id").val());
console.log($("#photoAttachId").val());
var attachId = $("#photoAttachId").val();
if(attachId){
$.ajax({
type: "get",
url: that.getListByAttachIdUrl,
data: {attachId:attachId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
result.data.forEach((item) => {
that.fileIdList.push(item.id);
that.fileList.push({name: item.name, url: item.url, attachFileId: item.id,isBind:true});
});
} else {
$.modal.msgError(result.msg);
}
},
error: function(error) {
$.modal.msgError("获取附件失败。");
}
});
}
},
methods: {
uploadSuccess(response, file, fileList) {
console.log(response);
if(response.code == web_status.SUCCESS){
var attachFileId = response.data.id;
file.attachFileId = attachFileId;
file.isBind = false;
this.fileIdList.push(attachFileId);
$("#fileIdStr").val(this.fileIdList.join(";"));
$.modal.msgSuccess("上传成功");
}else{
$.modal.alertError(response.msg);
}
},
uploadRemove(file, fileList) {
console.log(file, fileList);
var attachFileId = file.attachFileId;
var isBind = file.isBind;
if(isBind==false){
$.ajax({
type: "get",
url: this.fileDeleteUrl,
data: {id:attachFileId},
cache: false,
async: false, // 设置成同步
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
}
$.modal.msgSuccess("删除附件成功。");
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertError("删除附件失败。");
}
});
}else{
var index = this.fileIdList.indexOf(attachFileId);
if(index!=-1){
this.fileIdList.splice(index,1);
$("#fileIdStr").val(this.fileIdList.join(";"));
// 保存的时候才删除
this.removeFileIdList.push(attachFileId);
$("#removeFileIdStr").val(this.removeFileIdList.join(";"));
}
}
},
}
})
var prefix = ctx + "erp/material"; var prefix = ctx + "erp/material";
$("#form-material-edit").validate({ $("#form-material-edit").validate({
onkeyup: false, onkeyup: false,

7
ruoyi-admin/src/main/resources/templates/erp/material/material.html

@ -154,6 +154,13 @@
field: 'materialNo', field: 'materialNo',
title: '料号' title: '料号'
}, },
{
field: 'photoUrl',
title: '图片',
formatter: function(value, row, index) {
return $.table.imageView(value);
}
},
{ {
field: 'materialName', field: 'materialName',
title: '物料名称' title: '物料名称'

5
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java

@ -1,6 +1,7 @@
package com.ruoyi.common.utils.file; package com.ruoyi.common.utils.file;
import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException; import com.ruoyi.common.exception.file.FileNameLengthLimitExceededException;
import com.ruoyi.common.exception.file.FileSizeLimitExceededException; import com.ruoyi.common.exception.file.FileSizeLimitExceededException;
import com.ruoyi.common.exception.file.InvalidExtensionException; import com.ruoyi.common.exception.file.InvalidExtensionException;
@ -147,8 +148,8 @@ public class FileUploadUtils
{ {
int dirLastIndex = RuoYiConfig.getProfile().length() + 1; int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
String currentDir = StringUtils.substring(uploadDir, dirLastIndex); String currentDir = StringUtils.substring(uploadDir, dirLastIndex);
String pathFileName = "/" + fileName; // String pathFileName = "/" + fileName;
// String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName; String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir + "/" + fileName;
return pathFileName; return pathFileName;
} }

18
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java

@ -200,4 +200,22 @@ public class FileUtils extends org.apache.commons.io.FileUtils
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString()); String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
return encode.replaceAll("\\+", "%20"); return encode.replaceAll("\\+", "%20");
} }
/**
* 获取文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi.png
*
* @param fileName 路径名称
* @return 没有文件路径的名称
*/
public static String getName(String fileName)
{
if (fileName == null)
{
return null;
}
int lastUnixPos = fileName.lastIndexOf('/');
int lastWindowsPos = fileName.lastIndexOf('\\');
int index = Math.max(lastUnixPos, lastWindowsPos);
return fileName.substring(index + 1);
}
} }

Loading…
Cancel
Save