|
@@ -7,6 +7,7 @@ import com.caimei.model.ResponseJson;
|
|
|
import com.caimei.model.dto.ProductSaveDto;
|
|
|
import com.caimei.model.po.AuthImportPo;
|
|
|
import com.caimei.model.po.CmBrandAuthPo;
|
|
|
+import com.caimei.model.po.LdmDataPo;
|
|
|
import com.caimei.model.po.ProductParamPo;
|
|
|
import com.caimei.model.vo.AuthFormVo;
|
|
|
import com.caimei.model.vo.AuthVo;
|
|
@@ -14,10 +15,14 @@ import com.caimei.model.vo.ProductFormVo;
|
|
|
import com.caimei.service.AuthProductService;
|
|
|
import com.caimei.service.AuthService;
|
|
|
import com.caimei.service.ShopService;
|
|
|
+import com.caimei.service.UploadService;
|
|
|
import com.caimei.utils.ExcelOperateUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.github.tobato.fastdfs.domain.StorePath;
|
|
|
+import com.github.tobato.fastdfs.service.FastFileStorageClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
@@ -33,6 +38,7 @@ import javax.imageio.ImageIO;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
@@ -68,6 +74,13 @@ public class AuthServiceImpl implements AuthService {
|
|
|
this.shopService = shopService;
|
|
|
}
|
|
|
|
|
|
+ private UploadService uploadService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public void setUploadService(UploadService uploadService) {
|
|
|
+ this.uploadService = uploadService;
|
|
|
+ }
|
|
|
+
|
|
|
@Value("${spring.profiles.active}")
|
|
|
private String active;
|
|
|
|
|
@@ -77,6 +90,9 @@ public class AuthServiceImpl implements AuthService {
|
|
|
@Value("${caimei.imageDomain}")
|
|
|
private String imageDomain;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FastFileStorageClient storageClient;
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseJson<PageInfo<AuthVo>> getAuthList(Integer listType, Integer authUserId, String authParty, Integer status, Integer auditStatus, Integer lowerAuditStatus, Integer pageNum, Integer pageSize) {
|
|
|
if (null == authUserId) {
|
|
@@ -184,6 +200,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// 保存品牌授权信息,上线状态默认为“待上线”,审核状态为“待审核”
|
|
|
auth.setStatus(2);
|
|
|
auth.setAuditStatus(2);
|
|
|
+ auth.setDelFlag(0);
|
|
|
/*
|
|
|
保存授权
|
|
|
*/
|
|
@@ -256,6 +273,75 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public ResponseJson importLdmData(Integer authUserId) {
|
|
|
+ List<LdmDataPo> ldmDataList = authMapper.getLdmData();
|
|
|
+ ldmDataList.forEach(ldmData->{
|
|
|
+ String lngAndLat = ldmData.getLngAndLat();
|
|
|
+ if (StringUtils.isNotEmpty(lngAndLat)) {
|
|
|
+ String[] split = lngAndLat.split(",");
|
|
|
+ BigDecimal lng = new BigDecimal(split[0]);
|
|
|
+ BigDecimal lat = new BigDecimal(split[1]);
|
|
|
+ ldmData.setLng(lng);
|
|
|
+ ldmData.setLat(lat);
|
|
|
+ }
|
|
|
+ String regId1 = ldmData.getRegId1();
|
|
|
+ if (StringUtils.isNotEmpty(regId1)) {
|
|
|
+ Integer provinceId = authMapper.getProvinceId(regId1);
|
|
|
+ ldmData.setProvinceId(provinceId);
|
|
|
+ }
|
|
|
+ String regId2 = ldmData.getRegId2();
|
|
|
+ if (StringUtils.isNotEmpty(regId2)) {
|
|
|
+ Integer cityId = authMapper.getCityId(regId2);
|
|
|
+ ldmData.setCityId(cityId);
|
|
|
+ }
|
|
|
+ String regId3 = ldmData.getRegId3();
|
|
|
+ if (StringUtils.isNotEmpty(regId3)) {
|
|
|
+ Integer townId = authMapper.getTownId(regId3);
|
|
|
+ ldmData.setTownId(townId);
|
|
|
+ }
|
|
|
+ String pic1 = ldmData.getPic1();
|
|
|
+ String pic2 = ldmData.getPic2();
|
|
|
+ String pic3 = ldmData.getPic3();
|
|
|
+ String pic4 = ldmData.getPic4();
|
|
|
+ String pic5 = ldmData.getPic5();
|
|
|
+ List<String> picList = new ArrayList<>();
|
|
|
+ picList.add(pic1);
|
|
|
+ picList.add(pic2);
|
|
|
+ picList.add(pic3);
|
|
|
+ picList.add(pic4);
|
|
|
+ picList.add(pic5);
|
|
|
+ String logo = null;
|
|
|
+ List<String> addPicList = new ArrayList<>();
|
|
|
+ for (String pic : picList) {
|
|
|
+ if (StringUtils.isNotEmpty(pic)) {
|
|
|
+ try {
|
|
|
+ String imagePath = "https://wangdian.skinovachina.com" + pic;
|
|
|
+ String fileName = imagePath.substring(imagePath.lastIndexOf("/") + 1);
|
|
|
+ String imageUrl = uploadService.saveFileByUrl(imagePath, fileName);
|
|
|
+ addPicList.add(imageUrl);
|
|
|
+ if (null == logo) {
|
|
|
+ logo = imageUrl;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CmBrandAuthPo authPo = new CmBrandAuthPo();
|
|
|
+ BeanUtils.copyProperties(ldmData, authPo);
|
|
|
+ authPo.setAuthUserId(authUserId);
|
|
|
+ authPo.setCreateBy(authUserId);
|
|
|
+ authPo.setLogo(logo);
|
|
|
+ authMapper.insertAuth(authPo);
|
|
|
+ // 保存轮播图
|
|
|
+ if (addPicList.size() > 0) {
|
|
|
+ addPicList.forEach(banner -> authMapper.insertBanner(authPo.getId(), banner));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return ResponseJson.success();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response) {
|
|
|
try {
|
|
@@ -527,6 +613,273 @@ public class AuthServiceImpl implements AuthService {
|
|
|
return ResponseJson.success("导入成功");
|
|
|
}
|
|
|
|
|
|
+ /*private ResponseJson saveLdmData(String filePath, Integer authUserId, Integer createBy) {
|
|
|
+ //判断是否为excel类型文件
|
|
|
+ if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
|
|
|
+ System.out.println("文件不是excel类型");
|
|
|
+ }
|
|
|
+ // 获取供应商品牌
|
|
|
+ List<String> shopBrands = shopService.getShopBrands(authUserId);
|
|
|
+
|
|
|
+ // 授权列表
|
|
|
+ List<AuthImportPo> authImportList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> tempImageList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileInputStream fis = new FileInputStream(filePath);
|
|
|
+ // 得到表格数据
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(fis);
|
|
|
+ // 获取工作表数量
|
|
|
+ int sheetsNum = workbook.getNumberOfSheets();
|
|
|
+
|
|
|
+ //得到第一个工作表(机构表)
|
|
|
+ XSSFSheet authPartySheet = workbook.getSheetAt(0);
|
|
|
+ // 获得数据的总行数
|
|
|
+ int authPartyRowNum = authPartySheet.getLastRowNum();
|
|
|
+
|
|
|
+ //获得所有数据
|
|
|
+ for (int i = 1; i <= authPartyRowNum; i++) {
|
|
|
+ //获得第i行对象
|
|
|
+ Row row = authPartySheet.getRow(i);
|
|
|
+ //获得获得第i行第0列的机构名称
|
|
|
+ Cell cell1 = row.getCell(1);
|
|
|
+ String authParty = cell1.getStringCellValue();
|
|
|
+ // 机构状态
|
|
|
+ Cell cell2 = row.getCell(2);
|
|
|
+ Integer status = 1 == Integer.parseInt(cell2.getStringCellValue()) ? 1 : 0;
|
|
|
+ // 审核状态
|
|
|
+ Integer auditStatus = 1 == status ? 1 : 0;
|
|
|
+ // 手机号
|
|
|
+ Cell cell4 = row.getCell(4);
|
|
|
+ String mobile = cell4.getStringCellValue();
|
|
|
+ // 详细地址
|
|
|
+ Cell cell5 = row.getCell(5);
|
|
|
+ String address = cell5.getStringCellValue();
|
|
|
+ // 图片
|
|
|
+ Cell cell8 = row.getCell(8);
|
|
|
+ String pic1 = cell8.getStringCellValue();
|
|
|
+ Cell cell9 = row.getCell(9);
|
|
|
+ String pic2 = cell8.getStringCellValue();
|
|
|
+ Cell cell10 = row.getCell(10);
|
|
|
+ String pic3 = cell8.getStringCellValue();
|
|
|
+ Cell cell11 = row.getCell(11);
|
|
|
+ String pic4 = cell8.getStringCellValue();
|
|
|
+ Cell cell12 = row.getCell(12);
|
|
|
+ String pic5 = cell8.getStringCellValue();
|
|
|
+ // 经纬度
|
|
|
+ Cell cell13 = row.getCell(13);
|
|
|
+ String lngAndLat = cell13.getStringCellValue();
|
|
|
+ String[] split = lngAndLat.split(",");
|
|
|
+ BigDecimal lng = new BigDecimal(split[0]);
|
|
|
+ BigDecimal lat = new BigDecimal(split[1]);
|
|
|
+ // 删除标志
|
|
|
+ Cell cell16 = row.getCell(16);
|
|
|
+ String delTime = cell13.getStringCellValue();
|
|
|
+ Integer delFlag = !"NULL".equals(delTime) ? 1 : 0;
|
|
|
+ // 省市区
|
|
|
+ Cell cell18 = row.getCell(18);
|
|
|
+ String dbProvinceId = cell18.getStringCellValue();
|
|
|
+ Cell cell19 = row.getCell(19);
|
|
|
+ String dbCityId = cell18.getStringCellValue();
|
|
|
+ Cell cell20 = row.getCell(20);
|
|
|
+ String dbTownId = cell18.getStringCellValue();
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(authParty)) {
|
|
|
+ *//*
|
|
|
+ * 授权数据
|
|
|
+ *//*
|
|
|
+ AuthImportPo authImportPo = new AuthImportPo();
|
|
|
+ // 商品列表
|
|
|
+ List<ProductSaveDto> productList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 得到机构对应的商品工作表
|
|
|
+ XSSFSheet productSheet = i < sheetsNum ? workbook.getSheetAt(i) : null;
|
|
|
+ String sheetName = null != productSheet ? productSheet.getSheetName() : null;
|
|
|
+ if (null == productSheet || !authParty.equals(sheetName)) {
|
|
|
+ // 遍历所有工作表,找到表名与授权机构名称相同的商品工作表
|
|
|
+ for (int j = 1; j < sheetsNum; j++) {
|
|
|
+ productSheet = workbook.getSheetAt(j);
|
|
|
+ sheetName = productSheet.getSheetName();
|
|
|
+ if (!authParty.equals(sheetName)) {
|
|
|
+ // 没有该机构对应的商品表
|
|
|
+ productSheet = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != productSheet) {
|
|
|
+ //获得表头
|
|
|
+ Row productRowHead = productSheet.getRow(0);
|
|
|
+ //判断表头是否正确
|
|
|
+ short cellTotalNum = productRowHead.getLastCellNum();
|
|
|
+ if (cellTotalNum < 13) {
|
|
|
+ return ResponseJson.error(authParty + "机构商品表格式错误");
|
|
|
+ }
|
|
|
+ // 获取表格图片
|
|
|
+ Map<String, XSSFPictureData> pictures = ExcelOperateUtil.getPictures(productSheet);
|
|
|
+ Map<String, String> imageMap = ExcelOperateUtil.printImg(pictures);
|
|
|
+ // 校验商品数据是否符合规范
|
|
|
+ int productRowNum = productSheet.getLastRowNum();
|
|
|
+ for (int k = 1; k <= productRowNum; k++) {
|
|
|
+ XSSFRow productRow = productSheet.getRow(k);
|
|
|
+ if (null != productRow && productRow.getCell(0) != null) {
|
|
|
+ String errorReason = "";
|
|
|
+ // 校验商品名称
|
|
|
+ String productName = productRow.getCell(0).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(productName)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品名称不能为空";
|
|
|
+ }
|
|
|
+ // 校验商品sn码
|
|
|
+ String snCode = productRow.getCell(1).getStringCellValue();
|
|
|
+ if (StringUtils.isEmpty(snCode)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品名称不能为空";
|
|
|
+ } else {
|
|
|
+ Integer productIdBySnCode = authProductMapper.getProductIdBySnCode(snCode);
|
|
|
+ if (null != productIdBySnCode || snCodeList.contains(snCode)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品sn码已存在,请重新输入";
|
|
|
+ } else {
|
|
|
+ snCodeList.add(snCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验品牌名称
|
|
|
+ String brand = productRow.getCell(2).getStringCellValue();
|
|
|
+ Integer brandId = null;
|
|
|
+ if (StringUtils.isEmpty(brand)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品品牌不能为空";
|
|
|
+ } else {
|
|
|
+ if (!shopBrands.contains(brand)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品品牌不存在";
|
|
|
+ } else {
|
|
|
+ brandId = authProductMapper.getBrandIdByBrandName(brand);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 校验商品图片
|
|
|
+ String productImage = imageMap.get(k + "-3");
|
|
|
+ if (StringUtils.isEmpty(productImage)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行商品图片不能为空";
|
|
|
+ }
|
|
|
+ // 校验授权牌照
|
|
|
+ String certificateImage = imageMap.get(k + "-4");
|
|
|
+ if (StringUtils.isEmpty(certificateImage)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行授权牌照不能为空";
|
|
|
+ }
|
|
|
+ List<ProductParamPo> paramList = new ArrayList<>();
|
|
|
+ // 校验参数列表
|
|
|
+ for (int a = 5; a + 1 < cellTotalNum; a += 2) {
|
|
|
+ XSSFCell paramNameCell = productRow.getCell(a);
|
|
|
+ XSSFCell paramContentCell = productRow.getCell(a + 1);
|
|
|
+ boolean validName = null != paramNameCell;
|
|
|
+ boolean validContent = null != paramContentCell;
|
|
|
+ if (validName && validContent) {
|
|
|
+ String paramName = paramNameCell.getStringCellValue();
|
|
|
+ String paramContent = paramContentCell.getStringCellValue();
|
|
|
+ validName = StringUtils.isNotEmpty(paramName);
|
|
|
+ validContent = StringUtils.isNotEmpty(paramContent);
|
|
|
+ if (validName && validContent) {
|
|
|
+ ProductParamPo productParamPo = new ProductParamPo();
|
|
|
+ productParamPo.setParamName(paramName);
|
|
|
+ productParamPo.setParamContent(paramContent);
|
|
|
+ paramList.add(productParamPo);
|
|
|
+ } else if ((validName || validContent)) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行参数数据异常";
|
|
|
+ }
|
|
|
+ } else if (validName || validContent) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行参数数据异常";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (paramList.size() < 4) {
|
|
|
+ errorReason = authParty + "机构商品表第" + (k + 1) + "行参数数量不足";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(errorReason)) {
|
|
|
+ // 删除临时图片文件
|
|
|
+ for (String image : imageMap.values()) {
|
|
|
+ if (StringUtils.isNotEmpty(image)) {
|
|
|
+ File tempFile = new File(image);
|
|
|
+ tempFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseJson.error(errorReason);
|
|
|
+ }
|
|
|
+ *//*
|
|
|
+ 组装商品数据
|
|
|
+ *//*
|
|
|
+ ProductSaveDto product = new ProductSaveDto();
|
|
|
+ // 品牌id
|
|
|
+ product.setBrandId(brandId);
|
|
|
+ // 商品名称
|
|
|
+ product.setProductName(productName);
|
|
|
+ // sn码
|
|
|
+ product.setSnCode(snCode);
|
|
|
+ // 商品图片
|
|
|
+ product.setProductImage(uploadImage(productImage));
|
|
|
+ // 授权牌照
|
|
|
+ product.setCertificateImage(uploadImage(certificateImage));
|
|
|
+ // 参数列表
|
|
|
+ product.setParamList(paramList);
|
|
|
+ // 创建人
|
|
|
+ product.setCreateBy(createBy);
|
|
|
+ productList.add(product);
|
|
|
+ tempImageList.add(productImage);
|
|
|
+ tempImageList.add(certificateImage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 授权机构
|
|
|
+ authImportPo.setAuthParty(authParty);
|
|
|
+ // 商品列表
|
|
|
+ authImportPo.setProductList(productList);
|
|
|
+ // 添加数据
|
|
|
+ authImportList.add(authImportPo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseJson.error("导入失败,请检查表格数据");
|
|
|
+ } finally {
|
|
|
+ // 删除临时数据
|
|
|
+ File tempFile = new File(filePath);
|
|
|
+ boolean delete = tempFile.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
|
|
|
+ tempImageList.forEach(tempImagePath->{
|
|
|
+ File tempImage = new File(tempImagePath);
|
|
|
+ boolean del = tempImage.delete();
|
|
|
+ log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时商品图片:" + del);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 保存授权数据
|
|
|
+ authImportList.forEach(authImportPo -> {
|
|
|
+ String authParty = authImportPo.getAuthParty();
|
|
|
+ List<ProductSaveDto> productList = authImportPo.getProductList();
|
|
|
+ Integer authId = authMapper.getAuthIdByAuthParty(authParty, authUserId);
|
|
|
+ // 保存授权机构
|
|
|
+ if (null == authId) {
|
|
|
+ CmBrandAuthPo auth = new CmBrandAuthPo();
|
|
|
+ auth.setAuthUserId(authUserId);
|
|
|
+ auth.setAuthParty(authParty);
|
|
|
+ auth.setCreateBy(createBy);
|
|
|
+ ResponseJson responseJson = saveAuth(auth, null, true);
|
|
|
+ CmBrandAuthPo authPo = (CmBrandAuthPo) responseJson.getData();
|
|
|
+ authId = authPo.getId();
|
|
|
+ }
|
|
|
+ Integer finalAuthId = authId;
|
|
|
+ // 保存商品列表
|
|
|
+ productList.forEach(productDto -> {
|
|
|
+ try {
|
|
|
+ productDto.setAuthId(finalAuthId);
|
|
|
+ // 上传商品图片和授权牌照
|
|
|
+ String productImage = productDto.getProductImage();
|
|
|
+ String certificateImage = productDto.getCertificateImage();
|
|
|
+ productDto.setProductImage(productImage);
|
|
|
+ productDto.setCertificateImage(certificateImage);
|
|
|
+ authProductService.saveProduct(productDto, true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return ResponseJson.success("导入成功");
|
|
|
+ }*/
|
|
|
+
|
|
|
private ResponseJson exportData(List<CmBrandAuthPo> authPartyList, OutputStream outputStream) {
|
|
|
try {
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|