| | |
| | | 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.common.utils.PositionUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.modules.yw.entity.ProTarEntity; |
| | | import org.springblade.modules.yw.excel.ProTarExcel; |
| | | import org.springblade.modules.yw.vo.ProTarVO; |
| | | import org.springblade.modules.yw.mapper.ProTarMapper; |
| | | import org.springblade.modules.yw.service.IProTarService; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 保护目标表 服务实现类 |
| | |
| | | @Service |
| | | public class ProTarServiceImpl extends ServiceImpl<ProTarMapper, ProTarEntity> implements IProTarService { |
| | | |
| | | /** |
| | | * 自定义分页查询 |
| | | * @param page |
| | | * @param proTar |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<ProTarVO> selectProTarPage(IPage<ProTarVO> page, ProTarVO proTar) { |
| | | return page.setRecords(baseMapper.selectProTarPage(page, proTar)); |
| | | } |
| | | |
| | | /** |
| | | * 导入保护目标信息 |
| | | * @param data |
| | | * @param isCovered |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String importProTar(List<ProTarExcel> data, boolean isCovered) { |
| | | for (ProTarExcel proTarExcel : data) { |
| | | // 数据拷贝 |
| | | ProTarEntity proTarEntity = Objects.requireNonNull(BeanUtil.copy(proTarExcel, ProTarEntity.class)); |
| | | // 类目转换 |
| | | if (!Strings.isBlank(proTarExcel.getCategory())){ |
| | | proTarEntity.setCategory(Integer.parseInt(proTarExcel.getCategory())); |
| | | } |
| | | // 经纬度处理 |
| | | // if (!Strings.isBlank(proTarExcel.getLng())){ |
| | | // proTarEntity.setLng(PositionUtil.tranformPos(proTarExcel.getLng()).toString()); |
| | | // } |
| | | // if (!Strings.isBlank(proTarExcel.getLat())){ |
| | | // proTarEntity.setLat(PositionUtil.tranformPos(proTarExcel.getLat()).toString()); |
| | | // } |
| | | // if (!Strings.isBlank(proTarExcel.getEndLng())){ |
| | | // proTarEntity.setEndLng(PositionUtil.tranformPos(proTarExcel.getEndLng()).toString()); |
| | | // } |
| | | // if (!Strings.isBlank(proTarExcel.getEndLat())){ |
| | | // proTarEntity.setEndLat(PositionUtil.tranformPos(proTarExcel.getEndLat()).toString()); |
| | | // } |
| | | // 判断是否已经入库 |
| | | Long id = isSave(proTarExcel); |
| | | if (null!=id){ |
| | | if (isCovered){ |
| | | // 覆盖更新 |
| | | proTarEntity.setId(id); |
| | | updateById(proTarEntity); |
| | | continue; |
| | | } |
| | | } |
| | | // 保存入库 |
| | | save(proTarEntity); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 判断保护目标是否已入库 |
| | | * @param proTarExcel |
| | | * @return |
| | | */ |
| | | private Long isSave(ProTarExcel proTarExcel) { |
| | | QueryWrapper<ProTarEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("name",proTarExcel.getName()).eq("is_deleted",0); |
| | | ProTarEntity one = getOne(wrapper); |
| | | if (null!=one){ |
| | | return one.getId(); |
| | | } |
| | | return null; |
| | | } |
| | | } |