郑永安
2023-06-19 7a6abd05683528032687c75e80e0bd2030a3e46c
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
package com.gkhy.safePlatform.safeCheck.service.baseService.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.safePlatform.commons.enums.E;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.AusinessException;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.safeCheck.entity.SafeCheckRegion;
import com.gkhy.safePlatform.safeCheck.enums.DelectStatusEnum;
import com.gkhy.safePlatform.safeCheck.repository.SafeCheckRegionRepository;
import com.gkhy.safePlatform.safeCheck.service.baseService.SafeCheckRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
 
@Service("SafeCheckRegionService")
public class SafeCheckRegionServiceImpl extends ServiceImpl<SafeCheckRegionRepository, SafeCheckRegion> implements SafeCheckRegionService {
 
    @Autowired
    private SafeCheckRegionRepository safeCheckRegionRepository;
 
    /**
     * @description 根据巡检区域id、是否删除标志查询是否存在数据
     */
    @Override
    public SafeCheckRegion getOneRegion(Long id,int status) {
        return safeCheckRegionRepository.getOneRegion(id,status);
    }
 
    /**
     * @description 根据巡检区域name,是否删除标志查询是否存在数据
     */
    @Override
    public SafeCheckRegion getRegionByName(String regionName, int deleteStatus) {
        SafeCheckRegion safeCheckRegion = safeCheckRegionRepository.getRegionByName(regionName,deleteStatus);
        return safeCheckRegion;
    }
 
    /**
     * @description 根据巡检区域id,删除巡检区域
     */
    @Override
    public int deleteRegionById(SafeCheckRegion region,int status) {
        int result = safeCheckRegionRepository.deleteRegionById(region,status);
        if (result == 0) {
            throw new AusinessException(E.NOT_DELETE, "删除失败");
        }
        return result;
    }
 
    /**
     * @description 新增一个巡检区域
     */
    @Override
    public int saveRegion(SafeCheckRegion safeCheckRegion) {
        int insertResult = safeCheckRegionRepository.insert(safeCheckRegion);
        if (insertResult == 0){
            throw new BusinessException(ResultCodes.SERVER_ADD_ERROR);
        }
        return insertResult;
    }
 
    /**
     * @description 获取巡检区域所有有效的巡检区域名称
     */
    @Override
    public List<SafeCheckRegion> listRegionName(int deleteStatus) {
        LambdaQueryWrapper<SafeCheckRegion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SafeCheckRegion::getDeleteStatus,deleteStatus);
        return safeCheckRegionRepository.selectList(queryWrapper);
    }
 
    /**
     * @description 条件分页查询所有的区域  没有条件就是全部查询
     */
    @Override
    public Page listRegionByPage(Page pageInfo, HashMap<String, Object> selectCondition) {
        LambdaQueryWrapper<SafeCheckRegion> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(selectCondition.get("regionName") != null,SafeCheckRegion::getRegion,selectCondition.get("regionName"))
                .eq(selectCondition.get("regionTypeName") != null,SafeCheckRegion::getRegionType,selectCondition.get("regionTypeName"))
                .in(selectCondition.get("depIds") != null,SafeCheckRegion::getRegionDepartmentId,selectCondition.get("depIds"))
                .ne(SafeCheckRegion::getId,1)
                .orderByDesc(SafeCheckRegion::getGmtModitify)
                .eq(SafeCheckRegion::getDeleteStatus, DelectStatusEnum.DELECT_NO);
        Page page = safeCheckRegionRepository.selectPage(pageInfo, queryWrapper);
        return page;
    }
 
    /**
     * @description 根据巡检区域id、是否删除标志更新数据
     */
    @Override
    public void updateRegionById(SafeCheckRegion newRegion, int deleteStatus) {
        int updateResult = safeCheckRegionRepository.updateRegionById(newRegion,deleteStatus);
        if (updateResult == 0){
            throw new AusinessException(E.DATA_STATUS_NOT_EXIST,"巡检区域不存在,更新失败");
        }
    }
}