package com.sqx.modules.bl.commission.ywy.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.bl.commission.ywy.dao.YwyApplyDao;
import com.sqx.modules.bl.commission.ywy.entity.YwyApply;
import com.sqx.modules.bl.commission.ywy.service.YwyApplyService;
import com.sqx.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class YwyApplyServiceImpl extends ServiceImpl<YwyApplyDao, YwyApply> implements YwyApplyService {

    @Override
    public Result findPage(YwyApply ywyApply){
        Page<YwyApply> pages=new Page<>(ywyApply.getPage(),ywyApply.getLimit());
        return Result.success().put("data",new PageUtils(baseMapper.findPage(pages,ywyApply)));
    }

    @Override
    public int add(YwyApply ywyApply){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ywyApply.setCreateTime(sdf.format(new Date()));
        ywyApply.setStatus(0);
        return baseMapper.add(ywyApply);
    }

    @Override
    public int update(YwyApply ywyApply){
        return baseMapper.update(ywyApply);
    }

    @Override
    public int approve(YwyApply ywyApply){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ywyApply.setApproveTime(sdf.format(new Date()));
        ywyApply.setApproveUser(((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUserId());
        return baseMapper.approve(ywyApply);
    }

    @Override
    public Result findUserPage(YwyApply ywyApply){
        Page<YwyApply> pages=new Page<>(ywyApply.getUserPage(),ywyApply.getUserLimit());
        return Result.success().put("data",new PageUtils(baseMapper.findUserPage(pages,ywyApply)));
    }

}