From 49b34fc604f2983f406ab2db5aa0f2eca4ab0d74 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 15 十月 2025 16:26:52 +0800
Subject: [PATCH] bug修改
---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSalespersonController.java | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 254 insertions(+), 2 deletions(-)
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSalespersonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSalespersonController.java
index e82d97e..6b5a85d 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSalespersonController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSalespersonController.java
@@ -1,8 +1,43 @@
package com.ruoyi.web.controller.api;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.basic.PageInfo;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.WebUtils;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.dto.TCrmSalespersonDTO;
+import com.ruoyi.system.export.TCrmSalespersonExport;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TCrmSalespersonQuery;
+import com.ruoyi.system.query.TErpGoodsQuery;
+import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.system.service.TCrmBranchService;
+import com.ruoyi.system.service.TCrmChangePointsService;
+import com.ruoyi.system.service.TCrmSalespersonService;
+import com.ruoyi.system.vo.TCrmSalespersonVO;
+import com.ruoyi.system.vo.TErpGoodsVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
/**
* <p>
@@ -12,9 +47,226 @@
* @author xiaochen
* @since 2025-08-20
*/
+@Api(tags = "crm业务员管理")
@RestController
@RequestMapping("/t-crm-salesperson")
public class TCrmSalespersonController {
+ private final TCrmSalespersonService crmSalespersonService;
+ private final ISysUserService sysUserService;
+ private final TCrmChangePointsService crmChangePointsService;
+ private final TCrmBranchService crmBranchService;
+ private final TokenService tokenService;
+ @Autowired
+ public TCrmSalespersonController(TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmBranchService crmBranchService, TokenService tokenService) {
+ this.crmSalespersonService = crmSalespersonService;
+ this.sysUserService = sysUserService;
+ this.crmChangePointsService = crmChangePointsService;
+ this.crmBranchService = crmBranchService;
+ this.tokenService = tokenService;
+ }
+
+ /**
+ * 获取crm业务员管理管理列表
+ */
+ @ApiOperation(value = "获取crm业务员管理分页列表")
+ @PostMapping(value = "/pageList")
+ public R<PageInfo<TCrmSalespersonVO>> pageList(@RequestBody TCrmSalespersonQuery query) {
+ Long userId = tokenService.getLoginUser().getUser().getUserId();
+ Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+ if(roleType == 2){
+ // 查询分公司信息
+ TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
+ .eq(TCrmBranch::getUserId, userId)
+ .last("LIMIT 1"));
+ query.setBranchId(crmBranch.getId());
+ }
+ return R.ok(crmSalespersonService.pageList(query));
+ }
+
+ /**
+ * 获取crm业务员管理管理列表
+ */
+ @ApiOperation(value = "获取crm业务员管理列表")
+ @PostMapping(value = "/list")
+ public R<List<TCrmSalesperson>> list() {
+ Long userId = tokenService.getLoginUser().getUser().getUserId();
+ Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+ LambdaQueryWrapper<TCrmSalesperson> wrapper = new LambdaQueryWrapper<>();
+ if(roleType == 2){
+ // 查询分公司信息
+ TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
+ .eq(TCrmBranch::getUserId, userId)
+ .last("LIMIT 1"));
+ wrapper.eq(TCrmSalesperson::getBranchId,crmBranch.getId());
+ }
+ wrapper.eq(TCrmSalesperson::getStatus,1)
+ .orderByDesc(TCrmSalesperson::getCreateTime);
+ return R.ok(crmSalespersonService.list(wrapper));
+ }
+
+ /**
+ * 添加crm业务员管理管理
+ */
+ @Log(title = "crm业务员管理信息-新增crm业务员管理", businessType = BusinessType.INSERT)
+ @ApiOperation(value = "添加crm业务员管理")
+ @PostMapping(value = "/add")
+ public R<Boolean> add(@Validated @RequestBody TCrmSalespersonDTO dto) {
+ return crmSalespersonService.addSalesperson(dto);
+ }
+
+ /**
+ * 修改crm业务员管理
+ */
+ @Log(title = "crm业务员管理信息-修改crm业务员管理", businessType = BusinessType.UPDATE)
+ @ApiOperation(value = "修改crm业务员管理")
+ @PostMapping(value = "/update")
+ public R<Boolean> update(@Validated @RequestBody TCrmSalespersonDTO dto) {
+ return crmSalespersonService.updateSalesperson(dto);
+ }
+
+ /**
+ * 查看crm业务员管理详情
+ */
+ @ApiOperation(value = "查看crm业务员管理详情")
+ @GetMapping(value = "/getDetailById")
+ public R<TCrmSalespersonVO> getDetailById(@RequestParam String id) {
+ TCrmSalesperson crmSalesperson = crmSalespersonService.getById(id);
+ TCrmSalespersonVO crmSalespersonVO = new TCrmSalespersonVO();
+ BeanUtils.copyProperties(crmSalesperson, crmSalespersonVO);
+ // 查询分公司
+ TCrmBranch crmBranch = crmBranchService.getById(crmSalesperson.getBranchId());
+ if (Objects.nonNull(crmBranch)) {
+ crmSalespersonVO.setBranchName(crmBranch.getBranchName());
+ }
+ return R.ok(crmSalespersonVO);
+ }
+
+ /**
+ * 删除crm业务员管理
+ */
+ @Log(title = "crm业务员管理信息-删除crm业务员管理", businessType = BusinessType.DELETE)
+ @ApiOperation(value = "删除crm业务员管理")
+ @DeleteMapping(value = "/deleteById")
+ public R<Boolean> deleteById(@RequestParam String id) {
+ // 删除账号
+ TCrmSalesperson crmBranch = crmSalespersonService.getById(id);
+ sysUserService.deleteUserById(crmBranch.getUserId());
+ return R.ok(crmSalespersonService.removeById(id));
+ }
+
+ /**
+ * 批量删除crm业务员管理
+ */
+ @Log(title = "crm业务员管理信息-删除crm业务员管理", businessType = BusinessType.DELETE)
+ @ApiOperation(value = "批量删除crm业务员管理")
+ @DeleteMapping(value = "/deleteByIds")
+ public R<Boolean> deleteByIds(@RequestBody List<String> ids) {
+ // 删除账号
+ List<TCrmSalesperson> crmBranchList = crmSalespersonService.list(Wrappers.lambdaQuery(TCrmSalesperson.class).in(TCrmSalesperson::getId, ids));
+ List<Long> userIds = crmBranchList.stream().map(TCrmSalesperson::getUserId).collect(Collectors.toList());
+ sysUserService.deleteUserByIds(userIds);
+ return R.ok(crmSalespersonService.removeByIds(ids));
+ }
+
+ /**
+ * 批量删除crm业务员管理
+ */
+ @Log(title = "crm业务员管理信息-业务员管理解冻冻结", businessType = BusinessType.UPDATE)
+ @ApiOperation(value = "业务员管理解冻冻结",notes = "状态 1=使用中 2=冻结")
+ @PutMapping(value = "/thawOrFreeze")
+ public R<Boolean> thawOrFreeze(@RequestParam(value = "id")String id,
+ @RequestParam(value = "status")Integer status) {
+ TCrmSalesperson crmSalesperson = crmSalespersonService.getById(id);
+ crmSalesperson.setStatus(status);
+ crmSalespersonService.updateById(crmSalesperson);
+ // 查询用户
+ SysUser sysUser = sysUserService.selectUserById(crmSalesperson.getUserId());
+ switch (status){
+ case 1:
+ // 解冻
+ sysUser.setStatus("0");
+ sysUserService.updateUser(sysUser);
+ break;
+ case 2:
+ // 冻结
+ sysUser.setStatus("1");
+ sysUserService.updateUser(sysUser);
+ break;
+ }
+ return R.ok();
+ }
+
+ /**
+ * 批量删除crm业务员管理
+ */
+ @Log(title = "crm业务员管理信息-业务员管理修改积分", businessType = BusinessType.DELETE)
+ @ApiOperation(value = "业务员管理修改积分")
+ @PutMapping(value = "/changePoints")
+ public R<Boolean> changePoints(@RequestBody TCrmChangePoints changePoints) {
+ // 查询分公司信息
+ TCrmSalesperson crmSalesperson = crmSalespersonService.getById(changePoints.getBranchSalespersonId());
+ if (Objects.isNull(crmSalesperson)) {
+ return R.fail("未查询到该业务员");
+ }
+ switch (changePoints.getChangeType()){
+ case 1:
+ // 增加积分
+ crmSalesperson.setUserPoints(crmSalesperson.getUserPoints() + changePoints.getChangeValue());
+ break;
+ case 2:
+ // 减少积分
+ if (crmSalesperson.getUserPoints() < changePoints.getChangeValue()) {
+ return R.fail("操作失败,剩余积分数不足");
+ }
+ crmSalesperson.setUserPoints(crmSalesperson.getUserPoints() - changePoints.getChangeValue());
+ break;
+ }
+ crmSalespersonService.updateById(crmSalesperson);
+ changePoints.setUserType(2);
+ crmChangePointsService.save(changePoints);
+ return R.ok();
+ }
+
+ @Log(title = "crm业务员管理信息-crm业务员管理信息导出", businessType = BusinessType.EXPORT)
+ @ApiOperation(value = "crm业务员管理信息导出")
+ @PostMapping("/export")
+ public void listExport(@RequestBody TCrmSalespersonQuery query)
+ {
+ Long userId = tokenService.getLoginUser().getUser().getUserId();
+ Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
+ if(roleType == 2){
+ // 查询分公司信息
+ TCrmBranch crmBranch = crmBranchService.getOne(Wrappers.lambdaQuery(TCrmBranch.class)
+ .eq(TCrmBranch::getUserId, userId)
+ .last("LIMIT 1"));
+ query.setBranchId(crmBranch.getId());
+ }
+ List<TCrmSalespersonExport> crmSalespersonExports = crmSalespersonService.listExport(query);
+ Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmSalespersonExport.class, crmSalespersonExports);
+ HttpServletResponse response = WebUtils.response();
+ assert response != null;
+ response.setContentType("application/vnd.ms-excel");
+ response.setCharacterEncoding("utf-8");
+ ServletOutputStream outputStream = null;
+ try {
+ String fileName = URLEncoder.encode("业务员管理信息.xls", "utf-8");
+ response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+ response.setHeader("Pragma", "no-cache");
+ response.setHeader("Cache-Control", "no-cache");
+ outputStream = response.getOutputStream();
+ workbook.write(outputStream);
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ outputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
}
--
Gitblit v1.7.1