|
@@ -0,0 +1,239 @@
|
|
|
+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.po.CmBrandAuthFilePo;
|
|
|
+import com.caimei.model.po.ShopInfoPo;
|
|
|
+import com.caimei.model.po.UserPo;
|
|
|
+import com.caimei.model.vo.ShopVo;
|
|
|
+import com.caimei.service.ShopService;
|
|
|
+import com.caimei.utils.AliyunSmsUtil;
|
|
|
+import com.caimei.utils.CodeUtil;
|
|
|
+import com.caimei.utils.Md5Util;
|
|
|
+import com.caimei.utils.OSSUtils;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : Aslee
|
|
|
+ * @date : 2021/5/11
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ShopServiceImpl implements ShopService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ShopMapper shopMapper;
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PageInfo<ShopVo>> getShopList(String shopName, Integer shopType, Integer brandId, String mobile, String linkMan, Integer pageNum, Integer pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<ShopVo> shopList = shopMapper.getShopList(shopName, shopType, brandId, mobile, linkMan);
|
|
|
+ PageInfo<ShopVo> pageData = new PageInfo<>(shopList);
|
|
|
+ return ResponseJson.success(pageData);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson updateShopStatus(Integer authUserId, Integer status) {
|
|
|
+ if (authUserId == null) {
|
|
|
+ return ResponseJson.error("请输入用户id");
|
|
|
+ }
|
|
|
+ if (status == null) {
|
|
|
+ return ResponseJson.error("请输入要更新的状态值");
|
|
|
+ } else if (status != 0 && status != 1) {
|
|
|
+ return ResponseJson.error("状态值只能为0或1");
|
|
|
+ }
|
|
|
+ shopMapper.updateShopStatusByUserId(authUserId, status);
|
|
|
+ if (status == 0) {
|
|
|
+ return ResponseJson.success("停用供应商成功");
|
|
|
+ } else {
|
|
|
+ return ResponseJson.success("启用供应商成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson resetShopPassword(Integer authUserId) {
|
|
|
+ if (authUserId == null) {
|
|
|
+ return ResponseJson.error("请输入用户id");
|
|
|
+ }
|
|
|
+ String newPassword = CodeUtil.generateCode(8);
|
|
|
+ String md5Password = Md5Util.md5(newPassword);
|
|
|
+ userMapper.updatePasswordByUserId(authUserId, md5Password);
|
|
|
+ String mobile = shopMapper.getShopMobileByUserId(authUserId);
|
|
|
+ boolean smsFlag = AliyunSmsUtil.sendSms(mobile, 7, "{code:" + newPassword + "}");
|
|
|
+ if (!smsFlag) {
|
|
|
+ // 短信发送失败重试一次
|
|
|
+ AliyunSmsUtil.sendSms(mobile, 7, "{code:" + newPassword + "}");
|
|
|
+ }
|
|
|
+ log.info("正品联盟后台供应商重置密码,用户id:" + authUserId + ",新密码:" + newPassword);
|
|
|
+ return ResponseJson.success("密码重置成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Integer> uploadFile(Integer authUserId, MultipartFile file) {
|
|
|
+ String fileAllName = file.getOriginalFilename();
|
|
|
+ String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
|
|
|
+ String fffff = file.getName();
|
|
|
+ String fileName = file.getResource().getFilename();
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath = uuid + "." + fileType;
|
|
|
+ String contentType = OSSUtils.getContentType(fileAllName);
|
|
|
+ try {
|
|
|
+ //保存本地
|
|
|
+ File uploadFile = OSSUtils.ossUpload(file);
|
|
|
+ //判断文件的唯一性,转换成16进制md5值
|
|
|
+ String md5Hex = DigestUtils.md5Hex(new FileInputStream(uploadFile));
|
|
|
+ CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
|
|
|
+ searchFile.setAuthUserId(authUserId);
|
|
|
+ searchFile.setMd5Hex(md5Hex);
|
|
|
+ // 查找该供应商下是否已存在相同文件
|
|
|
+ CmBrandAuthFilePo cmBrandAuthFile = shopMapper.getStatementFile(searchFile);
|
|
|
+ if (cmBrandAuthFile == null) {
|
|
|
+ log.info("默认路径>>>" + uploadFile.getAbsolutePath());
|
|
|
+ // 修改情况下,如果原来已经选择了文件代理声明,并且旧文件与新文件不同,需要将旧文件删除
|
|
|
+ deleteFileByUserId(authUserId);
|
|
|
+ //将新文件上传oss
|
|
|
+ OSSUtils.ossUpload(filePath, uploadFile, contentType);
|
|
|
+ //删除本地文件
|
|
|
+ OSSUtils.deleteFile(uploadFile);
|
|
|
+ //保存关联关系
|
|
|
+ cmBrandAuthFile = new CmBrandAuthFilePo();
|
|
|
+ cmBrandAuthFile.setAuthUserId(authUserId);
|
|
|
+ cmBrandAuthFile.setName(fileName);
|
|
|
+ cmBrandAuthFile.setOssName(filePath);
|
|
|
+ cmBrandAuthFile.setMd5Hex(md5Hex);
|
|
|
+ cmBrandAuthFile.setUploadTime(new Date());
|
|
|
+ shopMapper.insertStatementFile(cmBrandAuthFile);
|
|
|
+ } else {
|
|
|
+ //删除本地文件
|
|
|
+ OSSUtils.deleteFile(uploadFile);
|
|
|
+ }
|
|
|
+ return ResponseJson.success("文件上传成功", cmBrandAuthFile.getId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("<<<<< 文件上传异常 >>>>>");
|
|
|
+ return ResponseJson.error("文件上传失败", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void deleteFileByUserId(Integer authUserId) {
|
|
|
+ CmBrandAuthFilePo searchFile = new CmBrandAuthFilePo();
|
|
|
+ searchFile.setAuthUserId(authUserId);
|
|
|
+ CmBrandAuthFilePo oldFile = shopMapper.getStatementFile(searchFile);
|
|
|
+ if (oldFile != null) {
|
|
|
+ Integer num = shopMapper.getFileNumByMd5Hex(oldFile.getMd5Hex());
|
|
|
+ if (num == 1) {
|
|
|
+ // 如果这个文件只有这个供应商在使用,删除oss服务器上的文件
|
|
|
+ OSSUtils.deleteSingleFile(oldFile.getOssName());
|
|
|
+ }
|
|
|
+ shopMapper.deleteStatementFile(oldFile.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson saveShop(ShopSaveDto shopSaveDto) {
|
|
|
+ Integer shopType = shopSaveDto.getShopType();
|
|
|
+ if (shopType == null) {
|
|
|
+ return ResponseJson.error("请选择供应商类型", null);
|
|
|
+ }
|
|
|
+ // 更新品牌授权logo
|
|
|
+ shopMapper.updateBrandAuthLogo(shopSaveDto.getBrandId());
|
|
|
+ /*
|
|
|
+ 组装供应商用户数据
|
|
|
+ */
|
|
|
+ UserPo shop = new UserPo();
|
|
|
+ // 供应商名称
|
|
|
+ shop.setName(shopSaveDto.getShopName());
|
|
|
+ // 手机号
|
|
|
+ shop.setMobile(shopSaveDto.getMobile());
|
|
|
+ // 联系人
|
|
|
+ shop.setLinkMan(shopSaveDto.getLinkMan());
|
|
|
+ // 供应商状态
|
|
|
+ shop.setStatus(shopSaveDto.getShopStatus());
|
|
|
+ if (null == shopSaveDto.getAuthUserId()) {
|
|
|
+ // 用户身份:1管理员,2供应商
|
|
|
+ shop.setUserIdentity(2);
|
|
|
+ // 创建管理员id
|
|
|
+ shop.setCreateBy(shopSaveDto.getCreateBy());
|
|
|
+ // 创建时间
|
|
|
+ shop.setCreateTime(new Date());
|
|
|
+ // 设置随机8位密码
|
|
|
+ shop.setPassword(CodeUtil.generateCode(8));
|
|
|
+ } else {
|
|
|
+ shop.setAuthUserId(shopSaveDto.getAuthUserId());
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ 保存供应商用户
|
|
|
+ */
|
|
|
+ if (null == shopSaveDto.getAuthUserId()) {
|
|
|
+ shopMapper.insertShop(shop);
|
|
|
+ } else {
|
|
|
+ shopMapper.updateShopByUserId(shop);
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ 组装供应商信息数据
|
|
|
+ */
|
|
|
+ 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());
|
|
|
+ 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()) {
|
|
|
+ // 更新代理声明文件
|
|
|
+ Integer statementFileId = shopSaveDto.getStatementFileId();
|
|
|
+ shopMapper.updateFileUserId(statementFileId, shop.getAuthUserId());
|
|
|
+ } else {
|
|
|
+ // 没有选择文件代理声明的情况下,若存在原来的文件,删除代理声明文件
|
|
|
+ deleteFileByUserId(shop.getAuthUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null == shopSaveDto.getAuthUserId()) {
|
|
|
+ shopMapper.insertShopInfo(shopInfo);
|
|
|
+ } else {
|
|
|
+ shopMapper.updateShopInfoByUserId(shopInfo);
|
|
|
+ }
|
|
|
+ return ResponseJson.success("保存供应商成功", null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<ShopVo> getShopFormData(Integer authUserId) {
|
|
|
+ if (null == authUserId) {
|
|
|
+ return ResponseJson.error("参数异常,请输入供应商用户id", null);
|
|
|
+ }
|
|
|
+ shopMapper.getShopByAuthUserId(authUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|