package ink.wgink.service.user.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.service.user.dao.IUserAdjustmentDao;
import ink.wgink.service.user.pojo.bos.UserAdjustmentBO;
import ink.wgink.service.user.pojo.dtos.UserLogDTO;
import ink.wgink.service.user.service.IUserAdjustmentService;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.util.map.HashMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: UserAdjustmentServiceImpl
 * @Description: 用户调整
 * @Author: wanggeng
 * @Date: 2021/2/12 3:39 下午
 * @Version: 1.0
 */
@Service
public class UserAdjustmentServiceImpl extends DefaultBaseService implements IUserAdjustmentService {

    @Autowired
    private IUserAdjustmentDao userAdjustmentDao;

    @Override
    public void save(UserAdjustmentBO userAdjustmentBO) {
        Map<String, Object> params = HashMapUtil.beanToMap(userAdjustmentBO);
        userAdjustmentDao.save(params);
    }

    @Override
    public SuccessResultList<List<UserLogDTO>> listPage(ListPage page) {
        PageHelper.startPage(page.getPage(), page.getRows());
        List<UserLogDTO> userLogDTOs = userAdjustmentDao.list(page.getParams());
        PageInfo<UserLogDTO> pageInfo = new PageInfo<>(userLogDTOs);
        return new SuccessResultList<>(userLogDTOs, pageInfo.getPageNum(), pageInfo.getTotal());
    }
}
