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.PPModelMapper;
import com.sa.ibiz.demo.demo.domain.PPModel;
import com.sa.ibiz.demo.demo.service.PPModelService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.PPModelSearchFilter;
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.PortalPageService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;
import com.sa.ibiz.demo.demo.service.PVPartService;

/**
 * 实体[PPModel] 服务对象接口实现
 */
@Service
public class PPModelServiceImpl extends ServiceImplBase<PPModelMapper, PPModel> implements PPModelService{

    @Autowired
    private PortalPageService portalpageService;
    @Autowired
    private PVPartService c1pvpartService;
    @Autowired
    private PVPartService c2pvpartService;
    @Autowired
    private PVPartService c3pvpartService;
    @Autowired
    private PVPartService c4pvpartService;
    @Autowired
    private PVPartService l1pvpartService;
    @Autowired
    private PVPartService l2pvpartService;
    @Autowired
    private PVPartService l3pvpartService;
    @Autowired
    private PVPartService l4pvpartService;
    @Autowired
    private PVPartService r1pvpartService;
    @Autowired
    private PVPartService r2pvpartService;
    @Autowired
    private PVPartService r3pvpartService;
    @Autowired
    private PVPartService r4pvpartService;

    @Resource
    private PPModelMapper ppmodelMapper;


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

    @Override
   	public boolean remove(PPModel et) {
        String primaryKey=et.getPpmodelid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setPpmodelid(primaryKey);
          }
   		     return super.remove(et);
   	}

    @Override
    public boolean update(PPModel et){
        String primaryKey=et.getPpmodelid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setPpmodelid(primaryKey);
          }
		     this.ppmodelMapper.updateOne(et);
		     this.get(et);
             return true;
    }


    public Object getEntityKey(PPModel et){
		return et.getPpmodelid();  
    }

    @Override
    public boolean getDraft(PPModel et)  {
    if((!StringUtils.isEmpty(et.getPortalpageid())) && et.getPortalpage() == null){
            try {
                et.setPortalpage(portalpageService.getById(et.getPortalpageid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getC1pvpartid())) && et.getC1pvpart() == null){
            try {
                et.setC1pvpart(c1pvpartService.getById(et.getC1pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getC2pvpartid())) && et.getC2pvpart() == null){
            try {
                et.setC2pvpart(c2pvpartService.getById(et.getC2pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getC3pvpartid())) && et.getC3pvpart() == null){
            try {
                et.setC3pvpart(c3pvpartService.getById(et.getC3pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getC4pvpartid())) && et.getC4pvpart() == null){
            try {
                et.setC4pvpart(c4pvpartService.getById(et.getC4pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getL1pvpartid())) && et.getL1pvpart() == null){
            try {
                et.setL1pvpart(l1pvpartService.getById(et.getL1pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getL2pvpartid())) && et.getL2pvpart() == null){
            try {
                et.setL2pvpart(l2pvpartService.getById(et.getL2pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getL3pvpartid())) && et.getL3pvpart() == null){
            try {
                et.setL3pvpart(l3pvpartService.getById(et.getL3pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getL4pvpartid())) && et.getL4pvpart() == null){
            try {
                et.setL4pvpart(l4pvpartService.getById(et.getL4pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getR1pvpartid())) && et.getR1pvpart() == null){
            try {
                et.setR1pvpart(r1pvpartService.getById(et.getR1pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getR2pvpartid())) && et.getR2pvpart() == null){
            try {
                et.setR2pvpart(r2pvpartService.getById(et.getR2pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getR3pvpartid())) && et.getR3pvpart() == null){
            try {
                et.setR3pvpart(r3pvpartService.getById(et.getR3pvpartid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getR4pvpartid())) && et.getR4pvpart() == null){
            try {
                et.setR4pvpart(r4pvpartService.getById(et.getR4pvpartid()));
            }catch (Exception ex){}
        }
            return true;
    }

	public List<PPModel> listDefault(PPModelSearchFilter filter) {
		return ppmodelMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<PPModel> searchDefault(PPModelSearchFilter filter) {
		return ppmodelMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }