fix
Helius
2021-08-09 35bfed834faee8b04988e9f202a0f5c79b13b405
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.xzx.gc.order.service;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xzx.gc.common.constant.OrderEnum;
import com.xzx.gc.entity.CityPartner;
import com.xzx.gc.entity.CoreUserRole;
import com.xzx.gc.entity.PartnerFence;
import com.xzx.gc.model.admin.PartnerAccountModel;
import com.xzx.gc.model.admin.XzxCityPartnerModel;
import com.xzx.gc.model.admin.XzxElectronicFenceModel;
import com.xzx.gc.order.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
@Transactional
public class PartnerFenceService {
 
    @Autowired
    CoreUserRoleMapper coreUserRoleMapper;
 
    @Autowired
    private SysMessageMapper sysMessageMapper;
    @Autowired
    private PartnerFenceMapper partnerFenceMapper;
    @Autowired
    private CityPartnerService cityPartnerService;
 
    @Autowired
    private PartnerAccountMapper partnerAccountMapper;
 
    @Autowired
    private AccountMapper accountMapper;
    
    
    public CityPartner queryPartnerIds(String fenceId){
        List<String> list = partnerFenceMapper.queryPartnerIds(fenceId);
        if(CollUtil.isNotEmpty(list)){
            CityPartner  partner = cityPartnerService.queryPartnerById(Long.parseLong(list.get(0)));
            return partner;
        }else{
            return null;
        }
    }
 
    /**
     * 根据围栏查找合伙人
     * @param fenceId
     * @return
     */
    public String findPartnerIdByFenceId(String fenceId){
        if(StrUtil.isNotBlank(fenceId)) {
            List<String> list = partnerFenceMapper.queryPartnerIds(fenceId);
            if (CollUtil.isNotEmpty(list)) {
                return list.get(0);
            }
        }
        return null;
    }
 
 
 
    public void updateByFenceId(PartnerFence pfInfo){
        partnerFenceMapper.updateByFenceId(pfInfo);
    }
 
    public void deleteByFenceId(String id){
        XzxElectronicFenceModel model = new XzxElectronicFenceModel();
        model.setId(Integer.parseInt(id));
        partnerFenceMapper.deleteByFenceId(model);
    }
 
    public Map<String,Object> queryElectronicFence(XzxCityPartnerModel model){
        List<String> partnerIdList= cityPartnerService.queryPartnerByCurrent();
        model.setPartnerIdList(partnerIdList);
        Map<String,Object> map = new HashMap<>();
 
        if(null!=model.getStartTime()&&!"".equals(model.getStartTime())){
            model.setStartTime(model.getStartTime()+" 00:00:00");
        }
        if(null!=model.getEndTime()&&!"".equals(model.getEndTime())){
            model.setEndTime(model.getEndTime()+" 23:59:59");
        }
        PageHelper.startPage(model.getPage(),model.getLimit());
        List<XzxCityPartnerModel>  list = partnerFenceMapper.queryElectronicFencePage(model);
        for (XzxCityPartnerModel model1:list) {
            String longLatiArr = model1.getLongLatiArr();
            String longi="";
            String lati="";
 
            if(null!=longLatiArr&&!"".equals(longLatiArr)){
                String[] objects = longLatiArr.split(";");
                List<Map<String,Object>> llarr = new ArrayList<>();
                for (String object : objects) {
                    Map<String, Object> ageMap = new HashMap<String, Object>();
                    String[] objStrs = object.split(",");
                    longi = objStrs[0];
                    lati = objStrs[1];
                    ageMap.put("longitude",longi);
                    ageMap.put("latitude",lati);
                    llarr.add(ageMap);
                    model1.setLongitude(longi);
                    model1.setLatitude(lati);
                    //break;
                }
                String jsonString = JSON.toJSONString(llarr);
                model1.setLongLatiArr(jsonString);
            }
        }
        PageInfo<XzxCityPartnerModel> pageInfo=new PageInfo<>(list);
        map.put("count",pageInfo.getTotal());
        map.put("code",0);
        map.put("data",pageInfo.getList());
        return map;
    }
 
    public boolean save(PartnerFence pfInfo) {
        return partnerFenceMapper.insertSelective(pfInfo)>0?true:false;
    }
 
 
    /**
     * 根据合伙人id查询围栏id集合
     * @param partnerId
     * @return
     */
    public List<String> findFences(String partnerId){
        PartnerFence partnerFence=new PartnerFence();
        partnerFence.setPartnerId(partnerId);
        List<PartnerFence> select = partnerFenceMapper.select(partnerFence);
        List<String> collect = select.stream().map(x -> x.getFenceId()).distinct().collect(Collectors.toList());
        return collect;
    }
}