|
@@ -1,6 +1,7 @@
|
|
|
package com.ruoyi.zdsz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
import com.ruoyi.common.core.domain.PageQuery;
|
|
@@ -8,19 +9,28 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.ruoyi.framework.obs.FileUtil;
|
|
|
+import com.ruoyi.system.mapper.SysDictDataMapper;
|
|
|
+import com.ruoyi.zdsz.domain.ZBuilding;
|
|
|
+import com.ruoyi.zdsz.domain.ZHouse;
|
|
|
+import com.ruoyi.zdsz.domain.ZUnit;
|
|
|
import com.ruoyi.zdsz.domain.vo.GExportsVo;
|
|
|
+import com.ruoyi.zdsz.domain.vo.GImportVo;
|
|
|
+import com.ruoyi.zdsz.mapper.ZBuildingMapper;
|
|
|
+import com.ruoyi.zdsz.mapper.ZHouseMapper;
|
|
|
+import com.ruoyi.zdsz.mapper.ZUnitMapper;
|
|
|
import com.ruoyi.zdsz.service.IZBuildingService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.Value;
|
|
|
import org.mybatis.logging.Logger;
|
|
|
import org.mybatis.logging.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.zdsz.domain.bo.ZAreaBo;
|
|
|
import com.ruoyi.zdsz.domain.vo.ZAreaVo;
|
|
|
import com.ruoyi.zdsz.domain.ZArea;
|
|
|
import com.ruoyi.zdsz.mapper.ZAreaMapper;
|
|
|
import com.ruoyi.zdsz.service.IZAreaService;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -30,10 +40,7 @@ import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Collection;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 小区管理Service业务层处理
|
|
@@ -52,7 +59,187 @@ public class ZAreaServiceImpl implements IZAreaService {
|
|
|
|
|
|
@Resource
|
|
|
private ZAreaMapper baseMapper;
|
|
|
+ @Resource
|
|
|
+ private ZBuildingMapper zBuildingMapper;
|
|
|
+ @Resource
|
|
|
+ private ZUnitMapper zUnitMapper;
|
|
|
+ @Resource
|
|
|
+ private ZHouseMapper zHouseMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SysDictDataMapper sysDictDataMapper;
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> importUser(List<GImportVo> list, Boolean isUpdateSupport, String operName, int n, int successNum) {
|
|
|
+ if (ObjectUtils.isEmpty(list) || list.size() == 0) {
|
|
|
+ throw new ServiceException("导入数据不能为空!");
|
|
|
+ }
|
|
|
+ Map<String, Object> ret = new HashMap<>();
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ for (int i = n; i < list.size(); i++) {
|
|
|
+ GImportVo vo = list.get(i);
|
|
|
+
|
|
|
+ String districtValue = sysDictDataMapper.queryValueTextByKey("district", vo.getDistrict());
|
|
|
+ if (StringUtils.isBlank(districtValue)) {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行行政区填写错误,导入失败!");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ n++;
|
|
|
+ // 验证是否存在这个小区
|
|
|
+ if (StringUtils.isNotEmpty(vo.getAreaName())) {
|
|
|
+ ZArea area = baseMapper.getByName(vo.getAreaName());
|
|
|
+ ZBuilding building = new ZBuilding();
|
|
|
+ ZUnit unit = new ZUnit();
|
|
|
+ ZHouse house = new ZHouse();
|
|
|
+ if (ObjectUtils.isEmpty(area)) {
|
|
|
+ area = new ZArea();
|
|
|
+ //小区zDsZ1a2b3c4d%1234!
|
|
|
+ area.setName(vo.getAreaName());
|
|
|
+ area.setCreateBy(operName);
|
|
|
+ area.setCreateTime(new Date());
|
|
|
+ area.setDistrict(districtValue);
|
|
|
+ baseMapper.insert(area);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getBuildName())) {
|
|
|
+ //楼宇
|
|
|
+ building.setName(vo.getBuildName());
|
|
|
+ building.setAreaId(area.getId());
|
|
|
+ building.setCreateBy(operName);
|
|
|
+ building.setCreateTime(new Date());
|
|
|
+ zBuildingMapper.insert(building);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getUnitName())) {
|
|
|
+ //单元
|
|
|
+ unit.setName(vo.getUnitName());
|
|
|
+ unit.setBuildingId(building.getId());
|
|
|
+ unit.setAreaId(area.getId());
|
|
|
+ unit.setCreateBy(operName);
|
|
|
+ unit.setCreateTime(new Date());
|
|
|
+ zUnitMapper.insert(unit);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getHouseName())) {
|
|
|
+ //房屋
|
|
|
+ house.setName(vo.getHouseName());
|
|
|
+ house.setAreaId(area.getId());
|
|
|
+ house.setBuildingId(building.getId());
|
|
|
+ house.setUnitId(unit.getId());
|
|
|
+ house.setCreateBy(operName);
|
|
|
+ house.setCreateTime(new Date());
|
|
|
+ zHouseMapper.insert(house);
|
|
|
+ successNum++;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else if (isUpdateSupport) {
|
|
|
+ if (StringUtils.isNotEmpty(vo.getBuildName())) {
|
|
|
+ building = zBuildingMapper.getByName(vo.getBuildName(), area.getId());
|
|
|
+ if (ObjectUtils.isEmpty(building)) {
|
|
|
+ building = new ZBuilding();
|
|
|
+ //楼宇
|
|
|
+ building.setName(vo.getBuildName());
|
|
|
+ building.setAreaId(area.getId());
|
|
|
+ building.setCreateBy(operName);
|
|
|
+ building.setCreateTime(new Date());
|
|
|
+ zBuildingMapper.insert(building);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getUnitName())) {
|
|
|
+ //单元
|
|
|
+ unit.setName(vo.getUnitName());
|
|
|
+ unit.setAreaId(area.getId());
|
|
|
+ unit.setBuildingId(building.getId());
|
|
|
+ unit.setCreateBy(operName);
|
|
|
+ unit.setCreateTime(new Date());
|
|
|
+ zUnitMapper.insert(unit);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getHouseName())) {
|
|
|
+ //房屋
|
|
|
+ house.setName(vo.getHouseName());
|
|
|
+ house.setAreaId(area.getId());
|
|
|
+ house.setBuildingId(building.getId());
|
|
|
+ house.setUnitId(unit.getId());
|
|
|
+ house.setCreateBy(operName);
|
|
|
+ house.setCreateTime(new Date());
|
|
|
+ zHouseMapper.insert(house);
|
|
|
+ successNum++;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(vo.getUnitName())) {
|
|
|
+ unit = zUnitMapper.getByName(vo.getUnitName(), building.getId());
|
|
|
+ if (ObjectUtils.isEmpty(unit)) {
|
|
|
+ unit = new ZUnit();
|
|
|
+ //单元
|
|
|
+ unit.setName(vo.getUnitName());
|
|
|
+ unit.setAreaId(area.getId());
|
|
|
+ unit.setBuildingId(building.getId());
|
|
|
+ unit.setCreateBy(operName);
|
|
|
+ unit.setCreateTime(new Date());
|
|
|
+ zUnitMapper.insert(unit);
|
|
|
+ if (StringUtils.isNotEmpty(vo.getHouseName())) {
|
|
|
+ //房屋
|
|
|
+ house.setName(vo.getHouseName());
|
|
|
+ house.setAreaId(area.getId());
|
|
|
+ house.setBuildingId(building.getId());
|
|
|
+ house.setUnitId(unit.getId());
|
|
|
+ house.setCreateBy(operName);
|
|
|
+ house.setCreateTime(new Date());
|
|
|
+ zHouseMapper.insert(house);
|
|
|
+ successNum++;
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (StringUtils.isNotEmpty(vo.getHouseName())) {
|
|
|
+ house = zHouseMapper.getByName(vo.getHouseName(), unit.getId());
|
|
|
+ if (ObjectUtils.isEmpty(house)) {
|
|
|
+ house = new ZHouse();
|
|
|
+ //房屋
|
|
|
+ house.setName(vo.getHouseName());
|
|
|
+ house.setAreaId(area.getId());
|
|
|
+ house.setBuildingId(building.getId());
|
|
|
+ house.setUnitId(unit.getId());
|
|
|
+ house.setCreateBy(operName);
|
|
|
+ house.setCreateTime(new Date());
|
|
|
+ zHouseMapper.insert(house);
|
|
|
+ successNum++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
|
|
|
+ }
|
|
|
+ ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
|
|
|
+ ret.put("n", n);
|
|
|
+ ret.put("is_success", true);
|
|
|
+ ret.put("successMsg", "");
|
|
|
+ ret.put("successNum", successNum);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条");
|
|
|
+ ret.put("bfb", String.format("%.2f", (Double.valueOf((n + 1)) / Double.valueOf(list.size())) * 100));
|
|
|
+ ret.put("n", n);
|
|
|
+ ret.put("is_success", false);
|
|
|
+ ret.put("successMsg", successMsg.toString());
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 小区下拉
|
|
@@ -189,7 +376,7 @@ public class ZAreaServiceImpl implements IZAreaService {
|
|
|
try {
|
|
|
FileUtil.downLoadFile(request, response, zipName, zipFilePath);
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
- throw new RuntimeException("导出失败~"+e);
|
|
|
+ throw new RuntimeException("导出失败~" + e);
|
|
|
}
|
|
|
}
|
|
|
}
|