package cn.com.ty.lift.ud.operation.service.impl;

import cn.com.ty.lift.ud.common.NotExamineDto;
import cn.com.ty.lift.ud.operation.mapper.VipPrerogativeMapper;
import cn.com.ty.lift.ud.operation.mapper.entity.VipPrerogativeEntity;
import cn.com.ty.lift.ud.operation.service.IVipPrerogativeService;
import cn.com.xwy.boot.web.dto.RestResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 会员特权 -ServiceImpl
 *
 * @author Xson
 * @date 2020-05-04
 */
@Service
@Transactional
public class VipPrerogativeServiceImpl extends ServiceImpl<VipPrerogativeMapper, VipPrerogativeEntity>
        implements IVipPrerogativeService {

    public static final int EXAMINEFLAG = 1;

    @Autowired
    private VipPrerogativeMapper vipPrerogativeMapper;

    /**
     * 审批
     *
     * @param neDto
     * @return
     */
    @Override
    public RestResponse examineById(NotExamineDto neDto) {
        if (EXAMINEFLAG == neDto.getExamineFlag()) {
            vipPrerogativeMapper.examineById(neDto.getId());
            return RestResponse.success(null, "审批通过");
        } else {
            //修改状态为 驳回，并加上驳回理由
            vipPrerogativeMapper.updateInfoById(neDto.getId(), neDto.getNotExamineReason());
            return RestResponse.fail(null, "审批驳回");
        }
    }

    /**
     * 提交操作
     *
     * @param id
     * @return
     */
    @Override
    public RestResponse submit(Long id) {
        int submit = vipPrerogativeMapper.submit(id);
        if (submit == 1) {
            return RestResponse.success(null, "提交成功");
        } else {
            return RestResponse.fail(null, "提交失败");
        }
    }

    /**
     * 新增提交
     *
     * @param entity
     * @return
     */
    @Override
    public RestResponse<VipPrerogativeEntity> create(VipPrerogativeEntity entity) {
        Long id = entity.getId();
        if (null == id) {
            //直接点的提交按钮
            entity.setExamineFlag(0);
            int insert = vipPrerogativeMapper.insert(entity);
            if (insert == 1) {
                return RestResponse.success(null, "新建成功");
            } else {
                return RestResponse.fail("新建失败");
            }
        } else {
            //先保存再提交,修改状态为未审核 0
            return submit(id);
        }
    }

}
