| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 | 
							- package com.ruixuan.live.service.impl;
 
- import com.alibaba.fastjson.JSON;
 
- import com.alibaba.fastjson.JSONArray;
 
- import com.alibaba.fastjson.JSONObject;
 
- import com.ruixuan.common.core.domain.ResultResponse;
 
- import com.ruixuan.common.core.domain.entity.SysUser;
 
- import com.ruixuan.common.utils.Check;
 
- import com.ruixuan.common.utils.PageUtils;
 
- import com.ruixuan.data.utils.LiveDataExcelUtils;
 
- import com.ruixuan.live.entity.KuaishouLiveProject;
 
- import com.ruixuan.live.entity.KuaishouLiveUserAccount;
 
- import com.ruixuan.live.mapper.KuaishouLiveProjectMapper;
 
- import com.ruixuan.live.mapper.KuaishouLiveUserAccountMapper;
 
- import com.ruixuan.live.mapper.KuaishouLiveUserAccountPartMapper;
 
- import com.ruixuan.live.service.IKuaishouLiveUserAccountService;
 
- import com.ruixuan.system.service.ISysRoleService;
 
- import com.ruixuan.system.service.ISysUserService;
 
- import org.springframework.beans.factory.annotation.Autowired;
 
- import org.springframework.stereotype.Service;
 
- import org.springframework.web.multipart.MultipartFile;
 
- import java.util.ArrayList;
 
- import java.util.Arrays;
 
- import java.util.List;
 
- import java.util.UUID;
 
- /**
 
-  * 快手直播账户Service业务层处理
 
-  *
 
-  * @author ruoyi
 
-  * @date 2022-05-31
 
-  */
 
- @Service
 
- public class KuaishouLiveUserAccountServiceImpl implements IKuaishouLiveUserAccountService {
 
-     @Autowired
 
-     private KuaishouLiveUserAccountMapper kuaishouLiveUserAccountMapper;
 
-     @Autowired
 
-     private KuaishouLiveUserAccountPartMapper accountPartMapper;
 
-     @Autowired
 
-     private KuaishouLiveProjectMapper kuaishouLiveProjectMapper;
 
-     @Autowired
 
-     private ISysUserService sysUserService;
 
-     @Autowired
 
-     private ISysRoleService roleService;
 
-     /**
 
-      * 查询快手直播账户
 
-      *
 
-      * @param id 快手直播账户主键
 
-      * @return 快手直播账户
 
-      */
 
-     @Override
 
-     public JSONObject selectKuaishouLiveUserAccountById(String id) {
 
-         KuaishouLiveUserAccount account = kuaishouLiveUserAccountMapper.selectKuaishouLiveUserAccountById(id);
 
-         JSONObject object = JSONObject.parseObject(JSON.toJSONString(account));
 
-         if (object != null) {
 
-             List<JSONObject> parts = accountPartMapper.queryCollaboratorsById(account.getKsId());
 
-             object.put("collaborators", parts);
 
-         }
 
-         return object;
 
-     }
 
-     /**
 
-      * 查询快手直播账户列表
 
-      *
 
-      * @param kuaishouLiveUserAccount 快手直播账户
 
-      * @return 快手直播账户
 
-      */
 
-     @Override
 
-     public List<KuaishouLiveUserAccount> selectKuaishouLiveUserAccountList(KuaishouLiveUserAccount kuaishouLiveUserAccount) {
 
-         List<KuaishouLiveUserAccount> list = new ArrayList<>();
 
-         if (Check.isNull(kuaishouLiveUserAccount.getAccountType())) {
 
-             kuaishouLiveUserAccount.setAccountType("cljn");
 
-         }
 
-         String roleCode = roleService.selectRoleByUserId(kuaishouLiveUserAccount.getUserId());
 
-         if ("admin".equals(roleCode)) {
 
-             PageUtils.startPage();
 
-             list = kuaishouLiveUserAccountMapper.selectKuaishouLiveUserAccountList(kuaishouLiveUserAccount);
 
-         } else {
 
-             List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(kuaishouLiveUserAccount.getUserId());
 
-             if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
 
-                 kuaishouLiveUserAccount.setAccountNames(accountNames);
 
-                 PageUtils.startPage();
 
-                 list = kuaishouLiveUserAccountMapper.selectAllListByAccountNames(kuaishouLiveUserAccount);
 
-             }
 
-         }
 
-         return list;
 
-     }
 
-     @Override
 
