‘linchangsheng’ il y a 3 semaines
Parent
commit
1f0935c229

+ 2 - 1
src/main/java/com/gree/mall/manager/controller/admin/AdminWebsitController.java

@@ -111,9 +111,10 @@ public class AdminWebsitController {
     @ApiOperation("导入商家附件(商家导入.xlsx)")
     public ResponseHelper importData(
             @RequestPart("file") MultipartFile file
+            , HttpServletRequest request
     ) throws IOException {
         List<Object> objects = ExcelUtils.importExcel(file);
-        adminWebsitLogic.importData(objects);
+        adminWebsitLogic.importData(objects,request);
         return ResponseHelper.success();
     }
 

+ 53 - 6
src/main/java/com/gree/mall/manager/logic/admin/AdminWebsitLogic.java

@@ -3,12 +3,15 @@ package com.gree.mall.manager.logic.admin;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.admin.AdminUserBean;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.admin.AdminWebsitTree;
 import com.gree.mall.manager.bean.admin.AdminWebsitVO;
+import com.gree.mall.manager.bean.admin.reqDto.AdminUserAddReqBean;
 import com.gree.mall.manager.commonmapper.AdminMapper;
 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.StringUtil;
@@ -50,6 +53,12 @@ public class AdminWebsitLogic {
     @Autowired
     SysDictCompanyService sysDictCompanyService;
 
+    @Autowired
+    AdminUserLogic adminUserLogic;
+
+    @Autowired
+    LbsAmapLogic lbsAmapLogic;
+
     /**
      * 区域列表
      */
@@ -105,15 +114,28 @@ public class AdminWebsitLogic {
         AdminCompanyWechat adminCompanyWechat = adminCompanyWechatService.getById(adminWebsit.getPayWorkerCodeId());
         AdminCompanyWechat adminCompanyWechatP = adminCompanyWechatService.getById(adminWebsit.getCompanyWechatId());
 
-        //Long aLong = workWechatLogic.addOrganization(adminWebsit.getName(), adminWebsit.getParentId(),adminUser.getAdminCompanyWechat());
-        String aLong = IdWorker.getIdStr();
-        adminWebsit.setWebsitId(aLong+"");
-//        adminWebsit.setCorpId(adminUser.getCorpIds().get(0));
-        adminWebsit.setWebsitId(aLong);
+
+        adminWebsit.setWebsitId(adminWebsit.getWebsitNumber());
         adminWebsit.setCompanyName(adminCompanyWechatP.getCompanyName());
         adminWebsit.setPayWorkerCodeName(adminCompanyWechat.getCompanyName());
         adminWebsit.insert();
 
+        AdminUserAddReqBean adminUserBean = new AdminUserAddReqBean();
+        adminUserBean.setUserName(adminWebsit.getWebsitId());
+        adminUserBean.setNickName(adminWebsit.getName());
+        adminUserBean.setLinkPhone(adminWebsit.getPersonMobile());
+        adminUserBean.setLinkName(adminWebsit.getPerson());
+        adminUserBean.setPassword("123456");
+        adminUserBean.setRoleId("1899638664615489538");
+        adminUserBean.setRoleName("网点");
+        adminUserBean.setWebsitId(adminWebsit.getWebsitId());
+        adminUserBean.setWebsitName(adminWebsit.getName());
+        adminUserBean.setCompanyWechatId(adminWebsit.getCompanyWechatId());
+        adminUserBean.setCompanyName(adminWebsit.getCompanyName());
+        adminUserBean.setAddress(adminWebsit.getAddress());
+        adminUserBean.setType(2);
+        adminUserLogic.save(adminUserBean, request);
+
     }
     /**
      * 编辑部门
@@ -240,7 +262,8 @@ public class AdminWebsitLogic {
         return adminDeptWebsitVOIPage;
     }
 
-    public void importData(List<Object> objects) {
+    @Transactional(rollbackFor = Exception.class)
+    public void importData(List<Object> objects,HttpServletRequest request) {
 
         List<AdminWebsit> adminWebsits = new ArrayList<>();
 
@@ -285,6 +308,11 @@ public class AdminWebsitLogic {
                 throw new RemoteServiceException("第"+rowIndex+"行,找不到支付商户");
             adminWebsit.setPayWorkerCodeName(one.getCompanyName());
             adminWebsit.setPayWorkerCodeId(one.getCompanyWechatId());
+
+            String lnglat = lbsAmapLogic.getLocationByAddress(adminWebsit.getAddress());
+
+            adminWebsit.setLng(lnglat.split(",")[0]);
+            adminWebsit.setLat(lnglat.split(",")[1]);
             if (row.size() > 7) {
                 adminWebsit.setYunAppid((String) row.get(9));
                 adminWebsit.setYunAppkey((String) row.get(10));
@@ -301,5 +329,24 @@ public class AdminWebsitLogic {
         }
 
         adminWebsitService.saveBatch(adminWebsits);
+
+        for (AdminWebsit adminWebsit : adminWebsits) {
+
+            AdminUserAddReqBean adminUserBean = new AdminUserAddReqBean();
+            adminUserBean.setUserName(adminWebsit.getWebsitId());
+            adminUserBean.setNickName(adminWebsit.getName());
+            adminUserBean.setLinkPhone(adminWebsit.getPersonMobile());
+            adminUserBean.setLinkName(adminWebsit.getPerson());
+            adminUserBean.setPassword("123456");
+            adminUserBean.setRoleId("1899638664615489538");
+            adminUserBean.setRoleName("网点");
+            adminUserBean.setWebsitId(adminWebsit.getWebsitId());
+            adminUserBean.setWebsitName(adminWebsit.getName());
+            adminUserBean.setCompanyWechatId(adminWebsit.getCompanyWechatId());
+            adminUserBean.setCompanyName(adminWebsit.getCompanyName());
+            adminUserBean.setAddress(adminWebsit.getAddress());
+            adminUserBean.setType(2);
+            adminUserLogic.save(adminUserBean, request);
+        }
     }
 }

+ 49 - 0
src/main/java/com/gree/mall/manager/logic/common/LbsAmapLogic.java

@@ -0,0 +1,49 @@
+package com.gree.mall.manager.logic.common;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class LbsAmapLogic {
+
+//    private static final String lbsWebKey = "b772f8b0ace6bc96c04ae8e48f241e36";
+    private static final String lbsWebKey = "428a7111e02ea8367a3b34804eaa025b";
+
+
+    /**
+     * 根据地址反查经纬度
+     * @Param 中文地址(最好详细)
+     * @return lng,lat
+     */
+    public String getLocationByAddress(String address){
+        //String lbsWebKey = "b772f8b0ace6bc96c04ae8e48f241e36";
+        //String address = "广东省广州市天河区华景新城";
+        String url = "https://restapi.amap.com/v3/geocode/geo?key="+lbsWebKey+"&address="+address;
+        String s = HttpUtil.get(url);
+        JSONObject jsonObject = new JSONObject(s);
+        String status = jsonObject.getStr("status");
+        if(!status.equals("1")){
+            return null;
+        }
+        JSONArray geocodes = jsonObject.getJSONArray("geocodes");
+        if(CollectionUtils.isEmpty(geocodes))
+            return null;
+        Map<String, Object> map = (Map<String, Object>) geocodes.get(0);
+        String location = (String)map.get("location");
+        log.info("根据地址【{}】反查经纬度【{}】",address,new JSONObject(map));
+        return location;
+    }
+
+
+
+}