|
@@ -1,22 +1,29 @@
|
|
|
package com.caimei.modules.zplm.service;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import com.caimei.dfs.image.beens.ImageUploadInfo;
|
|
|
import com.caimei.modules.brand.utils.ImagePathUtils;
|
|
|
+import com.caimei.modules.miniprogram.utils.UploadPicUtils;
|
|
|
+import com.caimei.modules.oss.entity.CmOssArchivePdf;
|
|
|
+import com.caimei.modules.oss.utils.OSSUtils;
|
|
|
import com.caimei.modules.sys.utils.UploadImageUtils;
|
|
|
import com.caimei.modules.zplm.entity.CmBrandAuth;
|
|
|
+import com.caimei.modules.zplm.entity.CmBrandAuthFile;
|
|
|
import com.thinkgem.jeesite.common.config.Global;
|
|
|
import com.thinkgem.jeesite.common.utils.Encodes;
|
|
|
import com.thinkgem.jeesite.common.utils.StringUtils;
|
|
|
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
import com.caimei.modules.zplm.dao.CmBrandAuthDao;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -45,20 +52,19 @@ public class CmBrandAuthService extends CrudService<CmBrandAuthDao, CmBrandAuth>
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
public void save(CmBrandAuth cmBrandAuth) {
|
|
|
+ //新增授权时,若授权有代理商且选择了文件代理声明,需要更新文件的授权Id
|
|
|
+ Boolean updateFileFlag = false;
|
|
|
+ if (StringUtils.isBlank(cmBrandAuth.getId())) {
|
|
|
+ updateFileFlag = true;
|
|
|
+ }
|
|
|
//保存图片
|
|
|
String logo = cmBrandAuth.getAuthLogo();
|
|
|
+ String statementImage = cmBrandAuth.getStatementImage();
|
|
|
if(StringUtils.isNotBlank(logo) && !logo.startsWith("http")){
|
|
|
- String photoServer = Global.getConfig("photoServer");//获取文件服务器地址
|
|
|
- logo= Encodes.urlDecode(logo);
|
|
|
- String realPath = UploadImageUtils.getAbsolutePath(logo);
|
|
|
- int pointerIndex = realPath.lastIndexOf(".");
|
|
|
- ImageUploadInfo saveImageSerivce;
|
|
|
- try {
|
|
|
- saveImageSerivce = ImagePathUtils.saveImageSerivce(realPath, pointerIndex,realPath);
|
|
|
- cmBrandAuth.setAuthLogo(photoServer+saveImageSerivce.getSource());
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("图片上传错误:"+e.toString(),e);
|
|
|
- }
|
|
|
+ cmBrandAuth.setAuthLogo(UploadPicUtils.saveImageToServer(logo, null));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(statementImage) && !statementImage.startsWith("http")){
|
|
|
+ cmBrandAuth.setStatementImage(UploadPicUtils.saveImageToServer(statementImage, null));
|
|
|
}
|
|
|
if (cmBrandAuth.getIsNewRecord()) {
|
|
|
cmBrandAuth.setCreateBy(UserUtils.getUser());
|
|
@@ -68,6 +74,23 @@ public class CmBrandAuthService extends CrudService<CmBrandAuthDao, CmBrandAuth>
|
|
|
cmBrandAuthDao.updateBrandAuthLogo(cmBrandAuth.getBrandId(), cmBrandAuth.getAuthLogo());
|
|
|
//保存品牌授权
|
|
|
super.save(cmBrandAuth);
|
|
|
+ //有代理商且选择了文件代理声明的情况下
|
|
|
+ if (cmBrandAuth.getAgentFlag() == 1 && cmBrandAuth.getStatementType() == 4) {
|
|
|
+ //新增授权时,更新代理声明文件
|
|
|
+ if (updateFileFlag) {
|
|
|
+ Integer statementFileId = cmBrandAuth.getStatementFileId();
|
|
|
+ if (statementFileId != null) {
|
|
|
+ CmBrandAuthFile cmBrandAuthFile = new CmBrandAuthFile();
|
|
|
+ cmBrandAuthFile.setId(statementFileId);
|
|
|
+ cmBrandAuthFile.setBrandAuthId(Integer.parseInt(cmBrandAuth.getId()));
|
|
|
+ cmBrandAuthDao.updateStatementFile(cmBrandAuthFile);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改授权情况下,不需要更新
|
|
|
+ } else {
|
|
|
+ // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
|
|
|
+ deleteFileByAuthId(cmBrandAuth.getId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
@@ -76,7 +99,81 @@ public class CmBrandAuthService extends CrudService<CmBrandAuthDao, CmBrandAuth>
|
|
|
cmBrandAuthDao.deleteParamsByAuthId(cmBrandAuth.getId());
|
|
|
//删除授权商品
|
|
|
cmBrandAuthDao.deleteProductsByAuthId(cmBrandAuth.getId());
|
|
|
+ //删除代理声明文件
|
|
|
+ if (cmBrandAuth.getAgentFlag() == 1 && cmBrandAuth.getStatementType() == 4) {
|
|
|
+ deleteFileByAuthId(cmBrandAuth.getId());
|
|
|
+ }
|
|
|
super.delete(cmBrandAuth);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代理声明文件上传
|
|
|
+ * @param fileName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public Map<String, Object> uploadFile(String brandAuthId, MultipartFile multipartFile, String fileName) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ String fileAllName = multipartFile.getOriginalFilename();
|
|
|
+ String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath = uuid + "." + fileType;
|
|
|
+ String contentType = OSSUtils.getContentType(fileAllName);
|
|
|
+ try {
|
|
|
+ //保存本地
|
|
|
+ File file = OSSUtils.ossUpload(multipartFile);
|
|
|
+ //判断文件的唯一性,转换成16进制md5值
|
|
|
+ String md5Hex = DigestUtils.md5Hex(new FileInputStream(file));
|
|
|
+ CmBrandAuthFile searchFile = new CmBrandAuthFile();
|
|
|
+ searchFile.setBrandAuthId(StringUtils.isBlank(brandAuthId) ? null : Integer.parseInt(brandAuthId));
|
|
|
+ searchFile.setMd5Hex(md5Hex);
|
|
|
+ // 查找该授权下是否已存在相同文件
|
|
|
+ CmBrandAuthFile cmBrandAuthFile = cmBrandAuthDao.findStatementFile(searchFile);
|
|
|
+ String url = "";
|
|
|
+ if (cmBrandAuthFile == null) {
|
|
|
+ logger.info("默认路径>>>" + file.getAbsolutePath());
|
|
|
+ // 修改情况下,如果原来已经选择了文件代理声明,并且旧文件与新文件不同,需要将旧文件删除
|
|
|
+ deleteFileByAuthId(brandAuthId);
|
|
|
+ //将新文件上传oss
|
|
|
+ url = OSSUtils.ossUpload(filePath, file, contentType);
|
|
|
+ //删除本地文件
|
|
|
+ OSSUtils.deleteFile(file);
|
|
|
+ //保存关联关系
|
|
|
+ cmBrandAuthFile = new CmBrandAuthFile();
|
|
|
+ cmBrandAuthFile.setBrandAuthId(searchFile.getBrandAuthId());
|
|
|
+ cmBrandAuthFile.setName(fileName);
|
|
|
+ cmBrandAuthFile.setOssName(filePath);
|
|
|
+ cmBrandAuthFile.setMd5Hex(md5Hex);
|
|
|
+ cmBrandAuthFile.setUploadTime(new Date());
|
|
|
+ cmBrandAuthDao.insertStatementFile(cmBrandAuthFile);
|
|
|
+ } else {
|
|
|
+ //删除本地文件
|
|
|
+ OSSUtils.deleteFile(file);
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "操作成功");
|
|
|
+ map.put("url", url);
|
|
|
+ map.put("statementFile", cmBrandAuthFile);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "操作失败");
|
|
|
+ logger.info("上传异常!!!");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteFileByAuthId(String brandAuthId) {
|
|
|
+ CmBrandAuthFile oldFile = cmBrandAuthDao.findStatementFileByAuthId(brandAuthId);
|
|
|
+ if (oldFile != null) {
|
|
|
+ Integer num = cmBrandAuthDao.findStatementFileByMd5Hex(oldFile.getMd5Hex());
|
|
|
+ if (num == 1) {
|
|
|
+ //删除oss服务器上的文件
|
|
|
+ OSSUtils.deleteSingleFile(oldFile.getOssName());
|
|
|
+ }
|
|
|
+ cmBrandAuthDao.deleteStatementFile(oldFile.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|