Browse Source

账户2.0——导入账户,添加查看,删除接口

zhaoxian 3 years ago
parent
commit
bf039c8bc7

+ 36 - 5
ruixuan-live/src/main/java/com/ruixuan/live/controller/KuaishouLiveUserAccountController.java

@@ -7,7 +7,6 @@ import com.ruixuan.common.core.domain.AjaxResult;
 import com.ruixuan.common.core.domain.ResultResponse;
 import com.ruixuan.common.core.page.TableDataInfo;
 import com.ruixuan.common.enums.BusinessType;
-import com.ruixuan.common.utils.poi.ExcelUtil;
 import com.ruixuan.live.entity.KuaishouLiveUserAccount;
 import com.ruixuan.live.service.IKuaishouLiveUserAccountService;
 import io.swagger.annotations.Api;
@@ -24,7 +23,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -50,7 +48,7 @@ public class KuaishouLiveUserAccountController extends BaseController {
         return getDataTable(list);
     }
 
-     /**
+    /**
      * 查询快手直播账户列表
      */
     @GetMapping("/queryAllList")
@@ -61,6 +59,39 @@ public class KuaishouLiveUserAccountController extends BaseController {
     }
 
     /**
+     * 查询账户关联人员
+     */
+    @GetMapping("/queryAccountAllUsers")
+    @ApiOperation(value = "查询账户关联人员")
+    public ResultResponse queryAccountAllUsers(@ApiParam("快手ID") @RequestParam(value = "ksId", required = true) Long ksId,
+                                               @ApiParam("账户ID") @RequestParam(value = "accountId", required = true) Long accountId) {
+        try {
+            return kuaishouLiveUserAccountService.queryAccountAllUsers(ksId, accountId);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ResultResponse.error("查询异常");
+    }
+
+    /**
+     * 删除账户关联人员
+     */
+    @GetMapping("/deleteAccountUser")
+    @ApiOperation(value = "删除账户关联人员")
+    public ResultResponse deleteAccountUser(
+            @ApiParam("快手ID") @RequestParam(value = "ksId", required = true) Long ksId,
+            @ApiParam("账户ID") @RequestParam(value = "accountId", required = true) Long accountId,
+            @ApiParam("角色code") @RequestParam(value = "role", required = true) String role,
+            @ApiParam("用户ID") @RequestParam(value = "userId", required = true) String userId) {
+        try {
+            return kuaishouLiveUserAccountService.deleteAccountAllUser(ksId, accountId, role, userId);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return ResultResponse.error("查询异常");
+    }
+
+    /**
      * 查询快手昵称
      */
     @GetMapping("/queryNicknameList")
@@ -107,8 +138,8 @@ public class KuaishouLiveUserAccountController extends BaseController {
     @ApiOperation(value = "通过excel导入账户")
     public ResultResponse insertByExcel(@ApiParam("excel文档") @RequestParam(value = "file", required = false) MultipartFile file,
                                         @ApiParam("创建人ID") @RequestParam(value = "createrId", required = false) Long createrId
-                                        ) {
-        return kuaishouLiveUserAccountService.insertByExcel(file,createrId);
+    ) {
+        return kuaishouLiveUserAccountService.insertByExcel(file, createrId);
     }
 
     /**

+ 4 - 4
ruixuan-live/src/main/java/com/ruixuan/live/entity/KuaishouLiveUserAccount.java

@@ -65,7 +65,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 销售负责人Id
      */
-    private Long saleLeaderId;
+    private String saleLeaderId;
 
     /**
      * 销售负责人
@@ -75,7 +75,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 运营(优化)负责人Id
      */
-    private Long operatorLeaderId;
+    private String operatorLeaderId;
 
     /**
      * 运营(优化)负责人
@@ -85,7 +85,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     /**
      * 设计负责人Id
      */
-    private Long designerLeaderId;
+    private String designerLeaderId;
 
     /**
      * 设计负责人
@@ -146,7 +146,7 @@ public class KuaishouLiveUserAccount implements Serializable {
     private Date createTime;
 
     private Integer count;
-    private List<String> accountNames;
+    private List<Long> accountIds;
 
     public KuaishouLiveUserAccount() {
 

+ 5 - 4
ruixuan-live/src/main/java/com/ruixuan/live/mapper/KuaishouLiveUserAccountMapper.java

@@ -65,15 +65,16 @@ public interface KuaishouLiveUserAccountMapper {
 
     List<JSONObject> queryAccountListByKsId(Long ksId);
 
-    KuaishouLiveUserAccount getOne(@Param("ksId") Long ksId, @Param("accountName") String accountName);
+    KuaishouLiveUserAccount getOne(KuaishouLiveUserAccount account);
 
     void replaceBatch(@Param(value = "accountList")  List<KuaishouLiveUserAccount> accountList);
 
     List<KuaishouLiveUserAccount> queryAllList(KuaishouLiveUserAccount kuaishouLiveUserAccount);
 
-    List<String> queryAccountNamesByUserId(@Param("userId") Long userId);
+    List<Long> queryAccountIdsByUserId(@Param("userId") Long userId);
 
-    List<KuaishouLiveUserAccount> queryAllListByAccountNames(KuaishouLiveUserAccount kuaishouLiveUserAccount);
+    List<KuaishouLiveUserAccount> queryAllListByAccountIds(KuaishouLiveUserAccount kuaishouLiveUserAccount);
+
+    List<KuaishouLiveUserAccount> selectAllListByAccountIds(KuaishouLiveUserAccount kuaishouLiveUserAccount);
 
-    List<KuaishouLiveUserAccount> selectAllListByAccountNames(KuaishouLiveUserAccount kuaishouLiveUserAccount);
 }

+ 10 - 0
ruixuan-live/src/main/java/com/ruixuan/live/mapper/KuaishouLiveUserAccountPartMapper.java

@@ -29,8 +29,18 @@ public interface KuaishouLiveUserAccountPartMapper {
      */
     public int deleteKuaishouLiveUserAccountPartById(Long ksId);
 
+    /**
+     * 删除快手账户协作人群
+     *
+     * @param id 快手账户协作人群主键
+     * @return 结果
+     */
+    public int deleteByAccountId(@Param("ksId") Long ksId, @Param("accountId") Long accountId);
+
 
     void replaceBatch(@Param(value = "collaborators") List<JSONObject> collaborators);
 
     List<JSONObject> queryCollaboratorsById(Long ksId);
+
+    List<JSONObject> queryAccountCollaborators(@Param("ksId") Long ksId, @Param("accountId") Long accountId);
 }

+ 2 - 0
ruixuan-live/src/main/java/com/ruixuan/live/service/IKuaishouLiveUserAccountService.java

@@ -72,5 +72,7 @@ public interface IKuaishouLiveUserAccountService {
 
     ResultResponse queryRoles(String type);
 
+    ResultResponse queryAccountAllUsers(Long ksId, Long accountId );
 
+    ResultResponse deleteAccountAllUser(Long ksId, Long accountId, String role, String userId);
 }

+ 77 - 13
ruixuan-live/src/main/java/com/ruixuan/live/service/impl/KuaishouLiveUserAccountServiceImpl.java

@@ -83,11 +83,11 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
             PageUtils.startPage();
             list = kuaishouLiveUserAccountMapper.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
         } else {
-            List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(kuaishouLiveUserAccount.getUserId());
-            if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
-                kuaishouLiveUserAccount.setAccountNames(accountNames);
+            List<Long> accountIds = kuaishouLiveUserAccountMapper.queryAccountIdsByUserId(kuaishouLiveUserAccount.getUserId());
+            if (Check.isNotNull(accountIds) && accountIds.size() > 0) {
+                kuaishouLiveUserAccount.setAccountIds(accountIds);
                 PageUtils.startPage();
-                list = kuaishouLiveUserAccountMapper.selectAllListByAccountNames(kuaishouLiveUserAccount);
+                list = kuaishouLiveUserAccountMapper.selectAllListByAccountIds(kuaishouLiveUserAccount);
             }
         }
         return list;
@@ -101,11 +101,11 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
             PageUtils.startPage();
             list = kuaishouLiveUserAccountMapper.queryAllList(userAccount);
         } else {
-            List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(userAccount.getUserId());
-            if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
-                userAccount.setAccountNames(accountNames);
+            List<Long> accountIds = kuaishouLiveUserAccountMapper.queryAccountIdsByUserId(userAccount.getUserId());
+            if (Check.isNotNull(accountIds) && accountIds.size() > 0) {
+                userAccount.setAccountIds(accountIds);
                 PageUtils.startPage();
-                list = kuaishouLiveUserAccountMapper.queryAllListByAccountNames(userAccount);
+                list = kuaishouLiveUserAccountMapper.queryAllListByAccountIds(userAccount);
             }
         }
         return list;
