xuhy
昨天 4955cdc73d9beb5733aa2c0a578c14798394fa61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.ruoyi.web.controller.api;
 
 
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.framework.web.service.TokenService;
import com.ruoyi.system.dto.TCrmWarehouseDTO;
import com.ruoyi.system.model.TCrmSupplier;
import com.ruoyi.system.model.TCrmSupplierToWarehouse;
import com.ruoyi.system.model.TCrmWarehouse;
import com.ruoyi.system.query.TCrmWarehouseQuery;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.TCrmSupplierService;
import com.ruoyi.system.service.TCrmSupplierToWarehouseService;
import com.ruoyi.system.service.TCrmWarehouseService;
import com.ruoyi.system.vo.TCrmWarehouseVO;
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.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * crm仓库管理 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-08-20
 */
@Api(tags = "crm仓库管理")
@RestController
@RequestMapping("/t-crm-warehouse")
public class TCrmWarehouseController {
 
    private final TCrmWarehouseService crmWarehouseService;
    private final ISysUserService sysUserService;
    private final TokenService tokenService;
    private final TCrmSupplierToWarehouseService crmSupplierToWarehouseService;
    private final TCrmSupplierService crmSupplierService;
    @Autowired
    public TCrmWarehouseController(TCrmWarehouseService crmWarehouseService, ISysUserService sysUserService, TokenService tokenService, TCrmSupplierToWarehouseService crmSupplierToWarehouseService, TCrmSupplierService crmSupplierService) {
        this.crmWarehouseService = crmWarehouseService;
        this.sysUserService = sysUserService;
        this.tokenService = tokenService;
        this.crmSupplierToWarehouseService = crmSupplierToWarehouseService;
        this.crmSupplierService = crmSupplierService;
    }
 
    /**
     * 获取crm仓库管理管理列表
     */
    @ApiOperation(value = "获取crm仓库管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TCrmWarehouseVO>> pageList(@RequestBody TCrmWarehouseQuery query) {
        return R.ok(crmWarehouseService.pageList(query));
    }
 
    /**
     * 获取crm仓库管理管理列表
     */
    @ApiOperation(value = "获取crm仓库管理列表")
    @PostMapping(value = "/list")
    public R<List<TCrmWarehouse>> list() {
        return R.ok(crmWarehouseService.list(Wrappers.lambdaQuery(TCrmWarehouse.class)
                .eq(TCrmWarehouse::getStatus,1)
                .orderByDesc(TCrmWarehouse::getCreateTime)));
    }
 
    /**
     * 获取crm仓库管理管理列表
     */
    @ApiOperation(value = "获取crm供应商下的仓库管理列表")
    @PostMapping(value = "/listBySupplierId")
    public R<List<TCrmWarehouse>> listBySupplierId() {
        Integer roleType = tokenService.getLoginUser().getUser().getRoleType();
        Long userId = tokenService.getLoginUser().getUserId();
        if(roleType == 4){
            TCrmSupplier crmSupplier = crmSupplierService.getOne(Wrappers.lambdaQuery(TCrmSupplier.class)
                    .eq(TCrmSupplier::getUserId, userId)
                    .last("LIMIT 1"));
            List<TCrmSupplierToWarehouse> list = crmSupplierToWarehouseService.list(Wrappers.lambdaQuery(TCrmSupplierToWarehouse.class)
                    .eq(TCrmSupplierToWarehouse::getSupplierId, crmSupplier.getId()));
            if(CollectionUtils.isEmpty(list)){
                return R.ok();
            }
            List<String> warehouseIds = list.stream().map(TCrmSupplierToWarehouse::getWarehouseId).collect(Collectors.toList());
            List<TCrmWarehouse> crmWarehouseList = crmWarehouseService.list(Wrappers.lambdaQuery(TCrmWarehouse.class)
                    .eq(TCrmWarehouse::getStatus, 1)
                    .in(TCrmWarehouse::getId, warehouseIds)
                    .orderByDesc(TCrmWarehouse::getCreateTime));
            return R.ok(crmWarehouseList);
        }
        return R.ok();
    }
 
    /**
     * 添加crm仓库管理管理
     */
    @Log(title = "crm仓库管理信息-新增crm仓库管理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "添加crm仓库管理")
    @PostMapping(value = "/add")
    public R<Boolean> add(@Validated @RequestBody TCrmWarehouseDTO dto) {
        return crmWarehouseService.addWarehouse(dto);
    }
 
    /**
     * 修改crm仓库管理
     */
    @Log(title = "crm仓库管理信息-修改crm仓库管理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改crm仓库管理")
    @PostMapping(value = "/update")
    public R<Boolean> update(@Validated @RequestBody TCrmWarehouseDTO dto) {
        return crmWarehouseService.updateWarehouse(dto);
    }
 
    /**
     * 查看crm仓库管理详情
     */
    @ApiOperation(value = "查看crm仓库管理详情")
    @GetMapping(value = "/getDetailById")
    public R<TCrmWarehouseVO> getDetailById(@RequestParam String id) {
        TCrmWarehouse crmSupplier = crmWarehouseService.getById(id);
        TCrmWarehouseVO crmSupplierVO = new TCrmWarehouseVO();
        BeanUtils.copyProperties(crmSupplier, crmSupplierVO);
        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) {
        // 删除账号
        TCrmWarehouse crmWarehouse = crmWarehouseService.getById(id);
        sysUserService.deleteUserById(crmWarehouse.getUserId());
        return R.ok(crmWarehouseService.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<TCrmWarehouse> crmWarehouseList = crmWarehouseService.list(Wrappers.lambdaQuery(TCrmWarehouse.class).in(TCrmWarehouse::getId, ids));
        List<Long> userIds = crmWarehouseList.stream().map(TCrmWarehouse::getUserId).collect(Collectors.toList());
        sysUserService.deleteUserByIds(userIds);
        return R.ok(crmWarehouseService.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) {
        TCrmWarehouse crmWarehouse = crmWarehouseService.getById(id);
        crmWarehouse.setStatus(status);
        crmWarehouseService.updateById(crmWarehouse);
        // 查询用户
        SysUser sysUser = sysUserService.selectUserById(crmWarehouse.getUserId());
        switch (status){
            case 1:
                // 解冻
                sysUser.setStatus("0");
                sysUserService.updateUser(sysUser);
                break;
            case 2:
                // 冻结
                sysUser.setStatus("1");
                sysUserService.updateUser(sysUser);
                break;
        }
        return R.ok();
    }
    
}