package cn.pluss.platform.user.impl;

import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.entity.UserExtra;
import cn.pluss.platform.entity.UserMultipleRemark;
import cn.pluss.platform.mapper.UserMultipleRemarkMapper;
import cn.pluss.platform.shiro.UserService;
import cn.pluss.platform.user.UserExtraService;
import cn.pluss.platform.user.UserMultipleRemarkService;
import cn.pluss.platform.userApp.UserAppService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Djh
 * @since 2022-05-31
 */
@Service
public class UserMultipleRemarkServiceImpl extends ServiceImpl<UserMultipleRemarkMapper, UserMultipleRemark> implements UserMultipleRemarkService {

    @Autowired
    private UserAppService uaService;

    @Override
    public Page<UserMultipleRemark> pageFollowDataList(Page<UserMultipleRemark> page, Long userId) {
        LambdaQueryWrapper<UserMultipleRemark> qWrapper = Wrappers.lambdaQuery();
        qWrapper.eq(UserMultipleRemark::getUserId, userId);
        qWrapper.orderByDesc(UserMultipleRemark::getCreateTime);

        return page(page, qWrapper);
    }

    @Override
    public Page<UserMultipleRemark> apiPageFollowDataList(Page<UserMultipleRemark> page) {
        final UserApp tokenUa = uaService.queryUserAppByToken();
        return pageFollowDataList(page, tokenUa.getUserId());
    }

    @Override
    public void addFollowUpData(Long userId, String remark) {
        UserMultipleRemark entity = new UserMultipleRemark();
        entity.setUserId(userId)
                .setRemark(remark)
                .setCode(UserExtraService.FU);

        save(entity);
    }
}
