CompanyController.java
5.31 KB
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
package com.huaheng.system.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.core.web.controller.BaseController;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.core.web.page.PageDomain;
import com.huaheng.common.core.web.page.TableDataInfo;
import com.huaheng.common.core.web.page.TableSupport;
import com.huaheng.common.log.annotation.Log;
import com.huaheng.common.log.enums.BusinessType;
import com.huaheng.common.security.annotation.PreAuthorize;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.system.api.domain.Company;
import com.huaheng.system.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.lang.management.PlatformManagedObject;
import java.util.List;
@RestController
@RequestMapping("/company")
@Api(value = "货主", tags = "货主")
public class CompanyController extends BaseController {
@Resource
private CompanyService companyService;
@GetMapping("/companies")
@ApiOperation(value = "根据用户id和仓库编码获取货主")
public List<Company> queryByUserIdAndWare(Long userId, String warehouseCode) {
return companyService.selectCompanyByCurrentUserId(userId, warehouseCode);
}
@GetMapping("/{code}")
@ApiOperation(value = "根据用户id和仓库编码获取货主")
public Company getCompanyByCode(@PathVariable String code) {
LambdaQueryWrapper<Company> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(Company::getCode, code);
return companyService.getOne(queryWrapper);
}
@PreAuthorize(hasPermi = "config:company:list")
@GetMapping("/list")
@ResponseBody
@ApiOperation(value = "获取货主列表")
public TableDataInfo list(Company company, String createdBegin, String createdEnd) {
LambdaQueryWrapper<Company> lambdaQueryWrapper = Wrappers.lambdaQuery();
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
lambdaQueryWrapper.gt(StrUtil.isNotEmpty(createdBegin), Company::getCreated, createdBegin)
.lt(StrUtil.isNotEmpty(createdEnd), Company::getCreated, createdEnd)
.eq(Company::getWarehouseCode, SecurityUtils.getWarehouseCode())
.like(StrUtil.isNotBlank(company.getCode()) && StrUtil.isNotEmpty(company.getCode()), Company::getCode, company.getCode())
.like(StrUtil.isNotBlank(company.getCode()) && StrUtil.isNotEmpty(company.getName()), Company::getName, company.getName())
.eq(Company::getDeleted, false)
.orderByDesc(Company::getId);
if (ObjectUtil.isNotNull(pageNum) && ObjectUtil.isNotNull(pageSize)) {
/**
* 使用分页查询
*/
Page<Company> page = new Page<>(pageNum, pageSize);
IPage<Company> iPage = companyService.page(page, lambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<Company> list = companyService.list(lambdaQueryWrapper);
return getDataTable(list);
}
}
@PreAuthorize(hasAnyPermi = "config:company:add")
@Log(title = "货主管理", businessType = BusinessType.INSERT)
@PostMapping
@ApiOperation(value = "新增货主")
public AjaxResult addSave(Company company) {
if (StrUtil.isEmpty(company.getCode()) && StrUtil.isEmpty(company.getName())) {
return AjaxResult.error("货主编码和名称不能为空!");
}
company.setWarehouseCode(SecurityUtils.getWarehouseCode());
return companyService.addCompany(company);
}
@ApiOperation(value = "修改货主")
@PreAuthorize(hasAnyPermi = "config:company:edit")
@Log(title = "配置-库存资料-货主管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult editSave(Company company) {
return companyService.updateCompany(company);
}
/**
* 删除货主
*/
@PreAuthorize(hasAnyPermi = "config:company:remove")
@Log(title = "配置-库存资料-货主管理", businessType = BusinessType.DELETE)
@DeleteMapping
@ApiOperation(value = "删除货主")
@Transactional(rollbackFor = Exception.class)
public AjaxResult remove(@ApiParam(value = "货主id") @RequestParam String ids) {
if (StrUtil.isEmpty(ids)) {
return AjaxResult.error("id不能为空");
}
for (Integer id : Convert.toIntArray(ids)) {
Company company = new Company();
company.setId(id);
company.setDeleted(true);
companyService.updateById(company);
}
return AjaxResult.success("删除成功!");
}
}