package com.aucma.api.service.impl;

import com.aucma.api.domain.dto.RepairSubmitInfoDto;
import com.aucma.api.mapper.PdaBindingMapper;
import com.aucma.api.service.IPdaBindingService;
import com.aucma.common.utils.StringUtils;
import com.aucma.report.domain.ReportQualityInspection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author wanghao
 * @date 2023/11/14  9:56
 */
@Service
public class PdaServiceImpl implements IPdaBindingService {
    @Autowired
    private PdaBindingMapper mapper;

    @Override
    public String selectBoxNameByCode(String boxCode) {

        return mapper.selectBoxNameByCode(boxCode.substring(7,17));
    }

    @Override
    public int insertBindingInfo(String boxCode, String boxName, String innerCode) {
        return mapper.insertBindingInfo(boxCode,boxName,innerCode);
    }

    @Override
    public int countQualityRecordByCode(String code) {
        return mapper.countQualityRecordByCode(code);
    }

    @Override
    public int updateCodeBinding(String boxCode, String innerCode) {
        return mapper.updateCodeBinding(boxCode,innerCode);
    }

    @Override
    public int submitRepair(RepairSubmitInfoDto info) {
        return mapper.submitRepair(info);
    }

    @Override
    public List<ReportQualityInspection> findCheckInfoByCode(String code) {
        return mapper.findCheckInfoByCode(code);
    }

    @Override
    public List<ReportQualityInspection> checkSelectRepairInfo(String code) {
        return mapper.checkSelectRepairInfo(code);
    }

    /**
     * PDA补打条码
     * @param barCode
     * @return
     */
    @Override
    public String rebarCode(String barCode) {
        String result = null;
        if (StringUtils.isEmpty(barCode)){
            return null;
        }
        List<HashMap<String, String>> barcodeList = mapper.selectPrintBarcode(barCode);
        if (barcodeList.size() > 0){
            //  维护条码补打记录表
            mapper.printSupplementBarcode(barcodeList.get(0));
            result = "请到条码打印机旁进行补打条码！";
        }
        return result;
    }

    /**
     * PDA解绑条码
     * @param  barCode
     * @return
     */
    @Override
    public String unbindBarCode(String barCode) {
        String result = null;
        if (StringUtils.isEmpty(barCode)){
            return null;
        }
        List<HashMap<String, String>> barcodeList = mapper.selectPrintBarcode(barCode);
        if (barcodeList.size() > 0){
            mapper.unbindBarCode(barCode);
            result = "解绑条码成功！";
        }
        return result;
    }

}
