linwe
2024-07-29 aeb7d068be92312dcdcea75e1240bcf2a78dd0fe
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
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.checkInRecords.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.cache.SysCache;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.checkInRecords.dto.CheckInRecordsDTO;
import org.springblade.modules.checkInRecords.entity.CheckInRecordsEntity;
import org.springblade.modules.checkInRecords.vo.CheckInRecordsVO;
import org.springblade.modules.checkInRecords.mapper.CheckInRecordsMapper;
import org.springblade.modules.checkInRecords.service.ICheckInRecordsService;
import org.springblade.modules.grid.entity.GridEntity;
import org.springblade.modules.grid.entity.GridPatrolRecordEntity;
import org.springblade.modules.grid.service.IGridService;
import org.springblade.modules.police.entity.PoliceAffairsGridEntity;
import org.springblade.modules.police.service.IPoliceAffairsGridService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
 
import java.util.List;
 
/**
 * 打卡记录表 服务实现类
 *
 * @author BladeX
 * @since 2023-12-04
 */
@Service
public class CheckInRecordsServiceImpl extends ServiceImpl<CheckInRecordsMapper, CheckInRecordsEntity> implements ICheckInRecordsService {
 
    @Override
    public IPage<CheckInRecordsVO> selectCheckInRecordsPage(IPage<CheckInRecordsVO> page, CheckInRecordsVO checkInRecords) {
        // todo 数据过滤
        String deptId = checkInRecords.getDeptId();
        if (Strings.isBlank(deptId) && !AuthUtil.isAdministrator() && !AuthUtil.isAdmin()) {
            deptId = AuthUtil.getDeptId();
        }
        List<Long> deptIdList = SysCache.getDeptChildIds(deptId);
        // 公共参数设置
//        CommonParamSet commonParamSet = new CommonParamSet().invoke(CheckInRecordsVO.class,checkInRecords);
 
        IPage<CheckInRecordsVO> checkInRecordsVOIPage = page.setRecords(baseMapper.selectCheckInRecordsPage(page, checkInRecords, deptIdList));
        return checkInRecordsVOIPage;
    }
 
 
    /**
     * 查询打卡记录表
     *
     * @param id 打卡记录表ID
     * @return 打卡记录表
     */
    @Override
    public CheckInRecordsDTO selectCheckInRecordsById(Integer id) {
        return this.baseMapper.selectCheckInRecordsById(id);
    }
 
    /**
     * 查询打卡记录表列表
     *
     * @param checkInRecordsDTO 打卡记录表
     * @return 打卡记录表集合
     */
    @Override
    public List<CheckInRecordsDTO> selectCheckInRecordsList(CheckInRecordsDTO checkInRecordsDTO) {
        return this.baseMapper.selectCheckInRecordsList(checkInRecordsDTO);
    }
 
    @Override
    public boolean saveCheckInRecords(CheckInRecordsEntity checkInRecords) {
        checkInRecords.setCreateUserId(AuthUtil.getUserId());
        setGridInfo(checkInRecords);
        return save(checkInRecords);
    }
 
 
    /**
     * 设置警格网格信息
     * @param checkInRecords
     */
    public void setGridInfo(CheckInRecordsEntity checkInRecords) {
        // 根据位置设置网格,警格编号
        IGridService gridService = SpringUtils.getBean(IGridService.class);
        IPoliceAffairsGridService policeAffairsGridService = SpringUtils.getBean(IPoliceAffairsGridService.class);
        String point = "'POINT(" + checkInRecords.getLng() + " " + checkInRecords.getLat() + ")'";
        //点坐标解析网格
        List<GridEntity> gridEntityList = gridService.spatialAnalysis(point);
        if (gridEntityList.size()>0){
            GridEntity gridEntity = gridEntityList.get(0);
            checkInRecords.setGridCode(gridEntity.getGridCode());
        }
        //点坐标解析警格
        List<PoliceAffairsGridEntity> policeAffairsGridEntityList = policeAffairsGridService.spatialAnalysis(point);
        if (policeAffairsGridEntityList.size()>0){
            PoliceAffairsGridEntity policeAffairsGridEntity = policeAffairsGridEntityList.get(0);
            checkInRecords.setJwGridCode(policeAffairsGridEntity.getJwGridCode());
        }
    }
}