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.UserMapper;
import com.sa.ibiz.demo.demo.domain.User;
import com.sa.ibiz.demo.demo.service.UserService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.UserSearchFilter;
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.UserLogic;
import java.util.HashMap;
import org.kie.api.runtime.KieContainer;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.aspectj.lang.annotation.Aspect;
/**
 * 实体[User] 处理逻辑接口实现
 */
@Service
public class UserLogicImpl  implements  UserLogic{

    @Aspect
    @org.springframework.core.annotation.Order(0)
    @Service
    class UserExecuteCreaterelatedinfoAfterUpdate{
         @org.aspectj.lang.annotation.After(value = "execution(* com.sa.ibiz.demo.*.service.UserService.update(..))")
          void execute(org.aspectj.lang.JoinPoint point) throws Exception {
             UserLogicImpl.this.ExecuteDELogic(point,"createRelatedInfo");
        }
    }
    @Aspect
    @org.springframework.core.annotation.Order(0)
    @Service
    class UserExecuteCreaterelatedinfoAfterCreate{
         @org.aspectj.lang.annotation.After(value = "execution(* com.sa.ibiz.demo.*.service.UserService.create(..))")
          void execute(org.aspectj.lang.JoinPoint point) throws Exception {
             UserLogicImpl.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 User){
            User entity = (User) obj;
            java.lang.reflect.Method method = this.getClass().getMethod(LogicName,User.class);
            method.invoke(this,entity);
        }
    }

    @Autowired
    private KieContainer kieContainer;

    @Autowired
    private com.sa.ibiz.demo.demo.service.MsgAccountService msgaccountservice;
    @Autowired
    private com.sa.ibiz.demo.demo.service.WFUserService wfuserservice;
    @Autowired
    private com.sa.ibiz.demo.demo.service.UserService iBzSysDefaultService;

	public boolean createRelatedInfo(User et){
           KieSession kieSession = null;
        try{
           kieSession=kieContainer.newKieSession();
           com.sa.ibiz.demo.demo.domain.WFUser  usercreaterelatedinfowfuser =new com.sa.ibiz.demo.demo.domain.WFUser();
           kieSession.insert(usercreaterelatedinfowfuser); 
           kieSession.setGlobal("usercreaterelatedinfowfuser",usercreaterelatedinfowfuser);
           com.sa.ibiz.demo.demo.domain.MsgAccount  usercreaterelatedinfomsgaccount =new com.sa.ibiz.demo.demo.domain.MsgAccount();
           kieSession.insert(usercreaterelatedinfomsgaccount); 
           kieSession.setGlobal("usercreaterelatedinfomsgaccount",usercreaterelatedinfomsgaccount);
           kieSession.insert(et); 
           kieSession.setGlobal("usercreaterelatedinfodefault",et);
           kieSession.setGlobal("msgaccountservice",msgaccountservice);
           kieSession.setGlobal("wfuserservice",wfuserservice);
           kieSession.setGlobal("iBzSysDefaultService",iBzSysDefaultService);
           kieSession.startProcess("com.sa.ibiz.demo.demo.logic.userlogic.createrelatedinfo");

        }catch(Exception e){
            throw new BadRequestAlertException("执行[建立用户相关信息]处理逻辑发生异常"+e,"","");
        }finally {
            if(kieSession!=null)
            kieSession.destroy();
        }
            return true;
    }

}