package com.sqx.modules.bl.commission.fxy.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.fxy.dao.FxyApplyDao;
import com.sqx.modules.bl.commission.fxy.entity.FxyApply;
import com.sqx.modules.bl.commission.fxy.service.FxyApplyService;
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 FxyApplyServiceImpl extends ServiceImpl<FxyApplyDao, FxyApply> implements FxyApplyService {

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

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

    @Override
    public int update(FxyApply fxyApply){
        return baseMapper.update(fxyApply);
    }

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

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