From 7a549bb5bdfb93cc0d1985a40c04b53b9e1f2476 Mon Sep 17 00:00:00 2001 From: bseayin Date: Sun, 15 Sep 2019 21:36:46 +0800 Subject: [PATCH] authorization --- .../com/cy/SpringBootHomeworkApplication.java | 12 ++ .../com/cy/controller/HomeworkController.java | 195 ++++++++++++++++++ .../com/cy/controller/UserController.java | 92 +++++++++ .../src/main/java/com/cy/entity/Homework.java | 66 ++++++ .../java/com/cy/entity/HomeworkRankDTO.java | 31 +++ .../java/com/cy/entity/HomeworkUserDTO.java | 63 ++++++ .../src/main/java/com/cy/entity/User.java | 59 ++++++ .../main/java/com/cy/repository/DTODao.java | 70 +++++++ .../com/cy/repository/HomeworkRepository.java | 15 ++ .../com/cy/repository/UserRepository.java | 13 ++ .../java/com/cy/service/HomeworkService.java | 127 ++++++++++++ .../main/java/com/cy/service/UserService.java | 31 +++ .../src/main/java/com/cy/utils/KeyUtils.java | 11 + .../com/cy/utils/WebMvcConfiguration.java | 19 ++ 14 files changed, 804 insertions(+) create mode 100644 SpringBootAngularjs/src/main/java/com/cy/SpringBootHomeworkApplication.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/controller/HomeworkController.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/controller/UserController.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/entity/Homework.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkRankDTO.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkUserDTO.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/entity/User.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/repository/DTODao.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/repository/HomeworkRepository.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/repository/UserRepository.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/service/HomeworkService.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/service/UserService.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/utils/KeyUtils.java create mode 100644 SpringBootAngularjs/src/main/java/com/cy/utils/WebMvcConfiguration.java diff --git a/SpringBootAngularjs/src/main/java/com/cy/SpringBootHomeworkApplication.java b/SpringBootAngularjs/src/main/java/com/cy/SpringBootHomeworkApplication.java new file mode 100644 index 0000000..c9e58d5 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/SpringBootHomeworkApplication.java @@ -0,0 +1,12 @@ +package com.cy; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootHomeworkApplication { + public static void main(String[] args) { + SpringApplication.run(SpringBootHomeworkApplication.class, args); + } + +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/controller/HomeworkController.java b/SpringBootAngularjs/src/main/java/com/cy/controller/HomeworkController.java new file mode 100644 index 0000000..d8b91df --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/controller/HomeworkController.java @@ -0,0 +1,195 @@ +package com.cy.controller; + +import com.cy.entity.Homework; +import com.cy.entity.HomeworkRankDTO; +import com.cy.entity.HomeworkUserDTO; +import com.cy.repository.DTODao; +import com.cy.service.HomeworkService; +import com.cy.utils.KeyUtils; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.tomcat.util.http.fileupload.IOUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.*; +import java.sql.Array; +import java.sql.Date; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + + +@RestController +@RequestMapping("homework") +public class HomeworkController { + @Resource + HomeworkService hs; + + @Resource + DTODao dd; + + @Value("${fileUpLoadPath}") + String filePath; + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + @RequestMapping("showByType/{type}") + public List showByType(@PathVariable("type") String type) { + + java.util.Date d1 = new java.util.Date(); + if (d1.getHours() <= 11 && "竞赛".equals(type)) { + Date datesql = new Date(d1.getTime()); + return hs.findByTypeAndFinishTime(type, datesql); + } else if (d1.getHours() >= 12 && "结对".equals(type)) { + Date datesql2 = new Date(d1.getTime()); + return hs.findByTypeAndFinishTime(type, datesql2); + } else { + return null; + } + } + + @RequestMapping("showByTypeAndFinishTime") + public List showByTypeAndFinishTime(HttpServletRequest request) { + String type = request.getParameter("type"); + java.util.Date d1 = null; + try { + d1 = sdf.parse(request.getParameter("finishTime")); + + } catch (ParseException e) { + e.printStackTrace(); + } + Date d2 = new Date(d1.getTime()); + return hs.findByTypeAndFinishTime(type, d2); + } + + @RequestMapping("showByTypeAndFinishTime/{page}") + public Iterable showByTypeAndFinishTime(@PathVariable("page") String page, HttpServletRequest request) { + Pageable pageable = new PageRequest(Integer.parseInt(page), 10); + String type = request.getParameter("type"); + java.util.Date d1 = null; + try { + d1 = sdf.parse(request.getParameter("finishTime")); + + } catch (ParseException e) { + e.printStackTrace(); + } + Date d2 = new Date(d1.getTime()); + return hs.findByTypeAndFinishTime(type, d2, pageable); + } + + @RequestMapping("save") + public Homework save(@RequestBody Homework homework) { + homework.setId(KeyUtils.genUniqueKey()); + homework.setUpdateTime(new Date(new java.util.Date().getTime())); + return hs.save(homework); + } + + @RequestMapping("findAllById/{id}") + public List findAllById(@PathVariable("id") String id) { + return hs.findAllById(id); + + } + + @RequestMapping("update") + public Homework update(@RequestBody Homework homework) { + return hs.update(homework); + } + + @RequestMapping("deleteById/{id}") + public Map deleteById(@PathVariable("id") String id) { + Map map = new HashMap(); + hs.deleteById(id); + if (hs.findAllById(id).size() == 0) { + map.put("rs", "success"); + } else { + map.put("rs", "fail"); + } + return map; + } + + @RequestMapping("showdetails/{id}") + public ArrayList showdetails(@PathVariable("id") String hid) { + return hs.gethomeworkdetail(hs.findAllById(hid).get(0)); + } + + + @RequestMapping(value = "/upload", method = RequestMethod.POST) + @ResponseBody + public Map upload(@RequestParam MultipartFile myFile, HttpSession session) throws IOException { + String originalFilename = myFile.getOriginalFilename(); + int pos = originalFilename.lastIndexOf("."); + String suffix = originalFilename.substring(pos); + + String uuid = UUID.randomUUID().toString(); + String fullPath = filePath + File.separator + uuid + suffix; + String homeworkid = File.separator + uuid + suffix; + InputStream in = null; + try { + in = myFile.getInputStream(); + OutputStream out = new FileOutputStream(new File(fullPath)); + int len = 0; + byte[] buf = new byte[3 * 1024]; + while ((len = in.read(buf)) != -1) { + out.write(buf, 0, len); + } + out.close(); + in.close(); + } catch (IOException e) { + e.printStackTrace(); + } + Map map = new HashMap(); + map.put("result", homeworkid); + return map; + } + + + + @RequestMapping(value = "/download/{homeworkid}", method = RequestMethod.GET) + public void downLoad(@PathVariable("homeworkid") String homeworkid, HttpServletResponse response) { + List> list = dd.queryfindhomework(homeworkid); + for (int i=0;i 0) { + map.put("rs", "success"); + } else if (rs == -1) { + map.put("rs", "outtime"); + } else { + map.put("rs", "fail"); + } + return map; + } + + @RequestMapping("rank/{type}") + public ArrayList rank(@PathVariable("type") String type) { + return hs.getRank(type); + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/controller/UserController.java b/SpringBootAngularjs/src/main/java/com/cy/controller/UserController.java new file mode 100644 index 0000000..9b37367 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/controller/UserController.java @@ -0,0 +1,92 @@ +package com.cy.controller; + +import com.cy.entity.User; +import com.cy.service.UserService; +import com.cy.utils.KeyUtils; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@RestController + +public class UserController { + //使用SpringIOC控制反转,让spring容器创建对象 + //userservice上添加@Service注解 + @Resource + UserService us; + + @RequestMapping("register") + public Object save(@RequestBody User user) { + user.setId(KeyUtils.genUniqueKey()); + if (us.save(user) != null) { + return "success"; + } else { + return "fail"; + } + } + + @RequestMapping("checkName") + @ResponseBody + public Map checkName(HttpServletRequest request) { + String username = request.getParameter("username"); + List user = us.findByName(username); + boolean result = false; + if (user.size() > 0) { + result = true; + } + Map map = new HashMap(); + map.put("result", result); + return map; + } + + @RequestMapping("login") + public User login(@RequestBody User user,HttpServletRequest request) { + String loginName = user.getUsername(); + String password = user.getPassword(); + User user1 = us.findByNameAndPassword(loginName, password); + if (user1 != null) { + HttpSession session = request.getSession(); + session.setAttribute("currentuser",user1); + + return user1; + } else { + return null; + } + } + + @RequestMapping("showId") + public Map showId(HttpServletRequest request) { + Map map = new HashMap(); + HttpSession session = request.getSession(); + User currentuser = (User)session.getAttribute("currentuser"); + map.put("username",currentuser.getUsername()); + map.put("id",currentuser.getId()); + map.put("type",currentuser.getType()); + return map; + } + + @RequestMapping("setId") + public Map setId(HttpServletRequest request){ + Map map = new HashMap(); + map.put("rs","y"); + String name = request.getParameter("username"); + String id = request.getParameter("id"); + String type = request.getParameter("type"); + HttpSession session = request.getSession(); + session.setAttribute("username",name); + session.setAttribute("id",id); + session.setAttribute("type",type); + return map; + } + + +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/entity/Homework.java b/SpringBootAngularjs/src/main/java/com/cy/entity/Homework.java new file mode 100644 index 0000000..cd89406 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/entity/Homework.java @@ -0,0 +1,66 @@ +package com.cy.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import java.sql.Date; +@Entity +public class Homework { + @Id + @Column(length = 80) + private String id; + private String title; + private String type; + private Date updateTime; + private Date finishTime; + private String details; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } + + public Date getFinishTime() { + return finishTime; + } + + public void setFinishTime(Date finishTime) { + this.finishTime = finishTime; + } + + public String getDetails() { + return details; + } + + public void setDetails(String details) { + this.details = details; + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkRankDTO.java b/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkRankDTO.java new file mode 100644 index 0000000..d24dd23 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkRankDTO.java @@ -0,0 +1,31 @@ +package com.cy.entity; + +public class HomeworkRankDTO { + private String username; + private String ac; + private String type; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getAc() { + return ac; + } + + public void setAc(String ac) { + this.ac = ac; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkUserDTO.java b/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkUserDTO.java new file mode 100644 index 0000000..745d3d1 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/entity/HomeworkUserDTO.java @@ -0,0 +1,63 @@ +package com.cy.entity; + +import java.sql.Date; + +public class HomeworkUserDTO { + private String id; + private String username; + private String hid; + private String completeTime; + private String status; + private String homeworkid; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getHid() { + return hid; + } + + public void setHid(String hid) { + this.hid = hid; + } + + + + public String getCompleteTime() { + return completeTime; + } + + public void setCompleteTime(String completeTime) { + this.completeTime = completeTime; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getHomeworkid() { + return homeworkid; + } + + public void setHomeworkid(String homeworkid) { + this.homeworkid = homeworkid; + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/entity/User.java b/SpringBootAngularjs/src/main/java/com/cy/entity/User.java new file mode 100644 index 0000000..9cb98b9 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/entity/User.java @@ -0,0 +1,59 @@ +package com.cy.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class User { + @Id + @Column(length = 80) + private String id; + private String username; + private String password; + private String type; + + public User(String id, String username, String password, String type) { + this.id = id; + this.username = username; + this.password = password; + this.type = type; + } + + + public User() { + + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/repository/DTODao.java b/SpringBootAngularjs/src/main/java/com/cy/repository/DTODao.java new file mode 100644 index 0000000..7f25777 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/repository/DTODao.java @@ -0,0 +1,70 @@ +package com.cy.repository; + +import com.cy.entity.Homework; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.sql.Types; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@Repository +public class DTODao { + @Resource + private JdbcTemplate jdbcTemplate; + + public List> queryHomeworkUserDTOListMap(Homework homework) { + String sql = "SELECT u.id,u.username,uh.h_id,uh.complete_time,uh.homeworkid from `user` u LEFT JOIN user_homework uh on (u.id=uh.u_id and uh.h_id= ? )where u.type='student'"; + Object[] args = {homework.getId()}; + int[] argTypes = {Types.VARCHAR}; + + return this.jdbcTemplate.queryForList(sql, args, argTypes); + } + + + public int queryuploadDTOListMap(String uid, String hid, String homeworkid,Date date) { + String sql = "insert into user_homework(h_id,u_id,complete_time,homeworkid,status) values(?,?,?,?,?)"; + Object[] args = {hid, uid, date, homeworkid,"完成"}; + int[] argTypes = {Types.VARCHAR, Types.VARCHAR, Types.DATE, Types.VARCHAR}; + + return this.jdbcTemplate.update(sql, args); + } + + public int queryuploadDTOListMap2(String uid, String hid,String homeworkid, Date date) { + String sql = "update user_homework set complete_time =? , homeworkid=? where u_id=? AND h_id=?"; + Object[] args = {date,homeworkid, uid,hid}; + int[] argTypes = {Types.VARCHAR, Types.VARCHAR, Types.DATE, Types.VARCHAR}; + + return this.jdbcTemplate.update(sql, args); + } + + public List> queryRankDTOListMap(String type) { + if ("全部".equals(type)) { + String sql = "SELECT `user`.`username`,COUNT(user_homework.`status`) ac, `user`.type FROM `user` LEFT JOIN user_homework ON `user`.id=user_homework.u_id GROUP BY `user`.id HAVING `user`.type='student' ORDER BY COUNT(user_homework.`status`) DESC"; + return this.jdbcTemplate.queryForList(sql); + } else { + String sql2 = "SELECT `user`.`username`,count(t.h_id) ac ,`user`.type FROM `user` LEFT JOIN (SELECT `user`.id,`user`.`username`,user_homework.h_id FROM `user` LEFT JOIN user_homework on `user`.id = user_homework.u_id LEFT JOIN homework on user_homework.h_id=homework.id where homework.type=?) t on t.id = `user`.id GROUP BY `user`.id HAVING `user`.type='student' ORDER BY COUNT(t.h_id) desc;"; + Object[] args = {type}; + int[] argTypes = {Types.VARCHAR}; + return this.jdbcTemplate.queryForList(sql2, args, argTypes); + } + } + + public List> queryfindhomework(String homeworkid) { + String sql = ("select * from user_homework where homeworkid=? "); + Object[] args = {homeworkid}; + int[] argTypes = {Types.VARCHAR}; + return this.jdbcTemplate.queryForList(sql, args,argTypes); + } + + public List> queryfindexit(String uid,String hid) { + String sql = ("select * from user_homework where u_id=? AND h_id=? "); + Object[] args = {uid,hid}; + int[] argTypes = {Types.VARCHAR,Types.VARCHAR}; + return this.jdbcTemplate.queryForList(sql, args,argTypes); + } + + +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/repository/HomeworkRepository.java b/SpringBootAngularjs/src/main/java/com/cy/repository/HomeworkRepository.java new file mode 100644 index 0000000..476571b --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/repository/HomeworkRepository.java @@ -0,0 +1,15 @@ +package com.cy.repository; + +import com.cy.entity.Homework; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.sql.Date; +import java.util.List; + +public interface HomeworkRepository extends JpaRepository { + List findByTypeAndFinishTime(String type, Date date); + List findAllById(String id); + Page findByTypeAndFinishTime(String type, Date date, Pageable pageable); +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/repository/UserRepository.java b/SpringBootAngularjs/src/main/java/com/cy/repository/UserRepository.java new file mode 100644 index 0000000..96f754d --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/repository/UserRepository.java @@ -0,0 +1,13 @@ +package com.cy.repository; + +import com.cy.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; + +public interface UserRepository extends JpaRepository { + List findByUsername(String username); + + User findByUsernameAndPassword(String username, String password); +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/service/HomeworkService.java b/SpringBootAngularjs/src/main/java/com/cy/service/HomeworkService.java new file mode 100644 index 0000000..fc7c1f4 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/service/HomeworkService.java @@ -0,0 +1,127 @@ +package com.cy.service; + +import com.cy.entity.Homework; +import com.cy.entity.HomeworkRankDTO; +import com.cy.entity.HomeworkUserDTO; +import com.cy.repository.DTODao; +import com.cy.repository.HomeworkRepository; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.sql.Date; + +import java.sql.Time; +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +public class HomeworkService { + @Resource + HomeworkRepository hr; + @Resource + DTODao dd; + + public List findByTypeAndFinishTime(String type, Date date) { + return hr.findByTypeAndFinishTime(type, date); + } + public Iterable findByTypeAndFinishTime(String type, Date date, Pageable pageable){ + return hr.findByTypeAndFinishTime(type,date,pageable); + } + + public Homework save(Homework homework) { + return hr.save(homework); + } + + public List findAllById(String id) { + return hr.findAllById(id); + } + + public Homework update(Homework homework) { + return hr.save(homework); + } + + public void deleteById(String id) { + hr.deleteById(id); + } + + + public ArrayList gethomeworkdetail(Homework homework) { + ArrayList ah = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd"); + List> listmap = dd.queryHomeworkUserDTOListMap(homework); + for (int i = 0; i < listmap.size(); i++) { + HomeworkUserDTO hud = new HomeworkUserDTO(); + String id = (String) listmap.get(i).get("id"); + String username = (String) listmap.get(i).get("username"); + String hid = (String) listmap.get(i).get("hid"); + String homeworkid = (String) listmap.get(i).get("homeworkid"); + try { + if (listmap.get(i).get("complete_time") != null) { + Date completeTime = new Date(sdf.parse(listmap.get(i).get("complete_time").toString()).getTime()); + hud.setCompleteTime(sdf.format(completeTime)); + } else { + + hud.setCompleteTime(""); + } + + } catch (ParseException e) { + e.printStackTrace(); + } + hud.setId(id); + hud.setUsername(username); + hud.setHid(hid); + hud.setHomeworkid(homeworkid); + if (hud.getCompleteTime() == "") { + hud.setStatus("未完成"); + } else { + hud.setStatus("完成"); + } + ah.add(hud); + } + return ah; + } + + + public ArrayList getRank(String type1) { + ArrayList hr = new ArrayList<>(); + List> listmap = dd.queryRankDTOListMap(type1); + for (int i = 0; i < listmap.size(); i++) { + HomeworkRankDTO hrd = new HomeworkRankDTO(); + String username = (String) listmap.get(i).get("username"); + String ac = listmap.get(i).get("ac").toString(); + String type = (String) listmap.get(i).get("type"); + hrd.setUsername(username); + hrd.setAc(ac); + hrd.setType(type); + hr.add(hrd); + } + return hr; + } + + public int savedetails(String uid, String hid,String homeworkid) { + int rs = 0; + List list = hr.findAllById(hid); + if (new Date(System.currentTimeMillis()).getTime() > list.get(0).getFinishTime().getTime()) { + rs = -1; + } else { +// dd.queryuploadDTOListMap(uid, hid, homeworkid,new Timestamp(new java.util.Date().getTime())); +// rs = 1; + if (dd.queryfindexit(uid,hid).size() > 0) { + dd.queryuploadDTOListMap2(uid, hid, homeworkid,new Timestamp(new java.util.Date().getTime())); + rs = 1; + } else { + dd.queryuploadDTOListMap(uid, hid, homeworkid,new Timestamp(new java.util.Date().getTime())); + rs = 1; + } + } + return rs; + } + + +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/service/UserService.java b/SpringBootAngularjs/src/main/java/com/cy/service/UserService.java new file mode 100644 index 0000000..ffd5221 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/service/UserService.java @@ -0,0 +1,31 @@ +package com.cy.service; + + +import com.cy.entity.Homework; +import com.cy.entity.User; +import com.cy.repository.UserRepository; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + + +@Service +public class UserService { + @Resource + UserRepository ur; + + public User save(User user) { + return ur.save(user); + } + + public List findByName(String name){ + return ur.findByUsername(name); + } + + public User findByNameAndPassword(String name,String password){ + return ur.findByUsernameAndPassword(name,password); + } + + +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/utils/KeyUtils.java b/SpringBootAngularjs/src/main/java/com/cy/utils/KeyUtils.java new file mode 100644 index 0000000..8725b23 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/utils/KeyUtils.java @@ -0,0 +1,11 @@ +package com.cy.utils; + +import java.util.Random; + +public class KeyUtils { + public static synchronized String genUniqueKey() { + Random random = new Random(); + Integer number = random.nextInt(900000) + 100000; + return System.currentTimeMillis() + String.valueOf(number); + } +} diff --git a/SpringBootAngularjs/src/main/java/com/cy/utils/WebMvcConfiguration.java b/SpringBootAngularjs/src/main/java/com/cy/utils/WebMvcConfiguration.java new file mode 100644 index 0000000..6ad7b06 --- /dev/null +++ b/SpringBootAngularjs/src/main/java/com/cy/utils/WebMvcConfiguration.java @@ -0,0 +1,19 @@ +package com.cy.utils; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +public class WebMvcConfiguration extends WebMvcConfigurerAdapter { + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + + //addResourceHandler是指你想在url请求的路径 + //addResourceLocations是图片存放的真实路径 + + registry.addResourceHandler("/homework/**").addResourceLocations("file:D:/tmp/").addResourceLocations("classpath:/static/"); + super.addResourceHandlers(registry); + } +}