package com.brilliance.isc.common.api.nid.service.Impl;

import com.brilliance.isc.bo.Nid;
import com.brilliance.isc.bo.Trn;
import com.brilliance.isc.common.api.nid.service.NidService;
import com.brilliance.isc.mda.dao.NidMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NidServiceImpl implements NidService {
    @Autowired
    private NidMapper nidMapper;

    @Override
    public int updateOpnstaOrAmesta(Trn trn) {
        if(trn!=null&&trn.getInifrm()!=null&&"NID".equals(trn.getObjtyp().toUpperCase())){
            if("hitame".equals(trn.getInifrm().toLowerCase())){
                Nid nid = nidMapper.selectByInr(trn.getObjinr());
                if(nid!=null){
                    //重开立，设置opnsta为R
                    if("P".equals(nid.getOpnsta())){
                        return nidMapper.updateOpnstaByinr("R",trn.getObjinr());
                    }
                    // 正常修改，设置amesta为R
                    if("S".equals(nid.getOpnsta())&&"P".equals(nid.getAmesta())){
                        return nidMapper.updateAmestaByinr("R",trn.getObjinr());
                    }
                }
            }
        }
        return 0;
    }
}
