package com.mortals.xhx.module.matter.service.impl;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.matter.dao.MatterSetbaseDao;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.model.MatterSetbaseEntity;
import com.mortals.xhx.module.matter.service.MatterService;
import com.mortals.xhx.module.matter.service.MatterSetbaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

/**
* MatterSetbaseService
* 事项设定依据 service实现
*
* @author zxfei
* @date 2022-01-12
*/
@Service("matterSetbaseService")
public class MatterSetbaseServiceImpl extends AbstractCRUDServiceImpl<MatterSetbaseDao, MatterSetbaseEntity, Long> implements MatterSetbaseService {

    @Autowired
    private MatterService matterService;


    @Override
    protected void saveBefore(MatterSetbaseEntity entity, Context context) throws AppException {

        if(!ObjectUtils.isEmpty(entity.getMatterId())){
            MatterEntity matterEntity = matterService.get(entity.getMatterId());
            entity.setMatterName(matterEntity==null?"":matterEntity.getMatterName());
        }
        super.saveBefore(entity, context);
    }

    @Override
    public void deleteByMatterId(Long matterId, Context context) {
        Map<String, Object> condition = new HashMap<>();
        condition.put("matterId", matterId);
        this.dao.delete(condition);
    }
}