package com.product.administration.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.administration.config.CmnConst;
import com.product.administration.config.SystemCode;
import com.product.administration.service.ReceiveFileManagerService;
import com.product.common.lang.StringUtils;
import com.product.core.config.CoreConst;
import com.product.core.controller.support.AbstractBaseController;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.RequestParameterEntity;
import com.product.core.exception.BaseException;
import com.product.module.sys.version.ApiVersion;
/**
* 鏀舵枃绠$悊
* @author 86151
*
*/
@RequestMapping("/api/receive-file")
@RestController
public class ReceiveFileManagerController extends AbstractBaseController{
@Autowired
ReceiveFileManagerService receiveFileManagerService;
/**
* 鏀舵枃绠$悊鍒楄〃
* @param response
* @param request
* @return
*/
@RequestMapping(value = "/list-file-info/{version}", method = RequestMethod.POST)
@ApiVersion(1)
public String listFileInfo(HttpServletResponse response,HttpServletRequest request) {
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 this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
}
//鍒ゆ柇琛ㄥ悕鏄惁姝e父
if (!CmnConst.PRODUCT_OA_RECEIVE_FILE.equals(fse.getTableName())) {
return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
}
DataTableEntity dt=receiveFileManagerService.listReceiveFile(fse.getInteger("cpage"),fse.getInteger("pagesize"),fse);
return OK_List(dt);
} catch (BaseException e) {
e.printStackTrace();
return this.error(e.getCode(),e.getMessage());
} catch (Exception e) {
e.printStackTrace();
return this.error(SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getValue(), SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getText()+e.getMessage());
}
}
/**
* 鏀舵枃绠$悊璇︽儏
* @param response
* @param request
* @return
*/
@RequestMapping(value = "/find-file-info/{version}", method = RequestMethod.POST)
@ApiVersion(1)
public String findFileInfo(HttpServletResponse response,HttpServletRequest request) {
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 this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
}
//鍒ゆ柇琛ㄥ悕鏄惁姝e父
if (!CmnConst.PRODUCT_OA_RECEIVE_FILE.equals(fse.getTableName())) {
return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
}
//鍒ゆ柇uuid鏄惁涓虹┖
if (StringUtils.isEmpty(fse.getUUID())) {
return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText());
}
FieldSetEntity fseInfo=receiveFileManagerService.findReceiveFile(fse.getUUID());
return OK_List(fseInfo);
} catch (BaseException e) {
e.printStackTrace();
return this.error(e.getCode(),e.getMessage());
} catch (Exception e) {
e.printStackTrace();
return this.error(SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getValue(), SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getText()+e.getMessage());
}
}
/**
* 鏀舵枃绠$悊鏂板
* @param response
* @param request
* @return
*/
@RequestMapping(value = "/add-file-info/{version}", method = RequestMethod.POST)
@ApiVersion(1)
public String addFileInfo(HttpServletResponse response,HttpServletRequest request) {
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 this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
}
//鍒ゆ柇琛ㄥ悕鏄惁姝e父
if (!CmnConst.PRODUCT_OA_RECEIVE_FILE.equals(fse.getTableName())) {
return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
}
boolean succ=receiveFileManagerService.addReceiveFile(fse);
return succ?OK():error(SystemCode.SYSTEM_DELETE_COOPERATES_FAIL.getValue(), SystemCode.SYSTEM_ADD_COOPERATES_FAIL.getText());
} catch (BaseException e) {
e.printStackTrace();
return this.error(e.getCode(),e.getMessage());
} catch (Exception e) {
e.printStackTrace();
return this.error(SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getValue(), SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getText()+e.getMessage());
}
}
/**
* 鏀舵枃绠$悊淇敼
* @param response
* @param request
* @return
*/
@RequestMapping(value = "/update-file-info/{version}", method = RequestMethod.POST)
@ApiVersion(1)
public String updateFileInfo(HttpServletResponse response,HttpServletRequest request) {
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 this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
}
//鍒ゆ柇琛ㄥ悕鏄惁姝e父
if (!CmnConst.PRODUCT_OA_RECEIVE_FILE.equals(fse.getTableName())) {
return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
}
//鍒ゆ柇uuid鏄惁涓虹┖
if (StringUtils.isEmpty(fse.getUUID())) {
return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText());
}
boolean succ=receiveFileManagerService.updateReceiveFile(fse);
return succ?OK():error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(),SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText());
} catch (BaseException e) {
e.printStackTrace();
return this.error(e.getCode(),e.getMessage());
} catch (Exception e) {
e.printStackTrace();
return this.error(SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getValue(), SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getText()+e.getMessage());
}
}
/**
* 鏀舵枃绠$悊鍒犻櫎
* @param response
* @param request
* @return
*/
@RequestMapping(value = "/delete-file-info/{version}", method = RequestMethod.POST)
@ApiVersion(1)
public String deleteFileInfo(HttpServletResponse response,HttpServletRequest request) {
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 this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
}
//鍒ゆ柇琛ㄥ悕鏄惁姝e父
if (!CmnConst.PRODUCT_OA_RECEIVE_FILE.equals(fse.getTableName())) {
return this.error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
}
//鍒ゆ柇uuid鏄惁涓虹┖
if (StringUtils.isEmpty(fse.getUUID())) {
return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText());
}
boolean succ=receiveFileManagerService.deleteReceiveFile(fse.getUUID());
return succ?OK():error(SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getValue(),SystemCode.SYSTEM_ACQUIRE_PARAM_FAIL.getText());
} catch (BaseException e) {
e.printStackTrace();
return this.error(e.getCode(),e.getMessage());
} catch (Exception e) {
e.printStackTrace();
return this.error(SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getValue(), SystemCode.SYSTEM_EARLY_WARNING_LIST_FAIL.getText()+e.getMessage());
}
}
}