栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

功能实现:客服辖区管理

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

功能实现:客服辖区管理

目录

项目:

业务逻辑:

需求:

具体实现:


#项目:

背景是一个电商+供应链管理,在已有的管理员模块上新增客服辖区管理功能。

#业务逻辑:

有权限的管理员账号可以给具有客服角色的管理员账号(admin,与已有的admin表相关联)分配辖区(或其他属性,待后期扩展,暂时只有辖区),客服只对该辖区的用户有权限进行查询、处理订单等操作。

#需求:

1.设置客服辖区

2.查询客服辖区

3.删除客服辖区(批量)

#具体实现:

主要是实现设置客服辖区这个需求,由于客服辖区一经设置少有改变,此处设计的逻辑比较简单:每次设置辖区时,就把该账号下原有已存在的辖区记录全部删除,再添加新的记录。辖区细分到市,每一个市一条辖区记录(例如,客服A的辖区为福建省福州市和福建省厦门市,数据库里就分别有两条相关的记录)。

查询所有记录时:将所有的data放进list里,再以客服的admin_id分组,

return出去的是的是的嵌套的list(List)。

Map listMap = authorList.stream().collect(Collectors.groupingBy(AdminAuthorDO::getAdminId));

        List groupList= new ArrayList<>();

        for(List list : listMap.values()){

            groupList.add(list);
        }

1.表结构:

