package com.huashe.park.core.service.impl;

import com.huashe.common.annotation.DataSource;
import com.huashe.common.enums.DataSourceType;
import com.huashe.park.common.DateTimeUtil;
import com.huashe.park.core.mapper.BdDevcTrailUwbMapper;
import com.huashe.park.core.service.IBdDevcTrailUwbService;
import com.huashe.park.domain.entity.BdDevcTrailUwb;
import com.huashe.park.infrastructure.uwb.UWBWebService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 室内坐标定位Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-16
 */
@Service
@DataSource(DataSourceType.PKB)
public class BdDevcTrailUwbServiceImpl implements IBdDevcTrailUwbService {
    @Autowired
    private BdDevcTrailUwbMapper bdDevcTrailUwbMapper;

    @Autowired
    private UWBWebService uwbWebService;

    /**
     * 查询室内坐标定位
     *
     * @param id 室内坐标定位主键
     * @return 室内坐标定位
     */
    @Override
    public BdDevcTrailUwb selectBdDevcTrailUwbById(Long id) {
        return bdDevcTrailUwbMapper.selectBdDevcTrailUwbById(id);
    }

    /**
     * 查询室内坐标定位列表
     *
     * @param bdDevcTrailUwb 室内坐标定位
     * @return 室内坐标定位
     */
    @Override
    public List<BdDevcTrailUwb> selectBdDevcTrailUwbList(BdDevcTrailUwb bdDevcTrailUwb) {
        return bdDevcTrailUwbMapper.selectBdDevcTrailUwbList(bdDevcTrailUwb);
    }

    /**
     * 新增室内坐标定位
     *
     * @param bdDevcTrailUwb 室内坐标定位
     * @return 结果
     */
    @Override
    public int insertBdDevcTrailUwb(BdDevcTrailUwb bdDevcTrailUwb) {
        return bdDevcTrailUwbMapper.insertBdDevcTrailUwb(bdDevcTrailUwb);
    }

    /**
     * 修改室内坐标定位
     *
     * @param bdDevcTrailUwb 室内坐标定位
     * @return 结果
     */
    @Override
    public int updateBdDevcTrailUwb(BdDevcTrailUwb bdDevcTrailUwb) {
        return bdDevcTrailUwbMapper.updateBdDevcTrailUwb(bdDevcTrailUwb);
    }

    /**
     * 批量删除室内坐标定位
     *
     * @param ids 需要删除的室内坐标定位主键
     * @return 结果
     */
    @Override
    public int deleteBdDevcTrailUwbByIds(Long[] ids) {
        return bdDevcTrailUwbMapper.deleteBdDevcTrailUwbByIds(ids);
    }

    /**
     * 删除室内坐标定位信息
     *
     * @param id 室内坐标定位主键
     * @return 结果
     */
    @Override
    public int deleteBdDevcTrailUwbById(Long id) {
        return bdDevcTrailUwbMapper.deleteBdDevcTrailUwbById(id);
    }

    @Override
    public void saveUwbTrail() {
        String yesterday = DateTimeUtil.yesterday(DateTimeUtil.DateFormatter.yyyyMMdd);
        bdDevcTrailUwbMapper.saveObjTail(yesterday);
    }

    @Override
    public Map uwbOAuth() {
        return uwbWebService.exchangeToken(new HashMap<String, Object>() {
            {
                put("username", "admin");
                put("password", "admin123");
                put("isfresh", 1);
            }
        });
    }
}
