package com.dxhy.jxpt.baseService.sign.service.singletable.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dxhy.common.enums.FplxEnum;
import com.dxhy.common.enums.QsfsEnum;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.jxpt.baseService.sign.dao.SignInvoiceDao;
import com.dxhy.api.model.sign.TDxInvoice;
import com.dxhy.api.model.sign.QsInvoiceCount;
import com.dxhy.jxpt.baseService.sign.service.singletable.SignInvoiceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

/**
 *
 * 发票扫描表业务处理实现类
 *
 * @author ld
 */
@Service("signInvoiceService")
@Slf4j

public class SignInvoiceServiceImpl extends MpBaseServiceImpl<SignInvoiceDao, TDxInvoice>
    implements SignInvoiceService {

    @Override
    public void delByUuid(String uuid, String userid) {
        TDxInvoice dxInvoice = new TDxInvoice();
        dxInvoice.setValid("0");
        QueryWrapper<TDxInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uuid", uuid);
        queryWrapper.eq("user_account", userid);
        super.remove(queryWrapper);
    }

    @Override
    public List<TDxInvoice> selectQsfpList(Map<String, Object> pramsMap) {
        return super.baseMapper.selectQsfpList(pramsMap);
    }

    @Override
    public String requestValidate(String uuid, String userid, String del) {
        String msg = null;
        QueryWrapper<TDxInvoice> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uuid", uuid);
        queryWrapper.eq("user_account", userid);
        TDxInvoice qsInfo = super.getOne(queryWrapper);
        // 二次签收操作
        if (del == null) {
            if (qsInfo == null) {
                msg = "请求不合法！";
            } else {
                String qsType = qsInfo.getQsType();
                String invoiceType = qsInfo.getInvoiceType();
                if (QsfsEnum.PDFQS.getQsfsDm().equals(qsType) || QsfsEnum.SMQS.getQsfsDm().equals(qsType)) {
                    if (FplxEnum.DZP.getFplxDm().equals(invoiceType) || FplxEnum.PP.getFplxDm().equals(invoiceType)
                        || FplxEnum.JSP.getFplxDm().equals(invoiceType)) {
                        msg = null;
                    } else {
                        msg = "仅" + FplxEnum.PP.getFplxMc(FplxEnum.PP.getIndex()) + "、"
                            + FplxEnum.DZP.getFplxMc(FplxEnum.DZP.getIndex()) + "、"
                            + FplxEnum.JSP.getFplxMc(FplxEnum.JSP.getIndex()) + "可以进行二次签收！";
                    }
                } else if (QsfsEnum.SMYQS.getQsfsDm().equals(qsType)) {
                    msg = null;
                } else {
                    msg = "仅" + QsfsEnum.SMQS.getQsfsMc(QsfsEnum.SMQS.getIndex()) + "、"
                        + QsfsEnum.SMYQS.getQsfsMc(QsfsEnum.SMYQS.getIndex()) + "、"
                        + QsfsEnum.PDFQS.getQsfsMc(QsfsEnum.PDFQS.getIndex()) + "可以进行二次签收！";
                }
            }
        } else {
            if (qsInfo == null) {
                msg = "您无权操作的发票！";
            }
        }

        return msg;
    }

    @Override
    public QsInvoiceCount selectQsfpListCount(Map<String, Object> pramsMap) {
        return baseMapper.selectQsfpListCount(pramsMap);
    }

    @Override
    public List<TDxInvoice> selectQsfpListMryx(Map<String, Object> pramsMap) {
        return super.baseMapper.selectQsfpListMryx(pramsMap);
    }

    @Override
    public QsInvoiceCount selectQsfpListCountMryx(Map<String, Object> pramsMap) {
        return baseMapper.selectQsfpListCountMryx(pramsMap);
    }
}
