From 3d2b51ea4520533de5e78f88dddf5b5c7dce4247 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期四, 06 六月 2024 15:56:18 +0800
Subject: [PATCH] 管理后台添加营销员导入功能

---
 meiya-admin/src/main/java/com/sinata/modular/member/controller/MemUserSalesController.java |   81 ++++++++++++++++++++++++++++++++++------
 1 files changed, 68 insertions(+), 13 deletions(-)

diff --git a/meiya-admin/src/main/java/com/sinata/modular/member/controller/MemUserSalesController.java b/meiya-admin/src/main/java/com/sinata/modular/member/controller/MemUserSalesController.java
index e1419dc..fe11369 100644
--- a/meiya-admin/src/main/java/com/sinata/modular/member/controller/MemUserSalesController.java
+++ b/meiya-admin/src/main/java/com/sinata/modular/member/controller/MemUserSalesController.java
@@ -3,6 +3,8 @@
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelReader;
+import cn.hutool.poi.excel.ExcelUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.enums.SqlLike;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
@@ -17,10 +19,13 @@
 import com.sinata.core.common.annotion.BussinessLog;
 import com.sinata.core.common.annotion.Permission;
 import com.sinata.core.common.constant.factory.PageFactory;
+import com.sinata.core.common.exception.BizExceptionEnum;
+import com.sinata.core.exception.GunsException;
 import com.sinata.core.shiro.ShiroKit;
 import com.sinata.core.shiro.ShiroUser;
 import com.sinata.core.util.Convert;
 import com.sinata.core.util.ExcelExportUtil;
+import com.sinata.core.util.ExcelImportUtil;
 import com.sinata.core.util.SqlUtil;
 import com.sinata.modular.mall.model.MallOrder;
 import com.sinata.modular.mall.service.IMallOrderService;
@@ -34,19 +39,25 @@
 import com.sinata.modular.system.service.IRoleService;
 import com.sinata.modular.system.service.ISystemNoticeService;
 import com.sinata.modular.system.service.ITCityRegionService;
+import java.io.IOException;
+import java.net.URLEncoder;
+import javax.servlet.ServletOutputStream;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 会员用户信息控制器
@@ -149,11 +160,11 @@
                             Collectors.toList());
             if (cityRoleList.contains(EnumCityRole.CITY_ROLE.index)) {
                 // 市级城市管理员
-                wrapper.like("o.city_code", shiroUser.getCityCode().substring(0, 4), SqlLike.RIGHT);
+                wrapper.like("o.agent_county_code", shiroUser.getCityCode().substring(0, 4), SqlLike.RIGHT);
             }
             else if (cityRoleList.contains(EnumCityRole.PROVINCE_ROLE.index)) {
                 // 省级城市管理员
-                wrapper.like("o.city_code", shiroUser.getCityCode().substring(0, 2), SqlLike.RIGHT);
+                wrapper.like("o.agent_county_code", shiroUser.getCityCode().substring(0, 2), SqlLike.RIGHT);
             }
         } catch (Exception e) {
             e.printStackTrace();
@@ -194,7 +205,7 @@
         // 封装数据
         for (Map<String, Object> map : list) {
             map.put("cityCode",
-                    cityRegionService.getProvinceCityCountyNameByAll(cityAll, Convert.toStr(map.get("city_code"))).stream()
+                    cityRegionService.getProvinceCityCountyNameByAll(cityAll, Convert.toStr(map.get("agent_county_code"))).stream()
                             .map(TCityRegion::getName)
                             .collect(Collectors.joining("-"))
             );
@@ -237,20 +248,13 @@
             // 用户等级
             Integer userMemberGradeId = map.get("member_grade_id") == null ? null : (Integer) map.get("member_grade_id");
             // 查询上级城市合伙人、市场总监信息
-            MemUser[] parentV4V5User = memUserRelationService.getParentV4V5ByRelationPath(
-                    v4UserList,
-                    v5UserList,
+            MemUser[] parentV4V5User = memUserRelationService.getParentV4V5ByRelationPath2(
                     map.get("relation_path") == null ? null : map.get("relation_path").toString(),
                     userMemberGradeId
             );
-            if (parentV4V5User[0] != null) {
+                if (parentV4V5User[0] != null) {
                 map.put("v4ShowId", parentV4V5User[0].getShowId());
                 map.put("v4Team", parentV4V5User[0].getRealName());
-            } else if (parentV4V5User[1] != null) {
-                map.put("v4ShowId", parentV4V5User[1].getShowId());
-                map.put("v4Team", parentV4V5User[1].getRealName());
-                map.put("v5ShowId", parentV4V5User[1].getShowId());
-                map.put("v5Team", parentV4V5User[1].getRealName());
             }
             if (parentV4V5User[1] != null) {
                 map.put("v5ShowId", parentV4V5User[1].getShowId());
@@ -496,6 +500,7 @@
                             + ", agent_province_code = " + SqlUtil.addSingleQuotes(province)
                             + ", agent_city_code = " + SqlUtil.addSingleQuotes(city)
                             + ", agent_county_code = " + SqlUtil.addSingleQuotes(county);
+                    log.info("用户:{}修改了营销员城市地址",memUser.getRealName());
                 }
             }
 
@@ -805,7 +810,7 @@
                 + ", agent_province_code = " + SqlUtil.addSingleQuotes(province)
                 + ", agent_city_code = " + SqlUtil.addSingleQuotes(city)
                 + ", agent_county_code = " + SqlUtil.addSingleQuotes(county);
-
+        log.info("用户:{}修改了营销员城市地址",userIdList.toString());
         boolean flag = memUserService.updateForSet(whereSql, new EntityWrapper<MemUser>().in("id", userIdList));
         return returnByFlag(flag, null);
     }
@@ -835,5 +840,55 @@
             return new ErrorTip(500, StrUtil.isNotBlank(msg) ? msg : "操作失败!");
         }
     }
