Commit 3122b373 authored by fupeiyang's avatar fupeiyang

值班导入导出

parent ddfa99c0
......@@ -618,4 +618,30 @@ public class DateUtils {
String name = sdf.format(calen.getTime());
return name;
}
/**
* 获取某月的日期List
*
* @param dateStr
* @return
*/
public static List<Date> getDayByMonth(String dateStr) {
List<Date> list = new ArrayList();
Date date = null;
try {
date = shortSdf.parse(dateStr);
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;//月份
int year = calendar.get(Calendar.YEAR);//年份
int day = calendar.getActualMaximum(Calendar.DATE);
for (int i = 1; i <= day; i++) {
String source = year+"-"+month+"-"+i;
list.add(shortSdf.parse(source));
}
} catch (ParseException e) {
e.printStackTrace();
}
return list;
}
}
......@@ -2,6 +2,8 @@ package com.yeejoin.amos.boot.module.common.api.dto;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.yeejoin.amos.boot.module.common.api.excel.ExplicitConstraint;
import com.yeejoin.amos.boot.module.common.api.excel.RoleNameExplicitConstraint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -26,7 +28,7 @@ public class DutyPersonExcelDto implements Serializable {
@ApiModelProperty(value = "序号")
private Integer number;
@ExcelProperty(value = "用户id", index = 1)
@ExcelProperty(value = "用户ID", index = 1)
@ApiModelProperty(value = "用户id")
private String userId;
......@@ -42,12 +44,12 @@ public class DutyPersonExcelDto implements Serializable {
@ApiModelProperty(value = "部门名称")
private String deptName;
@ExcelIgnore
@ApiModelProperty(value = "岗位id")
private String postType;
@ExplicitConstraint(type = "DUTY_POST_TYPE", indexNum = 3, sourceClass = RoleNameExplicitConstraint.class) //动态下拉内容
@ExcelProperty(value = "岗位", index = 3)
@ApiModelProperty(value = "岗位名称")
private String postTypeName;
@ApiModelProperty(value = "值班信息")
private List<DutyPersonShiftDto> dutyShift;
}
......@@ -121,7 +121,6 @@ public class ExcelUtil {
}
}
ExcelWriterSheetBuilder excelWriterSheetBuilder = EasyExcel.write(getOutputStream(fileName, response,
ExcelTypeEnum.XLSX)).head(dutyCarTitleList).excelType(ExcelTypeEnum.XLSX)
.sheet(sheetName).registerWriteHandler(new TemplateCellWriteHandlerDate(explicitListConstraintMap))
......
......@@ -12,4 +12,5 @@ public class ExcelEnums {
public static final String WXXFZ = "WXXFZ";//("WXXFZ","微型消防站")
public static final String XFRY = "XFRY";//("XFRY","消防人员")
public static final String CLZQ = "CLZQ";//("CLZQ","车辆执勤")
public static final String RYZB = "RYZB";//("RYZB","人员值班")
}
package com.yeejoin.amos.boot.module.common.biz.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @title: DateUtils
* @Author fpy
* @Date: 2021/7/8 14:58
* @Version 1.0
*/
public class DateUtils {
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();
public static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
/**
* 获取某月的日期List
*
* @param yearParam
* @param monthParam
* @return
*/
public static List<String> getDayByMonth(int yearParam, int monthParam) {
List list = new ArrayList();
Calendar aCalendar = Calendar.getInstance(Locale.CHINA);
aCalendar.set(yearParam, monthParam - 1, 1);
int year = aCalendar.get(Calendar.YEAR);//年份
int month = aCalendar.get(Calendar.MONTH) + 1;//月份
int day = aCalendar.getActualMaximum(Calendar.DATE);
for (int i = 1; i <= day; i++) {
list.add(year + "/" + month + "/" + i);
}
return list;
}
/**
* 获取某月的日期List
*
* @param dateStr
* @return
*/
public static List<Date> getDayByMonth(String dateStr) {
List list = new ArrayList();
Date date = null;
try {
date = shortSdf.parse(dateStr);
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;//月份
int year = calendar.get(Calendar.YEAR);//年份
int day = calendar.getActualMaximum(Calendar.DATE);
for (int i = 1; i <= day; i++) {
list.add(year + "/" + month + "/" + i);
}
} catch (ParseException e) {
e.printStackTrace();
}
return list;
}
/**
* 日期返回Date类型
*
* @param dateStr
* @return
*/
public static int strToDateShort(String dateStr) {
try {
Date date = shortSdf.parse(dateStr);
calendar.setTime(date);
int month = calendar.get(Calendar.MONTH) + 1;
return month;
} catch (Exception e) {
e.printStackTrace();
}
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
......@@ -8,20 +8,18 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
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.utils.DateUtils;
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.biz.service.IDutyPersonService;
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.jcs.api.entity.Aircraft;
import com.yeejoin.amos.boot.module.jcs.biz.service.impl.EquipmentServiceImpl;
import com.yeejoin.amos.boot.module.jcs.biz.service.impl.FireTeamServiceImpl;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
......@@ -86,6 +84,10 @@ public class ExcelController extends BaseController {
DutyPersonServiceImpl dutyPersonService;
@Autowired
DutyPersonShiftServiceImpl dutyPersonShiftService;
@Autowired
OrgUsrServiceImpl orgUsrService;
@Autowired
IDutyPersonService iDutyPersonService;
private static final String NOT_DUTY = "休";
......@@ -183,8 +185,10 @@ public class ExcelController extends BaseController {
excelImportFirefighters(multipartFile);
break;
case ExcelEnums.CLZQ:
excelImportDutyCar(multipartFile);
excelImportDutyPerson(multipartFile, ExcelEnums.CLZQ);
break;
case ExcelEnums.RYZB:
excelImportDutyPerson(multipartFile, ExcelEnums.RYZB);
}
} catch (Exception e) {
e.printStackTrace();
......@@ -192,7 +196,7 @@ public class ExcelController extends BaseController {
}
}
private void excelImportDutyCar(MultipartFile multipartFile) throws Exception {
private void excelImportDutyPerson(MultipartFile multipartFile, String dutyType) throws Exception {
String fileName = multipartFile.getOriginalFilename();
if (fileName == null) {
......@@ -207,16 +211,59 @@ public class ExcelController extends BaseController {
List<Map<String, Object>> dataList = new ArrayList<>();
if (sheet != null) {
//获取表头月份
String dateStr = "";
Row titleRow = sheet.getRow(0);
Cell monthCell = titleRow.getCell(5);
dateStr = monthCell == null ? "" : monthCell.toString();
String dateStr = monthCell == null ? "" : monthCell.toString();
List<Date> dayByMonth = DateUtils.getDayByMonth(dateStr);
if (ExcelEnums.CLZQ.equals(dutyType)) {
initDutyCarData(sheet, dataList, dayByMonth);
dutyCarService.saveImportData(dataList);
} else if (ExcelEnums.RYZB.equals(dutyType)) {
initDutyPersonData(sheet, dataList, dayByMonth);
dutyPersonService.saveImportData(dataList);
}
}
}
initDutyCarData(sheet, dataList, dayByMonth);
private void initDutyPersonData(XSSFSheet sheet, List<Map<String, Object>> dataList, List<Date> dayByMonth) {
//遍历行,i = 1,从第二行开始,第一行是表头跳过。
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
DutyPersonDto dutyPersonDto = new DutyPersonDto();
//row是一行数据,row.getCell(i),代表拿到这一行,第i列数据
Row row = sheet.getRow(i);
if (row == null) {
continue;
}
Cell cell = row.getCell(1);
if (cell != null) {
dutyPersonDto.setUserId(cell.toString());
}
cell = row.getCell(2);
if (cell != null) {
dutyPersonDto.setUserName(cell.toString());
}
cell = row.getCell(3);
if (cell != null) {
String[] split = cell.toString().split("@");
dutyPersonDto.setPostTypeName(split[0]);
dutyPersonDto.setPostType(split[1]);
}
List<DutyPersonShiftDto> dutyShift = new ArrayList<>();
for (int j = 0; j < dayByMonth.size(); j++) {
cell = row.getCell(4 + j);
String dutyType = cell == null ? "" : cell.toString();
if (!StringUtils.isEmpty(dutyType)) {
DutyPersonShiftDto dutyPersonShiftDto = new DutyPersonShiftDto();
dutyPersonShiftDto.setDutyDate(dayByMonth.get(j));
dutyPersonShiftDto.setShiftId(Long.valueOf(dutyType.split("@")[1]));
dutyShift.add(dutyPersonShiftDto);
}
}
dutyPersonDto.setDutyShift(dutyShift);
Map<String, Object> dutyPersonDtoMap = Bean.BeantoMap(dutyPersonDto);
dataList.add(dutyPersonDtoMap);
}
dutyCommonServiceImpl.saveImportData(dataList);
}
private void initDutyCarData(XSSFSheet sheet, List<Map<String, Object>> dataList, List<Date> dayByMonth) {
......@@ -228,8 +275,7 @@ public class ExcelController extends BaseController {
if (row == null) {
continue;
}
Cell cell = null;
cell = row.getCell(1);
Cell cell = row.getCell(1);
if (cell != null) {
String[] split = cell.toString().split("@");
dutyCarDto.setTeamName(split[0]);
......@@ -255,11 +301,10 @@ public class ExcelController extends BaseController {
}
List<DutyPersonShiftDto> dutyShift = dutyCarDto.getDutyShift();
for (int j = 0; j < dayByMonth.size(); j++) {
cell = row.getCell(4 + j);
cell = row.getCell(5 + j);
String dutyType = cell == null ? "" : cell.toString();
if (!StringUtils.isEmpty(dutyType)) {
DutyPersonShiftDto dutyPersonShiftDto = new DutyPersonShiftDto();
// dutyPersonShiftDto.setDutyDate(DateUtils.getDate(dayByMonth.get(j)));
dutyPersonShiftDto.setDutyDate(dayByMonth.get(j));
dutyPersonShiftDto.setShiftId(Long.valueOf(dutyType.split("@")[1]));
dutyShift.add(dutyPersonShiftDto);
......@@ -504,12 +549,17 @@ public class ExcelController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导出值班模板", notes = "导出值班模板")
@GetMapping(value = "/duty_car_template")
@GetMapping(value = "/duty_template")
public void dutyCarTemplate(HttpServletResponse response, @RequestParam("beginDate") String beginDate,
@RequestParam("endDate") String endDate, ExcelDto excelDto,
@RequestParam("teamIds") String teamIds) {
@RequestParam("ids") String ids) {
try {
List<List<Object>> data = initDutyTemplate(teamIds);
List<List<Object>> data = new ArrayList<>();
if (ExcelEnums.CLZQ.equals(excelDto.getType())) {
data = initDutyCarTemplate(ids);
} else if (ExcelEnums.RYZB.equals(excelDto.getType())) {
data = initDutyPersonTemplate(ids);
}
// 获取日期
List<Map<String, Object>> rangeDate = dutyPersonShiftService.getBaseMapper().genRangeDate(beginDate,
endDate);
......@@ -522,7 +572,40 @@ public class ExcelController extends BaseController {
}
}
private List<List<Object>> initDutyTemplate(String teamIds) {
private List<List<Object>> initDutyPersonTemplate(String ids) {
List<List<Object>> data = new ArrayList<>();
// 根据id列表获取部门下的人
List<Long> idList = Lists.newArrayList();
if (!ValidationUtil.isEmpty(ids)) {
String[] strings = ids.split(",");
Long[] convert = (Long[]) ConvertUtils.convert(strings, Long.class);
idList = Arrays.asList(convert);
}
try {
List<CompanyPerson> companyPeople = orgUsrService.returnCompanyPerson(idList);
if (!companyPeople.isEmpty()) {
AtomicInteger row = new AtomicInteger(1);
companyPeople.forEach(item -> {
List<OrgUsrDto> persons = item.getPersons();
if (persons != null && !persons.isEmpty()) {
persons.forEach(o -> {
ArrayList<Object> list = new ArrayList<>();
list.add(row.getAndIncrement());
list.add(o.getSequenceNbr().toString());
list.add(o.getBizOrgName());
data.add(list);
});
}
});
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常!");
}
return data;
}
private List<List<Object>> initDutyCarTemplate(String teamIds) {
List<List<Object>> data = new ArrayList<>();
// 根据id列表获取队伍下的人
List<String> teamIdList = Lists.newArrayList();
......@@ -547,7 +630,7 @@ public class ExcelController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "导出值班信息", notes = "导出值班模板")
@GetMapping(value = "/duty_car_info")
@GetMapping(value = "/duty_info")
public void dutyCarDuty(HttpServletResponse response, @RequestParam("beginDate") String beginDate,
@RequestParam("endDate") String endDate, ExcelDto excelDto) {
try {
......@@ -556,7 +639,12 @@ public class ExcelController extends BaseController {
endDate);
List<String> dayByMonth = new ArrayList<>();
rangeDate.forEach(item -> dayByMonth.add((String) item.get("date")));
List<List<Object>> data = initDutyInfo(beginDate, endDate, dayByMonth);
List<List<Object>> data = new ArrayList<>();
if (ExcelEnums.CLZQ.equals(excelDto.getType())) {
data = initDutyCarInfo(beginDate, endDate, dayByMonth);
} else if (ExcelEnums.RYZB.equals(excelDto.getType())) {
data = initDutyPersonInfo(beginDate, endDate, dayByMonth);
}
exportDutyTemplate(response, excelDto.getClassUrl(), dayByMonth, excelDto, data, false);
} catch (Exception e) {
......@@ -565,7 +653,42 @@ public class ExcelController extends BaseController {
}
}
private List<List<Object>> initDutyInfo(String beginDate, String endDate, List<String> dayByMonth) throws ParseException {
private List<List<Object>> initDutyPersonInfo(String beginDate, String endDate, List<String> dayByMonth) throws ParseException {
// 查询已值班数据
List<DutyPersonDto> contentList = iDutyPersonService.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.getUserId());
list.add(o.getUserName());
list.add(o.getPostTypeName());
List<DutyPersonShiftDto> dutyShift = o.getDutyShift();
HashMap<String, String> dutyShiftMap = new HashMap<>();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
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 List<List<Object>> initDutyCarInfo(String beginDate, String endDate, List<String> dayByMonth) throws ParseException {
// 查询已值班数据
List<DutyCarDto> contentList = dutyCarService.downloadList(beginDate, endDate);
List<List<Object>> data = new ArrayList<>();
......@@ -583,7 +706,7 @@ public class ExcelController extends BaseController {
List<DutyPersonShiftDto> dutyShift = o.getDutyShift();
HashMap<String, String> dutyShiftMap = new HashMap<>();
SimpleDateFormat format = new SimpleDateFormat("%Y-%m-%d");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
dutyShift.forEach(item -> dutyShiftMap.put(format.format(item.getDutyDate()), item.getShiftName()));
if (!dutyShift.isEmpty()) {
......@@ -618,7 +741,6 @@ public class ExcelController extends BaseController {
List<String> dutyShiftList = new ArrayList<>();
List<DutyShiftDto> dutyShiftDtoList = dutyShiftService.queryForDutyShiftList(null, false);
dutyShiftDtoList.forEach(item -> dutyShiftList.add(item.getName() + "@" + item.getSequenceNbr()));
String[] dutyNameList = dutyShiftList.toArray(new String[dutyShiftList.size()]);
return dutyNameList;
return dutyShiftList.toArray(new String[dutyShiftList.size()]);
}
}
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