<file_sep>package com.atguigu.guliedu.ucenter.service;

import com.atguigu.guliedu.ucenter.entity.MemberLoginLog;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * <p>
 * 会员登录日志表 服务类
 * </p>
 *
 * @author LiuZhiPeng
 * @since 2019-01-11
 */
public interface MemberLoginLogService extends IService<MemberLoginLog> {

    Integer loginCount(String day);
    Integer loginCount1(String day);
}
<file_sep>package com.atguigu.guliedu.ucenter.controller;


import com.atguigu.entity.R;
import com.atguigu.guliedu.ucenter.entity.Member;
import com.atguigu.guliedu.ucenter.service.MemberService;

import com.atguigu.guliedu.ucenter.service.impl.MemberServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author LiuZhiPeng
 * @since 2019-01-11
 */
@Api(description = "学员管理")
@RestController
@RequestMapping("/ucenter/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    //命名日志记录器
    private static final Logger DATA_LOGGER = LoggerFactory.getLogger("dataLogger");


    @ApiOperation(value = "学员注册",notes = "学员注册,memberId . createTime .updateTime后台自动填充")
    @PostMapping
    public R register(
            @ApiParam(name = "m",value = "学员信息的Json数据",required = true)
            @RequestBody Member member){ //@RequestBody   用 json 提交数据
        boolean result = memberService.save(member);
        DATA_LOGGER.info("module=Member`api=register`memberId={}",member.getMemberId());
        return R.ok().data("count",result);

    }



}

<file_sep>package com.atguigu.guliedu.ucenter.service.impl;

import com.atguigu.guliedu.ucenter.entity.MemberLoginLog;
import com.atguigu.guliedu.ucenter.mapper.MemberLoginLogMapper;
import com.atguigu.guliedu.ucenter.service.MemberLoginLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 会员登录日志表 服务实现类
 * </p>
 *
 * @author LiuZhiPeng
 * @since 2019-01-11
 */
@Service
public class MemberLoginLogServiceImpl extends ServiceImpl<MemberLoginLogMapper, MemberLoginLog> implements MemberLoginLogService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MemberLoginLogServiceImpl.class);


    @Override
    public Integer loginCount(String day) {
        QueryWrapper<MemberLoginLog> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("DATE(login_time)",day);
        Integer integer = baseMapper.selectCount(objectQueryWrapper);
        return integer;

    }

    @Override
    public Integer loginCount1(String day) {

    try {
       int i = 9/0;
        LOGGER.debug("命中缓存");
    }catch (Exception e){
        LOGGER.error("缓存获取失败");
    }

        return baseMapper.selectLoginCount1(day);
    }

/*    @Override
    public Integer loginCount1(String day) {
       return baseMapper.selectLoginCount1(day);
    }*/
}
<file_sep>package com.atguigu.guliedu.ucenter.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 会员登录日志表
 * </p>
 *
 * @author LiuZhiPeng
 * @since 2019-01-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="MemberLoginLog对象", description="会员登录日志表")
public class MemberLoginLog implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "登录日志id，分布式id")
    @TableId(value = "log_id", type = IdType.ID_WORKER)
    private Long logId;

    @ApiModelProperty(value = "登录时间")
    private Date loginTime;

    @ApiModelProperty(value = "登录IP")
    private String ip;

    @ApiModelProperty(value = "用户ID")
    private Long memberId;

    @ApiModelProperty(value = "昵称")
    private String nickname;

    @ApiModelProperty(value = "操作系统")
    private String osName;

    @ApiModelProperty(value = "浏览器")
    private String userAgent;


}
<file_sep><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>guliedu</artifactId>
        <groupId>com.atguigu</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>gulixedu_common</artifactId>
    <dependencies>
        <!--xls-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <optional>true</optional>
            <!-- <optional>true</optional>   意思是可选择性的引入,不是所有微服务都有-->
        </dependency>
        <dependency>
            <groupId>com.atguigu</groupId>
            <artifactId>guliedu_ucenter</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project><file_sep>package com.atguigu.guliedu.ucenter.controller.admin;

import com.atguigu.entity.R;
import com.atguigu.entity.ResultCode;
import com.atguigu.guliedu.ucenter.entity.Member;
import com.atguigu.guliedu.ucenter.entity.QueryMember;
import com.atguigu.guliedu.ucenter.service.MemberService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.sql.Wrapper;
import java.util.List;
@CrossOrigin
@Api(description = "学员管理")
@RestController
@RequestMapping("/admin/ucenter/member")
public class MemberAdminController {

    @Autowired
    private MemberService memberService;

    @GetMapping
    public R list(){
        List<Member> list = memberService.list(null);
        return R.ok().data("items",list);
    }