+    @Permission
+    @ResponseBody
+    @BussinessLog(value = "营销人员管理-下载导入模板")
+    @RequestMapping(value = "/downloadTemplate",method = RequestMethod.POST)
+    public Object downloadTemplate(HttpServletResponse response) {
+        // // 表格数据【封装】
+        // List<List<Object>> dataList = new ArrayList<>();
+        //     // 头部列【封装】
+        //     List<Object> shellList = new ArrayList<>();
+        //     shellList.add("姓名");
+        //     shellList.add("手机号");
+        //     shellList.add("性别");
+        //     shellList.add("生日 例:2024-06-06");
+        //     shellList.add("证件类型 0身份证 1护照");
+        //     shellList.add("身份证号");
+        //     shellList.add("银行名称");
+        //     shellList.add("银行卡号");
+        //     shellList.add("推荐人手机号");
+        //     dataList.add(shellList);
+        // try {
+        //     ExcelExportUtil.easySheet(URLEncoder.encode("营销人员导入模板", "UTF-8"),"sheet1",dataList,response);
+        // } catch (IOException e) {
+        //     throw new RuntimeException(e);
+        // }
+        String url = "https://meitianmeiya.obs.cn-southwest-2.myhuaweicloud.com/excel/%E8%90%A5%E9%94%80%E4%BA%BA%E5%91%98%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xls";
+        return new SuccessTip(200, url);
+    }
+    @Permission
+    @ResponseBody
+    @BussinessLog(value = "营销人员管理-导入")
+    @RequestMapping(value = "/importSalesUser",method = RequestMethod.POST)
+    public Object importUsers(MultipartFile file, HttpServletResponse response)  {
+        String s = file.getOriginalFilename();
 
+        if (s == null || !("xls".equals(s.substring(s.lastIndexOf(".") + 1)) || "xlsx".equals(s.substring(s.lastIndexOf(".") + 1)))) {
+            return new ErrorTip(500,"只能上传.xls或.xlsx格式的文件!");
+        }
+        List<Map<String, String>> mapList = null;
+        try {
+            mapList = ExcelImportUtil.getMapList(file,
+                    new String[]{"姓名", "手机号", "性别","生日 例:2024-06-06","证件类型 0身份证 1护照", "身份证号","银行名称","银行卡号","推荐人手机号","职级 3黄金营销员 4城市合伙人 5市场总监"});
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        String str = memUserService.importSalesUser(mapList, response);
+            if (str == null) {
+                return SUCCESS_TIP;
+            } else {
+                return new SuccessTip(201, str);
+            }
+    }
 }

--
Gitblit v1.7.1