@@ -118,10 +118,13 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
      */
     @Override
     public ResultResponse insertKuaishouLiveUserAccount(KuaishouLiveUserAccount account) {
-        KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account.getKsId(), account.getAccountName());
+        KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account);
         if (one != null) {
             return ResultResponse.error("快手ID:" + account.getKsId() + "下已存在该账户名,请重新命名!");
         }
+        if (Check.isNull(account.getAccountId())) {
+            account.setAccountId(System.currentTimeMillis());
+        }
         String collaboratorList = account.getCollaboratorList();
         if (collaboratorList != null) {
             List<JSONObject> collaborators = JSONArray.parseArray(collaboratorList, JSONObject.class);
@@ -207,13 +210,13 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
     }
 
     // 通过人员名字查询人员ID
-    private Long getUserIdByName(String name) {
+    private String getUserIdByName(String name) {
         if (Check.isNull(name)) {
             return null;
         }
         SysUser user = sysUserService.selectUserByNickName(name);
         if (Check.isNotNull(user)) {
-            return user.getUserId();
+            return user.getUserId().toString();
         }
         return null;
     }
@@ -223,7 +226,7 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
      */
     @Override
     public ResultResponse updateKuaishouLiveUserAccount(KuaishouLiveUserAccount account) {
-        KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account.getKsId(), account.getAccountName());
+        KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account);
         if (one == null) {
             return ResultResponse.error("未查询到账户");
         }
