Parcourir la source

网点管理导入

FengChaoYu il y a 9 mois
Parent
commit
5f8834cc7a

+ 10 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/admin/AdminWebsitController.java

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
@@ -107,4 +108,13 @@ public class AdminWebsitController {
         List<AdminWebsitPayConfig> list = adminWebsitLogic.payConfigList(websitId, type, status);
         return ResponseHelper.success(list);
     }
+
+    @PostMapping("/import")
+    @ApiOperation(value = "网点管理-导入(下载模板:网点管理导入模板.xlsx)")
+    public ResponseHelper<String> importData (
+            @RequestPart("file") MultipartFile file
+    ) throws Exception {
+        adminWebsitLogic.importData(file);
+        return ResponseHelper.success();
+    }
 }

+ 161 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/admin/AdminWebsitLogic.java

@@ -7,10 +7,13 @@ import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.admin.AdminWebsitNewBean;
 import com.gree.mall.manager.bean.admin.AdminWebsitTree;
 import com.gree.mall.manager.enums.admin.AdminWebsitTypeEnum;
+import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
 import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.logic.common.LbsAmapLogic;
 import com.gree.mall.manager.plus.entity.*;
 import com.gree.mall.manager.plus.service.*;
+import com.gree.mall.manager.utils.excel.ExcelUtils;
 import lombok.extern.slf4j.Slf4j;
 import me.chanjar.weixin.common.error.WxErrorException;
 import org.apache.commons.collections4.CollectionUtils;
