Prechádzať zdrojové kódy

bugfix-导入机构信息

Aslee 3 rokov pred
rodič
commit
7c9f601e04

+ 1 - 1
src/main/java/com/caimei/controller/admin/auth/AuthApi.java

@@ -214,7 +214,7 @@ public class AuthApi {
     @ApiImplicitParams({
             @ApiImplicitParam(name = "authUserId", required = true, value = "供应商用户id"),
             @ApiImplicitParam(name = "createBy", required = true, value = "创建人用户id"),
-            @ApiImplicitParam(name = "file", required = true, value = "代理声明文件"),
+            @ApiImplicitParam(name = "file", required = true, value = "机构excel表格"),
     })
     @PostMapping("/import/excel")
     public ResponseJson importDataByExcel(MultipartFile file, Integer authUserId, Integer createBy) {

+ 56 - 22
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -28,6 +28,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -304,12 +306,12 @@ public class AuthServiceImpl implements AuthService {
             TemplateVo authTemplate = authMapper.getAuthTemplate(auth.getId(), null, 1);
             authImage = generateAuthImage(authTemplate, auth);
             auth.setAuthImage(authImage);
-            // 添加水印
-            if (StringUtils.isNotEmpty(authImage)) {
-                auth.setPcAuthImage(addWaterMark(authImage, 1));
-                auth.setAppletsAuthImage(addWaterMark(authImage, 2));
-                authMapper.updateAuthImage(auth);
-            }
+        }
+        // 添加水印
+        if (StringUtils.isNotEmpty(auth.getAuthImage())) {
+            auth.setPcAuthImage(addWaterMark(auth.getAuthImage(), 1));
+            auth.setAppletsAuthImage(addWaterMark(auth.getAuthImage(), 2));
+            authMapper.updateAuthImage(auth);
         }
         // 保存轮播图
         if (null != bannerList) {
@@ -534,6 +536,7 @@ public class AuthServiceImpl implements AuthService {
     }
 
 
+    @Transactional(rollbackFor=Exception.class)
     private ResponseJson saveExcelData(String filePath, Integer authUserId, Integer createBy) {
         //判断是否为excel类型文件
         if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
@@ -565,13 +568,21 @@ public class AuthServiceImpl implements AuthService {
             for (int i = 1; i <= authPartyRowNum; i++) {
                 //获得第i行对象
                 Row authPartyRow = authPartySheet.getRow(i);
+                if (null == authPartyRow) {
+                    break;
+                }
+                Cell cell = null;
                 // 校验机构名称
-                String authParty = authPartyRow.getCell(0).getStringCellValue();
+                cell = authPartyRow.getCell(0);
+                cell.setCellType(CellType.STRING);
+                String authParty = cell.getStringCellValue();
                 if (StringUtils.isBlank(authParty)) {
                     return ResponseJson.error("第" + i + 1 + "行机构名称不能为空");
                 }
                 // 校验省市区
-                String area = authPartyRow.getCell(1).getStringCellValue();
+                cell = authPartyRow.getCell(1);
+                cell.setCellType(CellType.STRING);
+                String area = cell.getStringCellValue();
                 if (StringUtils.isBlank(area)) {
                     return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
                 }
@@ -605,7 +616,7 @@ public class AuthServiceImpl implements AuthService {
                         townName = townName.substring(0, townName.length() - 1).trim();
                     }
                     List<TownPo> townList = authMapper.getTownList(townName);
-                    for (int j = 0; j < townList.size(); i++) {
+                    for (int j = 0; j < townList.size(); j++) {
                         TownPo town = townList.get(j);
                         if (null == townId) {
                             if (null != cityId) {
@@ -626,12 +637,16 @@ public class AuthServiceImpl implements AuthService {
                     }
                 }
                 // 校验详细地址
-                String address = authPartyRow.getCell(2).getStringCellValue();
+                cell = authPartyRow.getCell(2);
+                cell.setCellType(CellType.STRING);
+                String address = cell.getStringCellValue();
                 if (StringUtils.isBlank(address)) {
                     return ResponseJson.error("第" + i + 1 + "行详细地址不能为空");
                 }
                 // 校验经纬度
-                String lngAndLat = authPartyRow.getCell(3).getStringCellValue();
+                cell = authPartyRow.getCell(3);
+                cell.setCellType(CellType.STRING);
+                String lngAndLat = cell.getStringCellValue();
                 if (StringUtils.isBlank(lngAndLat)) {
                     return ResponseJson.error("第" + i + 1 + "行经纬度不能为空");
                 }
@@ -642,22 +657,30 @@ public class AuthServiceImpl implements AuthService {
                 BigDecimal lng = new BigDecimal(split[0]);
                 BigDecimal lat = new BigDecimal(split[1]);
                 // 校验联系电话
-                String mobile = authPartyRow.getCell(4).getStringCellValue();
+                cell = authPartyRow.getCell(4);
+                cell.setCellType(CellType.STRING);
+                String mobile = cell.getStringCellValue();
                 if (StringUtils.isBlank(mobile)) {
                     return ResponseJson.error("第" + i + 1 + "行联系电话不能为空");
                 }
                 // 认证编号
-                String authCode = authPartyRow.getCell(5).getStringCellValue();
+                cell = authPartyRow.getCell(5);
+                cell.setCellType(CellType.STRING);
+                String authCode = cell.getStringCellValue();
                 // 认证日期
                 Date authDate = null;
-                String authDateStr = authPartyRow.getCell(6).getStringCellValue();
+                cell = authPartyRow.getCell(6);
+                cell.setCellType(CellType.STRING);
+                String authDateStr = cell.getStringCellValue();
                 if (StringUtils.isNotBlank(authDateStr)) {
                     SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd");
                     authDate = format.parse(authDateStr);
                 }
                 // 校验员工人数
                 Integer empNum = null;
-                String empNumStr = authPartyRow.getCell(7).getStringCellValue();
+                cell = authPartyRow.getCell(7);
+                cell.setCellType(CellType.STRING);
+                String empNumStr = cell.getStringCellValue();
                 if (StringUtils.isBlank(empNumStr)) {
                     return ResponseJson.error("第" + i + 1 + "行员工人数不能为空");
                 }
@@ -667,7 +690,9 @@ public class AuthServiceImpl implements AuthService {
                     return ResponseJson.error("第" + i + 1 + "行员工人数格式错误");
                 }
                 // 校验店铺备注
-                String remarks = authPartyRow.getCell(6).getStringCellValue();
+                cell = authPartyRow.getCell(8);
+                cell.setCellType(CellType.STRING);
+                String remarks = cell.getStringCellValue();
                 Integer customFlag = 0;
                 if (StringUtils.isNotEmpty(remarks)) {
                     customFlag = 1;
@@ -681,6 +706,9 @@ public class AuthServiceImpl implements AuthService {
                 authPo.setLng(lng);
                 authPo.setLat(lat);
                 authPo.setMobile(mobile);
+                authPo.setAuthCode(authCode);
+                authPo.setAuthDate(authDate);
+                authPo.setAuthImageType(1);
                 authPo.setEmpNum(empNum);
                 authPo.setCustomFlag(customFlag);
                 authPo.setRemarks(remarks);
@@ -696,14 +724,20 @@ public class AuthServiceImpl implements AuthService {
             log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
         }
         // 保存授权数据
-        authImportList.forEach(authPo -> {
+        for (int i = 0; i < authImportList.size(); i++) {
+            CmBrandAuthPo authPo = authImportList.get(i);
             // 保存授权机构
-            CmBrandAuthPo auth = new CmBrandAuthPo();
-            auth.setAuthUserId(authUserId);
-            auth.setCreateBy(createBy);
+            authPo.setAuthUserId(authUserId);
+            authPo.setCreateBy(createBy);
+            authPo.setFirstClubType(5);
             // 导入数据
-            ResponseJson responseJson = saveAuth(auth, null, true, 1);
-        });
+            ResponseJson result = saveAuth(authPo, null, true, 1);
+            if (result.getCode() != 0) {
+                // 设置手动回滚事务
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return ResponseJson.error("导入失败");
+            }
+        }
         return ResponseJson.success("导入成功");
     }