zrj
2024-10-28 6f3ba6d6f633f55607f10698ed624862342d1215
新增园区信息导入
11 files modified
1 files added
193 ■■■■■ changed files
src/main/java/org/springblade/modules/yw/controller/EmergencySpaceController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/EmergencySuppliesController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/IndParkInfoController.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/ProTarController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/RescueTeamController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/RiskSourceController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/SuppliesController.java 2 ●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/entity/IndParkInfoEntity.java 4 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/excel/IndParkInfoExcel.java 63 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/service/IIndParkInfoService.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/service/impl/FirmInfoServiceImpl.java 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/service/impl/IndParkInfoServiceImpl.java 87 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/yw/controller/EmergencySpaceController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-emergencySpace/emergencySpace")
@RequestMapping("yw/emergencySpace")
@Api(value = "应急空间表", tags = "应急空间表接口")
public class EmergencySpaceController {
src/main/java/org/springblade/modules/yw/controller/EmergencySuppliesController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-emergencySupplies/emergencySupplies")
@RequestMapping("yw/emergencySupplies")
@Api(value = "应急物资表", tags = "应急物资表接口")
public class EmergencySuppliesController{
src/main/java/org/springblade/modules/yw/controller/IndParkInfoController.java
@@ -6,15 +6,18 @@
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.yw.excel.IndParkInfoExcel;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.yw.entity.IndParkInfoEntity;
import org.springblade.modules.yw.vo.IndParkInfoVO;
import org.springblade.modules.yw.service.IIndParkInfoService;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Map;
@@ -26,7 +29,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-indParkInfo/indParkInfo")
@RequestMapping("yw/indParkInfo")
@Api(value = "园区基本信息表", tags = "园区基本信息表接口")
public class IndParkInfoController {
@@ -104,4 +107,15 @@
        return R.status(indParkInfoService.removeByIds(Func.toLongList(ids)));
    }
    /**
     * 导入园区信息
     */
    @PostMapping("import-indParkInfo")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "导入园区信息", notes = "传入excel")
    public R importIndParkInfo(MultipartFile file, Integer isCovered) {
        String data = indParkInfoService.importIndParkInfo(ExcelUtil.read(file, IndParkInfoExcel.class),isCovered == 1);
        return R.data(200, data, data);
    }
}
src/main/java/org/springblade/modules/yw/controller/ProTarController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-proTar/proTar")
@RequestMapping("yw/proTar")
@Api(value = "保护目标表", tags = "保护目标表接口")
public class ProTarController {
src/main/java/org/springblade/modules/yw/controller/RescueTeamController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-rescueTeam/rescueTeam")
@RequestMapping("yw/rescueTeam")
@Api(value = "救援队伍表", tags = "救援队伍表接口")
public class RescueTeamController {
src/main/java/org/springblade/modules/yw/controller/RiskSourceController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-riskSource/riskSource")
@RequestMapping("yw/riskSource")
@Api(value = "风险源表", tags = "风险源表接口")
public class RiskSourceController {
src/main/java/org/springblade/modules/yw/controller/SuppliesController.java
@@ -26,7 +26,7 @@
 */
@RestController
@AllArgsConstructor
@RequestMapping("blade-supplies/supplies")
@RequestMapping("yw/supplies")
@Api(value = "物资库表", tags = "物资库表接口")
public class SuppliesController {
src/main/java/org/springblade/modules/yw/entity/IndParkInfoEntity.java
@@ -67,7 +67,7 @@
    /**
     * 主导产业 -见字典
     */
    @ApiModelProperty(value = "主导产业 -见字典")
    @ApiModelProperty(value = "主导产业")
    private String leaInd;
    /**
     * 通过认定年份
@@ -83,7 +83,7 @@
     * 突发环境事件应急预案备案时间
     */
    @ApiModelProperty(value = "突发环境事件应急预案备案时间")
    private Date filTime;
    private String filTime;
    /**
     * 创建人
     */
src/main/java/org/springblade/modules/yw/excel/IndParkInfoExcel.java
New file
@@ -0,0 +1,63 @@
package org.springblade.modules.yw.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.common.excel.ExcelDictConverter;
import org.springblade.common.excel.ExcelDictItemLabel;
import java.io.Serializable;
/**
 * 企业excel 模板
 * @author zhongrj
 * @date 2024-10-26
 */
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class IndParkInfoExcel implements Serializable {
    private static final long serialVersionUID = 1L;
    @ColumnWidth(20)
    @ExcelProperty("园区名称")
    private String name;
    @ColumnWidth(20)
    @ExcelProperty("经度")
    private String lng;
    @ColumnWidth(20)
    @ExcelProperty("纬度")
    private String lat;
    @ExcelProperty("地址")
    private String address;
    @ExcelProperty("行政区划")
    private String areaCode;
    @ColumnWidth(20)
    @ExcelProperty(value = "园区级别(国家级/省级/市级/县级)",converter = ExcelDictConverter.class)
    @ExcelDictItemLabel(type = "ind_park_level")
    private String level;
    @ExcelProperty("主导产业")
    private String leaInd;
    @ExcelProperty("通过认定年份")
    private Integer accSureYear;
    @ExcelProperty("规划面积(平方公里)")
    private String plaArea;
    @ExcelProperty("突发环境事件应急预案备案时间")
    private String filTime;
    @ExcelProperty("园区描述")
    private String remark;
}
src/main/java/org/springblade/modules/yw/service/IIndParkInfoService.java
@@ -2,8 +2,11 @@
import com.baomidou.mybatisplus.extension.service.IService;
import org.springblade.modules.yw.entity.IndParkInfoEntity;
import org.springblade.modules.yw.excel.IndParkInfoExcel;
import org.springblade.modules.yw.vo.IndParkInfoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List;
/**
 * 园区基本信息表 服务类
@@ -21,4 +24,11 @@
     */
    IPage<IndParkInfoVO> selectIndParkInfoPage(IPage<IndParkInfoVO> page, IndParkInfoVO indParkInfo);
    /**
     * 导入园区信息
     * @param data
     * @param isCovered 是否覆盖
     * @return
     */
    String importIndParkInfo(List<IndParkInfoExcel> data, boolean isCovered);
}
src/main/java/org/springblade/modules/yw/service/impl/FirmInfoServiceImpl.java
@@ -51,7 +51,6 @@
            // 数据转换
            FirmInfo firmInfo = Objects.requireNonNull(BeanUtil.copy(firmInfoExcel, FirmInfo.class));
            // 经纬度转换
            System.out.println("firmInfo = " + firmInfo.getName());
            positionConvert(firmInfo);
            // 判断信息是否已录入
            FirmInfo oldFirmInfo = isSave(firmInfo);
src/main/java/org/springblade/modules/yw/service/impl/IndParkInfoServiceImpl.java
@@ -1,12 +1,24 @@
package org.springblade.modules.yw.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.system.entity.Region;
import org.springblade.modules.system.service.IRegionService;
import org.springblade.modules.yw.entity.IndParkInfoEntity;
import org.springblade.modules.yw.excel.IndParkInfoExcel;
import org.springblade.modules.yw.vo.IndParkInfoVO;
import org.springblade.modules.yw.mapper.IndParkInfoMapper;
import org.springblade.modules.yw.service.IIndParkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
 * 园区基本信息表 服务实现类
@@ -17,9 +29,84 @@
@Service
public class IndParkInfoServiceImpl extends ServiceImpl<IndParkInfoMapper, IndParkInfoEntity> implements IIndParkInfoService {
    @Autowired
    private IRegionService regionService;
    /**
     * 自定义分页查询
     * @param page
     * @param indParkInfo
     * @return
     */
    @Override
    public IPage<IndParkInfoVO> selectIndParkInfoPage(IPage<IndParkInfoVO> page, IndParkInfoVO indParkInfo) {
        return page.setRecords(baseMapper.selectIndParkInfoPage(page, indParkInfo));
    }
    /**
     * 导入园区信息
     * @param data
     * @param isCovered 是否覆盖
     * @return
     */
    @Override
    public String importIndParkInfo(List<IndParkInfoExcel> data, boolean isCovered) {
        for (IndParkInfoExcel parkInfoExcel : data) {
            // 数据转换
            IndParkInfoEntity indParkInfoEntity = Objects.requireNonNull(BeanUtil.copy(parkInfoExcel, IndParkInfoEntity.class));
            // 区划转换
            if (!Strings.isBlank(parkInfoExcel.getAreaCode())) {
                String adCode = shiftResidentResidentAdCode(parkInfoExcel.getAreaCode());
                // 转换行政区code
                indParkInfoEntity.setAreaCode(adCode);
            }
            // 判断是否已经录入
            Long id = isSave(indParkInfoEntity);
            if (null!=id){
                // 更新
                if (isCovered){
                    indParkInfoEntity.setId(id);
                    updateById(indParkInfoEntity);
                    break;
                }
            }
            // 保存
            boolean save = save(indParkInfoEntity);
        }
        return null;
    }
    /**
     * 判断是否已保存
     * @param indParkInfoEntity
     * @return
     */
    private Long isSave(IndParkInfoEntity indParkInfoEntity) {
        QueryWrapper<IndParkInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("name",indParkInfoEntity.getName()).eq("is_deleted",0);
        IndParkInfoEntity one = getOne(wrapper);
        if (null!=one){
            return one.getId();
        }
        return null;
    }
    /**
     * 根据名称转成code
     *
     * @param areaCode 行政区划
     */
    public String shiftResidentResidentAdCode(String areaCode) {
        String[] split = areaCode.split("-");
        // 根据省市县三级查询对应的区县code
        QueryWrapper<Region> wrapper = new QueryWrapper<>();
        wrapper.eq("province_name", split[0])
            .eq("city_name", split[1]);
        List<Region> list = regionService.list(wrapper);
        if (list.size() > 0) {
            return list.get(0).getProvinceCode()+","+list.get(0).getCityCode();
        }
        return "";
    }
}