瀏覽代碼

修改bug

JX.Li 1 年之前
父節點
當前提交
daf99cccbd

+ 63 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/GAreaController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.controller.gas;
 
+import cn.hutool.core.bean.BeanUtil;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
@@ -13,6 +14,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.obs.ObsService;
 import com.ruoyi.gas.domain.bo.GAreaBo;
 import com.ruoyi.gas.domain.vo.GAreaVo;
+import com.ruoyi.gas.domain.vo.GImportVo;
 import com.ruoyi.gas.service.IGAreaService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -21,12 +23,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 
 /**
  * 小区Controller
@@ -83,8 +85,8 @@ public class GAreaController extends BaseController {
     @Log(title = "小区", businessType = BusinessType.EXPORT)
     @GetMapping("/export")
     public void export(@Validated GAreaBo bo, HttpServletResponse response) {
-        List<GAreaVo> list = iGAreaService.queryList(bo);
-        ExcelUtil.exportExcel(list, "小区", GAreaVo.class, response);
+        List<GImportVo> gExportsVos = iGAreaService.selectList();
+        ExcelUtil.exportExcel(gExportsVos, "小区管理", GImportVo.class, response);
     }
 
     /**
@@ -131,4 +133,61 @@ public class GAreaController extends BaseController {
     public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
         return toAjax(iGAreaService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
     }
+
+    private String bfb="0";
+    private String message;
+
+    @GetMapping("/importTemplate")
+    @Log(title = "下载导入模板", businessType = BusinessType.EXPORT)
+    public void importTemplate(HttpServletResponse response) {
+        ExcelUtil.exportExcel(new ArrayList<>(), "小区", GImportVo.class, response);
+    }
+
+    @Log(title = "导入小区列表", businessType = BusinessType.EXPORT)
+    @PostMapping("/importData")
+    public synchronized AjaxResult<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception {
+        List<GImportVo> listVo = ExcelUtil.importExcel(file.getInputStream(), GImportVo.class);
+        List<GImportVo> list = BeanUtil.copyToList(listVo, GImportVo.class);
+        String operName = getUsername();
+        if(Double.valueOf(bfb)<=0){
+            forImportData(list,true,operName,0,0);
+        }
+        return  AjaxResult.success(message);
+    }
+
+    private void forImportData(List<GImportVo> list, Boolean isUpdateSupport, String operName,int n,int successNum) throws Exception
+    {
+        try{
+            Map<String,Object> ret = iGAreaService.importUser(list, isUpdateSupport, operName,n,successNum);//list, updateSupport, operName,第几条
+            if(Boolean.valueOf(ret.get("is_success").toString())){
+                bfb = ret.get("bfb").toString();
+                forImportData(list,isUpdateSupport,operName,Integer.valueOf(ret.get("n").toString()),Integer.valueOf(ret.get("successNum").toString()));
+            }else{
+                message = ret.get("successMsg").toString();
+            }
+        } catch (Exception e) {
+            message = e.getMessage();
+        }
+    }
+    /**
+     * 进度条刷新,
+     */
+    @GetMapping(value = "/flushProgress")
+    public AjaxResult<Map> flushProgress() throws Exception
+    {
+        Map<String,String> ret = new HashMap<>();
+        ret.put("bfb",bfb);
+        ret.put("message",message);
+        return AjaxResult.success(ret);
+    }
+    /**
+     * 结束进度条刷新,
+     */
+    @GetMapping(value = "/clearFlushProgress")
+    public AjaxResult<Void> clearFlushProgress() throws Exception
+    {
+        bfb="0";
+        message="";
+        return AjaxResult.success();
+    }
 }

+ 1 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -160,6 +160,7 @@ public class SysUser extends BaseEntity {
 	@ApiModelProperty(value = "岗位组")
 	@TableField(exist = false)
 	private Long[] postIds;
+	@TableField(exist = false)
 	private String postName;
 
 	/**

+ 1 - 3
ruoyi-gas/src/main/java/com/ruoyi/gas/domain/vo/GBuildingVo.java

@@ -2,12 +2,9 @@ package com.ruoyi.gas.domain.vo;
 
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
-import com.ruoyi.common.annotation.ExcelDictFormat;
-import com.ruoyi.common.convert.ExcelDictConvert;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import java.util.Date;
 
 
 
@@ -44,6 +41,7 @@ public class GBuildingVo {
 	@ExcelProperty(value = "小区id")
 	@ApiModelProperty("小区id")
 	private Long areaId;
+	private String areaName;
 
 
 }

+ 28 - 0
ruoyi-gas/src/main/java/com/ruoyi/gas/domain/vo/GImportVo.java

@@ -0,0 +1,28 @@
+package com.ruoyi.gas.domain.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+
+/**
+ * 导入VO
+ *
+ * @author Lion Li
+ */
+
+@Data
+@NoArgsConstructor
+// @Accessors(chain = true) // 导入不允许使用 会找不到set方法
+public class GImportVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ExcelProperty(value = "行政区")
+    private String district;
+    @ExcelProperty(value = "小区")
+    private String areaName;
+    @ExcelProperty(value = "楼宇")
+    private String buildName;
+
+}

