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());
|
}
|
}
|
}
|