@@ -273,7 +276,6 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
 
     @Override
     public List<JSONObject> queryNicknameList() {
-
         return kuaishouLiveUserAccountMapper.queryNicknameList();
     }
 
@@ -288,4 +290,66 @@ public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAcco
         return ResultResponse.success(list);
     }
 
+    @Override
+    public ResultResponse queryAccountAllUsers(Long ksId, Long accountId) {
+        List<JSONObject> collaborators = accountPartMapper.queryAccountCollaborators(ksId, accountId);
+        KuaishouLiveUserAccount account = new KuaishouLiveUserAccount();
+        account.setAccountId(accountId);
+        account.setKsId(ksId);
+        KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account);
+        if (Check.isNotNull(one)) {
+            if (Check.isNotNull(one.getSaleLeaderId())) {
+                JSONObject obj = new JSONObject();
+                obj.put("role", "saleLeader");
+                obj.put("roleName", "销售负责人");
+                obj.put("userId", one.getSaleLeaderId());
+                obj.put("name", one.getSaleLeader());
+                collaborators.add(obj);
+            }
+            if (Check.isNotNull(one.getOperatorLeaderId())) {
+                JSONObject obj = new JSONObject();
+                obj.put("role", "operatorLeader");
+                obj.put("roleName", "运营负责人");
+                obj.put("userId", one.getOperatorLeaderId());
+                obj.put("name", one.getOperatorLeader());
+                collaborators.add(obj);
+            }
+            if (Check.isNotNull(one.getDesignerLeaderId())) {
+                JSONObject obj = new JSONObject();
+                obj.put("role", "designerLeader");
+                obj.put("roleName", "设计负责人");
+                obj.put("userId", one.getDesignerLeaderId());
+                obj.put("name", one.getDesignerLeader());
+                collaborators.add(obj);
+            }
+        }
+        return ResultResponse.success(collaborators);
+    }
+
+    @Override
+    public ResultResponse deleteAccountAllUser(Long ksId, Long accountId, String role, String userId) {
+        if ("collaborator".equals(role)) {
+            accountPartMapper.deleteByAccountId(ksId, accountId);
+        } else {
+            KuaishouLiveUserAccount account = new KuaishouLiveUserAccount();
+            account.setAccountId(accountId);
+            account.setKsId(ksId);
+            KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account);
+            if ("saleLeader".equals(role)) {
+                one.setSaleLeader("");
+                one.setSaleLeaderId("");
+            }
+            if ("operatorLeader".equals(role)) {
+                one.setOperatorLeader("");
+                one.setOperatorLeaderId("");
+            }
+            if ("designerLeader".equals(role)) {
+                one.setDesignerLeader("");
+                one.setDesignerLeaderId("");
+            }
+            kuaishouLiveUserAccountMapper.updateKuaishouLiveUserAccount(one);
+        }
+        return ResultResponse.success();
+    }
+
 }

+ 28 - 16
ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountMapper.xml

@@ -95,7 +95,7 @@
     </select>
 
 
-    <select id="selectAllListByAccountNames" parameterType="com.ruixuan.live.entity.KuaishouLiveUserAccount"
+    <select id="selectAllListByAccountIds" parameterType="com.ruixuan.live.entity.KuaishouLiveUserAccount"
             resultMap="KuaishouLiveUserAccountResult">
         select id,
         ks_id,
@@ -119,11 +119,11 @@
         GROUP BY ksId ,accountName
         ) t2 ON t2.accountName = t1.account_name AND t2.ksId = t1.ks_id
         <where>
-            <if test="accountNames != null and accountNames.size() > 0">
-                and account_name in
-                <foreach item="name" index="index" collection="accountNames"
+            <if test="accountIds != null and accountIds.size() > 0">
+                and account_id in
+                <foreach item="id" index="index" collection="accountIds"
                          open="(" separator="," close=")">
-                    #{name}
+                    #{id}
                 </foreach>
             </if>
             <if test="ksId != null ">and ks_id = #{ksId}</if>
