package com.fjs.scenic.service.user.impl;

import com.fjs.scenic.entity.user.User;
import com.fjs.scenic.entity.user.UserStatistical;
import com.fjs.scenic.mapper.user.UserStatisticalMapper;
import com.fjs.scenic.service.user.UserStatisticalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * This class is used for ...
 *
 * @author lfj
 * @version 1.0
 * @CreateDate ${date} ${time}
 */
@Service
public class UserStatisticalServiceImpl implements UserStatisticalService {
    @Autowired
    private UserStatisticalMapper userStatisticalMapper;


    @Override
    public int allocationPermission(Integer userID, List<UserStatistical> list) {
        int delSum = userStatisticalMapper.deleteByUserId(userID);
        return list.size() == 0 ? delSum : userStatisticalMapper.inserts(list);
    }

    @Override
    public boolean verifySecretKey(Integer userID, String secretKey) {
        return true;
        /*List<UserStatistical> list = userStatisticalMapper.selectByUserId(userID);
        return (list.size() == 0) ? false : secretKey.equals(list.get(0).getSecretKey());*/
    }

    @Override
    public List<UserStatistical> selectByUserId(Integer userID) {
        return userStatisticalMapper.selectByUserId(userID);
    }

    @Override
    public Boolean verifyPermission(Integer userId, Integer pressId) {
        List<UserStatistical> list = userStatisticalMapper.verifyPermission(userId, pressId);
        return list.size() > 0;
    }

    @Override
    public int deleteByUserId(Integer userId) {
        return userStatisticalMapper.deleteByUserId(userId);
    }

    /**
     * 修改密码 （通过userid）
     * @param userId
     * @param newKey
     * @return
     */
    @Override
    public boolean updateSecretKeyByUserId(Integer userId, String newKey) {
        return userStatisticalMapper.updateSecretKeyByUserId(userId, newKey);
    }


    @Override
    public List<HashMap<String, Object>> page(UserStatistical record) {
        return userStatisticalMapper.selectForPage(record);
    }

    @Override
    public Boolean validUserId(Integer userID) {
        List<UserStatistical> list = userStatisticalMapper.selectByUserId(userID);
        return list.size() > 0;
    }

    @Override
    public int delByOpenid(String openid) {
        return userStatisticalMapper.delByOpenid(openid);
    }

}