-     public List<KuaishouLiveUserAccount> queryAllList(KuaishouLiveUserAccount userAccount) {
 
-         List<KuaishouLiveUserAccount> list = new ArrayList<>();
 
-         String roleCode = roleService.selectRoleByUserId(userAccount.getUserId());
 
-         if ("admin".equals(roleCode)) {
 
-             PageUtils.startPage();
 
-             list = kuaishouLiveUserAccountMapper.queryAllList(userAccount);
 
-         } else {
 
-             List<String> accountNames = kuaishouLiveUserAccountMapper.queryAccountNamesByUserId(userAccount.getUserId());
 
-             if (Check.isNotNull(accountNames) && accountNames.size() > 0) {
 
-                 userAccount.setAccountNames(accountNames);
 
-                 PageUtils.startPage();
 
-                 list = kuaishouLiveUserAccountMapper.queryAllListByAccountNames(userAccount);
 
-             }
 
-         }
 
-         return list;
 
-     }
 
-     /**
 
-      * @param kuaishouLiveUserAccount 快手直播账户
 
-      * @return 结果
 
-      */
 
-     @Override
 
-     public ResultResponse insertKuaishouLiveUserAccount(KuaishouLiveUserAccount account) {
 
-         KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account.getKsId(), account.getAccountName());
 
-         if (one != null) {
 
-             return ResultResponse.error("快手ID:" + account.getKsId() + "下已存在该账户名,请重新命名!");
 
-         }
 
-         String collaboratorList = account.getCollaboratorList();
 
-         if (collaboratorList != null) {
 
-             List<JSONObject> collaborators = JSONArray.parseArray(collaboratorList, JSONObject.class);
 
-             for (JSONObject obj : collaborators) {
 
-                 obj.put("ksId", account.getKsId());
 
-                 obj.put("ksName", account.getKsName());
 
-                 obj.put("accountId", account.getAccountId());
 
-                 obj.put("accountName", account.getAccountName());
 
-                 obj.put("createrId", account.getCreaterId());
 
-             }
 
-             if (Check.isNotNull(collaborators)) {
 
-                 accountPartMapper.replaceBatch(collaborators);
 
-             }
 
-         }
 
-         account.setId(UUID.randomUUID().toString().replace("-", ""));
 
-         account.setProjectId(getAndInsertProject(account.getKsId(), account.getKsName()));
 
-         account.setAccountStatus("审核通过");
 
-         int num = kuaishouLiveUserAccountMapper.insertKuaishouLiveUserAccount(account);
 
-         if (num > 0) {
 
-             return ResultResponse.success();
 
-         }
 
-         return ResultResponse.error("fail");
 
-     }
 
-     private Long getAndInsertProject(Long id, String projectName) {
 
-         KuaishouLiveProject project = kuaishouLiveProjectMapper.getOne(id, projectName);
 
-         if (Check.isNull(project)) {
 
-             KuaishouLiveProject kuaishouLiveProject = new KuaishouLiveProject();
 
-             kuaishouLiveProject.setId(id);
 
-             kuaishouLiveProject.setProjectName(projectName);
 
-             kuaishouLiveProjectMapper.insertKuaishouLiveProject(kuaishouLiveProject);
 
-         }
 
-         return id;
 
-     }
 
-     @Override
 
-     public ResultResponse insertByExcel(MultipartFile file, Long createrId) {
 
-         List<KuaishouLiveUserAccount> accountList = new ArrayList<>();
 
-         try {
 
-             String fileName = file.getOriginalFilename();
 
-             List<JSONObject> list = LiveDataExcelUtils.analysisFile(file, fileName);
 
-             for (JSONObject object : list) {
 
-                 KuaishouLiveUserAccount account = new KuaishouLiveUserAccount(object, createrId);
 
-                 account.setOperatorLeaderId(getUserIdByName(account.getOperatorLeader()));
 
-                 account.setSaleLeaderId(getUserIdByName(account.getSaleLeader()));
 
-                 account.setProjectId(getAndInsertProject(account.getKsId(), account.getProjectName()));
 
-                 insertAccountPart(account);
 
-                 accountList.add(account);
 
-             }
 
-         } catch (Exception e) {
 
-             e.printStackTrace();
 
-             return ResultResponse.error("导入异常");
 
-         }
 
-         if (Check.isNotNull(accountList)) {
 
-             kuaishouLiveUserAccountMapper.replaceBatch(accountList);
 
-         }
 
-         return ResultResponse.success();
 
-     }
 
