package com.unis.crk.basic.service.impl;

import com.unis.crk.basic.entity.UserOperationlog;
import com.unis.crk.basic.mapper.UserOperationlogMapper;
import com.unis.crk.basic.service.IUserOperationlogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.Map;
import cn.hutool.json.JSONObject;
import com.unis.crk.basic.entity.vo.UserOperationlogVo;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * 操作记录表 服务实现类
 * </p>
 *
 * @author ghh
 * @since 2021-12-13
 */
@Service
public class UserOperationlogServiceImpl extends ServiceImpl<UserOperationlogMapper, UserOperationlog> implements IUserOperationlogService {

    @Resource
    private UserOperationlogMapper userOperationlogMapper;


    /**
     *修改操作记录表
     * @param qcrk 操作记录表业务数据
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject update(UserOperationlog qcrk){
        return null;
    }
    /**
     *删除操作记录表数据
     * @param id 操作记录表主键尖
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JSONObject delete(String id){
        return null;
        }

    /**
     * 按照条件查询操作记录表信息
     * @param pageQuery
     * @throws Exception
     */
    @Override
    public IPage<Map<String,Object>> findPageVo(UserOperationlogVo pageQuery){
        {

        //条形查询器
        QueryWrapper<UserOperationlog> queryWrapper = new QueryWrapper<>();
            if(pageQuery.getEndData() !=null && pageQuery.getStartData() !=null){
            queryWrapper.between("d.operation_time",pageQuery.getStartData(),pageQuery.getEndData());
            }
            if(pageQuery.getUserName() !=null){
                queryWrapper.like("h.username",pageQuery.getUserName());
            }
        //分页相关
        Page<UserOperationlog> p =new Page<>(pageQuery.getPage(),pageQuery.getLimit());

            return  userOperationlogMapper.getPage(p, queryWrapper);
        }
    }

        @Override
        public List<Map<String, Object>> getPerData(UserOperationlogVo pageQuery) {
            List<Map<String,Object>> list = userOperationlogMapper.getPerData(pageQuery);
        return list;
        }
}
