提交 2a7385ec authored 作者: 133's avatar 133

[导出装备信息、用户模块] 代码提交修改

上级 343769f7
......@@ -7,12 +7,16 @@ import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.tykj.dev.config.swagger.AutoDocument;
import com.tykj.dev.device.excel.entity.TrainExcel;
import com.tykj.dev.device.excel.entity.TrainUserExcel;
import com.tykj.dev.device.excel.entity.UserExcel;
import com.tykj.dev.device.excel.utils.ExcelStyleUtil;
import com.tykj.dev.device.excel.utils.ExcelUtil;
import com.tykj.dev.device.library.repository.DeviceLibraryDao;
import com.tykj.dev.device.library.service.DeviceLibraryService;
import com.tykj.dev.device.library.subject.domin.DeviceLibrary;
import com.tykj.dev.device.library.subject.vo.DeviceExcel;
import com.tykj.dev.device.library.subject.vo.DeviceExcelVo;
import com.tykj.dev.misc.utils.MapperUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -21,14 +25,13 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
......@@ -51,14 +54,14 @@ public class ExeclController {
/**
* 保存报废草稿
*/
@GetMapping(value ="/test")
@GetMapping(value = "/test")
@ApiOperation(value = "下载培训excel", notes = "下载培训excel")
public ResponseEntity saveDeviceDestroyBill(HttpServletRequest request, HttpServletResponse response){
List<DeviceExcel> excelList=deviceLibraryDao.findAll().stream()
.filter(deviceLibrary -> deviceLibrary.getLifeStatus()==12&& "浙江省委机要局".equals(deviceLibrary.getOwnUnit()))
.map(DeviceLibrary::parseExcel)
.sorted(Comparator.comparing(DeviceExcel::getSeqNumber,Comparator.nullsLast(String::compareTo)).thenComparing(DeviceExcel::getName))
.collect(Collectors.toList());
public ResponseEntity saveDeviceDestroyBill(HttpServletRequest request, HttpServletResponse response) {
// List<DeviceExcel> excelList=deviceLibraryDao.findAll().stream()
// .filter(deviceLibrary -> deviceLibrary.getLifeStatus()==12&& "浙江省委机要局".equals(deviceLibrary.getOwnUnit()))
// .map(DeviceLibrary::parseExcel)
// .sorted(Comparator.comparing(DeviceExcel::getSeqNumber,Comparator.nullsLast(String::compareTo)).thenComparing(DeviceExcel::getName))
// .collect(Collectors.toList());
// Map<String,List<DeviceExcel>> map = excelList.stream().collect(groupingBy(DeviceExcel::getSeqNumber));
// List<DeviceExcel> deviceExcels= new ArrayList<>();
// for (String s : map.keySet()){
......@@ -77,30 +80,30 @@ public class ExeclController {
// .sorted(Comparator.comparing(DeviceExcel::getSeqNumber,Comparator.nullsLast(String::compareTo)).thenComparing(DeviceExcel::getName))
// .collect(Collectors.toList());
ExportParams exportParams = new ExportParams("xxx","xxx", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcel.class, excelList);
ExcelUtil.downloadExcel(request, response, workbook, "xxx");
// List<TrainUserExcel> tableInfoVos = new ArrayList<>();
// for (int i=0;i<6;i++){
// TrainUserExcel trainUserExcel=new TrainUserExcel();
// trainUserExcel.setIdCard("123123123131");
// trainUserExcel.setMobel("15171636570");
// trainUserExcel.setName("占金明");
// trainUserExcel.setSex("男");
// trainUserExcel.setNumber(i);
// tableInfoVos.add(trainUserExcel);
// }
// ExportParams exportParams = new ExportParams("xxx","xxx", ExcelType.XSSF);
// exportParams.setStyle(ExcelStyleUtil.class);
// Workbook workbook = ExcelExportUtil.exportExcel(exportParams, TrainUserExcel.class, tableInfoVos);
// Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcel.class, excelList);
// ExcelUtil.downloadExcel(request, response, workbook, "xxx");
List<UserExcel> tableInfoVos = new ArrayList<>();
for (int i = 0; i < 6; i++) {
UserExcel trainUserExcel = new UserExcel();
trainUserExcel.setArea("123123123131");
trainUserExcel.setUnit("15171636570");
trainUserExcel.setName("占金明");
trainUserExcel.setDes("男");
tableInfoVos.add(trainUserExcel);
}
ExportParams exportParams = new ExportParams("xxx", "xxx", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, UserExcel.class, tableInfoVos);
ExcelUtil.downloadExcel(request, response, workbook, "xxx");
return ResponseEntity.ok("ok");
}
@PostMapping(value ="/test1")
@PostMapping(value = "/test1")
@ApiOperation(value = "导入excel", notes = "下载培训excel")
public ResponseEntity importExcel(MultipartFile file) throws Exception {
ImportParams params = new ImportParams();
......@@ -118,14 +121,30 @@ public class ExeclController {
ExcelImportResult<DeviceExcel> result = ExcelImportUtil.importExcelMore(file.getInputStream(), DeviceExcel.class,
params);
List<DeviceExcel> deviceExcels= result.getList();
Map<Integer,DeviceLibrary> deviceLibraryMap = deviceLibraryService.getAllDeviceMap();
for (DeviceExcel d:deviceExcels){
List<DeviceExcel> deviceExcels = result.getList();
Map<Integer, DeviceLibrary> deviceLibraryMap = deviceLibraryService.getAllDeviceMap();
for (DeviceExcel d : deviceExcels) {
DeviceLibrary deviceLibrary = deviceLibraryMap.get(d.getId());
MapperUtils.copyNoNullProperties(d,deviceLibrary);
MapperUtils.copyNoNullProperties(d, deviceLibrary);
deviceLibraryService.update(deviceLibrary);
}
return ResponseEntity.ok(deviceExcels.size());
}
//根据装备id导出对应的表格
@PostMapping("/device")
@ApiOperation(value = "根据id导出对应的excel数据")
public ResponseEntity exportExcel(
@RequestBody List<Integer> ids,
HttpServletRequest request,
HttpServletResponse response) {
List<DeviceExcelVo> deviceExcelVos = deviceLibraryService.getAllDevByDevIds(ids).stream().map(DeviceLibrary::toDeviceExcelVo).collect(Collectors.toList());
ExportParams exportParams = new ExportParams("设备数量列表", "设备数量列表", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcelVo.class, deviceExcelVos);
ExcelUtil.downloadExcel(request, response, workbook, "xxx");
return ResponseEntity.ok("导出成功");
}
}
......@@ -20,6 +20,9 @@ import java.util.List;
@NoArgsConstructor
public class TrainExcel {
@Excel(name = "单位名称", orderNum = "1", width = 30, needMerge = true)
private String mark;
@ExcelCollection(name = "参加培训用户信息", orderNum = "2")
private List<TrainUserExcel> trainUserExcels;
}
package com.tykj.dev.device.excel.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author zjm
* @version 1.0.0
* @ClassName TrainExcel.java
* @Description excel导出实体类
* @createTime 2021年04月29日 15:22:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserExcel {
@Excel(name = "区域名称", orderNum = "1", width = 30, needMerge = true)
private String area;
@Excel(name = "单位名称", orderNum = "2", width = 30, needMerge = true)
private String unit;
@Excel(name = "姓名", orderNum = "3", width = 30, needMerge = true)
private String name;
@Excel(name = "账号", orderNum = "4", width = 30, needMerge = true)
private String des;
}
......@@ -126,5 +126,4 @@ public class UnitsController {
return ResponseEntity.ok(unitsService.findDirectlyUnder());
}
}
......@@ -33,4 +33,6 @@ public interface UserDao extends JpaRepository<User, Integer>, JpaSpecificationE
User findByName(String name);
User findByNameAndUnitsId(String name,Integer unitsId);
}
......@@ -352,7 +352,7 @@ public class UnitsServiceImpl implements UnitsService {
Optional<Area> optionalArea = areaDao.findById(units.getAreaId());
if (optionalArea.isPresent()) {
units.setLevel(optionalArea.get().getType());
units.setType(1);
// units.setType(1);
} else {
throw new ApiException(ResponseEntity.ok("[单位] 没找到对应的区域,请检查"));
}
......
......@@ -82,10 +82,11 @@ public class UserServiceImpl implements UserService {
Units units = unitsService.findById(user.getUnitsId());
user.setShowOrder(userDao.maxShowOrder(units.getUnitId())+1);
//先判断用户名是否被注册
User byName = userDao.findByName(user.getName());
User byName= userDao.findByNameAndUnitsId(user.getName(),user.getUnitsId());
if (byName != null){
map.put("error",byName);
return map;
// throw new ApiException(ResponseEntity.ok("同单位下有相同名称的专管员:"+user.getName()));
}
User byUsername = userDao.findByUsername(user.getUsername());
if (byUsername != null){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论