package com.kingdee.shr.ats.web.util.io;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.eas.hr.ats.*;
import com.kingdee.eas.hr.ats.util.AtsDateUtils;
import com.kingdee.eas.hr.ats.util.common.AtsCollectionUtile;
import com.kingdee.shr.base.syssetting.app.io.fileImport.BaseRowInfo;
import com.kingdee.shr.base.syssetting.app.io.fileImport.ImportException;

import java.util.Date;

/**fillcard
 * description: FillCardFileNewServiceEx <br>
 * date: 2025/6/30 11:03 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
public class FillCardFileNewServiceEx extends FillCardFileNewService {

    public void importRow(BaseRowInfo row) throws ImportException {
        super.importRow(row);
        try {
            CoreBaseCollection insertColls1 = this.insertColls;
            CoreBaseCollection punchColls1 = this.punchColls;
            CoreBaseCollection insertCollsTemp1 = this.insertCollsTemp;
            FillSignCardInfo fillSignCardInfo1 = this.fillSignCardInfo;
            System.out.println("FillCardFileNewServiceEx:insertColls1->" + insertColls1.size());
            IFillSignCard fillSignCard = FillSignCardFactory.getLocalInstance(this.getContext());
            IFillSignCardEntry fillSignCardEntry = FillSignCardEntryFactory.getLocalInstance(this.getContext());
            for (int i = 0; i < insertColls1.size(); i++) {
                FillSignCardInfo cardInfo = (FillSignCardInfo) insertColls1.get(i);
                CoreBaseCollection collection = new CoreBaseCollection();
                collection.add(cardInfo);
                fillSignCard.saveBatchData(collection);
                fillSignCardEntry.saveBatchData(AtsCollectionUtile.toCoreCollection(cardInfo.getEntries()));
            }
            System.out.println("FillCardFileNewServiceEx:punchColls1->" + punchColls1.size());
            System.out.println("FillCardFileNewServiceEx:insertCollsTemp1->" + insertCollsTemp1.size());
            System.out.println("FillCardFileNewServiceEx:fillSignCardInfo1->" + fillSignCardInfo1.size());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public AttencePolicyInfo getAttencePolicyInfo(Context ctx, AttendanceFileHISInfo atsFileHis, String personID, Date attendDate) {
        AttencePolicyInfo attencePolicyInfo = null;
        AttendanceFileHISInfo atsFileHisPre = null;
        String attencePolicyId;
        if (atsFileHis == null) {
            try {
                String attendDateStr =  AtsDateUtils.dateShortToString(attendDate);
                attencePolicyId =  "{ts '" + attendDateStr + " 00:00:00'}";
                String PredateStr = "{ts '" + AtsDateUtils.getPreDay(attendDateStr) + " 00:00:00'}";
                atsFileHis = AttendanceFileHISFactory.getLocalInstance(this.getContext()).getAttendanceFileHISInfo(" where proposer.id = '" + personID + "' and effdt <= " + attencePolicyId + "and leffdt >= " + attencePolicyId + " ");
                atsFileHisPre = AttendanceFileHISFactory.getLocalInstance(this.getContext()).getAttendanceFileHISInfo(" where proposer.id = '" + personID + "' and effdt <= " + PredateStr + "and leffdt >= " + PredateStr + " ");
            } catch (EASBizException var11) {
                var11.printStackTrace();
            } catch (BOSException var12) {
                var12.printStackTrace();
            }
        }

        if (null == atsFileHis && atsFileHisPre != null) {
            atsFileHis = atsFileHisPre;
        }

        if (atsFileHis != null && atsFileHis.getAttencePolicy() != null) {
            attencePolicyId = atsFileHis.getAttencePolicy().getId().toString();

            try {
                attencePolicyInfo = AttencePolicyFactory.getLocalInstance(this.getContext()).getAttencePolicyInfo(new ObjectUuidPK(attencePolicyId));
            } catch (EASBizException var9) {
                var9.printStackTrace();
            } catch (BOSException var10) {
                var10.printStackTrace();
            }
        }

        return attencePolicyInfo;
    }
}
