package com.njyunzhi.pet_identity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njyunzhi.pet_identity.common.Constants;
import com.njyunzhi.pet_identity.entity.SysSetting;
import com.njyunzhi.pet_identity.entity.TaApplication;
import com.njyunzhi.pet_identity.mapper.SysSettingMapper;
import com.njyunzhi.pet_identity.mapper.TaApplicationMapper;
import com.njyunzhi.pet_identity.service.ITaApplicationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 我的申请 服务实现类
 * </p>
 *
 * @author yansen
 * @since 2022-05-24
 */
@Service
public class TaApplicationServiceImpl extends BaseServiceImpl<TaApplicationMapper, TaApplication> implements ITaApplicationService {

    @Autowired
    SysSettingMapper sysSettingMapper;

    @Override
    public int countBetween(LocalDateTime dayStart, LocalDateTime dayEnd) {
        QueryWrapper<TaApplication> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("create_date", dayStart);
        queryWrapper.le("create_date", dayEnd);
        queryWrapper.gt("status", Constants.STATUS_DELETE);

        return count(queryWrapper);
    }

    @Override
    public Integer getTotalCharge(TaApplication taApplication) {

        // 申领方式
        Integer applyMethod = taApplication.getApplyMethod();

        // 获取工本费
        SysSetting setting1 = sysSettingMapper.selectById(Constants.SYSSETTING_PRODUCTION_COST);
        int fee1 = (int) (Float.parseFloat(setting1.getContent().trim()) * 100);

        if (Constants.APPLY_METHOD_AUTO == taApplication.getApplyMethod()) return fee1;

        // 获取快递费
        SysSetting setting2 = sysSettingMapper.selectById(Constants.SYSSETTING_EXPRESS_FEE);
        int fee2 = (int) (Float.parseFloat(setting2.getContent().trim()) * 100);

        return fee1 + fee2;
    }
}
