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.WFStepInstMapper;
import com.sa.ibiz.demo.demo.domain.WFStepInst;
import com.sa.ibiz.demo.demo.service.WFStepInstService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.WFStepInstSearchFilter;
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.WFInstanceService;
import com.sa.ibiz.demo.demo.service.WFStepService;

/**
 * 实体[WFStepInst] 服务对象接口实现
 */
@Service
public class WFStepInstServiceImpl extends ServiceImplBase<WFStepInstMapper, WFStepInst> implements WFStepInstService{

    @Autowired
    private WFInstanceService wfinstanceService;
    @Autowired
    private WFStepService wfstepService;

    @Resource
    private WFStepInstMapper wfstepinstMapper;


    @Override
    public boolean create(WFStepInst et) {
        this.beforeCreate(et);
        String primaryKey=et.getWfstepinstid();
        if(StringUtils.isEmpty(primaryKey))
        {
            primaryKey=(String)et.getDefaultPrimaryKey();
            et.setWfstepinstid(primaryKey);
         }
         return super.create(et);
    }
    @Override
	public WFStepInst get(WFStepInst et) {
        String primaryKey=et.getWfstepinstid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setWfstepinstid(primaryKey);
          }
		      return super.get(et);
	}

    @Override
   	public boolean remove(WFStepInst et) {
        String primaryKey=et.getWfstepinstid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setWfstepinstid(primaryKey);
          }
   		     return super.remove(et);
   	}

    @Override
    public boolean update(WFStepInst et){
        String primaryKey=et.getWfstepinstid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setWfstepinstid(primaryKey);
          }
		     this.wfstepinstMapper.updateOne(et);
		     this.get(et);
             return true;
    }


    public Object getEntityKey(WFStepInst et){
		return et.getWfstepinstid();  
    }

    @Override
    public boolean getDraft(WFStepInst et)  {
    if((!StringUtils.isEmpty(et.getWfinstanceid())) && et.getWfinstance() == null){
            try {
                et.setWfinstance(wfinstanceService.getById(et.getWfinstanceid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getWfstepid())) && et.getWfstep() == null){
            try {
                et.setWfstep(wfstepService.getById(et.getWfstepid()));
            }catch (Exception ex){}
        }
            return true;
    }

	public List<WFStepInst> listDefault(WFStepInstSearchFilter filter) {
		return wfstepinstMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<WFStepInst> searchDefault(WFStepInstSearchFilter filter) {
		return wfstepinstMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }