zrj
2024-11-09 166d2ad42c652c938b754cf2407770c752322b95
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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.Map;
import java.util.Objects;
 
/**
 * 救援队伍表 服务实现类
 *
 * @author BladeX
 * @since 2024-10-28
 */
@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(2);
                    // 设置企业id
                    setFirmId(rescueTeamExcel,rescueTeamEntity);
                }
                if (rescueTeamExcel.getType().equals("园区")){
                    rescueTeamEntity.setType(1);
                }
            }
            // 判断是否保存
            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());
        }
    }
 
    /**
     * 救援队伍统计查询
     * @param rescueTeam
     * @return
     */
    @Override
    public List<Map<String, Object>> getStatisticData(RescueTeamVO rescueTeam) {
        if (null==rescueTeam.getType()){
            // 设置默认为园区
            rescueTeam.setType(1);
        }
        // 查询并返回救援队伍统计
        return baseMapper.getStatisticData(rescueTeam);
    }
}