فهرست منبع

代理商管理

jinxia.mo 17 ساعت پیش
والد
کامیت
440cb24d0c

+ 61 - 10
back-ui/src/views/dz/agent/index.vue

@@ -13,16 +13,25 @@
                       </div>
                   </el-col>
               </pane> -->
-              <pane size="84">
+              <pane size="100">
                   <el-col>
                       <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
-                          <el-form-item label="名称" prop="name">
-                              <el-input
-                                      v-model=" queryParams.name"
-                                      placeholder="请输入代理商名称"
+                          <el-form-item label="代理商" prop="agentId">
+                              <el-select
+                                      v-model="queryParams.agentId"
+                                      placeholder="请选择或搜索代理商"
+                                      filterable
                                       clearable
+                                      style="width: 240px"
                                       @keyup.enter="handleQuery"
-                              />
+                              >
+                                  <el-option
+                                          v-for="item in flatAgentOptions"
+                                          :key="item.agentId"
+                                          :label="item.name"
+                                          :value="item.agentId"
+                                  />
+                              </el-select>
                           </el-form-item>
                           <!-- <el-form-item label="联系电话" prop="phonenumber">
                               <el-input
@@ -59,6 +68,15 @@
                                       @click="toggleExpandAll"
                               >展开/折叠</el-button>
                           </el-col>
+                          <el-col :span="1.5">
+                              <el-button
+                                      type="warning"
+                                      plain
+                                      icon="Download"
+                                      @click="handleExport"
+                                      v-hasPermi="['dz:agent:export']"
+                              >导出</el-button>
+                          </el-col>
                           <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
                       </el-row>
 
@@ -69,10 +87,12 @@
                               row-key="agentId"
                               :default-expand-all="isExpandAll"
                               :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
+                              :row-style="getRowStyle"
                       >
                           <!--      <el-table-column label="用户ID" prop="userId" />-->
                           <el-table-column label="名称" align="center" prop="name" />
                           <el-table-column label="账号/邀请码" align="center" prop="agentId" />
+                          <el-table-column label="密码" align="center" prop="password2" />
 <!--                          <el-table-column label="机构" align="center" prop="deptId" />-->
                           <el-table-column label="归属机构" align="center" key="deptName" prop="dept.deptName" :show-overflow-tooltip="true" />
                           <!-- <el-table-column label="联系电话" align="center" prop="phonenumber" /> -->
@@ -160,6 +180,7 @@ const appStore = useAppStore()
 
 const agentList = ref([])
 const agentOptions = ref([])
+const flatAgentOptions = ref([])
 const open = ref(false)
 const loading = ref(true)
 const showSearch = ref(true)