    @DeleteMapping("{memberId}")
    public R deleceById(@PathVariable String memberId){
        boolean result = memberService.removeById(memberId);
        return R.ok();
    }

/*    @PutMapping("{memberId}")
    public R test1(@PathVariable String memberId){
        Member member = new Member();
        member.setMemberId(memberId);
        member.setIsAvailable(false);
        boolean b = memberService.updateById(member);
        deleceById(memberId);
        return R.ok();
    }*/
    @ApiOperation(value = "冻结学员",notes = "冻结学员,memberId . createTime .updateTime后台自动填充")
    @PutMapping("lock/{memberId}")
    public R lockById(
            @ApiParam(name = "memberId",value = "学员ID",required = true)
            @PathVariable String memberId){
        boolean result = memberService.lockById(memberId, true);
        if(result){
            return R.ok();
        }else {
            return R.error().message("未更新数据").code(ResultCode.NOT_MOD);
        }

    }
    @ApiOperation(value = "解冻学员",notes = "解冻学员,memberId . createTime .updateTime后台自动填充")
    @PutMapping("unlock/{memberId}")
    public R unlockById(
            @ApiParam(name = "memberId",value = "学员ID",required = true)
            @PathVariable String memberId){
        boolean result = memberService.lockById(memberId, false);
        if(result){
            return R.ok();
        }else {
            return R.error().message("未更新数据").code(ResultCode.NOT_MOD);
        }

    }

    @ApiOperation(value = "某日的注册人数",notes = "某日的注册人数")
    @GetMapping("register-count/{day}")
    public R createByDate(
            @ApiParam(name = "day",value = "注册日期",required = true)
            @PathVariable String day){

        Integer count = memberService.createCount1(day);
        return R.ok().data("count",count);
    }

    @ApiOperation(value = "分页学员列表")
    @PostMapping(value = "{page}/{limit}")
    public R pageList(
            @ApiParam(name = "page",value = "当前页码",required = true)
            @PathVariable Long page,
            @ApiParam(name = "limit",value = "每页记录数",required = true)
            @PathVariable Long limit,
            @ApiParam(name = "searchObject",value = "查询条件封装成的对象")
            @RequestBody(required = false) QueryMember searchObject){

        Page<Member> objectPage = new Page<>(page, limit);
        memberService.pageList(objectPage, searchObject);

        long total = objectPage.getTotal();
        List<Member> records = objectPage.getRecords();

        return R.ok().data("total",total).data("rows",records);
    }

    @ApiOperation(value = "批量注册学员Excel")
    @PostMapping("import")
    public R addUser(MultipartFile file,Integer mark){



        return R.ok();
    }

}
<file_sep>package com.atguigu.guliedu.ucenter.service.impl;

import com.atguigu.guliedu.ucenter.entity.Member;
import com.atguigu.guliedu.ucenter.entity.QueryMember;
import com.atguigu.guliedu.ucenter.mapper.MemberMapper;
import com.atguigu.guliedu.ucenter.service.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author LiuZhiPeng
 * @since 2019-01-11
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    @Override
    public boolean lockById(String memberId, boolean lock) {
        Member member = new Member();
        member.setMemberId(memberId);
        member.setIsAvailable(!lock);
        int i = baseMapper.updateById(member);
        return resoultBool(i);
    }

    @Override
    public Integer createCount1(String day) {
       Integer count = baseMapper.createCount1(day);

        return count;
    }

    @Override
    public void pageList(Page<Member> objectPage, QueryMember searchObject) {
        //判断查询是否为空
        if(searchObject == null){
            baseMapper.selectPage(objectPage,null);
            return;
        }
        //获取查询参数
        String keyWord = searchObject.getKeyWord();
        Boolean isAvailable = searchObject.getIsAvailable();
        Date begin = searchObject.getBegin();
        Date end = searchObject.getEnd();
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
       // 判断keyWord
        if(!StringUtils.isEmpty(keyWord)){
            queryWrapper.and(i -> i.like("mobile",keyWord)//likeRight左边没有% 不会造成索引失效
                    .or()
                    .like("nickname",keyWord));
        }

        //判断isAvailable
        if(!StringUtils.isEmpty(isAvailable)){
            queryWrapper.eq("is_available",isAvailable);
        }
        //判断注册时间范围
        if(!StringUtils.isEmpty(begin)){
            queryWrapper.ge("create_time",begin);
        }
        if(!StringUtils.isEmpty(end)){
            queryWrapper.le("create_time",end);
        }
        //执行分页查询
        baseMapper.selectPage(objectPage,queryWrapper);

    }

    private static boolean resoultBool(Integer result){
        return null != result && result>=1;
    }


}
