package com.jiyun.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.jiyun.constant.MessageConstant;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.entity.Result;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Student;
import com.jiyun.service.StudetnService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;
@RestController
@RequestMapping("student")
public class StudentController {
@Reference
StudetnService studetnService;
@RequestMapping("findPage")
public PageResult findPage (@RequestBody QueryPageBean queryPageBean){
return studetnService.findPage(queryPageBean);
}
@RequestMapping("add")
public Result add (@RequestBody Student student,Integer[] ids){
studetnService.add(student,ids);
return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
}
@RequestMapping("update")
public Result update (@RequestBody Student student,Integer[] ids){
studetnService.update(student,ids);
return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
}
@RequestMapping("del")
public Result del (Integer id){
studetnService.del(id);
return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
}
@RequestMapping("getid")
public Result getid (Integer id){
List list= studetnService.getid(id);
return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS,list);
}
@RequestMapping("/export1")
public void export1 (HttpServletResponse response) throws Exception {
//创建空的工作薄
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建空的表
HSSFSheet sheet = workbook.createSheet();
//创建一个数组
String[] tital={"编号","名称","性别","年龄","地址","说明","课程说明"};
HSSFRow row = sheet.createRow(0);
for (int i = 0; i < tital.length; i++) {
row.createCell(i).setCellValue(tital[i]);
}
// 查询数据库
List list=studetnService.fan3();
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i+1);
row.createCell(0).setCellValue(list.get(i).getSid());
row.createCell(1).setCellValue(list.get(i).getName());
row.createCell(2).setCellValue(list.get(i).getSex());
row.createCell(3).setCellValue(list.get(i).getAge());
row.createCell(4).setCellValue(list.get(i).getAddress());
row.createCell(5).setCellValue(list.get(i).getZhu());
row.createCell(6).setCellValue(list.get(i).getNames());
}
//7.把工作簿对象返回给前端浏览
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("艺人列表.xls", "UTF-8"));
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream");
workbook.write(response.getOutputStream());
workbook.close();
}
@RequestMapping("/import1")
public Result import1 (MultipartFile impfile, HttpServletResponse response) throws Exception {
// 创建空的工作薄
HSSFWorkbook workbook = new HSSFWorkbook(impfile.getInputStream());
// 获取表
HSSFSheet sheetAt = workbook.getSheetAt(0);
// 获取最后一个交表
int lastRowNum = sheetAt.getLastRowNum();
for (int i = 1; i <=lastRowNum; i++) {
HSSFRow row = sheetAt.getRow(i);
String sid = row.getCell(0).getStringCellValue();
String name = row.getCell(1).getStringCellValue();
String sex = row.getCell(2).getStringCellValue();
int age = (int)row.getCell(3).getNumericCellValue();
String address = row.getCell(4).getStringCellValue();
String zhu = row.getCell(5).getStringCellValue();
String names = row.getCell(6).getStringCellValue();
Student student = new Student();
student.setSid(sid);
student.setName(name);
student.setAddress(address);
student.setAge(age);
student.setZhu(zhu);
student.setSex(sex);
student.setNames(names);
studetnService.add1(student);
}
return new Result(true, MessageConstant.UPLOAD_SUCCESS);
}
}
service:
package com.jiyun.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.mapper.StudentMapper;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Service
public class StudetnServiceimpl implements StudetnService {
@Autowired
StudentMapper studentMapper;
@Override
public PageResult findPage(QueryPageBean queryPageBean) {
PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
List list=studentMapper.findPage(queryPageBean.getQueryString());
// select * from zhongjian z join kew k on z.s_id=k.id where s_id=#{id}
for (Student student : list) {
// 获取学生的id
Integer id = student.getId();
//同过id在去中间表关联查询检查项的信息
List list2=studentMapper.zjianxinag(id);
// 再检查组 中自定义属性
String names= "";
for (Ke ke : list2) {
// 字符串拼接
names+=ke.getMing()+",";
}
//再把这个对象放到检查组自定义的属性
student.setNames(names);
}
PageInfo page = new PageInfo<>(list);
return new PageResult( page.getTotal(),page.getList());
}
@Override
public void add(Student student, Integer[] ids) {
studentMapper.add(student);
Integer id = student.getId();
for (Integer kid : ids) {
studentMapper.zjian(id,kid);
}
}
@Override
public void update(Student student, Integer[] ids) {
studentMapper.update(student);
Integer id = student.getId();
studentMapper.del(id);
for (Integer kid : ids) {
studentMapper.zjian(id,kid);
}
}
@Override
public void del(Integer id) {
studentMapper.del(id);
studentMapper.delAll(id);
}
@Override
public List getid(Integer id) {
return studentMapper.getid(id);
}
@Override
public List fan3() {
return studentMapper.fan3();
}
@Override
public void add1(Student student) {
studentMapper.add1(student);
}
}
定时删除:
package com.jiyun.jobs;
import com.alibaba.fastjson.JSON;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Strudent;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.List;
public class ClearImgJob {
@Autowired
JedisPool jedisPool;
public void clearImg(){
Jedis redis = jedisPool.getResource();
// 读取缓存中的信息
List list = redis.lrange("list", 0, -1);
redis.lpop("list");
redis.close();
redis.lrem("list",0,list.get(1));
在list中名字是小米粒用定时任务删除
// for (int i = 0; i < list.size(); i++) {
// Ke ke = JSON.parseObject(list.get(i), Ke.class);
// if(ke.getName().equals("小米粒")){
// redis.lrem("list",0,list.get(i));
// }
// }
}
}
mapper:
select * from studentw
where sid=#{value} or name=#{value}
select w.*, ming names from studentw w ,kew k where w.id=k.id
insert into studentw (sid, name, sex, age, address, zhu)
values (#{sid},#{name},#{sex},#{age},#{address},#{zhu})
insert into studentw (sid, name, sex, age, address, zhu)
values (#{sid},#{name},#{sex},#{age},#{address},#{zhu})
insert into zhongjian (s_id,k_id) values (#{sid},#{kid});
update studentw set sid=#{sid}, name=#{name}, sex=#{sex}, age=#{age}, address=#{address}, zhu=#{zhu} where id=#{id}
delete from zhongjian where s_id=#{id}
select k_id from zhongjian where s_id=#{id}
select * from zhongjian z join kew k on z.s_id=k.id where s_id=#{id}
delete from studentw where id=#{id}
效果展示:
添加:
修改:
统计图:
前端:
传智健康
统计分析会员数量
首页统计分析会员数量
饼图:
传智健康
统计分析
会员数量
首页统计分析会员数量
controller:
package com.jiyun.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.jiyun.entity.Result;
import com.jiyun.pojo.KeVo;
import com.jiyun.service.KeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("report")
public class tongji {
@Reference
KeService keService;
@RequestMapping("zzt")
public Result zzt(){
List list = keService.findcount1();
List num = new ArrayList<>();
List cname = new ArrayList<>();
Map map = new HashMap<>();
for (KeVo keVo : list) {
num.add(keVo.getNum());
cname.add(keVo.getCname());
}
map.put("num",num);
map.put("cname",cname);
return new Result(true,"显示成功",map);
}
@RequestMapping("bt")
public Result bingzhuangtu(){
List list = keService.findcount1();
List num = new ArrayList<>();
List cname = new ArrayList<>();
List
评论列表(0条)