+ 3 - 0
ruoyi-gas/src/main/java/com/ruoyi/gas/mapper/GAreaMapper.java

@@ -3,6 +3,7 @@ package com.ruoyi.gas.mapper;
 import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
 import com.ruoyi.gas.domain.GArea;
 import com.ruoyi.gas.domain.vo.GAreaVo;
+import com.ruoyi.gas.domain.vo.GImportVo;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -15,6 +16,8 @@ import java.util.List;
  */
 public interface GAreaMapper extends BaseMapperPlus<GArea> {
     List<String> getPhoto(Long id);
+    GArea getByName(String name);
+    List<GImportVo> selectGExportsList();
 
     //小区下拉
     List<GAreaVo> getArea(@Param("userId") String userId, @Param("name") String name);

+ 3 - 0
ruoyi-gas/src/main/java/com/ruoyi/gas/mapper/GBuildingMapper.java

@@ -3,6 +3,7 @@ package com.ruoyi.gas.mapper;
 import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
 import com.ruoyi.gas.domain.GBuilding;
 import com.ruoyi.gas.domain.vo.GBuildingVo;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -13,6 +14,8 @@ import java.util.List;
  * @date 2023-10-21
  */
 public interface GBuildingMapper extends BaseMapperPlus<GBuilding> {
+    GBuilding getByName(@Param("name")String name, @Param("areaId")Long areaId);
+
 
     List<GBuildingVo> getBuilding(Long areaId);
 }

+ 4 - 1
ruoyi-gas/src/main/java/com/ruoyi/gas/service/IGAreaService.java

@@ -5,9 +5,11 @@ import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.gas.domain.GArea;
 import com.ruoyi.gas.domain.bo.GAreaBo;
 import com.ruoyi.gas.domain.vo.GAreaVo;
+import com.ruoyi.gas.domain.vo.GImportVo;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 小区Service接口
@@ -16,7 +18,8 @@ import java.util.List;
  * @date 2023-10-21
  */
 public interface IGAreaService extends IServicePlus<GArea, GAreaVo> {
-
+    Map<String,Object> importUser(List<GImportVo> list, Boolean isUpdateSupport, String operName, int n, int successNum);
+    List<GImportVo> selectList();
     List<GAreaVo> getArea(String userId,String name);
     Boolean releaseIs(Long id);
 

+ 91 - 3
ruoyi-gas/src/main/java/com/ruoyi/gas/service/impl/GAreaServiceImpl.java

@@ -6,27 +6,31 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
 import com.ruoyi.common.core.page.PagePlus;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.PageUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.gas.domain.GArea;
+import com.ruoyi.gas.domain.GBuilding;
 import com.ruoyi.gas.domain.bo.GAreaBo;
 import com.ruoyi.gas.domain.bo.GAreaPhotoBo;
 import com.ruoyi.gas.domain.vo.GAreaVo;
+import com.ruoyi.gas.domain.vo.GImportVo;
 import com.ruoyi.gas.domain.vo.GUserVo;
 import com.ruoyi.gas.mapper.GAreaMapper;
+import com.ruoyi.gas.mapper.GBuildingMapper;
 import com.ruoyi.gas.service.IGAreaPhotoService;
 import com.ruoyi.gas.service.IGAreaService;
+import com.ruoyi.system.mapper.SysDictDataMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
+import javax.annotation.Resource;
 import java.io.File;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -48,6 +52,90 @@ public class GAreaServiceImpl extends ServicePlusImpl<GAreaMapper, GArea, GAreaV
         return baseMapper.getArea(userId, name);
     }
 
+    @Override
+    public List<GImportVo> selectList() {
+        return baseMapper.selectGExportsList();
+    }
+
+    @Resource
+    private SysDictDataMapper sysDictDataMapper;
+    @Resource
+    private GBuildingMapper gBuildingMapper;
+    @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())) {
+                    GArea area = baseMapper.getByName(vo.getAreaName());
+                    GBuilding building = new GBuilding();
+                    if (ObjectUtils.isEmpty(area)) {
+                        area = new GArea();
+                        //小区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());
+                            gBuildingMapper.insert(building);
+                        } else {
+                            throw new ServiceException("" + "第" + (n + 1) + "行格式错误,导入失败!");
+                        }
+                    } else if (isUpdateSupport) {
+                        if (StringUtils.isNotEmpty(vo.getBuildName())) {
+                            building = gBuildingMapper.getByName(vo.getBuildName(), area.getId());
+                            if (ObjectUtils.isEmpty(building)) {
+                                building = new GBuilding();
+                                //楼宇
+                                building.setName(vo.getBuildName());
+                                building.setAreaId(area.getId());
+                                building.setCreateBy(operName);
+                                building.setCreateTime(new Date());
+                                gBuildingMapper.insert(building);
+                            }
+                        } 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;
+    }
+
 
     @Override
     public Boolean releaseIs(Long id) {

+ 17 - 3
ruoyi-gas/src/main/java/com/ruoyi/gas/service/impl/GBuildingServiceImpl.java

@@ -5,6 +5,9 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.PageUtils;
 import com.ruoyi.common.core.page.PagePlus;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.gas.domain.vo.GAreaVo;
+import com.ruoyi.gas.service.IGAreaService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -14,6 +17,7 @@ import com.ruoyi.gas.domain.vo.GBuildingVo;
 import com.ruoyi.gas.domain.GBuilding;
 import com.ruoyi.gas.mapper.GBuildingMapper;
 import com.ruoyi.gas.service.IGBuildingService;
+import org.springframework.util.ObjectUtils;
 
 import java.util.List;
 import java.util.Map;
@@ -29,7 +33,7 @@ import java.util.Collection;
 public class GBuildingServiceImpl extends ServicePlusImpl<GBuildingMapper, GBuilding, GBuildingVo> implements IGBuildingService {
 
     @Override
-    public GBuildingVo queryById(Long id){
+    public GBuildingVo queryById(Long id) {
         return getVoById(id);
     }
 
@@ -38,9 +42,19 @@ public class GBuildingServiceImpl extends ServicePlusImpl<GBuildingMapper, GBuil
         return baseMapper.getBuilding(areaId);
     }
 
+    @Autowired
+    private IGAreaService service;
+
     @Override
     public TableDataInfo<GBuildingVo> queryPageList(GBuildingBo bo) {
         PagePlus<GBuilding, GBuildingVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo));
+        result.getRecordsVo().forEach(item -> {
+            GAreaVo gAreaVo = service.getVoById(item.getAreaId());
+            if (!ObjectUtils.isEmpty(gAreaVo))
+                item.setAreaName(gAreaVo.getName());
+            else
+                item.setAreaName("未知");
+        });
         return PageUtils.buildDataInfo(result);
     }
 
