159 lines
4.2 KiB
Java
159 lines
4.2 KiB
Java
package com.peanut.modules.book.controller;
|
||
|
||
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.peanut.common.utils.PageUtils;
|
||
import com.peanut.common.utils.R;
|
||
import com.peanut.modules.book.entity.BookClockinEntity;
|
||
import com.peanut.modules.book.entity.BookClockinPunchEntity;
|
||
import com.peanut.modules.book.entity.BookTaskEntity;
|
||
import com.peanut.modules.book.service.*;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import java.util.Arrays;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
|
||
/**
|
||
* 发布签到任务
|
||
*/
|
||
@RestController
|
||
@RequestMapping("book/task")
|
||
public class BookTaskController {
|
||
|
||
@Autowired
|
||
private BookTaskService bookTaskService;
|
||
@Autowired
|
||
private BookService bookService;
|
||
@Autowired
|
||
private BookClockinService bookClockinService;
|
||
@Autowired
|
||
private MyUserService myUserService;
|
||
@Autowired
|
||
private BookClockinPunchService bookClockinPunchService;
|
||
|
||
/**
|
||
* 列表后台
|
||
*
|
||
*/
|
||
@RequestMapping("/list")
|
||
public R list(@RequestParam Map<String, Object> params) {
|
||
PageUtils page = bookTaskService.queryPage(params);
|
||
|
||
|
||
return R.ok().put("page", page);
|
||
}
|
||
|
||
|
||
/**
|
||
* 列表app根据days查询
|
||
*
|
||
*/
|
||
@RequestMapping("/applist")
|
||
public R applist(@RequestParam Map<String, Object> params) {
|
||
PageUtils page = bookTaskService.queryPageServi(params);
|
||
|
||
|
||
return R.ok().put("page", page);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 信息
|
||
*/
|
||
@RequestMapping("/info/{id}")
|
||
public R info(@PathVariable("id") Integer id) {
|
||
|
||
//根据id找到详细数据信息
|
||
BookTaskEntity bookTaskEntity = bookTaskService.getById(id);
|
||
Integer ids = bookTaskEntity.getId();
|
||
Integer bookid = bookTaskEntity.getBookid();
|
||
List<BookClockinPunchEntity> bookClockinPunchEntity = bookClockinPunchService.getBaseMapper().selectList(new QueryWrapper<BookClockinPunchEntity>()
|
||
.eq("user_id", ids)
|
||
.eq("book_id", bookid));
|
||
|
||
// 遍历 bookClockinEntityList 中的每个 bookClockinEntity,查询 BookClockinEntity 表中对应的总数
|
||
int total = 0;
|
||
for ( BookClockinPunchEntity bookClockin : bookClockinPunchEntity) {
|
||
|
||
Integer id1 = bookClockin.getId();
|
||
// BookClockinEntity byId = bookClockinService.getById(id1);
|
||
//++获取到总条数
|
||
total ++;
|
||
}
|
||
//返回总条数
|
||
|
||
return R.ok().put("bookTaskEntity", bookTaskEntity).put("totalCont",total);
|
||
}
|
||
|
||
/**
|
||
* 保存
|
||
*/
|
||
@RequestMapping("/save")
|
||
public R save(@RequestBody BookTaskEntity bookTaskEntity) {
|
||
|
||
bookTaskEntity.setDelFlag(0);
|
||
bookTaskService.save(bookTaskEntity);
|
||
return R.ok();
|
||
}
|
||
|
||
|
||
/**
|
||
* 修改
|
||
*/
|
||
@RequestMapping("/update")
|
||
public R update(@RequestBody BookTaskEntity bookTaskEntity) {
|
||
|
||
bookTaskService.updateById(bookTaskEntity);
|
||
return R.ok();
|
||
}
|
||
|
||
|
||
/**
|
||
* 删除
|
||
*/
|
||
@RequestMapping("/delete")
|
||
public R delete(@RequestBody Integer[] ids) {
|
||
bookTaskService.removeByIds(Arrays.asList(ids));
|
||
|
||
return R.ok();
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 总条数
|
||
*/
|
||
@RequestMapping("/totalsum")
|
||
public R totalsum(@RequestBody BookTaskEntity bookTaskEntity) {
|
||
|
||
// 获取 BookTaskEntity 表中所有的 bookid和id
|
||
String days = bookTaskEntity.getDays();
|
||
Integer bookid = bookTaskEntity.getBookid();
|
||
List<BookClockinPunchEntity> books = bookClockinPunchService.getBaseMapper().selectList(new QueryWrapper<BookClockinPunchEntity>()
|
||
.eq("days", days)
|
||
.eq("book_id", bookid));
|
||
|
||
|
||
|
||
// 遍历 bookClockinEntityList 中的每个 bookClockinEntity,查询 BookClockinEntity 表中对应的总数
|
||
int total = 0;
|
||
for ( BookClockinPunchEntity book : books) {
|
||
// 使用 bookClockinEntity 进行匹配查询
|
||
Integer id1 = book.getId();
|
||
BookClockinPunchEntity byId = bookClockinPunchService.getById(id1);
|
||
//++获取到总条数
|
||
total ++;
|
||
}
|
||
//返回总条数
|
||
return R.ok().put("totalSum",total);
|
||
|
||
}
|
||
|
||
|
||
|
||
} |