diff --git a/bs-admin/src/main/java/com/bs/cm/controller/CmAttachController.java b/bs-admin/src/main/java/com/bs/cm/controller/CmAttachController.java index 17252cf..7b95045 100644 --- a/bs-admin/src/main/java/com/bs/cm/controller/CmAttachController.java +++ b/bs-admin/src/main/java/com/bs/cm/controller/CmAttachController.java @@ -12,7 +12,11 @@ import com.bs.common.enums.BusinessType; import com.bs.common.utils.poi.ExcelUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.apache.xmlbeans.impl.validator.ValidatorUtil; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -43,6 +47,20 @@ public class CmAttachController extends BaseController { return getDataTable(list); } + @PostMapping("/api/file/upload") + @ApiOperation("文件上传") + @Log(title = "文件上传", businessType = BusinessType.OTHER) + // @RepeatSubmit 有点小问题 先注释 + public AjaxResult upload(@RequestParam String fileId, CmAttach attach, @RequestParam("files") MultipartFile[] files) { + if (StringUtils.isBlank(fileId) || "null".equals(fileId)) { + return AjaxResult.error("fileId不能为空"); + } + if (Validator.isEmpty(files)) { + return AjaxResult.error("上传文件不可为空!"); + } + return AjaxResult.success(cmAttachService.uploadFileBatch(files, fileId)) ; + } + /** * 查询附件信息列表 */ diff --git a/bs-admin/src/main/java/com/bs/cm/service/ICmAttachService.java b/bs-admin/src/main/java/com/bs/cm/service/ICmAttachService.java index c387dd4..f8f36c8 100644 --- a/bs-admin/src/main/java/com/bs/cm/service/ICmAttachService.java +++ b/bs-admin/src/main/java/com/bs/cm/service/ICmAttachService.java @@ -1,8 +1,10 @@ package com.bs.cm.service; import com.bs.cm.domain.CmAttach; -import com.bs.common.core.domain.AjaxResult; import com.github.yulichang.base.MPJBaseService; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; /** * 附件信息Service接口 @@ -12,4 +14,5 @@ import com.github.yulichang.base.MPJBaseService; */ public interface ICmAttachService extends MPJBaseService{ + List uploadFileBatch(MultipartFile[] files, String fileId); } diff --git a/bs-admin/src/main/java/com/bs/cm/service/impl/CmAttachServiceImpl.java b/bs-admin/src/main/java/com/bs/cm/service/impl/CmAttachServiceImpl.java index 1c83609..849c4f8 100644 --- a/bs-admin/src/main/java/com/bs/cm/service/impl/CmAttachServiceImpl.java +++ b/bs-admin/src/main/java/com/bs/cm/service/impl/CmAttachServiceImpl.java @@ -1,11 +1,30 @@ package com.bs.cm.service.impl; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import com.bs.cm.mapper.CmAttachMapper; import com.bs.cm.domain.CmAttach; import com.bs.cm.service.ICmAttachService; +import com.bs.common.constant.Constants; +import com.bs.common.exception.ServiceException; +import com.bs.common.utils.FileUtil; +import com.bs.common.utils.OsInfoUtil; import com.github.yulichang.base.MPJBaseServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.File; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import static cn.hutool.core.date.DateUtil.format; +import static com.bs.common.config.BsConfig.*; + /** * 附件信息Service业务层处理 * @@ -15,5 +34,77 @@ import org.springframework.transaction.annotation.Transactional; @Service @Transactional(rollbackFor = Exception.class) public class CmAttachServiceImpl extends MPJBaseServiceImpl implements ICmAttachService { + @Resource + private ICmAttachService cmAttachService; + public static final String SEPARATOR = "/"; + public static final String SUFFIX = Constants.RESOURCE_PREFIX + SEPARATOR; + @Autowired + private Environment env; + + @Override + public List uploadFileBatch(MultipartFile[] files, String fileId) { + List attachs = new ArrayList<>(); + for (MultipartFile file : files) { + //插入附件表 + attachs.add(uploadFile(file, fileId)); + } + if (attachs.size() == 0) { + return null; + } + // 插入附件中间表 + List attachVos = new ArrayList<>(); + cmAttachService.saveBatch(attachs); +// cmAttachService.saveBatch(getAttachRef(attachs,attachVos, fileId, businessUnits)); + return attachVos; + } + + /** + * 保存附件及插入附件表,返回附件对象 + */ + @Transactional + public CmAttach uploadFile(MultipartFile multipartFile, String fileId) { + FileUtil.checkSize(Long.parseLong(env.getProperty("chain.maxSize")), multipartFile.getSize()); + String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); + String type = FileUtil.getFileType(suffix); + //新的文件名+后缀 + String fileName = FileUtil.fileRenameMos(null, null) + "." + suffix; + //绝对路径+年份+文件类型+文件名 + String filePath = format(new Date(), "yyyy") + SEPARATOR + + type + SEPARATOR + fileName; + File file = FileUtil.uploadMos(multipartFile, getFilePath() + SEPARATOR + filePath); + if (ObjectUtil.isNull(file)) { + throw new ServiceException("上传失败"); + } + try { + CmAttach attach = new CmAttach(); + attach.setFileId(fileId); +// attach.setAttachId(UUIDUtils.generatorUUID()); + attach.setAttachName(fileName); + attach.setAttachFileType(type); + attach.setAttachContentType(multipartFile.getContentType()); + attach.setAttachFileSize((long) multipartFile.getSize()); + attach.setAttachFileUrl(SUFFIX + filePath); + attach.setOldName(multipartFile.getOriginalFilename()); +// cmAttachMapper.insert(attach); + return attach; + } catch (Exception e) { + FileUtil.del(file); + throw e; + } + } + /** + * 根据系统切换存放附件绝对地址 + * + * @return 存放附件绝对地址 + */ + public static String getFilePath() { + if (OsInfoUtil.isLinux()) { + return getLinuxLocalFilePath(); + } + if (OsInfoUtil.isMacOS() || OsInfoUtil.isMacOSX()) { + return getMacLocalFilePath(); + } + return getWinLocalFilePath(); + } } diff --git a/bs-ui/src/components/FileUpload/BannerUpload.vue b/bs-ui/src/components/FileUpload/BannerUpload.vue new file mode 100644 index 0000000..9858973 --- /dev/null +++ b/bs-ui/src/components/FileUpload/BannerUpload.vue @@ -0,0 +1,203 @@ + + + + + diff --git a/bs-ui/src/components/FileUpload/PictureUpload.vue b/bs-ui/src/components/FileUpload/PictureUpload.vue new file mode 100644 index 0000000..6f61244 --- /dev/null +++ b/bs-ui/src/components/FileUpload/PictureUpload.vue @@ -0,0 +1,152 @@ + + + diff --git a/bs-ui/src/components/ImageUpload/index.vue b/bs-ui/src/components/ImageUpload/index.vue index b57a15e..989cb16 100644 --- a/bs-ui/src/components/ImageUpload/index.vue +++ b/bs-ui/src/components/ImageUpload/index.vue @@ -19,7 +19,7 @@ > - +
请上传 @@ -63,6 +63,7 @@ export default { type: Array, default: () => ["png", "jpg", "jpeg"], }, + // 是否显示提示 isShowTip: { type: Boolean, @@ -77,7 +78,7 @@ export default { dialogVisible: false, hideUpload: false, baseUrl: process.env.VUE_APP_BASE_API, - uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址 + uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/uploads", // 上传的图片服务器地址 headers: { Authorization: "Bearer " + getToken(), }, @@ -87,6 +88,8 @@ export default { watch: { value: { handler(val) { + console.log("val" + val); + console.log( val); if (val) { // 首先将值转为数组 const list = Array.isArray(val) ? val : this.value.split(','); @@ -101,6 +104,8 @@ export default { } return item; }); + console.log("this.fileList"); + console.log(this.fileList); } else { this.fileList = []; return []; @@ -119,6 +124,7 @@ export default { methods: { // 上传前loading加载 handleBeforeUpload(file) { + console.log("file" + file); let isImg = false; if (this.fileType.length) { let fileExtension = ""; diff --git a/bs-ui/src/main.js b/bs-ui/src/main.js index c66afbf..d6df0d8 100644 --- a/bs-ui/src/main.js +++ b/bs-ui/src/main.js @@ -45,6 +45,8 @@ import Rq from '@/components/Rq'; import MyPage from '@/components/MyPage'; import MyFormItem from '@/components/MyFormItem'; import MySelectButton from '@/components/MySelectButton'; +import BannerUpload from '@/components/FileUpload/BannerUpload'; +import PictureUpload from '@/components/FileUpload/PictureUpload'; // 全局方法挂载 Vue.prototype.getDicts = getDicts @@ -74,6 +76,8 @@ Vue.component('Rq', Rq) Vue.component('MyPage', MyPage) Vue.component('MyFormItem', MyFormItem) Vue.component('MySelectButton', MySelectButton) +Vue.component('BannerUpload', BannerUpload) +Vue.component('PictureUpload', PictureUpload) Vue.use(directive) Vue.use(plugins) diff --git a/bs-ui/src/views/article/article/index.vue b/bs-ui/src/views/article/article/index.vue index b6ef91f..a1afdee 100644 --- a/bs-ui/src/views/article/article/index.vue +++ b/bs-ui/src/views/article/article/index.vue @@ -381,7 +381,7 @@ export default { articleTitle: null, publishTime: null, articleContent: null, - status: null, + status: "0", remark: null, }; this.resetForm("form"); diff --git a/bs-ui/src/views/moment/moment/index.vue b/bs-ui/src/views/moment/moment/index.vue index fe378dc..d9f2e2f 100644 --- a/bs-ui/src/views/moment/moment/index.vue +++ b/bs-ui/src/views/moment/moment/index.vue @@ -326,7 +326,7 @@ export default { momentKind: null, momentTitle: null, momentContent: null, - status: null, + status: "0", remark: null, }; this.resetForm("form"); diff --git a/bs-ui/src/views/order/order/index.vue b/bs-ui/src/views/order/order/index.vue index 7a71bba..32160c0 100644 --- a/bs-ui/src/views/order/order/index.vue +++ b/bs-ui/src/views/order/order/index.vue @@ -1,30 +1,567 @@ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 搜索 + 重置 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 导出 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/bs-ui/src/views/product/info/index.vue b/bs-ui/src/views/product/info/index.vue index 5326cdf..c2d3e79 100644 --- a/bs-ui/src/views/product/info/index.vue +++ b/bs-ui/src/views/product/info/index.vue @@ -569,7 +569,6 @@ export default { let businessCities = this.form.businessCity.split(','); businessCities.forEach(cityId => { let matchedCity = this.cityList.find(city => city.areaId == cityId); - console.log(matchedCity); if (matchedCity) { selectedCities.push({ areaId: matchedCity.areaId, @@ -591,7 +590,6 @@ export default { this.$message.warning('该城市已经添加过了!'); } else { this.selectedCities.push(city); - this.$message.success('成功添加城市!'); } }, isCitySelected(city) { @@ -670,7 +668,7 @@ export default { productDetail: null, listBegin: null, listEnd: null, - status: null, + status: "0", remark: null, maxAmountBegin: null, maxAmountEnd: null,