package com.kingdee.shr.customer.gtiit.handler;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.custom.erp.util.SynSalaryFromErpUtils;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import com.kingdee.shr.compensation.request.ParseRequestHelper;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * description: ERPManualLogListHandler <br>
 * date: 2025/3/24 11:50 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
public class ERPManualLogListHandler extends ListHandler {

    public void dataToERPAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
        Context ctx = SHRContext.getInstance().getContext();
        String taxPeriodDate = (String) ParseRequestHelper.getParameterByRequest(request, "taxPeriodDate");
        insertERPManualLog(ctx,taxPeriodDate);
        SynSalaryFromErpUtils.synSalaryToErp(ctx,taxPeriodDate);
    }

    protected void insertERPManualLog(Context ctx,String taxPeriodDate) throws BOSException {
        String userId =HRFilterUtils.getCurrentUserId(ctx);
        String personId =HRFilterUtils.getCurrentPersonId(ctx);
        StringBuilder builder = new StringBuilder();
        builder.append(" insert into CT_CUS_ERPManualLog ");
        builder.append(" ( ");
        builder.append(" fid,FCreatorID,FCreateTime, ");
        builder.append(" FLastUpdateUserID,FLastUpdateTime,FControlUnitID, ");
        builder.append(" FShrBasicItemID,FUsePolicy,FIsSysPreset, ");
        builder.append(" FState,FIndex,FHrOrgUnitId, ");
        builder.append(" CFMonth,CFTriggerPersonID ");
        builder.append(" ) values( ");
        builder.append(" newbosid('F82D1DA6'),?,sysdate, ");
        builder.append(" ?,sysdate,'00000000-0000-0000-0000-000000000000CCE7AED4', ");
        builder.append(" '','100','0', ");
        builder.append(" '1','1','00000000-0000-0000-0000-000000000000CCE7AED4', ");
        builder.append(" ?,? ");
        builder.append(" ) ");
        DbUtil.execute(ctx,builder.toString(),new String[]{userId,userId,taxPeriodDate,personId});
    }


}
