package com.product.module.data.controller;
|
|
import com.alibaba.druid.util.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.core.spring.context.SpringMVCContextHolder;
|
import com.product.module.data.config.CmnCode;
|
import com.product.module.data.config.CmnConst;
|
import com.product.module.data.service.SystemDataExportService;
|
import com.product.module.sys.version.ApiVersion;
|
import com.product.util.BaseUtil;
|
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.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.xml.crypto.Data;
|
|
/**
|
* @Author cheng
|
* @Description 数据导出
|
* @Date 2021/6/10 14:33
|
* @Version 1.0
|
*/
|
@RestController
|
@RequestMapping("/api/data/export")
|
public class SystemDataExportController extends AbstractBaseController {
|
|
|
@Autowired
|
SystemDataExportService systemDataExportService;
|
|
@PostMapping("general-list/{version}")
|
@ApiVersion(1)
|
public String generalListDataExport(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) {
|
SpringMVCContextHolder.getSystemLogger().error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText());
|
return this.error(CmnCode.SYSTEM_FORM_NODATA.getValue(), CmnCode.SYSTEM_FORM_NODATA.getText());
|
}
|
// 判断参数是否正常
|
if (StringUtils.isEmpty(fse.getString(CmnConst.FILE_NAME))) {
|
SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getValue(), CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getText());
|
return this.error(CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getValue(), CmnCode.EXPORT_FILE_NAME_NOT_EMPTY.getText());
|
}
|
if (StringUtils.isEmpty(fse.getString(CmnConst.UPLOAD_API_URL))) {
|
SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getValue(), CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getText());
|
return this.error(CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getValue(), CmnCode.EXPORT_UPLOAD_URL_NOT_EMPTY.getText());
|
}
|
if (BaseUtil.dataTableIsEmpty(fse.getSubDataTable(CmnConst.EXPORT_PARAM))) {
|
SpringMVCContextHolder.getSystemLogger().error(CmnCode.EXPORT_PARAMS_NOT_EMPTY.getValue(), CmnCode.EXPORT_PARAMS_NOT_EMPTY.getText());
|
return this.error(CmnCode.EXPORT_PARAMS_NOT_EMPTY.getValue(), CmnCode.EXPORT_PARAMS_NOT_EMPTY.getText());
|
}
|
systemDataExportService.generalListDataExport(fse.clones());
|
return OK();
|
} catch (BaseException e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return error(e);
|
} catch (Exception e) {
|
e.printStackTrace();
|
SpringMVCContextHolder.getSystemLogger().error(e);
|
return error(CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getValue(), CmnCode.EXPORT_GENERAL_LIST_DATA_IMPORT_FIAL.getText() + e.getMessage());
|
}
|
}
|
|
|
|
}
|