This commit is contained in:
moxiangrong
2024-02-23 18:43:03 +08:00
parent 62684f1a2a
commit d6b833e181
8 changed files with 73 additions and 13 deletions

View File

@ -0,0 +1,6 @@
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2504, '客服管理', '', 2, 4, 2000, 'customerService', 'ep:avatar', 'product/customerService/index', '', 0, b'1', b'1', b'1', '1', '2024-02-23 17:30:08', '1', '2024-02-23 17:52:21', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2505, '新增客服', 'product:customerService:create', 3, 1, 2504, '', '', '', '', 0, b'1', b'1', b'1', '1', '2024-02-23 17:30:38', '1', '2024-02-23 17:31:34', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2506, '编辑客服', 'product:customerService:update', 3, 2, 2504, '', '', '', '', 0, b'1', b'1', b'1', '1', '2024-02-23 17:31:01', '1', '2024-02-23 17:31:01', b'0');
INSERT INTO `system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2507, '删除客服', 'product:customerService:delete', 3, 3, 2504, '', '', '', '', 0, b'1', b'1', b'1', '1', '2024-02-23 17:31:21', '1', '2024-02-23 17:31:21', b'0');
alter table yshop_customer_service add column avatar_url varchar(255) comment '客服头像url';

View File

@ -1,11 +1,12 @@
package co.yixiang.yshop.module.mp.controller.admin.customerservice; package co.yixiang.yshop.module.mp.controller.admin.customerservice;
import cn.hutool.core.io.FileTypeUtil;
import cn.hutool.core.io.FileUtil;
import co.yixiang.yshop.framework.common.pojo.CommonResult; import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageParam; import co.yixiang.yshop.framework.common.pojo.PageParam;
import co.yixiang.yshop.framework.common.pojo.PageResult; import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.AddServicerDTO; import co.yixiang.yshop.module.infra.api.file.FileApi;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.CustomerServiceVO; import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.*;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.ServicerVO;
import co.yixiang.yshop.module.mp.framework.cp.config.WxCpConfiguration; import co.yixiang.yshop.module.mp.framework.cp.config.WxCpConfiguration;
import co.yixiang.yshop.module.mp.service.customerservice.CustomerServiceService; import co.yixiang.yshop.module.mp.service.customerservice.CustomerServiceService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -21,12 +22,15 @@ import me.chanjar.weixin.cp.api.WxCpMediaService;
import me.chanjar.weixin.cp.api.WxCpUserService; import me.chanjar.weixin.cp.api.WxCpUserService;
import me.chanjar.weixin.cp.bean.WxCpDepart; import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUser;
import me.chanjar.weixin.cp.bean.kf.*; import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
import me.chanjar.weixin.cp.bean.kf.WxCpKfServicerListResp;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -42,6 +46,8 @@ import java.util.stream.Collectors;
public class CustomerServiceController { public class CustomerServiceController {
@Resource @Resource
private CustomerServiceService customerServiceService; private CustomerServiceService customerServiceService;
@Resource
private FileApi fileApi;
@SneakyThrows @SneakyThrows
@GetMapping("page") @GetMapping("page")
@ -54,7 +60,7 @@ public class CustomerServiceController {
@SneakyThrows @SneakyThrows
@PostMapping @PostMapping
@Operation(summary = "新增客服") @Operation(summary = "新增客服")
public CommonResult<WxCpKfAccountAddResp> save(@RequestBody WxCpKfAccountAdd add) { public CommonResult<WxCpKfAccountAddResp> save(@RequestBody WxCpKfAccountAddDTO add) {
WxCpKfAccountAddResp wxCpKfAccountAddResp = customerServiceService.save(add); WxCpKfAccountAddResp wxCpKfAccountAddResp = customerServiceService.save(add);
return CommonResult.success(wxCpKfAccountAddResp); return CommonResult.success(wxCpKfAccountAddResp);
} }
@ -62,7 +68,7 @@ public class CustomerServiceController {
@SneakyThrows @SneakyThrows
@PutMapping @PutMapping
@Operation(summary = "编辑客服") @Operation(summary = "编辑客服")
public CommonResult<Boolean> update(@RequestBody WxCpKfAccountUpd upd) { public CommonResult<Boolean> update(@RequestBody WxCpKfAccountUpdDTO upd) {
customerServiceService.update(upd); customerServiceService.update(upd);
return CommonResult.success(true); return CommonResult.success(true);
} }
@ -142,7 +148,16 @@ public class CustomerServiceController {
public CommonResult<WxMediaUploadResult> uploadMaterial(@RequestParam(value = "file") MultipartFile file) { public CommonResult<WxMediaUploadResult> uploadMaterial(@RequestParam(value = "file") MultipartFile file) {
WxCpMediaService mediaService = WxCpConfiguration.getCpService().getMediaService(); WxCpMediaService mediaService = WxCpConfiguration.getCpService().getMediaService();
WxMediaUploadResult upload = mediaService.upload(WxConsts.MediaFileType.IMAGE, file.getOriginalFilename(), file.getInputStream()); WxMediaUploadResult upload = mediaService.upload(WxConsts.MediaFileType.IMAGE, file.getOriginalFilename(), file.getInputStream());
//获取url
File download = mediaService.download(upload.getMediaId());
String url = uploadFile(upload.getMediaId(), download);
upload.setUrl(url);
return CommonResult.success(upload); return CommonResult.success(upload);
} }
private String uploadFile(String mediaId, File file) {
String path = mediaId + "." + FileTypeUtil.getType(file);
return fileApi.createFile(path, FileUtil.readBytes(file));
}
} }

View File

@ -18,6 +18,9 @@ public class CustomerServiceVO {
@Schema(description = "客服头像") @Schema(description = "客服头像")
private String avatar; private String avatar;
@Schema(description = "客服头像")
private String avatarUrl;
@Schema(description = "客服地址") @Schema(description = "客服地址")
private String accountLink; private String accountLink;
} }

View File

@ -0,0 +1,13 @@
package co.yixiang.yshop.module.mp.controller.admin.customerservice.vo;
import lombok.Data;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
/**
* @author pepis
* @apiNote
**/
@Data
public class WxCpKfAccountAddDTO extends WxCpKfAccountAdd {
private String avatarUrl;
}

View File

@ -0,0 +1,13 @@
package co.yixiang.yshop.module.mp.controller.admin.customerservice.vo;
import lombok.Data;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
/**
* @author pepis
* @apiNote
**/
@Data
public class WxCpKfAccountUpdDTO extends WxCpKfAccountUpd {
private String avatarUrl;
}

View File

@ -45,4 +45,9 @@ public class CustomerServiceDO extends BaseDO {
* 客服头像 * 客服头像
*/ */
private String avatar; private String avatar;
/**
* 客服头像url
*/
private String avatarUrl;
} }

View File

@ -3,11 +3,11 @@ package co.yixiang.yshop.module.mp.service.customerservice;
import co.yixiang.yshop.framework.common.pojo.PageParam; import co.yixiang.yshop.framework.common.pojo.PageParam;
import co.yixiang.yshop.framework.common.pojo.PageResult; import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.CustomerServiceVO; import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.CustomerServiceVO;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.WxCpKfAccountAddDTO;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.WxCpKfAccountUpdDTO;
import co.yixiang.yshop.module.mp.dal.dataobject.customerservice.CustomerServiceDO; import co.yixiang.yshop.module.mp.dal.dataobject.customerservice.CustomerServiceDO;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAdd;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp; import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountAddResp;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel; import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountDel;
import me.chanjar.weixin.cp.bean.kf.WxCpKfAccountUpd;
import java.util.List; import java.util.List;
@ -18,9 +18,9 @@ import java.util.List;
public interface CustomerServiceService { public interface CustomerServiceService {
PageResult<CustomerServiceVO> page(PageParam pageParam); PageResult<CustomerServiceVO> page(PageParam pageParam);
WxCpKfAccountAddResp save(WxCpKfAccountAdd add); WxCpKfAccountAddResp save(WxCpKfAccountAddDTO add);
void update(WxCpKfAccountUpd upd); void update(WxCpKfAccountUpdDTO upd);
void delete(WxCpKfAccountDel del); void delete(WxCpKfAccountDel del);

View File

@ -3,6 +3,8 @@ package co.yixiang.yshop.module.mp.service.customerservice;
import co.yixiang.yshop.framework.common.pojo.PageParam; import co.yixiang.yshop.framework.common.pojo.PageParam;
import co.yixiang.yshop.framework.common.pojo.PageResult; import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.CustomerServiceVO; import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.CustomerServiceVO;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.WxCpKfAccountAddDTO;
import co.yixiang.yshop.module.mp.controller.admin.customerservice.vo.WxCpKfAccountUpdDTO;
import co.yixiang.yshop.module.mp.dal.dataobject.customerservice.CustomerServiceDO; import co.yixiang.yshop.module.mp.dal.dataobject.customerservice.CustomerServiceDO;
import co.yixiang.yshop.module.mp.dal.mysql.customerservice.CustomerServiceMapper; import co.yixiang.yshop.module.mp.dal.mysql.customerservice.CustomerServiceMapper;
import co.yixiang.yshop.module.mp.framework.cp.config.WxCpConfiguration; import co.yixiang.yshop.module.mp.framework.cp.config.WxCpConfiguration;
@ -33,12 +35,13 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
public PageResult<CustomerServiceVO> page(PageParam pageParam) { public PageResult<CustomerServiceVO> page(PageParam pageParam) {
WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService(); WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService();
//客服列表 //客服列表
PageResult<CustomerServiceDO> page = mapper.selectPage(pageParam, Wrappers.emptyWrapper()); PageResult<CustomerServiceDO> page = mapper.selectPage(pageParam, Wrappers.<CustomerServiceDO>lambdaQuery().orderByDesc(CustomerServiceDO::getId));
List<CustomerServiceVO> collect = page.getList().stream().map(item -> { List<CustomerServiceVO> collect = page.getList().stream().map(item -> {
CustomerServiceVO customerServiceVO = new CustomerServiceVO(); CustomerServiceVO customerServiceVO = new CustomerServiceVO();
customerServiceVO.setName(item.getName()); customerServiceVO.setName(item.getName());
customerServiceVO.setAvatar(item.getAvatar()); customerServiceVO.setAvatar(item.getAvatar());
customerServiceVO.setOpenKfid(item.getOpenKfid()); customerServiceVO.setOpenKfid(item.getOpenKfid());
customerServiceVO.setAvatarUrl(item.getAvatarUrl());
//客服链接 //客服链接
WxCpKfAccountLink link = new WxCpKfAccountLink(); WxCpKfAccountLink link = new WxCpKfAccountLink();
link.setOpenKfid(item.getOpenKfid()); link.setOpenKfid(item.getOpenKfid());
@ -60,26 +63,28 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
@Override @Override
@SneakyThrows @SneakyThrows
public WxCpKfAccountAddResp save(WxCpKfAccountAdd add) { public WxCpKfAccountAddResp save(WxCpKfAccountAddDTO add) {
WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService(); WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService();
WxCpKfAccountAddResp wxCpKfAccountAddResp = kfService.addAccount(add); WxCpKfAccountAddResp wxCpKfAccountAddResp = kfService.addAccount(add);
CustomerServiceDO customerServiceDO = new CustomerServiceDO(); CustomerServiceDO customerServiceDO = new CustomerServiceDO();
customerServiceDO.setName(add.getName()); customerServiceDO.setName(add.getName());
customerServiceDO.setAvatar(add.getMediaId()); customerServiceDO.setAvatar(add.getMediaId());
customerServiceDO.setOpenKfid(wxCpKfAccountAddResp.getOpenKfid()); customerServiceDO.setOpenKfid(wxCpKfAccountAddResp.getOpenKfid());
customerServiceDO.setAvatarUrl(add.getAvatarUrl());
mapper.insert(customerServiceDO); mapper.insert(customerServiceDO);
return wxCpKfAccountAddResp; return wxCpKfAccountAddResp;
} }
@SneakyThrows @SneakyThrows
@Override @Override
public void update(WxCpKfAccountUpd upd) { public void update(WxCpKfAccountUpdDTO upd) {
WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService(); WxCpKfService kfService = WxCpConfiguration.getCpService().getKfService();
WxCpBaseResp resp = kfService.updAccount(upd); WxCpBaseResp resp = kfService.updAccount(upd);
CustomerServiceDO customerServiceDO = new CustomerServiceDO(); CustomerServiceDO customerServiceDO = new CustomerServiceDO();
customerServiceDO.setName(upd.getName()); customerServiceDO.setName(upd.getName());
customerServiceDO.setAvatar(upd.getMediaId()); customerServiceDO.setAvatar(upd.getMediaId());
customerServiceDO.setOpenKfid(upd.getOpenKfid()); customerServiceDO.setOpenKfid(upd.getOpenKfid());
customerServiceDO.setAvatarUrl(upd.getAvatarUrl());
mapper.update(customerServiceDO, Wrappers.<CustomerServiceDO>lambdaUpdate().eq(CustomerServiceDO::getOpenKfid, upd.getOpenKfid())); mapper.update(customerServiceDO, Wrappers.<CustomerServiceDO>lambdaUpdate().eq(CustomerServiceDO::getOpenKfid, upd.getOpenKfid()));
} }