@@ -18,11 +21,14 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -51,6 +57,10 @@ public class AdminWebsitLogic {
 
     @Autowired
     AdminDeptWebsitService adminDeptWebsitService;
+    @Resource
+    LbsAmapLogic lbsAmapLogic;
+    @Resource
+    AdminCompanyWechatPayConfigService adminCompanyWechatPayConfigService;
 //    @Autowired
 //    EnterpriseWechatWorkerLogic enterpriseWechatWorkerLogic;
 
@@ -430,4 +440,155 @@ public class AdminWebsitLogic {
                 .eq(Objects.nonNull(status), AdminWebsitPayConfig::getStatus, status)
                 .list();
     }
+
+    @Transactional
+    public void importData(MultipartFile file) throws Exception {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        String companyWechatId = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyWechatId() : null;
+        String companyName = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyName() : null;
+
+        if (org.apache.commons.lang3.StringUtils.isBlank(companyWechatId)) {
+            throw new RemoteServiceException("商户编号缺失,导入中止");
+        }
+
+        final AdminWebsit parentWebsit = adminWebsitService.lambdaQuery()
+                .eq(AdminWebsit::getCompanyWechatId, companyWechatId)
+                .eq(AdminWebsit::getType, AdminWebsitTypeEnum.B.getKey())
+                .last("limit 1")
+                .one();
+
+        if (Objects.isNull(parentWebsit)) {
+            throw new RemoteServiceException("未发现上级");
+        }
+
+        List<Object> objects = ExcelUtils.importExcel(file);
+
+        List<AdminWebsit> adminWebsitList = new ArrayList<>();
+        for (int i = 0; i < objects.size(); i++) {
+            int rowIndex = i + 2;
+            List<Object> row = (List<Object>) objects.get(i);
+            if (Objects.isNull(row.get(0)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(0).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 网点名称不能为空");
+            }
+            if (Objects.isNull(row.get(1)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(1).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 联系人不能为空");
+            }
+            if (Objects.isNull(row.get(2)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(2).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 联系电话不能为空");
+            }
+            if (Objects.isNull(row.get(3)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(3).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 详细地址不能为空");
+            }
+            if (Objects.isNull(row.get(4)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(4).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 电子支付商户不能为空");
+            }
+            if (Objects.isNull(row.get(5)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(5).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 状态不能为空");
+            }
+            if (Objects.isNull(row.get(6)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(6).toString())) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 通联支付开关不能为空");
+            }
+
+            String websitName = row.get(0).toString().trim();
+            final Integer existNameCount = adminWebsitService.lambdaQuery()
+                    .eq(AdminWebsit::getName, websitName)
+                    .count();
+            if (existNameCount > 0) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 网点名称已重复存在");
+            }
+            String address = row.get(3).toString().trim();
+            String lnglat = lbsAmapLogic.getLocationByAddress(address);
+
+            String payName = row.get(4).toString().trim();
+            final AdminCompanyWechatPayConfig wechatPayConfig = adminCompanyWechatPayConfigService.lambdaQuery()
+                    .eq(AdminCompanyWechatPayConfig::getPayMerchantName, payName)
+                    .one();
+            if (Objects.isNull(wechatPayConfig)) {
+                throw new RemoteServiceException("第" + rowIndex + "行, 电子支付商户不存在");
+            }
+            final String statusName = row.get(5).toString().trim();
+            final boolean status = statusName.equals("启用");
+            final String allinpayName = row.get(6).toString().trim();
+            final boolean isUseAllinpay = allinpayName.equals("开启");
+
+            AdminWebsit addWebsit = new AdminWebsit();
+            addWebsit.setWebsitId(IdWorker.getIdStr());
+            addWebsit.setName(websitName);
+            addWebsit.setType(AdminWebsitTypeEnum.C.getKey());
+            addWebsit.setParentId(parentWebsit.getWebsitId());
+            addWebsit.setWebsitNumber(addWebsit.getWebsitId());
+            addWebsit.setStatus(status);
+            addWebsit.setAddress(address);
+            addWebsit.setCompanyWechatId(companyWechatId);
+            addWebsit.setCompanyWechatName(companyName);
+            addWebsit.setLng(lnglat.split(",")[0]);
+            addWebsit.setLat(lnglat.split(",")[1]);
+            addWebsit.setLinkName(row.get(1).toString().trim());
+            addWebsit.setWebsitPhone(row.get(2).toString().trim());
+            addWebsit.setPayWorkerCodeId(wechatPayConfig.getId());
+            addWebsit.setIsUseAllinpay(isUseAllinpay);
+
+            adminWebsitList.add(addWebsit);
+            List<AdminWebsitPayConfig> payConfigList = new ArrayList<>();
+            if (isUseAllinpay) {
+                boolean isOn = true;
+                int detailIndex = 1;
+                int detailStartIndex = 6;
+                while (isOn) {
+                    try {
+                        row.get(detailStartIndex + 1);
+                    } catch (IndexOutOfBoundsException e) {
+                        isOn = false;
+                        continue;
+                    }
+
+                    try {
+                        if (Objects.isNull(row.get(detailStartIndex + 1)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 1).toString())) {
+                            throw new RemoteServiceException("第" + rowIndex + "行, 通联商户名称" + detailIndex + "不能为空");
+                        }
+
+//                      if (Objects.isNull(row.get(detailStartIndex + 2)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 2).toString())) {
+//                          throw new RemoteServiceException("第" + rowIndex + "行, 通联集团号" + detailIndex + "不能为空");
+//                      }
+                        if (Objects.isNull(row.get(detailStartIndex + 3)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 3).toString())) {
+                            throw new RemoteServiceException("第" + rowIndex + "行, 类别" + detailIndex + "不能为空");
+                        }
+                        if (Objects.isNull(row.get(detailStartIndex + 4)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 4).toString())) {
+                            throw new RemoteServiceException("第" + rowIndex + "行, 通联商户号" + detailIndex + "不能为空");
+                        }
+                        if (Objects.isNull(row.get(detailStartIndex + 5)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 5).toString())) {
+                            throw new RemoteServiceException("第" + rowIndex + "行, 通联商户appid" + detailIndex + "不能为空");
+                        }
+                        if (Objects.isNull(row.get(detailStartIndex + 6)) || org.apache.commons.lang3.StringUtils.isBlank(row.get(detailStartIndex + 6).toString())) {
+                            throw new RemoteServiceException("第" + rowIndex + "行, 状态" + detailIndex + "不能为空");
+                        }
+                        AdminWebsitPayConfig config = new AdminWebsitPayConfig();
+                        config.setCompanyWechatId(addWebsit.getCompanyWechatId());
+                        config.setCompanyWechatName(addWebsit.getCompanyWechatName());
+                        config.setWebsitId(addWebsit.getWebsitId());
+                        config.setName(row.get(detailStartIndex + 1).toString());
+                        config.setOrgId(Optional.ofNullable(row.get(detailStartIndex + 2)).orElse("").toString().trim());
+                        config.setType(row.get(detailStartIndex + 3).toString().equals(WebsitGoodsTypeEnum.M.getRemark()) ? WebsitGoodsTypeEnum.M.getKey() : WebsitGoodsTypeEnum.P.getKey());
+                        config.setMchNo(row.get(detailStartIndex + 4).toString().trim());
+                        config.setAppid(row.get(detailStartIndex + 5).toString().trim());
+                        config.setStatus(row.get(detailStartIndex + 6).toString().trim().equals("开启"));
+                        payConfigList.add(config);
+
+                        detailIndex++;
+                        detailStartIndex = detailStartIndex * detailIndex;
+                    } catch (IndexOutOfBoundsException e) {
+                        throw new RemoteServiceException("第" + rowIndex + "行, 第" + (detailStartIndex + 1) + "个通联相关配置缺失");
+                    }
+                }
+            }
+
+            if (CollectionUtil.isNotEmpty(adminWebsitList)) {
+                adminWebsitService.saveBatch(adminWebsitList);
+                if (CollectionUtil.isNotEmpty(payConfigList)) {
+                    adminWebsitPayConfigService.saveBatch(payConfigList);
+                }
+            }
+        }
+    }
 }

BIN
mall-server-api/src/main/resources/template/网点管理导入模板.xlsx