puzhibing
2023-03-15 79962435853baf5a28e08461f46a831fffa1a4b0
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
package com.stylefeng.guns.modular.system.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.modular.system.model.TLocation;
import com.stylefeng.guns.modular.system.dao.TLocationMapper;
import com.stylefeng.guns.modular.system.service.ITLocationService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 * 地点 服务实现类
 * </p>
 *
 * @author 吕雪
 * @since 2020-09-04
 */
@Service
public class TLocationServiceImpl extends ServiceImpl<TLocationMapper, TLocation> implements ITLocationService {
 
    @Autowired
    private GDMapElectricFenceUtil gdMapElectricFenceUtil;
 
 
    /**
     * 定时任务更新线上围栏的有效时间
     * @throws Exception
     */
    @Override
    public void updateFence() throws Exception {
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 35);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<TLocation> type = this.selectList(new EntityWrapper<TLocation>().eq("type", 2));
        for(TLocation location : type){
            if((date.getTime() - location.getUpdateTime().getTime()) > 30 * 24 * 60 * 60 * 1000){//更新一个月之前的数据
                String[] s = location.getGid().split("_");
                String[] s1 = location.getCoordinate().split("_");
                for(int i = 0; i < s.length; i++){
                    String[] split = s1[i].split(";");
                    gdMapElectricFenceUtil.updateElectricFenc(s[i], "location_" + location.getId(),
                            (split.length > 2 ? "" : split[0]), (split.length > 2 ? "" : split[1]),
                            (split.length > 2 ? s1[i] : ""), sdf.format(calendar.getTime()));
                }
 
            }
        }
    }
}