package com.kingdee.eas.custom.expandassess.hadler;

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.custom.expandassess.*;
import com.kingdee.eas.custom.expandassess.app.PeriodStatusEnum;
import com.kingdee.eas.framework.CoreBaseInfo;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.shr.base.syssetting.web.handler.EditHandler;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import org.springframework.ui.ModelMap;

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

/**
 * @author qingwu
 * @date 2024/5/15
 * @apiNote
 */
public class ExpandAssessListHandler extends ListHandler {
    private Context ctx = SHRContext.getInstance().getContext();

    @Override
    public String deleteAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        try {
            IExpandAssess iExpandAssess = ExpandAssessFactory.getLocalInstance(ctx);
            String billId = this.getBillId(request);
            String[] ids = billId.split(",");
            for (int i = 0; i < ids.length; i++) {
                String id = ids[i];
                ExpandAssessCollection expandAssessCollection = iExpandAssess.getExpandAssessCollection("where id = '" + id + "'");
                if (expandAssessCollection.size() > 0) {
                    ExpandAssessInfo expandAssessInfo = expandAssessCollection.get(0);
                    if (expandAssessInfo.getPeriodStatus() == PeriodStatusEnum.LOCK) {
                        throw new ShrWebBizException("周期已被锁定不可删除！");
                    }
                }
            }
        } catch (BOSException e) {
            e.printStackTrace();
            throw new ShrWebBizException(e);
        }
        return super.deleteAction(request, response, modelMap);
    }
}