@@ -80,13 +94,13 @@ public class GBuildingServiceImpl extends ServicePlusImpl<GBuildingMapper, GBuil
      *
      * @param entity 实体类数据
      */
-    private void validEntityBeforeSave(GBuilding entity){
+    private void validEntityBeforeSave(GBuilding entity) {
         //TODO 做一些数据校验,如唯一约束
     }
 
     @Override
     public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
-        if(isValid){
+        if (isValid) {
             //TODO 做一些业务上的校验,判断是否需要校验
         }
         return removeByIds(ids);

+ 17 - 0
ruoyi-gas/src/main/resources/mapper/GAreaMapper.xml

@@ -27,6 +27,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           and del_flag = '0'
     </select>
 
+    <select id="selectGExportsList" resultType="com.ruoyi.gas.domain.vo.GImportVo">
+        SELECT za.name AS areaName,
+               sd.dict_label AS district,
+               zb.name AS buildName
+        FROM z_area za
+                 LEFT JOIN sys_dict_data sd on sd.dict_type = 'district' and za.district = sd.dict_value
+                 LEFT JOIN z_building zb on zb.area_id = za.id and zb.del_flag = 0
+        WHERE za.del_flag = 0
+        order by za.create_time desc
+    </select>
+    <select id="getByName" resultType="com.ruoyi.gas.domain.GArea">
+        select *
+        from g_area
+        where name = #{name}
+          and del_flag = '0'
+        order by create_time desc
+    </select>
     <select id="getArea" resultType="com.ruoyi.gas.domain.vo.GAreaVo">
         select id   as id,
                name as name

+ 8 - 1
ruoyi-gas/src/main/resources/mapper/GBuildingMapper.xml

@@ -15,11 +15,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="updateTime" column="update_time"/>
     </resultMap>
 
+
     <select id="getBuilding" resultType="com.ruoyi.gas.domain.vo.GBuildingVo">
         select id   as id,
                name as name
         from g_building
         where area_id = #{areaId} and del_flag = '0'
     </select>
-
+    <select id="getByName" resultType="com.ruoyi.gas.domain.GBuilding">
+        select * from g_building
+        where name = #{name} and area_id = #{areaId}
+          and del_flag = '0'
+        order by id
+            LIMIT 1
+    </select>
 </mapper>