金蝶预算查看、预算返还、预算扣减功能实现类原创
金蝶云社区-飞天
飞天
3人赞赏了该文章 448次浏览 未经作者许可,禁止转载编辑于2020年12月15日 10:02:00
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.bos.webframework.exception.WafException;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.cp.bc.util.NBgControlCallerUtil;

/**
 * 预算功能实现类
 */
public class GetBudgetFacadeControllerBean extends AbstractGetBudgetFacadeControllerBean
{
    
    /**
     * 根据model获取预算
     * @param ctx
     * @param model
     * @return
     * @throws BOSException
     * @throws EASBizException
     */
    @Override
    public Map _getBudget(Context ctx, IObjectValue model) throws BOSException,EASBizException {
        Map map = new HashMap();
        if(model!=null){
            List BgCtrlResult = NBgControlCallerUtil.getBalance(ctx,model);
            if (BgCtrlResult != null) {
                 int i = 0; for (int n = BgCtrlResult.size(); i < n; ++i) {
                     String[] al = (String[])BgCtrlResult.get(i);
                     map.put("bgItem",al[0]);//预算申请项目
                     map.put("orgUnit",al[1]);//组织
                     map.put("element",al[2]);//要素
                     map.put("period",al[3]);//预算期间            
                     map.put("budget",al[4]);//本期预算额        
                     map.put("actual",al[5]);//实际发生额        
                     map.put("balance",al[6]);//可用预算        
                 }
            }
        }
        return map;
    }
    
    /**
     * 根据id返还预算
     * @param ctx
     * @param id
     * @return
     * @throws BOSException
     */
    @Override
    public boolean returnBudget(Context ctx, BOSUuid id) throws BOSException {
        boolean returnBudget = false;
        try {
            if(id!=null){
                           // 注意事项:
                // 根据业务场景选择调用时机,如单据在【反审批、作废、删除】等操作之前进行调用
                // 即使该单据以前没有扣减过预算,那末调用该方法也不会引发数据问题
                IControlResult returnResult = NBgControlCallerUtil.returnBudget(ctx, id);
                if(returnResult!=null){
                    returnBudget = true;
                }
            }
        } catch (EASBizException e) {
            e.printStackTrace();
                   throw new BOSException(e.getMessage());
        }
        return returnBudget;
    }
    
    /**
     * 根据id扣减预算
     * @param ctx
     * @param uuid
     * @return
     * @throws BOSException
     */
    @Override
    protected boolean _requestBudget(Context ctx, BOSUuid uuid)
            throws BOSException {
        boolean request =false;
        try {
            if(uuid!=null){
                request = NBgControlCallerUtil.requestBudget(ctx, uuid);
            }        
        } catch (EASBizException e) {
            e.printStackTrace();
            throw new BOSException(e.getMessage());
        }
        return request;
    }
    
}
赞 3