package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.fire.domain.DemNewAgreeUse;
import com.usky.fire.domain.DemNewDisagreeUse;
import com.usky.fire.domain.DemNewLaw;
import com.usky.fire.mapper.DemNewAgreeUseMapper;
import com.usky.fire.mapper.DemNewDisagreeUseMapper;
import com.usky.fire.mapper.DemNewLawMapper;
import com.usky.fire.service.DemNewLawService;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.fire.service.vo.AdLicenseStatisticVO;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 法律文书记录表 服务实现类
 * </p>
 *
 * @author han
 * @since 2023-10-11
 */
@Service
public class DemNewLawServiceImpl extends AbstractCrudService<DemNewLawMapper, DemNewLaw> implements DemNewLawService {
    @Autowired
    private DemNewAgreeUseMapper demNewAgreeUseMapper;

    @Autowired
    private DemNewDisagreeUseMapper demNewDisagreeUseMapper;

    @Override
    public AdLicenseStatisticVO adLicenseStatistic(){
        AdLicenseStatisticVO statisticVO = new AdLicenseStatisticVO();
        //承诺数
        LambdaQueryWrapper<DemNewLaw> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(DemNewLaw::getCheckType,"安全检查(承诺制)")
                .like(DemNewLaw::getDocumentTransmission,"安凭字〔2023〕");
        int committedCount = this.count(queryWrapper);
        //非承诺数
        LambdaQueryWrapper<DemNewLaw> queryWrapper1 = Wrappers.lambdaQuery();
        queryWrapper1.like(DemNewLaw::getCheckType,"安全检查（非承诺制）")
                .like(DemNewLaw::getDocumentTransmission,"安凭字〔2023〕");
        int uncommittedCount = this.count(queryWrapper1);
        //受理数
        int acceptCount = committedCount + uncommittedCount;
        statisticVO.setAcceptNum(acceptCount);
        statisticVO.setCommittedNum(committedCount);
        statisticVO.setUncommittedNum(uncommittedCount);
        //同意数
        LambdaQueryWrapper<DemNewAgreeUse> queryWrapper2 = Wrappers.lambdaQuery();
        queryWrapper2.like(DemNewAgreeUse::getDocument2,"安许")
            .eq(DemNewAgreeUse::getDeleteFlag,0);
        int agreeCount = demNewAgreeUseMapper.selectCount(queryWrapper2);
        //不同意数
        LambdaQueryWrapper<DemNewDisagreeUse> queryWrapper3 = Wrappers.lambdaQuery();
        queryWrapper3.like(DemNewDisagreeUse::getDocument2,"安许不")
                .eq(DemNewDisagreeUse::getDeleteFlag,0);
        int disagreeCount = demNewDisagreeUseMapper.selectCount(queryWrapper3);
        //检查数
        int checkCount = agreeCount + disagreeCount;
        //合格率
        double rate = (double)agreeCount/checkCount*100;
        statisticVO.setPassRate(rate);
        statisticVO.setCheckNum(checkCount);

        return statisticVO;
    }
}
