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;
|
}
|
}
|