@@ -175,6 +196,7 @@ const data = reactive({
   form: {},
   queryParams: {
     userId: null,
+    agentId: null,
     name: null,
     deptId: null,
     phonenumber: null,
@@ -196,14 +218,22 @@ const filterNode = (value, data) => {
 
 /** 根据名称筛选机构树 */
 watch(deptName, val => {
-    proxy.$refs["deptTreeRef"].filter(val)
+    if (proxy.$refs["deptTreeRef"]) {
+        proxy.$refs["deptTreeRef"].filter(val)
+    }
 })
 
 /** 查询机构代理列表 */
 function getList() {
   loading.value = true
   listAgent(queryParams.value).then(response => {
-    agentList.value = proxy.handleTree(response.data, "agentId", "parentId")
+    const dataList = response.data || []
+    agentList.value = proxy.handleTree(dataList, "agentId", "parentId")
+    // 从原始数据中提取代理商列表用于下拉选择
+    flatAgentOptions.value = dataList.map(item => ({
+      agentId: item.agentId,
+      name: item.name
+    }))
     loading.value = false
   })
 }
@@ -276,10 +306,14 @@ function handleQuery() {
 function resetQuery() {
     // 清空机构ID
     queryParams.value.deptId = undefined
+    // 清空代理商ID
+    queryParams.value.agentId = undefined
     // 清空机构名称
     deptName.value = ""
-    // 取消树节点的选中状态
-    proxy.$refs.deptTreeRef.setCurrentKey(null)
+    // 取消树节点的选中状态(如果树组件存在)
+    if (proxy.$refs.deptTreeRef) {
+        proxy.$refs.deptTreeRef.setCurrentKey(null)
+    }
   proxy.resetForm("queryRef")
   handleQuery()
 }
@@ -308,6 +342,16 @@ function toggleExpandAll() {
   })
 }
 
+/** 设置表格行样式 */
+function getRowStyle({ row }) {
+  if (row.parentId != null && row.parentId !== 0) {
+    return {
+      backgroundColor: '#C4E7F8'
+    }
+  }
+  return {}
+}
+
 /** 修改按钮操作 */
 async function handleUpdate(row) {
   reset()
@@ -364,6 +408,13 @@ function handleDelete(row) {
   }).catch(() => {})
 }
 
+/** 导出按钮操作 */
+function handleExport() {
+  proxy.download('dz/agent/export', {
+    ...queryParams.value
+  }, `agent_${new Date().getTime()}.xlsx`)
+}
+
 // getList()
 
 onMounted(() => {

+ 40 - 0
ie-admin/src/main/java/com/ruoyi/web/controller/dz/DzAgentController.java

@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import cn.hutool.core.collection.CollectionUtil;
 import com.google.common.collect.Lists;
+import org.apache.commons.collections.CollectionUtils;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -93,6 +94,8 @@ public class DzAgentController extends BaseController
             }
         }
 
+        allList = processAgentList(allList);
+
         return success(allList);
     }
 
@@ -105,6 +108,17 @@ public class DzAgentController extends BaseController
     public void export(HttpServletResponse response, DzAgent dzAgent)
     {
         List<DzAgent> list = dzAgentService.selectDzAgentList(dzAgent);
+        // 设置机构名称
+        if (CollectionUtils.isNotEmpty(list)) {
+            list.forEach(agent -> {
+                if (agent.getDept() != null && agent.getDept().getDeptName() != null) {
+                    agent.setDeptName(agent.getDept().getDeptName());
+                }
+            });
+        }
+        //处理密码
+        list = processAgentList(list);
+
         ExcelUtil<DzAgent> util = new ExcelUtil<DzAgent>(DzAgent.class);
         util.exportExcel(response, list, "机构代理数据");
     }
@@ -178,4 +192,30 @@ public class DzAgentController extends BaseController
     {
         return toAjax(dzAgentService.deleteDzAgentByAgentIds(agentIds));
     }
+
+    private List<DzAgent> processAgentList(List<DzAgent> allList) {
+        if (CollectionUtils.isNotEmpty(allList)) {
+            List<Long> userIds = allList.stream()
+                    .map(DzAgent::getUserId).filter(userId -> userId != null)
+                    .distinct().collect(Collectors.toList());
+            if (!userIds.isEmpty()) {
+                List<SysUser> users = userService.selectUserByUserIds(userIds);
+                // 创建userId到SysUser的映射
+                Map<Long, SysUser> userMap = users.stream()
+                        .filter(user -> user.getUserId() != null)
+                        .collect(Collectors.toMap(
+                                SysUser::getUserId,
+                                user -> user,
+                                (existing, replacement) -> existing
+                        ));
+                // 设置每个agent的password2
+                allList.forEach(agent -> {
+                    if (agent.getUserId() != null && userMap.containsKey(agent.getUserId())) {
+                        agent.setPassword2(userMap.get(agent.getUserId()).getPassword2());
+                    }
+                });
+            }
+        }
+        return allList;
+    }
 }

+ 42 - 8
ie-system/src/main/java/com/ruoyi/dz/domain/DzAgent.java

