weaver-hrm-salary/src/com/engine/salary/cmd/datacollection/AddUpSituationPreviewCmd.java

86 lines
2.8 KiB
Java

package com.engine.salary.cmd.datacollection;
import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.salary.entity.datacollection.dto.AddUpSituationDTO;
import com.engine.salary.entity.datacollection.param.AddUpSituationImportParam;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.util.excel.ExcelParseHelper;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.IOUtils;
import weaver.file.ImageFileManager;
import weaver.general.Util;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddUpSituationPreviewCmd extends AbstractCommonCommand<Map<String, Object>> {
protected HttpServletRequest request;
public AddUpSituationPreviewCmd(Map<String, Object> params, User user) {
this.user = user;
this.params = params;
}
@Override
public BizLogContext getLogContext() {
return null;
}
@SneakyThrows
@Override
public Map<String, Object> execute(CommandContext commandContext) {
Map<String, Object> apidatas = new HashMap<String, Object>();
//检验参数
checkImportParam();
//导入参数
AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
InputStream fileInputStream = null;
// try {
fileInputStream = ImageFileManager.getInputStreamById(Integer.valueOf(imageId));
// fileInputStream = new FileInputStream("C:\\Users\\钱涛\\Desktop\\salary\\addUpSituation\\importTemplate.xlsx");
// } catch (FileNotFoundException e) {
// e.printStackTrace();
// }
try {
List<AddUpSituationDTO> excelDates = ExcelParseHelper.parse(fileInputStream, AddUpSituationDTO.class, 0, 1, 21, "template.xlsx");
apidatas.put("preview", excelDates);
} finally {
IOUtils.closeQuietly(fileInputStream);
}
return apidatas;
}
private void checkImportParam() {
AddUpSituationImportParam importParam = (AddUpSituationImportParam) params.get("importParam");
//excel文件id
String imageId = Util.null2String(importParam.getImageId());
//税款所属期
String declareMonthStr = Util.null2String(importParam.getTaxYearMonth());
if (StringUtils.isBlank(imageId)) {
throw new SalaryRunTimeException("文件不存在");
}
if (StringUtils.isBlank(declareMonthStr)) {
throw new SalaryRunTimeException("税款所属期为空");
}
}
}