src/main/java/org/springblade/modules/yw/controller/RescueTeamController.java
@@ -6,15 +6,19 @@ 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.RescueTeamExcel; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.modules.yw.entity.RescueTeamEntity; import org.springblade.modules.yw.vo.RescueTeamVO; import org.springblade.modules.yw.service.IRescueTeamService; import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import java.util.Map; @@ -104,4 +108,14 @@ return R.status(rescueTeamService.removeByIds(Func.toLongList(ids))); } /** * 导入救援队伍信息 */ @PostMapping("import-rescueTeam") @ApiOperationSupport(order = 8) @ApiOperation(value = "导入救援队伍信息", notes = "传入excel") public R importRescueTeam(MultipartFile file, Integer isCovered) { String data = rescueTeamService.importRescueTeam(ExcelUtil.read(file, RescueTeamExcel.class),isCovered == 1); return R.data(200, data, data); } } src/main/java/org/springblade/modules/yw/entity/RescueTeamEntity.java
@@ -34,6 +34,23 @@ */ @ApiModelProperty(value = "所属企业id") private Long firmId; /** * 类型 1:企业救援队伍 2:园区救援队伍 */ @ApiModelProperty(value = "类型 1:企业救援队伍 2:园区救援队伍") private Integer type; /** * 救援队伍组名称 */ @ApiModelProperty(value = "救援队伍组名称") private String teamName; /** * 救援队伍组职务 */ @ApiModelProperty(value = "救援队伍组职务") private String teamJob; /** * 责任人姓名 */ @@ -45,6 +62,11 @@ @ApiModelProperty(value = "责任人联系电话") private String perInChaPho; /** * 责任人职务 */ @ApiModelProperty(value = "责任人职务") private String job; /** * 创建人 */ @ApiModelProperty(value = "创建人", example = "") src/main/java/org/springblade/modules/yw/excel/RescueTeamExcel.java
New file @@ -0,0 +1,45 @@ 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 lombok.Data; import java.io.Serializable; /** * 救援队伍 excel 模板 * @author zhongrj * @date 2024-10-29 */ @Data @ColumnWidth(25) @HeadRowHeight(20) @ContentRowHeight(18) public class RescueTeamExcel implements Serializable { private static final long serialVersionUID = 1L; @ColumnWidth(20) @ExcelProperty("企业名称") private String firmName; @ColumnWidth(20) @ExcelProperty("类型") private String type; @ColumnWidth(20) @ExcelProperty(value = "组名称") private String teamName; @ExcelProperty("组职务") private String teamJob; @ExcelProperty("负责人") private String perInCha; @ExcelProperty("职务") private String job; @ExcelProperty("负责人电话") private String perInChaPho; } src/main/java/org/springblade/modules/yw/service/IRescueTeamService.java
@@ -2,8 +2,11 @@ import com.baomidou.mybatisplus.extension.service.IService; import org.springblade.modules.yw.entity.RescueTeamEntity; import org.springblade.modules.yw.excel.RescueTeamExcel; import org.springblade.modules.yw.vo.RescueTeamVO; import com.baomidou.mybatisplus.core.metadata.IPage; import java.util.List; /** * 救援队伍表 服务类 @@ -21,4 +24,11 @@ */ IPage<RescueTeamVO> selectRescueTeamPage(IPage<RescueTeamVO> page, RescueTeamVO rescueTeam); /** * 导入救援队伍信息 * @param data * @param isCovered * @return */ String importRescueTeam(List<RescueTeamExcel> data, boolean isCovered); } src/main/java/org/springblade/modules/yw/service/impl/RescueTeamServiceImpl.java
@@ -1,12 +1,22 @@ 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.yw.entity.FirmInfo; import org.springblade.modules.yw.entity.RescueTeamEntity; import org.springblade.modules.yw.excel.RescueTeamExcel; import org.springblade.modules.yw.service.IFirmInfoService; import org.springblade.modules.yw.vo.RescueTeamVO; import org.springblade.modules.yw.mapper.RescueTeamMapper; import org.springblade.modules.yw.service.IRescueTeamService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.baomidou.mybatisplus.core.metadata.IPage; import java.util.List; import java.util.Objects; /** * 救援队伍表 服务实现类 @@ -17,9 +27,87 @@ @Service public class RescueTeamServiceImpl extends ServiceImpl<RescueTeamMapper, RescueTeamEntity> implements IRescueTeamService { @Autowired private IFirmInfoService firmInfoService; /** * 自定义分页查询 * @param page * @param rescueTeam * @return */ @Override public IPage<RescueTeamVO> selectRescueTeamPage(IPage<RescueTeamVO> page, RescueTeamVO rescueTeam) { return page.setRecords(baseMapper.selectRescueTeamPage(page, rescueTeam)); } /** * 导入救援队伍信息 * @param data * @param isCovered * @return */ @Override public String importRescueTeam(List<RescueTeamExcel> data, boolean isCovered) { for (RescueTeamExcel rescueTeamExcel : data) { // 数据拷贝 RescueTeamEntity rescueTeamEntity = Objects.requireNonNull(BeanUtil.copy(rescueTeamExcel, RescueTeamEntity.class)); // 类型转换 if (!Strings.isBlank(rescueTeamExcel.getType())){ if (rescueTeamExcel.getType().equals("企业")){ rescueTeamEntity.setType(1); // 设置企业id setFirmId(rescueTeamExcel,rescueTeamEntity); } if (rescueTeamExcel.getType().equals("园区")){ rescueTeamEntity.setType(2); } } // 判断是否保存 Long id = isSave(rescueTeamExcel); if (null!=id){ if (isCovered){ // 覆盖更新 rescueTeamEntity.setId(id); updateById(rescueTeamEntity); continue; } } // 保存 save(rescueTeamEntity); } return null; } /** * 判断是否已经保存救援队伍信息 * @param rescueTeamExcel * @return */ private Long isSave(RescueTeamExcel rescueTeamExcel) { QueryWrapper<RescueTeamEntity> wrapper = new QueryWrapper<>(); wrapper.eq("per_in_cha",rescueTeamExcel.getPerInCha()) .eq("per_in_cha_pho",rescueTeamExcel.getPerInChaPho()) .eq("is_deleted",0); RescueTeamEntity one = getOne(wrapper); if (null!=one){ return one.getId(); } return null; } /** * 设置企业id * @param rescueTeamExcel * @param rescueTeamEntity */ private void setFirmId(RescueTeamExcel rescueTeamExcel, RescueTeamEntity rescueTeamEntity) { QueryWrapper<FirmInfo> wrapper = new QueryWrapper<>(); wrapper.eq("name",rescueTeamExcel.getFirmName()) .eq("is_deleted",0); FirmInfo firmInfo = firmInfoService.getOne(wrapper); if (null!=firmInfo){ rescueTeamEntity.setFirmId(firmInfo.getId()); } } }