-     private void insertAccountPart(KuaishouLiveUserAccount account) {
 
-         String collaborators = account.getCollaboratorList();
 
-         if (Check.isNotNull(collaborators)) {
 
-             List<String> users = Arrays.asList(collaborators.split(";"));
 
-             List<JSONObject> list = new ArrayList<>();
 
-             for (String user : users) {
 
-                 JSONObject obj = new JSONObject();
 
-                 obj.put("ksId", account.getKsId());
 
-                 obj.put("ksName", account.getKsName());
 
-                 obj.put("accountId", account.getAccountId());
 
-                 obj.put("accountName", account.getAccountName());
 
-                 obj.put("createrId", account.getCreaterId());
 
-                 String idAndName = user.replace("(", "(").replace(")", ")").trim();
 
-                 String[] split = idAndName.split("(");
 
-                 obj.put("userId", getUserIdByName(split[0]));
 
-                 obj.put("nickName", split[0]);
 
-                 list.add(obj);
 
-             }
 
-             if (Check.isNotNull(collaborators)) {
 
-                 accountPartMapper.replaceBatch(list);
 
-             }
 
-         }
 
-     }
 
-     // 通过人员名字查询人员ID
 
-     private Long getUserIdByName(String name) {
 
-         if (Check.isNull(name)) {
 
-             return null;
 
-         }
 
-         SysUser user = sysUserService.selectUserByNickName(name);
 
-         if (Check.isNotNull(user)) {
 
-             return user.getUserId();
 
-         }
 
-         return null;
 
-     }
 
-     /**
 
-      * 修改快手直播账户
 
-      */
 
-     @Override
 
-     public ResultResponse updateKuaishouLiveUserAccount(KuaishouLiveUserAccount account) {
 
-         KuaishouLiveUserAccount one = kuaishouLiveUserAccountMapper.getOne(account.getKsId(), account.getAccountName());
 
-         if (one == null) {
 
-             return ResultResponse.error("未查询到账户");
 
-         }
 
-         int i = kuaishouLiveUserAccountMapper.updateKuaishouLiveUserAccount(account);
 
-         if (i > 0) {
 
-             String collaboratorList = account.getCollaboratorList();
 
-             if (Check.isNotNull(collaboratorList)) {
 
-                 List<JSONObject> collaborators = JSONArray.parseArray(collaboratorList, JSONObject.class);
 
-                 for (JSONObject obj : collaborators) {
 
-                     obj.put("ksId", account.getKsId());
 
-                     obj.put("ksName", account.getKsName());
 
-                     obj.put("accountId", account.getAccountId());
 
-                     obj.put("accountName", account.getAccountName());
 
-                     obj.put("createrId", account.getCreaterId());
 
-                 }
 
-                 if (Check.isNotNull(collaborators)) {
 
-                     accountPartMapper.deleteKuaishouLiveUserAccountPartById(account.getKsId());
 
-                     accountPartMapper.replaceBatch(collaborators);
 
-                 }
 
-             }
 
-             return ResultResponse.success();
 
-         }
 
-         return ResultResponse.error("fail");
 
-     }
 
-     /**
 
-      * 批量删除快手直播账户
 
-      *
 
-      * @param ids 需要删除的快手直播账户主键
 
-      * @return 结果
 
-      */
 
-     @Override
 
-     public int deleteKuaishouLiveUserAccountByIds(String[] ids) {
 
-         return kuaishouLiveUserAccountMapper.deleteKuaishouLiveUserAccountByIds(ids);
 
-     }
 
-     /**
 
-      * 删除快手直播账户信息
 
-      *
 
-      * @param id 快手直播账户主键
 
-      * @return 结果
 
-      */
 
-     @Override
 
-     public int deleteKuaishouLiveUserAccountById(String id) {
 
-         return kuaishouLiveUserAccountMapper.deleteKuaishouLiveUserAccountById(id);
 
-     }
 
-     @Override
 
-     public List<JSONObject> queryNicknameList() {
 
-         return kuaishouLiveUserAccountMapper.queryNicknameList();
 
-     }
 
-     @Override
 
-     public List<JSONObject> queryAccountListByKsId(Long ksId) {
 
-         return kuaishouLiveUserAccountMapper.queryAccountListByKsId(ksId);
 
-     }
 
-     @Override
 
-     public ResultResponse queryRoles(String type) {
 
-         List<JSONObject> list = sysUserService.queryRoles(type);
 
-         return ResultResponse.success(list);
 
-     }
 
- }
 
 
  |