CREATE TABLE `es_admin_author` (
  `id` bigint(20) NOT NULL COMMENT 'ID主键',
  `admin_id` bigint(20) DEFAULT NULL COMMENT '管理员id',
  `province_id` bigint(20) DEFAULT NULL COMMENT '省份id',
  `province` varchar(255) DEFAULT NULL COMMENT '省份名称',
  `city_id` bigint(20) DEFAULT NULL COMMENT '城市id',
  `city` varchar(255) DEFAULT NULL COMMENT '城市名称',
  `create_time` datetime DEFAULT NULL COMMENT '生成时间',
  `create_by` varchar(64) DEFAULT NULL COMMENT '创建者',
  `update_by` varchar(64) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='客服授权辖区分配表';

2.api:

package com.enation.app.javashop.api.manager.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.enation.app.javashop.framework.database.WebPage;
import com.enation.app.javashop.framework.exception.ServiceException;
import com.enation.app.javashop.framework.util.oConvertUtils;
import com.enation.app.javashop.model.errorcode.SystemErrorCode;
import com.enation.app.javashop.model.errorcode.TradeErrorCode;
import com.enation.app.javashop.model.system.dos.AdminAuthorDO;

import com.enation.app.javashop.model.system.dto.AdminAuthorEditParam;
import com.enation.app.javashop.model.system.dto.AdminAuthorQueryParam;
import com.enation.app.javashop.service.system.AdminAuthorManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;



@RestController
@RequestMapping("/admin/systems/admin-author")
public class AdminAuthorManagerController {

    @Autowired
    AdminAuthorManager adminAuthorManager;

    
    

    
    @PostMapping("/edit")
    public List edit(@RequestBody AdminAuthorEditParam editParam){

        if (oConvertUtils.isEmpty(editParam.getAdminId())) {
            throw new ServiceException(SystemErrorCode.E908.code(), "缺少需要配置的客服账号的AdminID");
        }
        if(oConvertUtils.listIsEmpty(editParam.getAreaList())){
            throw new ServiceException(SystemErrorCode.E908.code(), "缺少辖区信息");
        }

        List editList = this.adminAuthorManager.edit(editParam);

        return editList;
    }
    
    @PostMapping("/remove")
    public Boolean remove(@RequestBody List idList){

        if(oConvertUtils.listIsNotEmpty(idList)){
            idList.forEach(id->{

                this.adminAuthorManager.remove(id);
            });
        }else {
            throw new ServiceException(SystemErrorCode.E908.code(), "未传入要删除的授权记录主键id");
        }
        return true;
    }

    
    @PostMapping("/query")
    public WebPage> query(@RequestBody AdminAuthorQueryParam param){
        if(oConvertUtils.isEmpty(param.getPageNo())){
            param.setPageNo(1L);
        }

        if(oConvertUtils.isEmpty(param.getPageSize())){
            param.setPageSize(10L);
        }

        WebPage page= this.adminAuthorManager.selectAdminAuthorPage(new Page(param.getPageNo(), param.getPageSize()), param);

        return page;
    }
}

3.service:

package com.enation.app.javashop.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.enation.app.javashop.framework.context.user.AdminUserContext;
import com.enation.app.javashop.framework.database.WebPage;
import com.enation.app.javashop.framework.exception.ServiceException;
import com.enation.app.javashop.framework.security.model.Admin;
import com.enation.app.javashop.framework.util.oConvertUtils;
import com.enation.app.javashop.mapper.system.AdminAuthorMapper;
import com.enation.app.javashop.mapper.system.AdminUserMapper;
import com.enation.app.javashop.model.errorcode.SystemErrorCode;
import com.enation.app.javashop.model.system.dos.AdminAuthorDO;
import com.enation.app.javashop.model.system.dos.AdminUser;
import com.enation.app.javashop.model.system.dto.AdminAuthorEditParam;
import com.enation.app.javashop.model.system.dto.AdminAuthorQueryParam;
import com.enation.app.javashop.model.trade.order.vo.OrderLineVO;
import com.enation.app.javashop.service.system.AdminAuthorManager;
import com.enation.app.javashop.service.system.AdminUserManager;
import com.sun.mail.imap.protocol.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;



@Service
public class AdminAuthorManagerImpl implements AdminAuthorManager {

    @Autowired
    AdminAuthorMapper adminAuthorMapper;

    @Autowired
    AdminUserManager adminUserManager;

    @Override
    public AdminAuthorDO add(AdminAuthorDO param) {

        AdminUser model = adminUserManager.getModel(param.getAdminId());

        if(oConvertUtils.isEmpty(model)){
            throw new ServiceException(SystemErrorCode.E908.code(), "id为"+param.getAdminId()+"的客服Admin账号不存在");
        }

        Admin admin = AdminUserContext.getAdmin();

        param.setUpdateBy(admin.getUsername());
        param.setCreateTime(new Date());
        param.setCreateBy(admin.getUsername());
        param.setUpdateTime(new Date());

        this.adminAuthorMapper.insert(param);
        return param;
    }

    @Override
    public void remove(Long id) {

        this.adminAuthorMapper.deleteById(id);

    }

    @Override
    public WebPage> selectAdminAuthorPage(Page page, AdminAuthorQueryParam paramDTO) {

        QueryWrapper queryWrapper = new QueryWrapper<>();

        if(oConvertUtils.isNotEmpty(paramDTO.getAdminId())){
            queryWrapper.eq("admin_id",paramDTO.getAdminId());
        }

        if(oConvertUtils.isNotEmpty(paramDTO.getProvince())){
            queryWrapper.eq("province",paramDTO.getProvince());
        }

        if(oConvertUtils.isNotEmpty(paramDTO.getUsername())){
            queryWrapper.eq("username",paramDTO.getUsername());
        }

        if(oConvertUtils.isNotEmpty(paramDTO.getRealName())){
            queryWrapper.eq("real_name",paramDTO.getRealName());
        }

        IPage iPage = this.adminAuthorMapper.selectPage(page, queryWrapper);

        List authorList=iPage.getRecords();

        Map listMap = authorList.stream().collect(Collectors.groupingBy(AdminAuthorDO::getAdminId));

        List groupList= new ArrayList<>();

        for(List list : listMap.values()){

            groupList.add(list);
        }


        // 生成新的Page
        WebPage> webPage =
                new WebPage(paramDTO.getPageNo(), iPage.getTotal(), paramDTO.getPageSize(), groupList);

        return webPage;
    }

    @Override
    public AdminAuthorDO getSameOne(AdminAuthorQueryParam param) {

        QueryWrapper queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("admin_id",param.getAdminId());
        queryWrapper.eq("province",param.getProvince());
        queryWrapper.eq("city",param.getCity());

        // TODO: 2022/6/14 后面如果增加品类的限制 这里可能需要修改逻辑 selectOne如果符合条件的不止一个 就会报错
        AdminAuthorDO authorDO = this.adminAuthorMapper.selectOne(queryWrapper);

        return authorDO;
    }

    
    @Override
    public List edit(AdminAuthorEditParam editParam) {

        //先删掉该客服原有的配置
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("admin_id",editParam.getAdminId());
        List authorDOList = this.adminAuthorMapper.selectList(queryWrapper);
        if(oConvertUtils.listIsNotEmpty(authorDOList)){
            authorDOList.forEach(item->{
                this.adminAuthorMapper.deleteById(item.getId());
            });
        }
        //添加新配置
        List list = new ArrayList<>();
        editParam.getAreaList().forEach(item->{
            AdminAuthorDO adminAuthor = new AdminAuthorDO();
            adminAuthor.setAdminId(editParam.getAdminId());
            adminAuthor.setCity(item.getCity());
            adminAuthor.setProvince(item.getProvince());
            adminAuthor.setCityId(item.getCityId());
            adminAuthor.setProvinceId(item.getProvinceId());
            adminAuthor.setRealName(editParam.getRealName());
            adminAuthor.setUsername(editParam.getRealName());

            Admin admin = AdminUserContext.getAdmin();
            adminAuthor.setUpdateBy(admin.getUsername());
            adminAuthor.setCreateTime(new Date());
            adminAuthor.setCreateBy(admin.getUsername());
            adminAuthor.setUpdateTime(new Date());

            this.adminAuthorMapper.insert(adminAuthor);
            list.add(adminAuthor);
        });
        return list;
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/988495.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号