From ce531d3bb32f5221b35f9e24d027ef83450ebbc6 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 21 十月 2025 16:58:34 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSupplierController.java |  187 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 185 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSupplierController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSupplierController.java
index ad75acc..6e86aa1 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSupplierController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCrmSupplierController.java
@@ -1,8 +1,38 @@
 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.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.system.dto.TCrmSupplierDTO;
+import com.ruoyi.system.export.TCrmBranchExport;
+import com.ruoyi.system.export.TCrmSupplierExport;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TCrmBranchQuery;
+import com.ruoyi.system.query.TCrmSupplierQuery;
+import com.ruoyi.system.service.*;
+import com.ruoyi.system.vo.TCrmSupplierVO;
+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 +42,162 @@
  * @author xiaochen
  * @since 2025-08-20
  */
+@Api(tags = "crm供应商管理")
 @RestController
 @RequestMapping("/t-crm-supplier")
 public class TCrmSupplierController {
 
+    private final TCrmSupplierService crmSupplierService;
+    private final ISysUserService sysUserService;
+    private final TCrmWarehouseService crmWarehouseService;
+    @Autowired
+    public TCrmSupplierController(TCrmSupplierService crmSupplierService, ISysUserService sysUserService, TCrmWarehouseService crmWarehouseService) {
+        this.crmSupplierService = crmSupplierService;
+        this.sysUserService = sysUserService;
+        this.crmWarehouseService = crmWarehouseService;
+    }
+
+    /**
+     * 获取crm供应商管理管理列表
+     */
+    @ApiOperation(value = "获取crm供应商管理分页列表")
+    @PostMapping(value = "/pageList")
+    public R<PageInfo<TCrmSupplierVO>> pageList(@RequestBody TCrmSupplierQuery query) {
+        return R.ok(crmSupplierService.pageList(query));
+    }
+
+    /**
+     * 获取crm供应商管理管理列表
+     */
+    @ApiOperation(value = "获取crm供应商管理列表")
+    @PostMapping(value = "/list")
+    public R<List<TCrmSupplier>> list() {
+        return R.ok(crmSupplierService.list(Wrappers.lambdaQuery(TCrmSupplier.class)
+                .eq(TCrmSupplier::getStatus,1)
+                .orderByDesc(TCrmSupplier::getCreateTime)));
+    }
+
+    /**
+     * 添加crm供应商管理管理
+     */
+    @Log(title = "crm供应商管理信息-新增crm供应商管理", businessType = BusinessType.INSERT)
+    @ApiOperation(value = "添加crm供应商管理")
+    @PostMapping(value = "/add")
+    public R<Boolean> add(@Validated @RequestBody TCrmSupplierDTO dto) {
+        return crmSupplierService.addSupplier(dto);
+    }
+
+    /**
+     * 修改crm供应商管理
+     */
+    @Log(title = "crm供应商管理信息-修改crm供应商管理", businessType = BusinessType.UPDATE)
+    @ApiOperation(value = "修改crm供应商管理")
+    @PostMapping(value = "/update")
+    public R<Boolean> update(@Validated @RequestBody TCrmSupplierDTO dto) {
+        return crmSupplierService.updateSupplier(dto);
+    }
+
+    /**
+     * 查看crm供应商管理详情
+     */
+    @ApiOperation(value = "查看crm供应商管理详情")
+    @GetMapping(value = "/getDetailById")
+    public R<TCrmSupplierVO> getDetailById(@RequestParam String id) {
+        TCrmSupplier crmSupplier = crmSupplierService.getById(id);
+        TCrmSupplierVO crmSupplierVO = new TCrmSupplierVO();
+        BeanUtils.copyProperties(crmSupplier, crmSupplierVO);
+        // 查询仓库
+        TCrmWarehouse crmWarehouse = crmWarehouseService.getById(crmSupplier.getWarehouseId());
+        if(Objects.nonNull(crmWarehouse)){
+            crmSupplierVO.setWarehouseName(crmWarehouse.getWarehouseName());
+        }
+        return R.ok(crmSupplierVO);
+    }
+
+    /**
+     * 删除crm供应商管理
+     */
+    @Log(title = "crm供应商管理信息-删除crm供应商管理", businessType = BusinessType.DELETE)
+    @ApiOperation(value = "删除crm供应商管理")
+    @DeleteMapping(value = "/deleteById")
+    public R<Boolean> deleteById(@RequestParam String id) {
+        // 删除账号
+        TCrmSupplier crmBranch = crmSupplierService.getById(id);
+        sysUserService.deleteUserById(crmBranch.getUserId());
+        return R.ok(crmSupplierService.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<TCrmSupplier> crmSupplierList = crmSupplierService.list(Wrappers.lambdaQuery(TCrmSupplier.class).in(TCrmSupplier::getId, ids));
+        List<Long> userIds = crmSupplierList.stream().map(TCrmSupplier::getUserId).collect(Collectors.toList());
+        sysUserService.deleteUserByIds(userIds);
+        return R.ok(crmSupplierService.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) {
+        TCrmSupplier crmSupplier = crmSupplierService.getById(id);
+        crmSupplier.setStatus(status);
+        crmSupplierService.updateById(crmSupplier);
+        // 查询用户
+        SysUser sysUser = sysUserService.selectUserById(crmSupplier.getUserId());
+        switch (status){
+            case 1:
+                // 解冻
+                sysUser.setStatus("0");
+                sysUserService.updateUser(sysUser);
+                break;
+            case 2:
+                // 冻结
+                sysUser.setStatus("1");
+                sysUserService.updateUser(sysUser);
+                break;
+        }
+        return R.ok();
+    }
+
+    @Log(title = "crm供应商管理信息-供应商管理导出", businessType = BusinessType.EXPORT)
+    @ApiOperation(value = "供应商管理导出")
+    @PostMapping("/exportList")
+    public void exportList(@RequestBody TCrmSupplierQuery query){
+        List<TCrmSupplierExport> crmSupplierExports = crmSupplierService.exportList(query);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TCrmSupplierExport.class, crmSupplierExports);
+        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