zhongrj
2024-12-24 957ce4a101415487eb2d747a59243bfbbadccc4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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;
 
/**
 * 保护目标表 服务实现类
 *
 * @author BladeX
 * @since 2024-10-28
 */
@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;
    }
}