package com.example.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.JieyuejiluInfo;
import com.example.dao.JieyuejiluInfoDao;
import com.example.entity.TushuxinxiInfo;
import com.example.service.JieyuejiluInfoService;
import com.example.exception.CustomException;
import com.example.common.ResultCode;
import com.example.vo.EchartsData;
import com.example.vo.JieyuejiluInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.example.service.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping(value = "/jieyuejiluInfo")
public class JieyuejiluInfoController {
@Resource
private JieyuejiluInfoService jieyuejiluInfoService;
@Resource
private JieyuejiluInfoDao jieyuejiluInfoDao;
@PostMapping
public Result<JieyuejiluInfo> add(@RequestBody JieyuejiluInfoVo jieyuejiluInfo) {
//mixmajixami
jieyuejiluInfoService.add(jieyuejiluInfo);
return Result.success(jieyuejiluInfo);
}
//youtixing1
//youtixing2
@DeleteMapping("/{id}")
public Result delete(@PathVariable Long id) {
jieyuejiluInfoService.delete(id);
return Result.success();
}
@PutMapping
public Result update(@RequestBody JieyuejiluInfoVo jieyuejiluInfo) {
jieyuejiluInfoService.update(jieyuejiluInfo);
return Result.success();
}
//@PutMapping("/update2")
// public Result update2(@RequestBody JieyuejiluInfoVo jieyuejiluInfo) {
// jieyuejiluInfoService.update2(jieyuejiluInfo);
// return Result.success();
// }
@GetMapping("/{id}")
public Result<JieyuejiluInfo> detail(@PathVariable Long id) {
JieyuejiluInfo jieyuejiluInfo = jieyuejiluInfoService.findById(id);
return Result.success(jieyuejiluInfo);
}
@GetMapping("/changeStatus/{id}")
public Result<JieyuejiluInfo> changeStatus(@PathVariable Long id) {
jieyuejiluInfoService.changeStatus(id);
return Result.success();
}
@GetMapping
public Result<List<JieyuejiluInfoVo>> all() {
return Result.success(jieyuejiluInfoService.findAll());
}
@GetMapping("/page/{name}")
public Result<PageInfo<JieyuejiluInfoVo>> page(@PathVariable String name,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "5") Integer pageSize,
HttpServletRequest request) {
return Result.success(jieyuejiluInfoService.findPage(name, pageNum, pageSize, request));
}
@GetMapping("/pageqt/{name}")
public Result<PageInfo<JieyuejiluInfoVo>> pageqt(@PathVariable String name,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "8") Integer pageSize,
HttpServletRequest request) {
return Result.success(jieyuejiluInfoService.findPageqt(name, pageNum, pageSize, request));
}
// @PostMapping("/register")
// public Result<JieyuejiluInfo> register(@RequestBody JieyuejiluInfo jieyuejiluInfo) {
// if (StrUtil.isBlank(jieyuejiluInfo.getName()) || StrUtil.isBlank(jieyuejiluInfo.getPassword())) {
// throw new CustomException(ResultCode.PARAM_ERROR);
// }
// return Result.success(jieyuejiluInfoService.add(jieyuejiluInfo));
// }
/**
* 批量通过excel添加信息
* @param file excel文件
* @throws IOException
*/
@PostMapping("/upload")
public Result upload(MultipartFile file) throws IOException {
List<JieyuejiluInfo> infoList = ExcelUtil.getReader(file.getInputStream()).readAll(JieyuejiluInfo.class);
if (!CollectionUtil.isEmpty(infoList)) {
// 处理一下空数据
List<JieyuejiluInfo> resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getShuming())).collect(Collectors.toList());
for (JieyuejiluInfo info : resultList) {
jieyuejiluInfoService.add(info);
}
}
return Result.success();
}
@GetMapping("/get/jieyuejilu_tj_shuming")
Result<List<EchartsData>> jieyuejilu_tj_shuming() {
List<EchartsData> list = new ArrayList<>();
List<Map<String, Object>> jieyuejilu_tj_shumingList = jieyuejiluInfoDao.jieyuejilu_tj_shuming();
Map<String, Double> typeMap = new HashMap<>();
for (Map<String, Object> map : jieyuejilu_tj_shumingList) {
typeMap.put((String)map.get("aa"), (Double.valueOf((String)map.get("bb").toString())));
}
getPieData("借阅记录按书名统计", list, typeMap);
getBarData("借阅记录按书名统计", list, typeMap);
return Result.success(list);
}
@GetMapping("/get/jieyuejilu_tj_leibie")
Result<List<EchartsData>> jieyuejilu_tj_leibie() {
List<EchartsData> list = new ArrayList<>();
List<Map<String, Object>> jieyuejilu_tj_leibieList = jieyuejiluInfoDao.jieyuejilu_tj_leibie();
Map<String, Double> typeMap = new HashMap<>();
for (Map<String, Object> map : jieyuejilu_tj_leibieList) {
typeMap.put((String)map.get("aa"), (Double.valueOf((String)map.get("bb").toString())));
}
getPieData("借阅记录按类别统计", list, typeMap);
getBarData("借阅记录按类别统计", list, typeMap);
return Result.success(list);
}
@GetMapping("/get/jieyuejilu_tj_jieyueriqi")
Result<List<EchartsData>> jieyuejilu_tj_jieyueriqi() {
List<EchartsData> list = new ArrayList<>();
List<Map<String, Object>> jieyuejilu_tj_jieyueriqiList = jieyuejiluInfoDao.jieyuejilu_tj_jieyueriqi();
Map<String, Double> typeMap = new HashMap<>();
for (Map<String, Object> map : jieyuejilu_tj_jieyueriqiList) {
typeMap.put((String)map.get("aa"), (Double.valueOf((String)map.get("bb").toString())));
}
getPieData("借阅记录按借阅日期统计", list, typeMap);
getBarData("借阅记录按借阅日期统计", list, typeMap);
return Result.success(list);
}
@GetMapping("/get/jieyuejilu_tj_shijianduan")
Result<List<EchartsData>> jieyuejilu_tj_shijianduan() {
List<EchartsData> list = new ArrayList<>();
List<Map<String, Object>> jieyuejilu_tj_shijianduanList = jieyuejiluInfoDao.jieyuejilu_tj_shijianduan();
Map<String, Double> typeMap = new HashMap<>();
for (Map<String, Object> map : jieyuejilu_tj_shijianduanList) {
typeMap.put((String)map.get("aa"), (Double.valueOf((String)map.get("bb").toString())));
}
getPieData("借阅记录按时间段统计", list, typeMap);
getBarData("借阅记录按时间段统计", list, ty