| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | 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.system.dto.TCrmSalespersonDTO; |
| | | import com.ruoyi.system.model.TCrmBranch; |
| | | import com.ruoyi.system.model.TCrmChangePoints; |
| | | import com.ruoyi.system.model.TCrmSalesperson; |
| | | import com.ruoyi.system.query.TCrmSalespersonQuery; |
| | | 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 io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | 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 java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @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; |
| | | @Autowired |
| | | public TCrmSalespersonController(TCrmSalespersonService crmSalespersonService, ISysUserService sysUserService, TCrmChangePointsService crmChangePointsService, TCrmBranchService crmBranchService) { |
| | | this.crmSalespersonService = crmSalespersonService; |
| | | this.sysUserService = sysUserService; |
| | | this.crmChangePointsService = crmChangePointsService; |
| | | this.crmBranchService = crmBranchService; |
| | | } |
| | | |
| | | /** |
| | | * 获取crm业务员管理管理列表 |
| | | */ |
| | | @ApiOperation(value = "获取crm业务员管理分页列表") |
| | | @PostMapping(value = "/pageList") |
| | | public R<PageInfo<TCrmSalespersonVO>> pageList(@RequestBody TCrmSalespersonQuery query) { |
| | | return R.ok(crmSalespersonService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 获取crm业务员管理管理列表 |
| | | */ |
| | | @ApiOperation(value = "获取crm业务员管理列表") |
| | | @PostMapping(value = "/list") |
| | | public R<List<TCrmSalesperson>> list() { |
| | | return R.ok(crmSalespersonService.list(Wrappers.lambdaQuery(TCrmSalesperson.class) |
| | | .eq(TCrmSalesperson::getStatus,1) |
| | | .orderByDesc(TCrmSalesperson::getCreateTime))); |
| | | } |
| | | |
| | | /** |
| | | * 添加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(); |
| | | } |
| | | |
| | | } |
| | | |