Browse Source

1.7.1-机构导出

Aslee 2 years ago
parent
commit
78ef8cfba3

+ 1 - 2
src/main/java/com/caimei/mapper/cmMapper/AuthMapper.java

@@ -6,7 +6,6 @@ import com.caimei.model.po.TownPo;
 import com.caimei.model.vo.AuthFormVo;
 import com.caimei.model.vo.AuthVo;
 import com.caimei.model.vo.TemplateVo;
-import com.caimei.module.base.entity.po.CmBrand;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -42,7 +41,7 @@ public interface AuthMapper {
 
     Integer getAuthIdByAuthParty(@Param("authParty") String authParty, @Param("authUserId") Integer authUserId);
 
-    List<CmBrandAuthPo> getAuthPartyList(Integer authUserId);
+    List<AuthFormVo> getAuthPartyList(Integer authUserId);
 
     void deleteBanner(Integer authId);
 

+ 6 - 245
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -473,6 +473,7 @@ public class AuthServiceImpl implements AuthService {
 
 
     @Override
+    @Transactional(rollbackFor=Exception.class)
     public ResponseJson importDataByExcel(MultipartFile file, Integer authUserId, Integer createBy) {
         String originalFilename = file.getOriginalFilename();
         String randomStr = UUID.randomUUID().toString();
@@ -502,10 +503,10 @@ public class AuthServiceImpl implements AuthService {
     public ResponseJson exportDataByExcel(Integer authUserId, HttpServletResponse response) {
         try {
             // 导出表格名
-            String fileName = new String("机构商品数据.xls".getBytes("UTF-8"),"iso-8859-1");
+            String fileName = new String("机构信息.xls".getBytes("UTF-8"),"iso-8859-1");
             // 机构数据
-            List<CmBrandAuthPo> authPartyList = authMapper.getAuthPartyList(authUserId);
-            authPartyList.forEach(authParty->{
+            List<AuthFormVo> authPartyList = authMapper.getAuthPartyList(authUserId);
+            /*authPartyList.forEach(authParty->{
                 // 商品参数数量最大值
                 final Integer[] maxParamNum = {0};
                 Integer authId = authParty.getId();
@@ -520,7 +521,7 @@ public class AuthServiceImpl implements AuthService {
                 });
                 authParty.setMaxParamNum(maxParamNum[0]);
                 authParty.setProductList(productList);
-            });
+            });*/
             OutputStream outputStream = response.getOutputStream();
             response.reset();
             response.setHeader("Access-Control-Allow-Origin", "*");
@@ -536,7 +537,6 @@ 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")) {
@@ -741,246 +741,7 @@ public class AuthServiceImpl implements AuthService {
         return ResponseJson.success("导入成功");
     }
 
-    /**
-     * 已停用
-     */
-    private ResponseJson saveExcelDataBak(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);
-            //获得表头
-            Row rowHead = authPartySheet.getRow(0);
-            //判断表头是否正确
-            if (1 != rowHead.getLastCellNum() || !"授权机构".equals(rowHead.getCell(0).getStringCellValue())) {
-                return ResponseJson.error("授权机构表格式错误");
-            }
-            // 获得数据的总行数
-            int authPartyRowNum = authPartySheet.getLastRowNum();
-            // 商品sn码列表
-            List<String> snCodeList = new ArrayList<>();
-
-            //获得所有数据
-            for (int i = 1; i <= authPartyRowNum; i++) {
-                //获得第i行对象
-                Row row = authPartySheet.getRow(i);
-                //获得获得第i行第0列的机构名称
-                Cell cell = row.getCell(0);
-                // 机构名称
-                String authParty = cell.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);
-                                // 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, 1);
-                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);
-                    productDto.setSource(1);
-                    authProductService.saveProduct(productDto, true);
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            });
-        });
-        return ResponseJson.success("导入成功");
-    }
-
-    private ResponseJson exportData(List<CmBrandAuthPo> authPartyList, OutputStream outputStream) {
+    private ResponseJson exportData(List<AuthFormVo> authPartyList, OutputStream outputStream) {
         try {
             HSSFWorkbook workbook = new HSSFWorkbook();
             // 创建机构工作表

+ 14 - 3
src/main/resources/mapper/AuthMapper.xml

@@ -194,9 +194,20 @@
           and authUserId = #{authUserId}
           and delFlag = 0
     </select>
-    <select id="getAuthPartyList" resultType="com.caimei.model.po.CmBrandAuthPo">
-        select id, authParty
-        from cm_brand_auth
+    <select id="getAuthPartyList" resultType="com.caimei.model.vo.AuthFormVo">
+        select authParty,
+               concat(ifnull(p.name, ''), '/', ifnull(c.name, ''), '/', ifnull(t.name, '')) as area,
+               address,
+               concat(lng, ',', lat),
+               mobile,
+               authCode,
+               authDate,
+               empNum,
+               if(customFlag = 1, remarks, '')
+        from cm_brand_auth a
+                 left join province p on a.provinceId = p.provinceID
+                 left join city c on a.cityId = c.cityID
+                 left join town t on a.townId = t.townID
         where authUserId = #{authUserId}
         order by createTime desc
     </select>