@@ -176,15 +176,15 @@
         ORDER BY create_time desc
     </select>
 
-    <select id="queryAllListByAccountNames" parameterType="com.ruixuan.live.entity.KuaishouLiveUserAccount"
+    <select id="queryAllListByAccountIds" parameterType="com.ruixuan.live.entity.KuaishouLiveUserAccount"
             resultMap="KuaishouLiveUserAccountResult">
         <include refid="selectKuaishouLiveUserAccountVo"/>
         <where>
-            <if test="accountNames != null and accountNames.size() > 0">
+            <if test="accountIds != null and accountIds.size() > 0">
                 and account_name in
-                <foreach item="name" index="index" collection="accountNames"
+                <foreach item="id" index="index" collection="accountIds"
                          open="(" separator="," close=")">
-                    #{name}
+                    #{id}
                 </foreach>
             </if>
 
@@ -211,29 +211,41 @@
     </select>
 
 
-    <select id="getOne" parameterType="String" resultType="com.ruixuan.live.entity.KuaishouLiveUserAccount">
+    <select id="getOne" parameterType="com.ruixuan.live.entity.KuaishouLiveUserAccount"
+            resultType="com.ruixuan.live.entity.KuaishouLiveUserAccount">
         <include refid="selectKuaishouLiveUserAccountVo"/>
         <where>
             <if test="ksId != null ">and ks_id = #{ksId}</if>
             <if test="accountName != null  and accountName != ''">and account_name=#{accountName}</if>
+            <if test="accountId != null ">and account_id = #{accountId}</if>
+            <if test="accountType != null  and accountType != ''">and account_type= #{accountType}</if>
+            <if test="saleLeaderId != null  and saleLeaderId != ''">and sale_leader_id = #{saleLeaderId}</if>
+            <if test="operatorLeaderId != null  and operatorLeaderId != ''">and operator_leader_id =
+                #{operatorLeaderId}
+            </if>
+            <if test="designerLeaderId != null  and designerLeaderId != ''">and designer_leader_id =
+                #{designerLeaderId}
+            </if>
+            <if test="createrId != null  and createrId != ''">and creater_id = #{createrId}</if>
+            <if test="accountStatus != null  and accountStatus != ''">and account_status = #{accountStatus}</if>
         </where>
         LIMIT 1
     </select>
 
-    <select id="queryAccountNamesByUserId" parameterType="Long" resultType="String">
-        SELECT account_name
+    <select id="queryAccountIdsByUserId" parameterType="Long" resultType="Long">
+        SELECT account_id
         FROM (
-                 SELECT account_name
+                 SELECT account_id
                  FROM `kuaishou_live_user_account`
                  WHERE sale_leader_id = #{userId}
                     OR operator_leader_id = #{userId}
                     OR designer_leader_id = #{userId}
                  UNION ALL
-                 SELECT account_name
+                 SELECT account_id
                  FROM `kuaishou_live_user_account_part`
                  WHERE collaborator_id = #{userId}
              ) t
-        GROUP BY account_name
+        GROUP BY account_id
     </select>
 
     <select id="selectKuaishouLiveUserAccountById" parameterType="String" resultMap="KuaishouLiveUserAccountResult">
@@ -313,7 +325,7 @@
         <trim prefix="SET" suffixOverrides=",">
             <if test="projectId != null">project_id = #{projectId},</if>
             ks_id = #{ksId},
-           ks_name = #{ksName},
+            ks_name = #{ksName},
             account_id = #{accountId},
             account_name = #{accountName},
             account_type = #{accountType},

+ 18 - 1
ruixuan-live/src/main/resources/mapper/live/KuaishouLiveUserAccountPartMapper.xml

@@ -34,7 +34,16 @@
         select collaborator_id as 'userId', collaborator as 'name'
         from kuaishou_live_user_account_part
         where ks_id = #{ksId}
-        and collaborator_id is not null
+          and collaborator_id is not null
+        group by collaborator_id
+    </select>
+
+    <select id="queryAccountCollaborators" parameterType="Long" resultType="com.alibaba.fastjson.JSONObject">
+        select 'collaborator' as 'role', collaborator_id as 'userId', collaborator as 'name'
+        from kuaishou_live_user_account_part
+        where ks_id = #{ksId}
+          and collaborator_id is not null
+          and account_id = #{accountId}
         group by collaborator_id
     </select>
 
@@ -52,6 +61,14 @@
     </delete>
 
 
+    <delete id="deleteByAccountId" parameterType="Long">
+        delete
+        from kuaishou_live_user_account_part
+        where ks_id = #{ksId}
+          AND account_id = #{accountId}
+    </delete>
+
+
     <insert id="replaceBatch">
         replace into kuaishou_live_user_account_part(
         ks_id,