|
|
@@ -0,0 +1,264 @@
|
|
|
+package com.idea.buildManage.excel;
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.idea.buildManage.model.MnpBuilding;
|
|
|
+import com.idea.buildManage.model.ParkRoom;
|
|
|
+import com.idea.buildManage.service.MnpBuildingService;
|
|
|
+import com.idea.buildManage.service.ParkFloorDiscService;
|
|
|
+import com.idea.buildManage.service.ParkInfoService;
|
|
|
+import com.idea.buildManage.service.ParkRoomService;
|
|
|
+import com.rockstar.shiro.util.ShiroUtils;
|
|
|
+import com.rockstar.system.service.SysDictService;
|
|
|
+import com.rockstar.util.StringUtils;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+public class ParkRoomListener extends AnalysisEventListener<ParkRoomExcel> {
|
|
|
+
|
|
|
+ private List<ParkRoom> list = new ArrayList<>();
|
|
|
+
|
|
|
+ private List<ParkRoomExcel> excelList = new ArrayList<>();
|
|
|
+
|
|
|
+ private List<ParkRoomExcel> badList = new ArrayList<>();
|
|
|
+
|
|
|
+ Integer count;
|
|
|
+
|
|
|
+ private JSONObject jsonObject;
|
|
|
+ private ParkRoomService roomService;
|
|
|
+ private MnpBuildingService buildingService;
|
|
|
+ private ParkFloorDiscService floorDiscService;
|
|
|
+ private ParkInfoService parkInfoService;
|
|
|
+ private SysDictService sysDictService;
|
|
|
+
|
|
|
+
|
|
|
+ public ParkRoomListener(MnpBuildingService buildingService, ParkFloorDiscService floorDiscService,
|
|
|
+ ParkInfoService parkInfoService, SysDictService sysDictService, JSONObject jsonObject) {
|
|
|
+ this.buildingService = buildingService;
|
|
|
+ this.floorDiscService = floorDiscService;
|
|
|
+ this.parkInfoService = parkInfoService;
|
|
|
+ this.sysDictService = sysDictService;
|
|
|
+ this.jsonObject = jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(ParkRoomExcel parkRoomExcel, AnalysisContext analysisContext) {
|
|
|
+ excelList.add(parkRoomExcel);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+
|
|
|
+
|
|
|
+ // 用途字典
|
|
|
+ List<Map<String, String>> houseUsage = sysDictService.selectDictList("HOUSE_USAGE");
|
|
|
+ // 装修情况字典
|
|
|
+ List<Map<String, String>> decorationSituation = sysDictService.selectDictList("DECORATION_SITUATION");
|
|
|
+ // 可售状态字典
|
|
|
+ List<Map<String, String>> saleStatus = sysDictService.selectDictList("SALE_STATUS");
|
|
|
+
|
|
|
+
|
|
|
+ if(CollectionUtils.isNotEmpty(excelList)){
|
|
|
+ ParkRoom data;
|
|
|
+ ParkRoomExcel excel = null;
|
|
|
+ Map<String, String> buildNameIdMap = buildingService.getNameIdMap();
|
|
|
+ Map<String, String> discNameIdMap = floorDiscService.getNameIdMap();
|
|
|
+ Map<String, String> parkNameIdMap = parkInfoService.getNameIdMap();
|
|
|
+ for(int i = 0; i < excelList.size(); i++){
|
|
|
+ try {
|
|
|
+ data = new ParkRoom();
|
|
|
+ excel = excelList.get(i);
|
|
|
+ if (StringUtils.isEmpty(excel.getGroupName())) {
|
|
|
+ throw new RuntimeException("楼盘/小区名称为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(excel.getDiscName())) {
|
|
|
+ throw new RuntimeException("分期名称为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(excel.getBuildNum())) {
|
|
|
+ throw new RuntimeException("单元楼栋号为空");
|
|
|
+ }
|
|
|
+ // 判断小区是否存在
|
|
|
+ if(StringUtils.isEmpty(parkNameIdMap.get(excel.getGroupName()))){
|
|
|
+ throw new RuntimeException("楼盘/小区不存在");
|
|
|
+ }
|
|
|
+ data.setGroupId(parkNameIdMap.get(excel.getGroupName()));
|
|
|
+ // 判断分期是否存在
|
|
|
+ if(StringUtils.isEmpty(discNameIdMap.get(excel.getGroupName()))){
|
|
|
+ throw new RuntimeException("分期不存在");
|
|
|
+ }
|
|
|
+ data.setDiscId(discNameIdMap.get(excel.getGroupName()));
|
|
|
+ // 判断楼栋是否存在
|
|
|
+ if(StringUtils.isEmpty(buildNameIdMap.get(excel.getBuildNum()))){
|
|
|
+ throw new RuntimeException("楼栋不存在");
|
|
|
+ }
|
|
|
+ // 户室号
|
|
|
+ if (StringUtils.isEmpty(excel.getRoomNo())) {
|
|
|
+ throw new RuntimeException("户室号为空");
|
|
|
+ }
|
|
|
+ data.setRoomNo(excel.getRoomNo());
|
|
|
+ // 所在层
|
|
|
+ if (StringUtils.isEmpty(excel.getFloor())) {
|
|
|
+ throw new RuntimeException("所在层为空");
|
|
|
+ }
|
|
|
+ data.setFloor(excel.getFloor());
|
|
|
+ // 预测套内面积
|
|
|
+ if (StringUtils.isEmpty(excel.getPredictionInternalArea())) {
|
|
|
+ throw new RuntimeException("预测套内面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setPredictionInternalArea(Double.valueOf(excel.getPredictionInternalArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("预测套内面积格式有误");
|
|
|
+ }
|
|
|
+ // 预测分摊面积
|
|
|
+ if (StringUtils.isEmpty(excel.getPredictionShareArea())) {
|
|
|
+ throw new RuntimeException("预测分摊面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setPredictionShareArea(Double.valueOf(excel.getPredictionShareArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("预测分摊面积格式有误");
|
|
|
+ }
|
|
|
+ // 预测建筑面积
|
|
|
+ if (StringUtils.isEmpty(excel.getPredictionBuildArea())) {
|
|
|
+ throw new RuntimeException("预测建筑面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setPredictionBuildArea(Double.valueOf(excel.getPredictionBuildArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("预测建筑面积格式有误");
|
|
|
+ }
|
|
|
+ // 预测土地面积
|
|
|
+ if (StringUtils.isEmpty(excel.getPredictionLandArea())) {
|
|
|
+ throw new RuntimeException("预测土地面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setPredictionLandArea(Double.valueOf(excel.getPredictionLandArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("预测土地面积");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 实测套内面积
|
|
|
+ if (StringUtils.isEmpty(excel.getActualInternalArea())) {
|
|
|
+ throw new RuntimeException("实测套内面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setActualInternalArea(Double.valueOf(excel.getActualInternalArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("实测套内面积格式有误");
|
|
|
+ }
|
|
|
+ // 实测分摊面积
|
|
|
+ if (StringUtils.isEmpty(excel.getActualShareArea())) {
|
|
|
+ throw new RuntimeException("实测分摊面积为空");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setActualShareArea(Double.valueOf(excel.getActualShareArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("实测分摊面积格式有误");
|
|
|
+ }
|
|
|
+ // 实测建筑面积
|
|
|
+ if (StringUtils.isEmpty(excel.getActualBuildArea())) {
|
|
|
+ throw new RuntimeException("实测建筑面积");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setActualBuildArea(Double.valueOf(excel.getActualBuildArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("预测建筑面积格式有误");
|
|
|
+ }
|
|
|
+ // 实测土地面积
|
|
|
+ if (StringUtils.isEmpty(excel.getActualLandArea())) {
|
|
|
+ throw new RuntimeException("实测土地面积");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ data.setActualLandArea(Double.valueOf(excel.getActualLandArea()));
|
|
|
+ }catch (NumberFormatException e){
|
|
|
+ throw new RuntimeException("实测土地面积格式有误");
|
|
|
+ }
|
|
|
+ // 用途
|
|
|
+ if (StringUtils.isNotEmpty(excel.getRoomUse())) {
|
|
|
+ throw new RuntimeException("用途为空");
|
|
|
+ }
|
|
|
+ for (Map<String, String> stringStringMap : houseUsage) {
|
|
|
+ if (stringStringMap.get("label").equals(excel.getRoomUse())) {
|
|
|
+ data.setRoomUse(Integer.valueOf(stringStringMap.get("value")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没匹配上的情况
|
|
|
+ if(data.getRoomUse() == null){
|
|
|
+ throw new RuntimeException("用途格式有误");
|
|
|
+ }
|
|
|
+ // 户编号
|
|
|
+ if (StringUtils.isNotEmpty(excel.getRoomNumber())) {
|
|
|
+ throw new RuntimeException("户编号为空");
|
|
|
+ }
|
|
|
+ data.setRoomNumber(excel.getRoomNumber());
|
|
|
+ // 装修情况
|
|
|
+ if (StringUtils.isNotEmpty(excel.getDecorationSituation())) {
|
|
|
+ throw new RuntimeException("装修情况为空");
|
|
|
+ }
|
|
|
+ for (Map<String, String> stringStringMap : decorationSituation) {
|
|
|
+ if (stringStringMap.get("label").equals(excel.getDecorationSituation())) {
|
|
|
+ data.setDecorationSituation(Integer.valueOf(stringStringMap.get("value")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没匹配上的情况
|
|
|
+ if(data.getDecorationSituation() == null){
|
|
|
+ throw new RuntimeException("装修情况格式有误");
|
|
|
+ }
|
|
|
+ data.setRemark(excel.getRemark());
|
|
|
+ // 可售状态
|
|
|
+ if (StringUtils.isNotEmpty(excel.getSaleStatus())) {
|
|
|
+ throw new RuntimeException("可售状态为空");
|
|
|
+ }
|
|
|
+ for (Map<String, String> stringStringMap : saleStatus) {
|
|
|
+ if (stringStringMap.get("label").equals(excel.getSaleStatus())) {
|
|
|
+ data.setSaleStatus(Integer.valueOf(stringStringMap.get("value")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 没匹配上的情况
|
|
|
+ if(data.getSaleStatus() == null){
|
|
|
+ throw new RuntimeException("可售状态格式有误");
|
|
|
+ }
|
|
|
+ data.setId(IdUtil.simpleUUID());
|
|
|
+ data.setCreatedId(ShiroUtils.getUserId());
|
|
|
+ data.setCreatedAt(new Date());
|
|
|
+ list.add(data);
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ String message = e.getMessage();
|
|
|
+ excel.setReason(message);
|
|
|
+ badList.add(excel);
|
|
|
+ }
|
|
|
+
|
|
|
+ count = list.size();
|
|
|
+ jsonObject.put("successCount", count);
|
|
|
+ jsonObject.put("errorList", badList);
|
|
|
+ jsonObject.put("errorCount", badList.size());
|
|
|
+ //保存
|
|
|
+ saveData();
|
|
|
+
|
|
|
+ excelList.clear();
|
|
|
+ list.clear();
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new RuntimeException("excel无数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveData(){
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
+ roomService.insertBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|