Переглянути джерело

查询产品下项目和账户

zhaoxian 3 роки тому
батько
коміт
a8f7c62b4b

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/ProjectMapper.java

@@ -33,4 +33,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<Long> getProjectIdsByProductIdAndNotIn(@Param("productId") Long productId, @Param("partakeProjectIds") List<Long> partakeProjectIds);
 
     JSONObject getProjectByAccountId(@Param("accountId") Long accountId);
+
+    List<JSONObject> queryProductList(@Param("projectList") List<JSONObject> projectList);
 }

+ 12 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/ProjectMapper.xml

@@ -75,6 +75,7 @@
         </if>
 
     </select>
+
     <select id="getProjectByAccountId" resultType="com.alibaba.fastjson.JSONObject">
     SELECT
 	id AS 'projectId',
@@ -93,4 +94,15 @@
 	)
     </select>
 
+    <select id="queryProductList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t1.product_id as 'productId',t2.product_name as 'productName' FROM ctop_project t1
+        LEFT JOIN ctop_product t2 ON t1.product_id = t2.id
+        WHERE t1.product_id is not null
+        and t1.id IN
+        <foreach item="item" index="index" collection="projectList" open="(" separator="," close=")">
+            #{item.projectId}
+        </foreach>
+        GROUP BY t1.product_id
+    </select>
+
 </mapper>

+ 2 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IProjectService.java

@@ -32,4 +32,6 @@ public interface IProjectService extends IService<Project> {
     List<Long> getProjectIdsByProductIdAndNotIn(Long productId, List<Long> partakeProjectIds);
 
     JSONObject getProjectByAccountId(Long accountId);
+
+    List<JSONObject> queryProductInfo(List<JSONObject> projectList);
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/ProjectServiceImpl.java

@@ -80,4 +80,9 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     public JSONObject getProjectByAccountId(Long accountId) {
         return projectMapper.getProjectByAccountId(accountId);
     }
+
+    @Override
+    public List<JSONObject> queryProductInfo(List<JSONObject> projectList) {
+        return projectMapper.queryProductList(projectList);
+    }
 }

+ 116 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/ProjectMemberController.java

@@ -151,6 +151,122 @@ public class ProjectMemberController {
         return map;
     }
 
+    /**
+     * 获取项目以及账户信息
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/getProductProjectAndAccountList")
+    public Result<List<JSONObject>> getProductProjectAndAccountList(@RequestBody JSONObject requestJson) {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            String userId = requestJson.getString("userId");
+            if (Check.isNull(userId)) {
+                throw new Exception("请选择userId");
+            }
+            List<Integer> mediaIds = new ArrayList<>();
+            //查询用户角色
+            String roleCode = sysRoleService.getRoleCodeByUserId(userId);
+            //角色为 管理员 || 销售 || 媒介 查询全部
+            if ("admin".equals(roleCode) || roleCode.contains("sale") || "meidaManager".equals(roleCode)) {
+                userId = null;
+            }
+            //查询项目信息以及广告主
+            List<JSONObject> projectList = projectMemberService.getProjectByUserIdAndMediaIds(userId, mediaIds);
+            List<JSONObject> haveList = new ArrayList<>();
+            List<JSONObject> list = new ArrayList<>();
+            if (!Check.isNull(projectList)) {
+                list = projectService.queryProductInfo(projectList);
+                if (Check.isNull(list)) {
+                    result.setSuccess(false);
+                    result.setMessage("该用户没有可用的产品");
+                    return result;
+                }
+                //项目id 查询账户人员信息
+                Map<Long, List<JSONObject>> accountMap = userAllocationService.getAccountListByProjectList(projectList);
+                for (int i = 0; i < projectList.size(); i++) {
+                    JSONObject project = projectList.get(i);
+                    if (!Check.isNull(project)) {
+                        List<JSONObject> accountList = accountMap.get(project.getLong("projectId"));
+                        if (!Check.isNull(accountList)) {
+                            project.put("accountList", accountList);
+                            haveList.add(project);
+                        }
+                    }
+                }
+
+                for (JSONObject object : list) {
+                    List<JSONObject> proList = new ArrayList<>();
+                    for (JSONObject have : haveList) {
+                        if (object.getLong("productId") == have.getLong("productId")) {
+                            proList.add(have);
+                        }
+                    }
+                    object.put("projectList", proList);
+                }
+            }
+            result.setSuccess(true);
+            result.setResult(list);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
+    /**
+     * 获取项目以及账户信息
+     *
+     * @param requestJson
+     * @return
+     */
+    @PostMapping(value = "/getProductProjectList")
+    public Result<List<JSONObject>> getProductProjectList(@RequestBody JSONObject requestJson) {
+        Result<List<JSONObject>> result = new Result<>();
+        try {
+            String userId = requestJson.getString("userId");
+            if (Check.isNull(userId)) {
+                throw new Exception("请选择userId");
+            }
+            List<Integer> mediaIds = new ArrayList<>();
+            //查询用户角色
+            String roleCode = sysRoleService.getRoleCodeByUserId(userId);
+            //角色为 管理员 || 销售 || 媒介 查询全部
+            if ("admin".equals(roleCode) || roleCode.contains("sale") || "meidaManager".equals(roleCode)) {
+                userId = null;
+            }
+            //查询项目信息以及广告主
+            List<JSONObject> projectList = projectMemberService.getProjectByUserIdAndMediaIds(userId, mediaIds);
+            List<JSONObject> list = new ArrayList<>();
+            if (!Check.isNull(projectList)) {
+                list = projectService.queryProductInfo(projectList);
+                if (Check.isNull(list)) {
+                    result.setSuccess(false);
+                    result.setMessage("该用户没有可用的产品");
+                    return result;
+                }
+                for (JSONObject object : list) {
+                    List<JSONObject> proList = new ArrayList<>();
+                    for (JSONObject have : projectList) {
+                        if (object.getLong("productId") == have.getLong("productId")) {
+                            proList.add(have);
+                        }
+                    }
+                    object.put("projectList", proList);
+                }
+            }
+            result.setSuccess(true);
+            result.setResult(list);
+        } catch (Exception e) {
+            e.printStackTrace();
+            result.setSuccess(false);
+            result.setMessage(e.getMessage());
+        }
+        return result;
+    }
+
 
     /**
      * 获取项目以及账户信息

+ 1 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/ProjectMemberMapper.xml

@@ -244,6 +244,7 @@
         select
         t2.id as 'projectId',
         t2.project_name as 'projectName',
+        t2.product_id as 'productId',
         (select name from ctop_advertiser where id = t2.advertiser_id) as 'advertiserName'
         from ctop_project_member t1
         left join ctop_project t2