package com.sa.ibiz.demo.demo.logic.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.mapper.OrgUserMapper;
import com.sa.ibiz.demo.demo.domain.OrgUser;
import com.sa.ibiz.demo.demo.service.OrgUserService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.OrgUserSearchFilter;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.UUID;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.BigInteger;
import com.sa.ibiz.demo.ibizutil.annotation.PreField;
import java.lang.reflect.Field;
import org.kie.api.runtime.KieSession;
import com.sa.ibiz.demo.demo.logic.OrgUserLogic;
import java.util.HashMap;
import org.kie.api.runtime.KieContainer;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.aspectj.lang.annotation.Aspect;
/**
 * 实体[OrgUser] 处理逻辑接口实现
 */
@Service
public class OrgUserLogicImpl  implements  OrgUserLogic{

    @Aspect
    @org.springframework.core.annotation.Order(0)
    @Service
    class OrguserExecuteUpdaterelatedinfoAfterUpdate{
         @org.aspectj.lang.annotation.After(value = "execution(* com.sa.ibiz.demo.*.service.OrgUserService.update(..))")
          void execute(org.aspectj.lang.JoinPoint point) throws Exception {
             OrgUserLogicImpl.this.ExecuteDELogic(point,"updateRelatedInfo");
        }
    }
    @Aspect
    @org.springframework.core.annotation.Order(0)
    @Service
    class OrguserExecuteCreaterelatedinfoAfterCreate{
         @org.aspectj.lang.annotation.After(value = "execution(* com.sa.ibiz.demo.*.service.OrgUserService.create(..))")
          void execute(org.aspectj.lang.JoinPoint point) throws Exception {
             OrgUserLogicImpl.this.ExecuteDELogic(point,"createRelatedInfo");
        }
    }
    /**
     * 执行处理逻辑
     * @param point
     * @param LogicName
     * @throws Exception
     */
    public void ExecuteDELogic(org.aspectj.lang.JoinPoint point,String LogicName) throws Exception {
        Object [] args = point.getArgs();
        Object obj =args[0];
        if (obj instanceof OrgUser){
            OrgUser entity = (OrgUser) obj;
            java.lang.reflect.Method method = this.getClass().getMethod(LogicName,OrgUser.class);
            method.invoke(this,entity);
        }
    }

    @Autowired
    private KieContainer kieContainer;

    @Autowired
    private com.sa.ibiz.demo.demo.service.OrgUserService orguserservice;
    @Autowired
    private com.sa.ibiz.demo.demo.service.UserService userservice;
    @Autowired
    private com.sa.ibiz.demo.demo.service.UserDictService userdictservice;
    @Autowired
    private com.sa.ibiz.demo.demo.service.OrgUserService iBzSysDefaultService;

	public boolean getCurUser(OrgUser et){
           KieSession kieSession = null;
        try{
           kieSession=kieContainer.newKieSession();
           kieSession.insert(et); 
           kieSession.setGlobal("orgusergetcuruserdefault",et);
           kieSession.setGlobal("orguserservice",orguserservice);
           kieSession.setGlobal("iBzSysDefaultService",iBzSysDefaultService);
           kieSession.startProcess("com.sa.ibiz.demo.demo.logic.orguserlogic.getcuruser");

        }catch(Exception e){
            throw new BadRequestAlertException("执行[获取当前用户]处理逻辑发生异常"+e,"","");
        }finally {
            if(kieSession!=null)
            kieSession.destroy();
        }
            return true;
    }
	public boolean createRelatedInfo(OrgUser et){
           KieSession kieSession = null;
        try{
           kieSession=kieContainer.newKieSession();
           com.sa.ibiz.demo.demo.domain.UserDict  orgusercreaterelatedinfouserdict =new com.sa.ibiz.demo.demo.domain.UserDict();
           kieSession.insert(orgusercreaterelatedinfouserdict); 
           kieSession.setGlobal("orgusercreaterelatedinfouserdict",orgusercreaterelatedinfouserdict);
           kieSession.insert(et); 
           kieSession.setGlobal("orgusercreaterelatedinfodefault",et);
           com.sa.ibiz.demo.demo.domain.User  orgusercreaterelatedinfouser =new com.sa.ibiz.demo.demo.domain.User();
           kieSession.insert(orgusercreaterelatedinfouser); 
           kieSession.setGlobal("orgusercreaterelatedinfouser",orgusercreaterelatedinfouser);
           kieSession.setGlobal("userservice",userservice);
           kieSession.setGlobal("userdictservice",userdictservice);
           kieSession.setGlobal("iBzSysDefaultService",iBzSysDefaultService);
           kieSession.startProcess("com.sa.ibiz.demo.demo.logic.orguserlogic.createrelatedinfo");

        }catch(Exception e){
            throw new BadRequestAlertException("执行[建立关联信息]处理逻辑发生异常"+e,"","");
        }finally {
            if(kieSession!=null)
            kieSession.destroy();
        }
            return true;
    }
	public boolean updateRelatedInfo(OrgUser et){
           KieSession kieSession = null;
        try{
           kieSession=kieContainer.newKieSession();
           com.sa.ibiz.demo.demo.domain.User  orguserupdaterelatedinfouser =new com.sa.ibiz.demo.demo.domain.User();
           kieSession.insert(orguserupdaterelatedinfouser); 
           kieSession.setGlobal("orguserupdaterelatedinfouser",orguserupdaterelatedinfouser);
           kieSession.insert(et); 
           kieSession.setGlobal("orguserupdaterelatedinfodefault",et);
           kieSession.setGlobal("userservice",userservice);
           kieSession.setGlobal("iBzSysDefaultService",iBzSysDefaultService);
           kieSession.startProcess("com.sa.ibiz.demo.demo.logic.orguserlogic.updaterelatedinfo");

        }catch(Exception e){
            throw new BadRequestAlertException("执行[更新关联信息]处理逻辑发生异常"+e,"","");
        }finally {
            if(kieSession!=null)
            kieSession.destroy();
        }
            return true;
    }
	public boolean updateCurUser(OrgUser et){
           KieSession kieSession = null;
        try{
           kieSession=kieContainer.newKieSession();
           kieSession.insert(et); 
           kieSession.setGlobal("orguserupdatecuruserdefault",et);
           kieSession.setGlobal("orguserservice",orguserservice);
           kieSession.setGlobal("iBzSysDefaultService",iBzSysDefaultService);
           kieSession.startProcess("com.sa.ibiz.demo.demo.logic.orguserlogic.updatecuruser");

        }catch(Exception e){
            throw new BadRequestAlertException("执行[更新当前用户]处理逻辑发生异常"+e,"","");
        }finally {
            if(kieSession!=null)
            kieSession.destroy();
        }
            return true;
    }

}