|
@@ -3,30 +3,23 @@ package com.caimei.service.impl;
|
|
|
import com.caimei.mapper.ShopMapper;
|
|
|
import com.caimei.mapper.UserMapper;
|
|
|
import com.caimei.model.ResponseJson;
|
|
|
-import com.caimei.model.dto.ShopSaveDto;
|
|
|
+import com.caimei.model.dto.ShopInfoDto;
|
|
|
import com.caimei.model.po.CmBrandAuthFilePo;
|
|
|
-import com.caimei.model.po.ShopInfoPo;
|
|
|
import com.caimei.model.po.UserPo;
|
|
|
-import com.caimei.model.vo.BrandVo;
|
|
|
-import com.caimei.model.vo.CountryVo;
|
|
|
-import com.caimei.model.vo.ShopFormVo;
|
|
|
-import com.caimei.model.vo.ShopListVo;
|
|
|
+import com.caimei.model.vo.*;
|
|
|
import com.caimei.service.ShopService;
|
|
|
import com.caimei.utils.*;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -88,7 +81,7 @@ public class ShopServiceImpl implements ShopService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson<Integer> uploadFile(Integer authUserId, MultipartFile file) {
|
|
|
+ public ResponseJson<Integer> uploadFile(Integer authUserId, Integer brandId, MultipartFile file) {
|
|
|
authUserId = (null != authUserId && authUserId > 0) ? authUserId : null;
|
|
|
String fileAllName = file.getOriginalFilename();
|
|
|
String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
|
|
@@ -109,7 +102,7 @@ public class ShopServiceImpl implements ShopService {
|
|
|
if (cmBrandAuthFile == null) {
|
|
|
log.info("默认路径>>>" + uploadFile.getAbsolutePath());
|
|
|
// 修改情况下,如果原来已经选择了文件代理声明,并且旧文件与新文件不同,需要将旧文件删除
|
|
|
- deleteFileByUserId(authUserId);
|
|
|
+ deleteFile(authUserId, brandId);
|
|
|
//将新文件上传oss
|
|
|
OSSUtils.ossUpload(filePath, uploadFile, contentType);
|
|
|
//删除本地文件
|
|
@@ -117,6 +110,7 @@ public class ShopServiceImpl implements ShopService {
|
|
|
//保存关联关系
|
|
|
cmBrandAuthFile = new CmBrandAuthFilePo();
|
|
|
cmBrandAuthFile.setAuthUserId(authUserId);
|
|
|
+ cmBrandAuthFile.setBrandId(brandId);
|
|
|
cmBrandAuthFile.setName(fileName);
|
|
|
cmBrandAuthFile.setOssName(filePath);
|
|
|
cmBrandAuthFile.setMd5Hex(md5Hex);
|
|
@@ -134,9 +128,10 @@ public class ShopServiceImpl implements ShopService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteFileByUserId(Integer authUserId) {
|
|
|
+ public void deleteFile(Integer authUserId, Integer brandId) {
|
|
|
CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
|
|
|
searchFile.setAuthUserId(authUserId);
|
|
|
+ searchFile.setBrandId(brandId);
|
|
|
CmBrandAuthFilePo oldFile = shopMapper.getStatementFile(searchFile);
|
|
|
if (oldFile != null) {
|
|
|
Integer num = shopMapper.getFileNumByMd5Hex(oldFile.getMd5Hex());
|
|
@@ -151,18 +146,9 @@ public class ShopServiceImpl implements ShopService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson saveShop(ShopSaveDto shopSaveDto) {
|
|
|
- Integer shopType = shopSaveDto.getShopType();
|
|
|
- if (shopType == null) {
|
|
|
- return ResponseJson.error("请选择供应商类型", null);
|
|
|
- }
|
|
|
+ public ResponseJson saveShop(Integer authUserId, Integer shopType, String shopName, String mobile, String linkMan, Integer shopStatus, Integer createBy, List<ShopInfoDto> shopInfoList) {
|
|
|
// 是否为添加操作
|
|
|
- boolean insertFlag = null == shopSaveDto.getAuthUserId();
|
|
|
- // 手机号
|
|
|
- String mobile = shopSaveDto.getMobile();
|
|
|
- if (StringUtils.isBlank(mobile)) {
|
|
|
- return ResponseJson.error("参数异常,请输入手机号");
|
|
|
- }
|
|
|
+ boolean insertFlag = null == authUserId;
|
|
|
if (insertFlag) {
|
|
|
// 添加时验证手机号是否已被使用
|
|
|
Integer userIdByMobile = shopMapper.getUserIdByMobile(mobile);
|
|
@@ -171,41 +157,45 @@ public class ShopServiceImpl implements ShopService {
|
|
|
}
|
|
|
}
|
|
|
// 更新品牌授权logo
|
|
|
- shopMapper.updateBrandAuthLogo(shopSaveDto.getBrandId(),shopSaveDto.getBrandAuthLogo());
|
|
|
+ shopInfoList.forEach(shopInfo->{
|
|
|
+ shopMapper.updateBrandAuthLogo(shopInfo.getBrandId(), shopInfo.getBrandAuthLogo());
|
|
|
+ });
|
|
|
/*
|
|
|
组装供应商用户数据
|
|
|
*/
|
|
|
UserPo shop = new UserPo();
|
|
|
// 供应商名称
|
|
|
- shop.setName(shopSaveDto.getShopName());
|
|
|
+ shop.setName(shopName);
|
|
|
// 手机号
|
|
|
- shop.setMobile(shopSaveDto.getMobile());
|
|
|
+ shop.setMobile(mobile);
|
|
|
// 联系人
|
|
|
- shop.setLinkMan(shopSaveDto.getLinkMan());
|
|
|
+ shop.setLinkMan(linkMan);
|
|
|
// 供应商状态
|
|
|
- shop.setStatus(shopSaveDto.getShopStatus());
|
|
|
+ shop.setStatus(shopStatus);
|
|
|
if (insertFlag) {
|
|
|
// 用户身份:1管理员,2供应商
|
|
|
shop.setUserIdentity(2);
|
|
|
+ // 供应商类型
|
|
|
+ shop.setShopType(shopType);
|
|
|
// 创建管理员id
|
|
|
- shop.setCreateBy(shopSaveDto.getCreateBy());
|
|
|
+ shop.setCreateBy(createBy);
|
|
|
// 创建时间
|
|
|
shop.setCreateTime(new Date());
|
|
|
// 设置随机8位密码
|
|
|
String password = CodeUtil.generateCode(8);
|
|
|
String md5Pwd = Md5Util.md5(password);
|
|
|
shop.setPassword(md5Pwd);
|
|
|
+ // 插入供应商用户
|
|
|
+ shopMapper.insertShop(shop);
|
|
|
// 发送短信
|
|
|
- boolean smsFlag = AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
|
|
|
+ boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + password + "\"}");
|
|
|
if (!smsFlag) {
|
|
|
// 短信发送失败重试一次
|
|
|
- AliyunSmsUtil.sendSms(shopSaveDto.getMobile(), 14, "{password:\"" + password + "\"}");
|
|
|
+ AliyunSmsUtil.sendSms(mobile, 14, "{password:\"" + password + "\"}");
|
|
|
}
|
|
|
- // 插入供应商用户
|
|
|
- shopMapper.insertShop(shop);
|
|
|
log.info("添加供应商,供应商用户id:" + shop.getAuthUserId());
|
|
|
} else {
|
|
|
- shop.setAuthUserId(shopSaveDto.getAuthUserId());
|
|
|
+ shop.setAuthUserId(authUserId);
|
|
|
// 更新供应商用户
|
|
|
shopMapper.updateShopByUserId(shop);
|
|
|
log.info("更新供应商,供应商用户id:" + shop.getAuthUserId());
|
|
@@ -213,45 +203,50 @@ public class ShopServiceImpl implements ShopService {
|
|
|
/*
|
|
|
组装供应商信息数据
|
|
|
*/
|
|
|
- ShopInfoPo shopInfo = new ShopInfoPo();
|
|
|
- // 供应商用户id
|
|
|
- shopInfo.setAuthUserId(shop.getAuthUserId());
|
|
|
- // 供应商类型:1品牌方,2代理商
|
|
|
- shopInfo.setType(shopSaveDto.getShopType());
|
|
|
- // 品牌id
|
|
|
- shopInfo.setBrandId(shopSaveDto.getBrandId());
|
|
|
- // 国家id
|
|
|
- shopInfo.setCountryId(shopSaveDto.getCountryId());
|
|
|
- // 官网认证链接
|
|
|
- shopInfo.setSecurityLink(shopSaveDto.getSecurityLink());
|
|
|
- if (null != shopSaveDto.getStatementType()) {
|
|
|
- shopInfo.setStatementType(shopSaveDto.getStatementType());
|
|
|
- if (1 == shopSaveDto.getStatementType()) {
|
|
|
- // 声明弹窗
|
|
|
- shopInfo.setStatementContent(shopSaveDto.getStatementContent());
|
|
|
- } else if (2 == shopSaveDto.getStatementType()) {
|
|
|
- // 声明链接
|
|
|
- shopInfo.setStatementLink(shopSaveDto.getStatementLink());
|
|
|
- } else if (3 == shopSaveDto.getStatementType()) {
|
|
|
- // 声明图片
|
|
|
- shopInfo.setStatementImage(shopSaveDto.getStatementImage());
|
|
|
- }
|
|
|
- if (4 == shopSaveDto.getStatementType()) {
|
|
|
- if (insertFlag){
|
|
|
- // 更新代理声明文件
|
|
|
- Integer statementFileId = shopSaveDto.getStatementFileId();
|
|
|
- shopMapper.updateFileUserId(statementFileId, shop.getAuthUserId());
|
|
|
- }
|
|
|
- } else if (!insertFlag){
|
|
|
- // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
|
|
|
- deleteFileByUserId(shop.getAuthUserId());
|
|
|
- }
|
|
|
- }
|
|
|
- // 保存供应商信息
|
|
|
if (insertFlag) {
|
|
|
- shopMapper.insertShopInfo(shopInfo);
|
|
|
+ shopInfoList.forEach(shopInfo->{
|
|
|
+ shopInfo.setAuthUserId(shop.getAuthUserId());
|
|
|
+ // 插入供应商信息
|
|
|
+ shopMapper.insertShopInfo(shopInfo);
|
|
|
+ if (4 == shopInfo.getStatementType()) {
|
|
|
+ shopMapper.updateFileUserId(shopInfo.getStatementFileId(), shop.getAuthUserId());
|
|
|
+ }
|
|
|
+ });
|
|
|
} else {
|
|
|
- shopMapper.updateShopInfoByUserId(shopInfo);
|
|
|
+ // 数据库中供应商信息数据
|
|
|
+ List<ShopBrandVo> dbInfoBrandList = shopMapper.getDbInfoBrandList(shop.getAuthUserId());
|
|
|
+ List<Integer> updateInfoBrandList = new ArrayList<>();
|
|
|
+ List<Integer> newInfoBrandList = new ArrayList<>();
|
|
|
+ // 编辑后的供应商品牌id
|
|
|
+ shopInfoList.forEach(shopInfo->{
|
|
|
+ newInfoBrandList.add(shopInfo.getBrandId());
|
|
|
+ });
|
|
|
+ for (ShopBrandVo shopBrand : dbInfoBrandList) {
|
|
|
+ if (!newInfoBrandList.contains(shopBrand.getBrandId())) {
|
|
|
+ // 删除被删除的数据
|
|
|
+ shopMapper.deleteShopInfoById(shopBrand.getId());
|
|
|
+ // 删除文件
|
|
|
+ deleteFile(authUserId, shopBrand.getBrandId());
|
|
|
+ } else {
|
|
|
+ // 保存数据库已有且未被删除的供应商品牌id
|
|
|
+ updateInfoBrandList.add(shopBrand.getBrandId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ shopInfoList.forEach(shopInfoVo -> {
|
|
|
+ shopInfoVo.setAuthUserId(shop.getAuthUserId());
|
|
|
+ // 保存供应商信息数据
|
|
|
+ if (updateInfoBrandList.contains(shopInfoVo.getBrandId())) {
|
|
|
+ // 更新
|
|
|
+ shopMapper.updateShopInfo(shopInfoVo);
|
|
|
+ if (4 != shopInfoVo.getStatementType()) {
|
|
|
+ // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
|
|
|
+ deleteFile(shop.getAuthUserId(),shopInfoVo.getBrandId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 插入
|
|
|
+ shopMapper.insertShopInfo(shopInfoVo);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
return ResponseJson.success("保存供应商成功", null);
|
|
|
}
|
|
@@ -261,16 +256,22 @@ public class ShopServiceImpl implements ShopService {
|
|
|
if (null == authUserId) {
|
|
|
return ResponseJson.error("参数异常,请输入供应商用户id", null);
|
|
|
}
|
|
|
- ShopFormVo shopForm = shopMapper.getShopByAuthUserId(authUserId);
|
|
|
+ ShopFormVo shopForm = shopMapper.getShopByUserId(authUserId);
|
|
|
if (null == shopForm) {
|
|
|
return ResponseJson.error("供应商不存在", null);
|
|
|
}
|
|
|
+ List<ShopInfoVo> shopInfoList = shopMapper.getShopInfoByUserId(authUserId);
|
|
|
+ shopForm.setShopInfo(shopInfoList);
|
|
|
return ResponseJson.success(shopForm);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseJson<List<BrandVo>> getBrandList(Integer type) {
|
|
|
- List<BrandVo> brandList = shopMapper.getBrandList(type);
|
|
|
+ public ResponseJson<List<BrandVo>> getBrandList(Integer type, Integer authUserId) {
|
|
|
+ type = null == type ? 2 : type;
|
|
|
+ if (3 == type && null == authUserId) {
|
|
|
+ return ResponseJson.error("参数异常,请输入供应商用户id", null);
|
|
|
+ }
|
|
|
+ List<BrandVo> brandList = shopMapper.getBrandList(type, authUserId);
|
|
|
return ResponseJson.success(brandList);
|
|
|
}
|
|
|
|