-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,382 additions
and
104 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/java/com/emperorws/hrmanagement/config/VerificationCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.emperorws.hrmanagement.config; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.Random; | ||
|
||
/** | ||
* @Author: EmperorWS | ||
* @Date: 2020/3/4 15:59 | ||
* @Description: 生成验证码的工具类 | ||
**/ | ||
public class VerificationCode { | ||
|
||
private int width = 100;// 生成验证码图片的宽度 | ||
private int height = 30;// 生成验证码图片的高度 | ||
private String[] fontNames = { "宋体", "楷体", "隶书", "微软雅黑" }; | ||
private Color bgColor = new Color(255, 255, 255);// 定义验证码图片的背景颜色为白色 | ||
private Random random = new Random(); | ||
private String codes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
private String text;// 记录随机字符串 | ||
|
||
/** | ||
* 获取一个随意颜色 | ||
* | ||
* @return | ||
*/ | ||
private Color randomColor() { | ||
int red = random.nextInt(150); | ||
int green = random.nextInt(150); | ||
int blue = random.nextInt(150); | ||
return new Color(red, green, blue); | ||
} | ||
|
||
/** | ||
* 获取一个随机字体 | ||
* | ||
* @return | ||
*/ | ||
private Font randomFont() { | ||
String name = fontNames[random.nextInt(fontNames.length)]; | ||
int style = random.nextInt(4); | ||
int size = random.nextInt(5) + 24; | ||
return new Font(name, style, size); | ||
} | ||
|
||
/** | ||
* 获取一个随机字符 | ||
* | ||
* @return | ||
*/ | ||
private char randomChar() { | ||
return codes.charAt(random.nextInt(codes.length())); | ||
} | ||
|
||
/** | ||
* 创建一个空白的BufferedImage对象 | ||
* | ||
* @return | ||
*/ | ||
private BufferedImage createImage() { | ||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | ||
Graphics2D g2 = (Graphics2D) image.getGraphics(); | ||
g2.setColor(bgColor);// 设置验证码图片的背景颜色 | ||
g2.fillRect(0, 0, width, height); | ||
return image; | ||
} | ||
|
||
public BufferedImage getImage() { | ||
BufferedImage image = createImage(); | ||
Graphics2D g2 = (Graphics2D) image.getGraphics(); | ||
StringBuffer sb = new StringBuffer(); | ||
for (int i = 0; i < 4; i++) { | ||
String s = randomChar() + ""; | ||
sb.append(s); | ||
g2.setColor(randomColor()); | ||
g2.setFont(randomFont()); | ||
float x = i * width * 1.0f / 4; | ||
g2.drawString(s, x, height - 8); | ||
} | ||
this.text = sb.toString(); | ||
drawLine(image); | ||
return image; | ||
} | ||
|
||
/** | ||
* 绘制干扰线 | ||
* | ||
* @param image | ||
*/ | ||
private void drawLine(BufferedImage image) { | ||
Graphics2D g2 = (Graphics2D) image.getGraphics(); | ||
int num = 5; | ||
for (int i = 0; i < num; i++) { | ||
int x1 = random.nextInt(width); | ||
int y1 = random.nextInt(height); | ||
int x2 = random.nextInt(width); | ||
int y2 = random.nextInt(height); | ||
g2.setColor(randomColor()); | ||
g2.setStroke(new BasicStroke(1.5f)); | ||
g2.drawLine(x1, y1, x2, y2); | ||
} | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public static void output(BufferedImage image, OutputStream out) throws IOException { | ||
ImageIO.write(image, "JPEG", out); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/emperorws/hrmanagement/config/VerificationCodeFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.emperorws.hrmanagement.config; | ||
|
||
import com.emperorws.hrmanagement.model.RespBean; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.servlet.*; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
/** | ||
* @Author: EmperorWS | ||
* @Date: 2020/3/4 16:29 | ||
* @Description: 登陆前校验验证码 | ||
**/ | ||
@Component | ||
public class VerificationCodeFilter extends GenericFilter { | ||
@Override | ||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { | ||
HttpServletRequest req = (HttpServletRequest) servletRequest; | ||
HttpServletResponse resp = (HttpServletResponse) servletResponse; | ||
if ("POST".equals(req.getMethod()) && "/doLogin".equals(req.getServletPath())) { | ||
//登录请求 | ||
String code = req.getParameter("code"); | ||
String verify_code = (String) req.getSession().getAttribute("verify_code"); | ||
if (code == null || verify_code == null || "".equals(code) || !verify_code.toLowerCase().equals(code.toLowerCase())) { | ||
//验证码不正确 | ||
resp.setContentType("application/json;charset=utf-8"); | ||
PrintWriter out = resp.getWriter(); | ||
out.write(new ObjectMapper().writeValueAsString(RespBean.error("验证码错误"))); | ||
out.flush(); | ||
out.close(); | ||
return; | ||
} else { | ||
filterChain.doFilter(req, resp); | ||
} | ||
} else { | ||
filterChain.doFilter(req, resp); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/emperorws/hrmanagement/controller/LoginController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.emperorws.hrmanagement.controller; | ||
|
||
import com.emperorws.hrmanagement.config.VerificationCode; | ||
import com.emperorws.hrmanagement.model.RespBean; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @Author: EmperorWS | ||
* @Date: 2020/3/4 16:05 | ||
* @Description: 用户登录控制层 | ||
**/ | ||
@RestController | ||
public class LoginController { | ||
@GetMapping("/login") | ||
public RespBean login() { | ||
return RespBean.error("尚未登录,请登录!"); | ||
} | ||
|
||
@GetMapping("/verifyCode") | ||
public void verifyCode(HttpSession session, HttpServletResponse resp) throws IOException { | ||
VerificationCode code = new VerificationCode(); | ||
BufferedImage image = code.getImage(); | ||
String text = code.getText(); | ||
session.setAttribute("verify_code", text); | ||
VerificationCode.output(image,resp.getOutputStream()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/emperorws/hrmanagement/controller/UserInfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.emperorws.hrmanagement.controller; | ||
|
||
import com.emperorws.hrmanagement.model.RespBean; | ||
import com.emperorws.hrmanagement.model.User; | ||
import com.emperorws.hrmanagement.service.UserService; | ||
import com.qiniu.util.Auth; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @Author: EmperorWS | ||
* @Date: 2020/3/4 12:49 | ||
* @Description: 员工修改个人信息控制层 | ||
**/ | ||
@RestController | ||
@RequestMapping("/user") | ||
public class UserInfoController { | ||
@Autowired | ||
UserService userService; | ||
|
||
@GetMapping("/info") | ||
public User getCurrentUser(Authentication authentication) { | ||
return ((User) authentication.getPrincipal()); | ||
} | ||
|
||
@PutMapping("/info") | ||
public RespBean updateHr(@RequestBody User user, Authentication authentication) { | ||
if (userService.updateUser(user) == 1) { | ||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(user, authentication.getCredentials(), authentication.getAuthorities())); | ||
return RespBean.ok("更新成功!"); | ||
} | ||
return RespBean.error("更新失败!"); | ||
} | ||
|
||
@PutMapping("/password") | ||
public RespBean updateUserPassword(@RequestBody Map<String, Object> info) { | ||
String oldpassword = (String) info.get("oldpassword"); | ||
String password = (String) info.get("password"); | ||
Integer userid = (Integer) info.get("userid"); | ||
if (userService.updateUserPassword(oldpassword, password, userid)) { | ||
return RespBean.ok("更新成功!"); | ||
} | ||
return RespBean.error("更新失败!"); | ||
} | ||
|
||
@GetMapping("/check/username/{username}") | ||
public Boolean getUserByUsername(@PathVariable String username){ | ||
return userService.getUserByUsername(username); | ||
} | ||
|
||
@GetMapping("/check/password") | ||
public Boolean getUserByPassword(String password,Integer userid){ | ||
return userService.getUserByPassword(password,userid); | ||
} | ||
|
||
@GetMapping("/token") | ||
public String getToken(){ | ||
String accessKey = "HHpVv8wj2T-IGv8JrjZFArdSUy6QGMxuo10k7Hnd"; | ||
String secretKey = "qoAkFOku7m6wouAwum45Ef-SiCTrOarj5QTgZQ3y"; | ||
String bucket = "emperorws"; | ||
Auth auth = Auth.create(accessKey, secretKey); | ||
String upToken = auth.uploadToken(bucket); | ||
return upToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/com/emperorws/hrmanagement/controller/salary/SalaryinfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.emperorws.hrmanagement.controller.salary; | ||
|
||
import com.emperorws.hrmanagement.model.Employee; | ||
import com.emperorws.hrmanagement.model.RespPageBean; | ||
import com.emperorws.hrmanagement.model.Salaryinfo; | ||
import com.emperorws.hrmanagement.service.SalaryinfoService; | ||
import com.emperorws.hrmanagement.utils.SalInfoPOIUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
/** | ||
* @Author: EmperorWS | ||
* @Date: 2020/3/3 17:15 | ||
* @Description: 员工历史薪资信息控制层 | ||
**/ | ||
@RestController | ||
@RequestMapping("/salary/information") | ||
public class SalaryinfoController { | ||
@Autowired | ||
SalaryinfoService salaryinfoService; | ||
|
||
@GetMapping("/") | ||
public RespPageBean getSalaryinfoByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Employee employee, Date[] payoffdata) { | ||
return salaryinfoService.getSalaryinfoByPage(page, size, employee, payoffdata); | ||
} | ||
|
||
@PostMapping("/export") | ||
public ResponseEntity<byte[]> exportData(@RequestBody List<Salaryinfo> list) { | ||
return SalInfoPOIUtils.salaryinfo2Excel(list); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.