package com.emr.service.ipml;

import com.emr.dao.Archive_MasterMapper;
import com.emr.dao.TempMasterIDMapper;
import com.emr.entity.Archive_Master;
import com.emr.entity.TempMasterID;
import com.emr.entity.TempMasterIDExample;
import com.emr.service.TempMasterIDService;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TempMasterIDServiceImpl implements TempMasterIDService {
    @Autowired
    private TempMasterIDMapper tempMasterIDMapper;
    @Autowired
    private Archive_MasterMapper archive_masterMapper;
    @Value("${HomepageDictionary}")
    private String HomepageDictionary;
    @Value("${HomepageMethod}")
    private String HomepageMethod;


    @Override
    public int insert(TempMasterID record) {
        return tempMasterIDMapper.insert(record);
    }

    @Override
    public int insertSelective(TempMasterID record) {
        return tempMasterIDMapper.insertSelective(record);
    }

    @Override
    public List<TempMasterID> selectAllMasterID() {
        return tempMasterIDMapper.selectByExample(new TempMasterIDExample());
    }

    @Override
    public int reloadWz(String masterId) {
        String result = "";
        int rows = 0;
        Archive_Master archive_master = new Archive_Master();
        try {
            String endpoint = HomepageDictionary;
            String method = HomepageMethod;
            JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
            Client client = factory.createClient(endpoint);
            Object[] res = null;
            res = client.invoke(method, masterId);
            result = (String) res[0];

            //修改lockinfo
            archive_master.setId(masterId);
            archive_master.setLockinfo(result);

            rows = archive_masterMapper.updateByClo(archive_master);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
        return rows;
    }
}
