package com.huimv.admin.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.admin.common.utils.Result;
import com.huimv.admin.common.utils.ResultCode;
import com.huimv.admin.entity.EartagDeviceRegister;
import com.huimv.admin.entity.EartagEartagRegister2;
import com.huimv.admin.mapper.EartagDeviceRegisterMapper;
import com.huimv.admin.mapper.EartagEartagRegister2Mapper;
import com.huimv.admin.service.IEartagDeviceRegisterService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2023-09-20
 */
@Service
public class EartagDeviceRegisterServiceImpl extends ServiceImpl<EartagDeviceRegisterMapper, EartagDeviceRegister> implements IEartagDeviceRegisterService {

    @Autowired
    private EartagDeviceRegisterMapper registerMapper;
    @Autowired
    private EartagEartagRegister2Mapper register2Mapper;
    @Override
    public Result listCount(Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        QueryWrapper<EartagDeviceRegister> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId);
        QueryWrapper<EartagEartagRegister2> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId);
        Integer integer = registerMapper.selectCount(queryWrapper);
        List<EartagEartagRegister2> register2s = register2Mapper.selectList(queryWrapper2);
        Integer count = register2s.size();
        Integer count2 = 0;
        Integer count3 = 0;
        for (EartagEartagRegister2 register2 : register2s) {
            if (register2.getLiveStatus() == 1) {
                count2 = count2 + 1;
            }
            if (register2.getLiveStatus() == 0) {
                count3 = count3 + 1;
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", count);
        jsonObject.put("count1", integer);
        jsonObject.put("count2", count2);
        jsonObject.put("count3", count3);
        return new Result(ResultCode.SUCCESS, jsonObject);
    }
}
