MaterialApi.java
2.47 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
package com.huaheng.api;
import com.huaheng.common.utils.DataUtils;
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.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.mchange.lang.IntegerUtils;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/api/material")
@Api(tags = {"Material"}, description = "物料接口")
public class MaterialApi  extends BaseController {
    @Autowired
    private IMaterialService materialService;
    /**
     * 新增保存物料
     */
    @RequiresPermissions("api:material:add")
    @Log(title = "物料添加", action = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Material material)
    {
        material.setId(null);
        material.setWarehouseId(ShiroUtils.getWarehouseId());
        Map<String, Object> map = materialService.selectFirstMap("id", material);
        material.setWarehouseCode(ShiroUtils.getWarehouseCode());
        material.setCreatedBy(ShiroUtils.getLoginName());
        material.setLastUpdatedBy(ShiroUtils.getLoginName());
        if (map != null && map.size() > 0)
        {
            return AjaxResult.toAjax(materialService.insert(material) > 0);
        }
        else
        {
            material.setId(DataUtils.getInteger(map.get("id")));
            return AjaxResult.toAjax(materialService.updateByModel(material) > 0);
        }
    }
//    /**
//     * 新增保存物料
//     */
//    @RequiresPermissions("api:material:add")
//    @Log(title = "物料添加", action = BusinessType.INSERT)
//    @PostMapping("/add")
//    @ResponseBody
//    public AjaxResult addSave(Material material)
//    {
//        AjaxResult ajaxResult = materialService.addMaterial(material);
//        return ajaxResult;
//    }
}