@@ -21,38 +21,56 @@ public class DzAgent extends TreeEntity
 {
     private static final long serialVersionUID = 1L;
 
+    /** 代理商名称 */
+    @Excel(name = "姓名")
+    private String name;
+
     /** 代理商ID */
+    @Excel(name = "账号")
     private Long agentId;
 
     /** 上级代理商ID */
     private Long parentId;
     /** 机构ID */
-    @Excel(name = "机构ID")
+//    @Excel(name = "机构ID")
     private Long deptId;
 
     /** 用户ID */
-    @Excel(name = "用户ID")
+//    @Excel(name = "用户ID")
     private Long userId;
 
-    /** 代理商名称 */
-    @Excel(name = "代理商名称")
-    private String name;
+
 
     /** 联系电话 */
-    @Excel(name = "联系电话")
+//    @Excel(name = "联系电话")
     private String phonenumber;
 
     /** 负责校区列表 */
-    @Excel(name = "负责校区列表")
+//    @Excel(name = "负责校区列表")
     private String schools;
     private Long[] schoolIds;
     private String schoolName;
-
+    
     private String username;
     private String invitationCode;
 
+    /** 密码 */
+    @Excel(name = "密码")
+    private String password2;
+    /** 机构名称 */
+    @Excel(name = "机构名称")
+    private String deptName;
+
     private SysDept dept;
 
+    public String getInvitationCode() {
+        return invitationCode;
+    }
+
+    public void setInvitationCode(String invitationCode) {
+        this.invitationCode = invitationCode;
+    }
+
     public String getSchoolName() {
         return schoolName;
     }
@@ -61,6 +79,14 @@ public class DzAgent extends TreeEntity
         this.schoolName = schoolName;
     }
 
+    public String getDeptName() {
+        return deptName;
+    }
+
+    public void setDeptName(String deptName) {
+        this.deptName = deptName;
+    }
+
     public Long[] getSchoolIds() {
         return (null==schoolIds||schoolIds.length==0)?(StringUtils.isNotEmpty(schools)?
                 Arrays.stream(schools.split(",")).map(String::trim).filter(s -> !s.isEmpty()).map(Long::valueOf).toArray(Long[]::new):new Long[0]):schoolIds;
@@ -86,6 +112,14 @@ public class DzAgent extends TreeEntity
         this.username = username;
     }
 
+    public String getPassword2() {
+        return password2;
+    }
+
+    public void setPassword2(String password2) {
+        this.password2 = password2;
+    }
+
     public void setAgentId(Long agentId)
     {
         this.agentId = agentId;

+ 2 - 2
ie-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -612,8 +612,8 @@ public class SysUserServiceImpl implements ISysUserService
         user.setNickName(nickName);
         user.setUserType(userType.getVal());
         user.setUserTypeId(userTypeId);
-        String pwd = StringUtils.isEmpty(user.getPassword())?configService.selectConfigByKey("sys.user.initPassword"):user.getPassword();
-        String pass = NumberUtils.generatePwd(6);//不是0开头的6位随机数密码
+//        String pwd = StringUtils.isEmpty(user.getPassword())?configService.selectConfigByKey("sys.user.initPassword"):user.getPassword();
+        String pwd = NumberUtils.generatePwd(6);//不是0开头的6位随机数密码
 //        user.setPassword2(RandomUtil.randomNumbers(6));
         user.setPassword2(pwd);
         user.setPassword(SecurityUtils.encryptPassword(pwd));

+ 1 - 0
ie-system/src/main/resources/mapper/dz/DzAgentMapper.xml

@@ -36,6 +36,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectDzAgentList" parameterType="DzAgent" resultMap="DzAgentResult">
         <include refid="selectDzAgentVo"/>
         <where>
+            <if test="agentId != null "> and t1.agent_id = #{agentId}</if>
             <if test="userId != null "> and t1.user_id = #{userId}</if>
 <!--            <if test="deptId != null "> and t1.dept_id = #{deptId}</if>-->
             <if test="deptId != null ">