发表于: 2019-12-11 20:53:23
1 672
一、今天完成的事
完成前台-签到模块
controller
package com.jnshu.checkin.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jnshu.checkin.service.CheckinService;
import com.jnshu.model.Student;
import com.jnshu.model.StudentCheckin;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.checkin.controller
* @ClassName academy-ctrl-wx-provider
* @Description
* @create 2019-12-10 11:21
*/
@RestController
@RequestMapping("/wx/checkin/a")
public class CheckinController {
private static final Logger log= LogManager.getLogger(CheckinController.class);
@Autowired
CheckinService checkinService;
/**
* 获取签到信息
* @param id
* @return
*/
@GetMapping("/u/getCheckin")
private Student getCheckin(Long id){
return checkinService.getStudent(id);
}
/**
* 获取签到信息(日历)
* @param id
* @return
*/
@GetMapping("/u/getCheckinDate")
private PageInfo<StudentCheckin> getCheckinDate(@RequestParam(value = "start",defaultValue = "1")int start,Long id){
PageHelper.startPage(start,10);
List<StudentCheckin> studentCheckinList= checkinService.getCheckinDate(id);
return new PageInfo<>(studentCheckinList);
}
@PostMapping("/u/checkin")
private boolean checkin(Long id){
Student student = checkinService.getStudent(id);
StudentCheckin studentCheckin = new StudentCheckin();
//增加签到记录
Long date = (System.currentTimeMillis());
studentCheckin.setDate(date);
boolean status = checkinService.addCheckin(student.getId(),date);
if(status){
status = checkinService.updateCheckin(student);
}
return status;
}
}
serviceImpl
package com.jnshu.checkin.service.serviceImpl;
import com.jnshu.checkin.mapper.CheckinMapper;
import com.jnshu.checkin.service.CheckinService;
import com.jnshu.model.Student;
import com.jnshu.model.StudentCheckin;
import com.jnshu.utils.ScheduledTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.checkin.service
* @ClassName academy-ctrl-wx-provider
* @Description
* @create 2019-12-10 11:20
*/
@Service
public class CheckinServiceImpl implements CheckinService {
@Autowired
CheckinMapper checkinMapper;
@Override
public Student getStudent( Long id) {
//查询连续签到信息
Student student = new Student();
StudentCheckin studentCheckin = checkinMapper.getDate(id);
long verifyDate = (System.currentTimeMillis())-86400000L;
System.out.println(studentCheckin.getDate());
System.out.println((System.currentTimeMillis()));
if(studentCheckin.getDate()<(verifyDate)){
student.setCurrent_continued_check(0);
checkinMapper.clearCheckin(id);
}
return checkinMapper.getStudent(id);
}
@Override
public List<StudentCheckin> getCheckinDate(Long id) {
return checkinMapper.getCheckinDate(id);
}
@Override
public int totalCheck(Long id) {
return checkinMapper.totalCheck(id);
}
@Override
public boolean currentCheck(Long id) {
return checkinMapper.currentCheck(id);
}
@Override
public boolean clearCheckin(Long id) {
return checkinMapper.clearCheckin(id);
}
@Override
public StudentCheckin getDate(Long id) {
return checkinMapper.getDate(id);
}
@Override
public boolean addCheckin(Long id, Long date) {
return checkinMapper.addCheckin(id, date);
}
@Override
public boolean updateCheckin(Student student) {
//增加累计签到
student.setTotal_check(checkinMapper.totalCheck(student.getId())+1);
//增加当前连续签到
student.setCurrent_continued_check(student.getCurrent_continued_check()+1);
//修改最高连续签到次数
if(student.getHighest_continued_check()<student.getCurrent_continued_check()){
student.setHighest_continued_check(student.getCurrent_continued_check());
}
//增加逆袭豆数量
Long beansAmount = student.getBeans_amount();
if(student.getCurrent_continued_check()<5){
student.setBeans_amount(beansAmount+(long) student.getCurrent_continued_check());
}else{
student.setBeans_amount(beansAmount+5L);
}
return checkinMapper.updateCheckin(student);
}
}
mapper
package com.jnshu.checkin.mapper;
import com.jnshu.model.Student;
import com.jnshu.model.StudentCheckin;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.checkin.mapper
* @ClassName academy-ctrl-wx-provider
* @Description
* @create 2019-12-10 11:21
*/
@Mapper
public interface CheckinMapper {
/**
* 查看学生签到信息
* @param id
* @return
*/
@Select("select student.id,student.image,student.name,student.beans_amount,student.total_check,student.highest_continued_check," +
"current_continued_check from student \n" +
"where student.id=#{id}")
Student getStudent(Long id);
/**
* 查看签到日期(日历)
* @param id
* @return
*/
@Select("select * from student_checkin where student_id=#{id} order by date desc ")
List<StudentCheckin> getCheckinDate(Long id);
/**
* 计算总共签到次数
* @param id
* @return
*/
@Select("select count(*) from student_checkin where id=#{id}")
int totalCheck(Long id);
/**
* 获取当前连续签到次数
* @return
*/
@Select("select current_continued_checkin from student where id=#{id}")
boolean currentCheck(Long id);
/**
* 清空连续签到
* @return
*/
@Update("update student set current_continued_check=#{current_continued_check} where id=#{id}")
boolean clearCheckin(Long id);
/**
* 查询最后一条记录时间
* @return
*/
@Select("select * from student_checkin where student_id=#{id} order by date desc LIMIT 1")
StudentCheckin getDate(Long id);
/**
* 点击签到
* @param id
* @param date
* @return
*/
@Insert("insert into student_checkin(student_id,date) values(#{id},#{date})")
boolean addCheckin(Long id,Long date);
/**
* 点击签到-修改学生-签到记录
* @param student
* @return
*/
@Update("update student set total_check=#{total_check},highest_continued_check=#{highest_continued_check}," +
"current_continued_check=#{current_continued_check},beans_amount=#{beans_amount} where id=#{id}")
boolean updateCheckin(Student student);
}
完成后台-模块管理
controller
package com.jnshu.module.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jnshu.model.Module;
import com.jnshu.module.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.PUT;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.module.controller
* @ClassName academy-ctrl-web-provider
* @Description
* @create 2019-12-11 19:21
*/
@RestController
@RequestMapping("/module/a")
public class ModuleController {
@Autowired
ModuleService moduleService;
@GetMapping(value = "/u/moduleList")
private PageInfo<Module> getModuleList(@RequestParam(value = "start",defaultValue = "1")int start){
PageHelper.startPage(start,10);
List<Module> moduleList = moduleService.moduleList();
return new PageInfo<>(moduleList);
}
@DeleteMapping(value = "/u/delModule")
private boolean delModule(Long id){
return moduleService.delModule(id);
}
@PutMapping(value = "/u/putModule")
private boolean putModuel(Module module){
return moduleService.putModule(module);
}
@PostMapping(value = "/u/addModule")
private boolean addModule(@RequestBody Module module){
return moduleService.addModule(module);
}
}
serviceImpl
package com.jnshu.module.service.serviceImpl;
import com.jnshu.model.Module;
import com.jnshu.module.mapper.ModuleMapper;
import com.jnshu.module.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.module.service.serviceImpl
* @ClassName academy-ctrl-web-provider
* @Description
* @create 2019-12-11 19:22
*/
@Service
public class ModuleServiceImpl implements ModuleService {
@Autowired
ModuleMapper moduleMapper;
@Override
public List<Module> moduleList() {
return moduleMapper.moduleList();
}
@Override
public boolean delModule(Long id) {
return moduleMapper.delModule(id);
}
@Override
public boolean putModule(Module module) {
Long time = (System.currentTimeMillis());
module.setUpdate_at(time);
module.setUpdate_by("wq");
return moduleMapper.putModule(module);
}
@Override
public boolean addModule(Module module) {
Long time = (System.currentTimeMillis());
module.setCreate_at(time);
module.setCreate_by("ksy");
return moduleMapper.addModule(module);
}
}
mapper
package com.jnshu.module.mapper;
import com.jnshu.model.Module;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* @author Admin
* @PackageName com.jnshu.module.mapper
* @ClassName academy-ctrl-web-provider
* @Description
* @create 2019-12-11 19:22
*/
@Mapper
public interface ModuleMapper {
/**
* 查询所有模块
* @return
*/
@Select("select * from module")
List<Module> moduleList();
/**
* 删除
* @param id
* @return
*/
@Delete("delete from module where id=#{id}")
boolean delModule(Long id);
/**
* 编辑
* @param module
* @return
*/
@Update("update module set name=#{name},module_url=#{module_url},parent_id=#{parent_id},update_at=#{update_at},update_by=#{update_by}\n" +
"where id=#{id} ")
boolean putModule(Module module);
/**
* 新增
* @param module
* @return
*/
@Insert("insert into module(name,module_url,parent_id,create_at,create_by)\n" +
"values(#{name},#{module_url},#{parent_id},#{create_at},#{create_by})")
boolean addModule(Module module);
}
二、遇到的问题
三、收获
四、明天的计划
剩下 后台登录,优化程序,编写部署代码
评论