Blame view

src/main/java/com/huaheng/pc/config/company/controller/CompanyController.java 6.59 KB
1
package com.huaheng.pc.config.company.controller;
2
3
4
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
周鸿 authored
5
import com.huaheng.common.utils.Wrappers;
6
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
7
import com.huaheng.common.exception.service.ServiceException;
8
9
10
11
12
13
14
15
16
17
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
18
19
20
21
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.warehouse.domain.Warehouse;
import com.huaheng.pc.config.warehouse.service.WarehouseService;
22
import org.apache.shiro.authz.annotation.RequiresPermissions;
23
import org.springframework.stereotype.Controller;
24
25
26
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
27
28

import javax.annotation.Resource;
29
import java.util.Date;
30
31
import java.util.List;
import java.util.Map;
32
33

@Controller
34
@RequestMapping("/config/company")
35
public class CompanyController extends BaseController {
36
37
    @Resource
    private CompanyService companyService;
38
39
40
    @Resource
    private WarehouseService warehouseService;
41
    private String prefix = "config/company";
42
43
    @RequiresPermissions("config:company:view")
44
45
46
47
48
49
50
51
    @GetMapping()
    public String company() {
        return prefix + "/company";
    }

    /**
     * 查询货主列表
     */
52
    @RequiresPermissions("config:company:list")
huhai authored
53
    @Log(title = "配置-库存资料-货主管理", operating = "查看货主列表", action = BusinessType.GRANT)
54
55
56
57
58
59
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Company company, String createdBegin, String createdEnd) {
        LambdaQueryWrapper<Company> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
60
        Integer pageSize = pageDomain.getPageSize();
61
62
        lambdaQueryWrapper.gt(StringUtils.isNotEmpty(createdBegin), Company::getCreated, createdBegin)
63
                .lt(StringUtils.isNotEmpty(createdEnd), Company::getCreated, createdEnd)
64
                .eq(Company::getWarehouseCode,ShiroUtils.getWarehouseCode())
65
66
                .like(StringUtils.isNotNull(company.getCode())&&StringUtils.isNotEmpty(company.getCode()), Company::getCode, company.getCode())
                .like(StringUtils.isNotNull(company.getCode())&&StringUtils.isNotEmpty(company.getName()), Company::getName, company.getName())
67
                .eq(Company::getDeleted,false)
68
                .orderByDesc(Company::getId);
69
游杰 authored
70
        if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
71
72
73
74
75
            /**
             * 使用分页查询
             */
            Page<Company> page = new Page<>(pageNum, pageSize);
            IPage<Company> iPage = companyService.page(page, lambdaQueryWrapper);
76
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
77
78
79
80
81
82
83
84
85
86
87
        } else {
            List<Company> list = companyService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 新增货主
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
88
        /*LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQuery();
89
90
91
92
93
        lambdaQueryWrapper.select(Warehouse::getCode,Warehouse::getName,Warehouse::getEnable);
        List<Map<String, Object>> warehouseList = warehouseService.listMaps(lambdaQueryWrapper);
        for (Map<String, Object> item : warehouseList){
            item.put("value",item.get("code").toString());
        }
94
        modelMap.put("warehouseList",warehouseList);*/
95
96
97
98
99
100
        return prefix + "/add";
    }

    /**
     * 新增保存货主
     */
101
    @RequiresPermissions("config:company:add")
huhai authored
102
    @Log(title = "配置-库存资料-货主管理", operating = "新增货主", action = BusinessType.INSERT)
103
104
105
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Company company) {
106
107
108
        if(StringUtils.isEmpty(company.getCode()) && StringUtils.isEmpty(company.getName())){
            return AjaxResult.error("货主编码和名称不能为空!");
        }
109
        company.setWarehouseCode(ShiroUtils.getWarehouseCode());
110
        company.setCreated(new Date());
111
        company.setCreatedBy(ShiroUtils.getLoginName());
112
        company.setLastUpdated(new Date());
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
        company.setLastUpdatedBy(ShiroUtils.getLoginName());
        return companyService.addCompany(company);
    }

    /**
     * 修改货主
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        Company company = companyService.getById(id);
        mmap.put("company", company);
        mmap.put("warehouseList",warehouseService.getWarehouseList(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存货主
     */
131
    @RequiresPermissions("config:company:edit")
huhai authored
132
    @Log(title = "配置-库存资料-货主管理", operating = "修改货主", action = BusinessType.UPDATE)
133
134
135
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Company company) {
136
        company.setLastUpdated(new Date());
137
138
139
140
141
142
143
        company.setLastUpdatedBy(ShiroUtils.getLoginName());
        return companyService.updateCompany(company);
    }

    /**
     * 删除货主
     */
144
    @RequiresPermissions("config:company:remove")
huhai authored
145
    @Log(title = "配置-库存资料-货主管理", operating ="删除货主", action = BusinessType.DELETE)
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
    @PostMapping( "/remove")
    @ResponseBody
    @Transactional
    public AjaxResult remove(String ids) {
        if (StringUtils.isEmpty(ids)){
            return AjaxResult.error("id不能为空");
        }

        for (Integer id : Convert.toIntArray(ids)){
            Company company = new Company();
            company.setId(id);
            company.setDeleted(true);
            company.setLastUpdatedBy(ShiroUtils.getLoginName());
            companyService.updateById(company);
        }
        return AjaxResult.success("删除成功!");
//        List<Integer> idList =  Arrays.asList(Convert.toIntArray(ids));
//        return toAjax(companyService.removeByIds(idList));
    }
165
}