Commit e5a11f16 authored by tangwei's avatar tangwei

Merge branch 'developer' of http://172.16.10.76/moa/amos-boot-biz into developer

parents fd0038b6 b1cc8c37
...@@ -4,4 +4,5 @@ target/ ...@@ -4,4 +4,5 @@ target/
.classpath .classpath
.project .project
/org.eclipse /org.eclipse
.settings .settings
\ No newline at end of file log/
...@@ -62,9 +62,4 @@ public class DutyCarExcelDto implements Serializable { ...@@ -62,9 +62,4 @@ public class DutyCarExcelDto implements Serializable {
@ExcelProperty(value = "车辆名称(车牌)", index = 4) @ExcelProperty(value = "车辆名称(车牌)", index = 4)
@ApiModelProperty(value = "车辆名称") @ApiModelProperty(value = "车辆名称")
private String carName; private String carName;
}
@ExcelIgnore
@ApiModelProperty(value = "值班信息")
private List<DutyPersonShiftDto> dutyShift = new ArrayList<>();
}
...@@ -9,18 +9,9 @@ import java.nio.charset.StandardCharsets; ...@@ -9,18 +9,9 @@ import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.yeejoin.amos.boot.module.common.api.enums.TitleEnum;
import org.apache.poi.hssf.usermodel.DVConstraint;
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.springframework.util.ObjectUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
...@@ -93,21 +84,9 @@ public class ExcelUtil { ...@@ -93,21 +84,9 @@ public class ExcelUtil {
HorizontalCellStyleStrategy horizontalCellStyleStrategy = setMyCellStyle(); HorizontalCellStyleStrategy horizontalCellStyleStrategy = setMyCellStyle();
try { try {
//下拉列表集合 // 组装表头
Map<Integer, String[]> explicitListConstraintMap = new HashMap<>();
List<List<String>> dutyCarTitleList = new ArrayList<>(); List<List<String>> dutyCarTitleList = new ArrayList<>();
//循环获取对应列得下拉列表信息
Field[] declaredFields = model.getDeclaredFields(); Field[] declaredFields = model.getDeclaredFields();
if (flag) {
for (int i = 0; i < declaredFields.length; i++) {
Field field = declaredFields[i];
//解析注解信息
ExplicitConstraint explicitConstraint = field.getAnnotation(ExplicitConstraint.class);
resolveExplicitConstraint(explicitListConstraintMap, explicitConstraint, dataDictionaryMapper);
}
}
// 组装表头
for (int i = 0; i < declaredFields.length; i++) { for (int i = 0; i < declaredFields.length; i++) {
Field field = declaredFields[i]; Field field = declaredFields[i];
ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class); ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
...@@ -120,18 +99,35 @@ public class ExcelUtil { ...@@ -120,18 +99,35 @@ public class ExcelUtil {
int size = dutyCarTitleList.size(); int size = dutyCarTitleList.size();
if (dayByMonth != null) { if (dayByMonth != null) {
for (int i = 0; i < dayByMonth.size(); i++) { for (int i = 0; i < dayByMonth.size(); i++) {
explicitListConstraintMap.put(size + i, dutyNameList);
ArrayList<String> dutyDay = new ArrayList<>(); ArrayList<String> dutyDay = new ArrayList<>();
dutyDay.add(dayByMonth.get(i)); dutyDay.add(dayByMonth.get(i));
dutyCarTitleList.add(dutyDay); dutyCarTitleList.add(dutyDay);
} }
} }
//下拉列表集合
Map<Integer, String[]> explicitListConstraintMap = new HashMap<>();
if (flag) {
// 组装下拉列表
for (int i = 0; i < declaredFields.length; i++) {
Field field = declaredFields[i];
//解析注解信息
ExplicitConstraint explicitConstraint = field.getAnnotation(ExplicitConstraint.class);
resolveExplicitConstraint(explicitListConstraintMap, explicitConstraint, dataDictionaryMapper);
}
if (dayByMonth != null) {
for (int i = 0; i < dayByMonth.size(); i++) {
explicitListConstraintMap.put(size + i, dutyNameList);
}
}
}
EasyExcel.write(getOutputStream(fileName, response, ExcelTypeEnum.XLSX)).head(dutyCarTitleList).excelType(ExcelTypeEnum.XLSX)
ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcel.write(getOutputStream(fileName, response,
ExcelTypeEnum.XLSX)).head(dutyCarTitleList).excelType(ExcelTypeEnum.XLSX)
.sheet(sheetName).registerWriteHandler(new TemplateCellWriteHandlerDate(explicitListConstraintMap)) .sheet(sheetName).registerWriteHandler(new TemplateCellWriteHandlerDate(explicitListConstraintMap))
.registerWriteHandler(new TemplateCellWriteHandler()) .registerWriteHandler(new TemplateCellWriteHandler())
.registerWriteHandler(horizontalCellStyleStrategy) .registerWriteHandler(horizontalCellStyleStrategy);
.doWrite(data); excelWriterSheetBuilder.doWrite(data);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("系统异常!"); throw new RuntimeException("系统异常!");
......
...@@ -12,8 +12,10 @@ import java.util.*; ...@@ -12,8 +12,10 @@ import java.util.*;
*/ */
public class DateUtils { public class DateUtils {
private static final SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy/M/d"); private static final SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
public static final String DATE_PATTERN = "yyyy-MM-dd";
private static final Calendar calendar = Calendar.getInstance(); private static final Calendar calendar = Calendar.getInstance();
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
/** /**
* 获取某月的日期List * 获取某月的日期List
...@@ -78,4 +80,14 @@ public class DateUtils { ...@@ -78,4 +80,14 @@ public class DateUtils {
return 0; return 0;
} }
public static Date getDate(String dateStr) {
try {
Date date = shortSdf.parse(dateStr);
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
} }
\ No newline at end of file
package com.yeejoin.amos.boot.module.jcs.biz.controller; package com.yeejoin.amos.boot.module.jcs.biz.controller;
import java.io.InputStream; import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService; import com.yeejoin.amos.boot.biz.common.feign.AmosFeignService;
import com.yeejoin.amos.boot.biz.common.utils.MenuFrom;
import com.yeejoin.amos.boot.module.common.api.dto.*; import com.yeejoin.amos.boot.module.common.api.dto.*;
import com.yeejoin.amos.boot.module.common.api.entity.*; import com.yeejoin.amos.boot.module.common.api.entity.*;
import com.yeejoin.amos.boot.module.common.api.enums.TitleEnum;
import com.yeejoin.amos.boot.module.common.biz.service.impl.*; import com.yeejoin.amos.boot.module.common.biz.service.impl.*;
import com.yeejoin.amos.boot.module.common.biz.utils.DateUtils; import com.yeejoin.amos.boot.module.common.biz.utils.DateUtils;
import com.yeejoin.amos.boot.module.jcs.api.entity.Aircraft; import com.yeejoin.amos.boot.module.jcs.api.entity.Aircraft;
...@@ -21,14 +24,15 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; ...@@ -21,14 +24,15 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
...@@ -78,6 +82,12 @@ public class ExcelController extends BaseController { ...@@ -78,6 +82,12 @@ public class ExcelController extends BaseController {
DutyShiftServiceImpl dutyShiftService; DutyShiftServiceImpl dutyShiftService;
@Autowired @Autowired
DutyCommonServiceImpl dutyCommonServiceImpl; DutyCommonServiceImpl dutyCommonServiceImpl;
@Autowired
DutyPersonServiceImpl dutyPersonService;
@Autowired
DutyPersonShiftServiceImpl dutyPersonShiftService;
private static final String NOT_DUTY = "休";
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
...@@ -173,7 +183,6 @@ public class ExcelController extends BaseController { ...@@ -173,7 +183,6 @@ public class ExcelController extends BaseController {
excelImportFirefighters(multipartFile); excelImportFirefighters(multipartFile);
break; break;
case ExcelEnums.CLZQ: case ExcelEnums.CLZQ:
excelImportDutyCar(multipartFile); excelImportDutyCar(multipartFile);
break; break;
} }
...@@ -184,6 +193,7 @@ public class ExcelController extends BaseController { ...@@ -184,6 +193,7 @@ public class ExcelController extends BaseController {
} }
private void excelImportDutyCar(MultipartFile multipartFile) throws Exception { private void excelImportDutyCar(MultipartFile multipartFile) throws Exception {
String fileName = multipartFile.getOriginalFilename(); String fileName = multipartFile.getOriginalFilename();
if (fileName == null) { if (fileName == null) {
throw new Exception("文件不存在!"); throw new Exception("文件不存在!");
...@@ -192,8 +202,8 @@ public class ExcelController extends BaseController { ...@@ -192,8 +202,8 @@ public class ExcelController extends BaseController {
throw new Exception("文件类型异常!"); throw new Exception("文件类型异常!");
} }
InputStream input = multipartFile.getInputStream(); InputStream input = multipartFile.getInputStream();
HSSFWorkbook xssfWorkbook = new HSSFWorkbook(input); XSSFWorkbook workbook = new XSSFWorkbook(input);
HSSFSheet sheet = xssfWorkbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
List<Map<String, Object>> dataList = new ArrayList<>(); List<Map<String, Object>> dataList = new ArrayList<>();
if (sheet != null) { if (sheet != null) {
//获取表头月份 //获取表头月份
...@@ -209,7 +219,7 @@ public class ExcelController extends BaseController { ...@@ -209,7 +219,7 @@ public class ExcelController extends BaseController {
dutyCommonServiceImpl.saveImportData(dataList); dutyCommonServiceImpl.saveImportData(dataList);
} }
private void initDutyCarData(HSSFSheet sheet, List<Map<String, Object>> dataList, List<Date> dayByMonth) { private void initDutyCarData(XSSFSheet sheet, List<Map<String, Object>> dataList, List<Date> dayByMonth) {
//遍历行,i = 1,从第二行开始,第一行是表头跳过。 //遍历行,i = 1,从第二行开始,第一行是表头跳过。
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) { for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
DutyCarDto dutyCarDto = new DutyCarDto(); DutyCarDto dutyCarDto = new DutyCarDto();
...@@ -249,6 +259,7 @@ public class ExcelController extends BaseController { ...@@ -249,6 +259,7 @@ public class ExcelController extends BaseController {
String dutyType = cell == null ? "" : cell.toString(); String dutyType = cell == null ? "" : cell.toString();
if (!StringUtils.isEmpty(dutyType)) { if (!StringUtils.isEmpty(dutyType)) {
DutyPersonShiftDto dutyPersonShiftDto = new DutyPersonShiftDto(); DutyPersonShiftDto dutyPersonShiftDto = new DutyPersonShiftDto();
// dutyPersonShiftDto.setDutyDate(DateUtils.getDate(dayByMonth.get(j)));
dutyPersonShiftDto.setDutyDate(dayByMonth.get(j)); dutyPersonShiftDto.setDutyDate(dayByMonth.get(j));
dutyPersonShiftDto.setShiftId(Long.valueOf(dutyType.split("@")[1])); dutyPersonShiftDto.setShiftId(Long.valueOf(dutyType.split("@")[1]));
dutyShift.add(dutyPersonShiftDto); dutyShift.add(dutyPersonShiftDto);
...@@ -493,41 +504,119 @@ public class ExcelController extends BaseController { ...@@ -493,41 +504,119 @@ public class ExcelController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导出值班模板", notes = "导出值班模板") @ApiOperation(value = "导出值班模板", notes = "导出值班模板")
@GetMapping(value = "/duty_car_template/{year}/{month}") @GetMapping(value = "/duty_car_template")
public void dutyCarTemplate(HttpServletResponse response, @PathVariable("year") int year, public void dutyCarTemplate(HttpServletResponse response, @RequestParam("beginDate") String beginDate,
@PathVariable("month") int month, ExcelDto excelDto, @RequestParam("endDate") String endDate, ExcelDto excelDto,
@RequestParam(value = "orgCode", required = false) String orgCode) { @RequestParam("teamIds") String teamIds) {
try { try {
List<Map<String, Object>> contentList = new ArrayList<>(); List<List<Object>> data = initDutyTemplate(teamIds);
// 根据id列表获取队伍下的人
List<DutyCarDto> orgTeam = new ArrayList<>();
if (!orgTeam.isEmpty()) {
AtomicInteger row = new AtomicInteger(1);
orgTeam.forEach(o -> {
Map<String, Object> map = new HashMap<>();
map.put(TitleEnum.NUMBER.getKey(), "" + (row.getAndIncrement()));
map.put(TitleEnum.FIRE_TEAM.getKey(), o.getTeamName());
map.put(TitleEnum.USER_NAME.getKey(), o.getUserName());
map.put(TitleEnum.POST.getKey(), o.getPostTypeName());
contentList.add(map);
});
}
// 获取日期 // 获取日期
List<String> dayByMonth = DateUtils.getDayByMonth(year, month); List<Map<String, Object>> rangeDate = dutyPersonShiftService.getBaseMapper().genRangeDate(beginDate,
// 获取排班类型 endDate);
String[] dutyNameList = getDutyNameList(); List<String> dayByMonth = new ArrayList<>();
ExcelUtil.createDutyTemplate(response, excelDto.getFileName(), excelDto.getSheetName(), contentList, rangeDate.forEach(item -> dayByMonth.add((String) item.get("date")));
DutyCarExcelDto.class, dayByMonth, dutyNameList, dataSourcesImpl, true); exportDutyTemplate(response, excelDto.getClassUrl(), dayByMonth, excelDto, data, true);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常!");
}
}
private List<List<Object>> initDutyTemplate(String teamIds) {
List<List<Object>> data = new ArrayList<>();
// 根据id列表获取队伍下的人
List<String> teamIdList = Lists.newArrayList();
if (!ValidationUtil.isEmpty(teamIds)) {
teamIdList = Lists.newArrayList(teamIds.split(","));
}
List<FirefightersDto> firefightersDtoList = fireTeamService.getFighterByTeamId(teamIdList);
if (!firefightersDtoList.isEmpty()) {
AtomicInteger row = new AtomicInteger(1);
firefightersDtoList.forEach(o -> {
ArrayList<Object> list = new ArrayList<>();
list.add(row.getAndIncrement());
list.add(o.getFireTeamName() + "@" + o.getFireTeamId());
list.add(o.getName() + "@" + o.getSequenceNbr());
list.add(o.getJobTitle() + "@" + o.getJobTitleCode());
data.add(list);
});
}
return data;
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导出值班信息", notes = "导出值班模板")
@GetMapping(value = "/duty_car_info")
public void dutyCarDuty(HttpServletResponse response, @RequestParam("beginDate") String beginDate,
@RequestParam("endDate") String endDate, ExcelDto excelDto) {
try {
// 获取日期
List<Map<String, Object>> rangeDate = dutyPersonShiftService.getBaseMapper().genRangeDate(beginDate,
endDate);
List<String> dayByMonth = new ArrayList<>();
rangeDate.forEach(item -> dayByMonth.add((String) item.get("date")));
List<List<Object>> data = initDutyInfo(beginDate, endDate, dayByMonth);
exportDutyTemplate(response, excelDto.getClassUrl(), dayByMonth, excelDto, data, false);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("系统异常!"); throw new RuntimeException("系统异常!");
} }
} }
private List<List<Object>> initDutyInfo(String beginDate, String endDate, List<String> dayByMonth) throws ParseException {
// 查询已值班数据
List<DutyCarDto> contentList = dutyCarService.downloadList(beginDate, endDate);
List<List<Object>> data = new ArrayList<>();
// 组装导出数据
if (!contentList.isEmpty()) {
AtomicInteger row = new AtomicInteger(1);
contentList.forEach(o -> {
ArrayList<Object> list = new ArrayList<>();
list.add(row.getAndIncrement());
list.add(o.getTeamName());
list.add(o.getUserName());
list.add(o.getPostTypeName());
list.add(o.getCarName());
List<DutyPersonShiftDto> dutyShift = o.getDutyShift();
HashMap<String, String> dutyShiftMap = new HashMap<>();
SimpleDateFormat format = new SimpleDateFormat("%Y-%m-%d");
dutyShift.forEach(item -> dutyShiftMap.put(format.format(item.getDutyDate()), item.getShiftName()));
if (!dutyShift.isEmpty()) {
for (int i = 0; i < dayByMonth.size(); i++) {
if (dutyShiftMap.containsKey(dayByMonth.get(i))) {
list.add(dutyShiftMap.get(dayByMonth.get(i)));
} else {
list.add(NOT_DUTY);
}
}
}
data.add(list);
});
}
return data;
}
private void exportDutyTemplate(HttpServletResponse response, String classUrl, List<String> dayByMonth,
ExcelDto excelDto, List<? extends Object> data, Boolean flag) {
try {
// 获取排班类型
String[] dutyNameList = getDutyNameList();
Class<?> clz = Class.forName(classUrl);
ExcelUtil.createDutyTemplate(response, excelDto.getFileName(), excelDto.getSheetName(), data,
clz, dayByMonth, dutyNameList, dataSourcesImpl, flag);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private String[] getDutyNameList() { private String[] getDutyNameList() {
List<String> dutyShiftList = new ArrayList<>(); List<String> dutyShiftList = new ArrayList<>();
List<DutyShiftDto> dutyShiftDtoList = dutyShiftService.queryForDutyShiftList(null,false); List<DutyShiftDto> dutyShiftDtoList = dutyShiftService.queryForDutyShiftList(null, false);
dutyShiftDtoList.forEach(item -> dutyShiftList.add(item.getName() + "@" + item.getSequenceNbr())); dutyShiftDtoList.forEach(item -> dutyShiftList.add(item.getName() + "@" + item.getSequenceNbr()));
String[] dutyNameList = dutyShiftList.toArray(new String[dutyShiftList.size()]); String[] dutyNameList = dutyShiftList.toArray(new String[dutyShiftList.size()]);
return dutyNameList; return dutyNameList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment