package com.sa.ibiz.demo.demo.service.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.WFInstanceMapper;
import com.sa.ibiz.demo.demo.domain.WFInstance;
import com.sa.ibiz.demo.demo.service.WFInstanceService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.WFInstanceSearchFilter;
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 com.sa.ibiz.demo.demo.service.OrgService;
import com.sa.ibiz.demo.demo.service.WFInstanceService;
import com.sa.ibiz.demo.demo.service.WFWorkflowService;

/**
 * 实体[WFInstance] 服务对象接口实现
 */
@Service
public class WFInstanceServiceImpl extends ServiceImplBase<WFInstanceMapper, WFInstance> implements WFInstanceService{

    @Autowired
    private OrgService orgService;
    @Autowired
    private WFInstanceService pwfinstanceService;
    @Autowired
    private WFWorkflowService wfworkflowService;

    @Resource
    private WFInstanceMapper wfinstanceMapper;


    @Override
    public boolean create(WFInstance et) {
        this.beforeCreate(et);
         return super.create(et);
    }
    @Override
    public boolean update(WFInstance et){
        this.beforeUpdate(et);
		this.wfinstanceMapper.updateOne(et);
		this.get(et);
		return true;
    }

    public Object getEntityKey(WFInstance et){
		return et.getWfinstanceid();  
    }

    @Override
    public boolean getDraft(WFInstance et)  {
    if((!StringUtils.isEmpty(et.getOrgid())) && et.getOrg() == null){
            try {
                et.setOrg(orgService.getById(et.getOrgid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getPwfinstanceid())) && et.getPwfinstance() == null){
            try {
                et.setPwfinstance(pwfinstanceService.getById(et.getPwfinstanceid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getWfworkflowid())) && et.getWfworkflow() == null){
            try {
                et.setWfworkflow(wfworkflowService.getById(et.getWfworkflowid()));
            }catch (Exception ex){}
        }
            return true;
    }
    @Override
    public WFInstance userCancel(WFInstance et)  {
		return et;
    }
    @Override
    public WFInstance restart(WFInstance et)  {
		return et;
    }

	public List<WFInstance> listDefault(WFInstanceSearchFilter filter) {
		return wfinstanceMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<WFInstance> searchDefault(WFInstanceSearchFilter filter) {
		return wfinstanceMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}

    public  List<Map<String,Object>> selectRow(String sql){
       return wfinstanceMapper.selectRow(sql);
    }

 }