2369059705@qq.com
2023-07-07 c913a335643619ac7d1943d75ce06f71a31b8185
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
package com.product.base.controller;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
import com.product.base.config.BaseErrorCode;
import com.product.base.config.CmnConst;
import com.product.base.service.MaterialManagerService;
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.module.sys.version.ApiVersion;
import com.product.util.BaseUtil;
 
/**
 *     材料信息
 *     包含接口:材料类型树接口、列表接口、保存接口
 *     不包含接口:详情接口、删除接口,采用通用接口
 * @author 
 *
 */
@RequestMapping("/api/material")
@RestController
public class MaterialManagerController extends AbstractBaseController{
 
    @Autowired
    MaterialManagerService materialManagerService;
    
    /**
     *     获取所有材料信息
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/get-material-type-tree/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String getMaterialTypeTree(HttpServletRequest request, HttpServletResponse response) {
        try {
            //获取参数
            FieldSetEntity fse = null;
            Object bean=request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
            if(bean != null){
                RequestParameterEntity reqp=(RequestParameterEntity)bean;
                fse = reqp.getFormData();
            }
            //判断上传参数是否为空
            if(bean == null || fse == null) {
                return error(BaseErrorCode.SYSTEM_FORM_NODATA.getValue(), BaseErrorCode.SYSTEM_FORM_NODATA.getText());
            }
            //判断表名是否正确
            if(!CmnConst.PRODUCT_PROJECT_BASE_MATERIAL.equals(fse.getTableName())) {
                return error(BaseErrorCode.SYSTEM_TABLE_NODATA.getValue(), BaseErrorCode.SYSTEM_TABLE_NODATA.getText());
            }
            return OK_List(materialManagerService.getMaterialTypeTree());
        } catch (Exception e) {
            return this.error(BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getText()+e.getMessage());
        }
    }
    
    /**
     *     获取所有材料信息
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/list/{version}", method = RequestMethod.POST)
    @ApiVersion(1)
    public String listWarehousrInfo(HttpServletRequest request, HttpServletResponse response) {
        try {
            //获取参数
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_PROJECT_BASE_MATERIAL);;
            
            //判断分页参数是否为空
            if (BaseUtil.strIsNull(fse.getString(CmnConst.CPAGE)) || BaseUtil.strIsNull(fse.getString(CmnConst.PAGESIZE))) {
                return error(BaseErrorCode.SYSTEM_CPAGES_NOT_NULL.getValue(), BaseErrorCode.SYSTEM_CPAGES_NOT_NULL.getText());
            }
            return OK_List(materialManagerService.listMaterialInfo(fse));
        } catch (Exception e) {
            return this.error(BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getText()+e.getMessage());
        }
    }
    
    
    /**
     *     保存材料信息
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/save/{version}",method = RequestMethod.POST)
    @ApiVersion(1)
    public String saveWarehousrInfo(HttpServletRequest request, HttpServletResponse response) {
        try {
            //获取参数
            FieldSetEntity fse = BaseUtil.getFieldSetEntity(request, CmnConst.PRODUCT_PROJECT_BASE_MATERIAL);;
            
            //保存
            boolean succ = materialManagerService.saveMaterialInfo(fse);
            if (succ) {
                return OK();
            }
            return error(BaseErrorCode.PROJECT_BASE_MATERIAL_SAVE_FAIL.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_DELETE_FAIL.getText());
        } catch (Exception e) {
            return this.error(BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getValue(), BaseErrorCode.PROJECT_BASE_MATERIAL_OPERATE_FAIL.getText()+e.getMessage());
        }
    }
}