40 changed files with 1290 additions and 0 deletions
@ -0,0 +1,24 @@
|
||||
package com.biutag.outeradmin.config; |
||||
|
||||
import com.biutag.outeradmin.interceptor.UserLoginInterceptor; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistration; |
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
||||
@Configuration |
||||
public class LoginConfig implements WebMvcConfigurer { |
||||
@Autowired |
||||
private UserLoginInterceptor userLoginInterceptor; |
||||
@Override |
||||
public void addInterceptors(InterceptorRegistry registry) { |
||||
InterceptorRegistration interceptorRegistration = registry.addInterceptor(userLoginInterceptor); |
||||
interceptorRegistration.addPathPatterns("/**"); |
||||
interceptorRegistration.excludePathPatterns( |
||||
"/login", |
||||
"/captcha", |
||||
"/refresh-token" |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,19 @@
|
||||
package com.biutag.outeradmin.config; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType; |
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
||||
import org.mybatis.spring.annotation.MapperScan; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
@Configuration |
||||
@MapperScan("com.biutag.outeradmin.mapper") |
||||
public class MyBatisPlusConfig { |
||||
@Bean |
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() { |
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.POSTGRE_SQL)); |
||||
return interceptor; |
||||
} |
||||
} |
||||
@ -0,0 +1,78 @@
|
||||
package com.biutag.outeradmin.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.biutag.outeradmin.dto.HolidayDTO; |
||||
import com.biutag.outeradmin.dto.HolidayRefresh; |
||||
import com.biutag.outeradmin.dto.HolidayYear; |
||||
import com.biutag.outeradmin.entity.Holiday; |
||||
import com.biutag.outeradmin.mapper.HolidayMapper; |
||||
import com.biutag.outeradmin.service.HolidayService; |
||||
import com.biutag.outeradmin.util.HolidayUtil; |
||||
import com.biutag.util.StringUtils; |
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@RequiredArgsConstructor |
||||
@RestController |
||||
@Api(tags = "节假日接口") |
||||
@RequestMapping("/outer/holiday") |
||||
public class HolidayController { |
||||
private final HolidayService holidayService; |
||||
private final HolidayMapper holidayMapper; |
||||
|
||||
@PostMapping("/refresh-holiday") |
||||
@ApiOperation("同步节假日信息") |
||||
public HolidayRefresh setlist(@RequestBody String year) throws Exception { |
||||
HolidayYear getYear = JSON.parseObject(year, HolidayYear.class); |
||||
HolidayRefresh holidayRefresh = new HolidayRefresh(); |
||||
LocalDateTime currentDate = LocalDateTime.now(); |
||||
|
||||
String currentYear = Integer.toString(currentDate.getYear()); |
||||
// String currentYear = "2025";
|
||||
if (getYear.getYear().equals(currentYear)) { |
||||
holidayRefresh.setMessage("success"); |
||||
} else { |
||||
holidayMapper.delete(null); |
||||
List<Holiday> holidays = HolidayUtil.getAllHolidayByYear(getYear.getYear()); |
||||
holidayService.saveBatch(holidays); |
||||
holidayRefresh.setMessage("success"); |
||||
} |
||||
holidayRefresh.setHolidayList(getlist()); |
||||
return holidayRefresh; |
||||
} |
||||
|
||||
|
||||
@RequestMapping("/show-holiday") |
||||
@ApiOperation("进入页面显示节假日") |
||||
public List<HolidayDTO> getlist() { |
||||
List<Holiday> holidayList = holidayService.list(); |
||||
List<HolidayDTO> result = new ArrayList<>(); |
||||
for (Holiday holiday : holidayList) { |
||||
if (holiday.getHolidayFlag().equals("Y")) { |
||||
HolidayDTO holidayDTO = new HolidayDTO(); |
||||
holidayDTO.setHolidayFlag(holiday.getHolidayFlag()); |
||||
holidayDTO.setDetail(holiday.getDetail()); |
||||
holidayDTO.setDate(holiday.getDate()); |
||||
result.add(holidayDTO); |
||||
} else if (holiday.getHolidayFlag().equals("N") && StringUtils.isNotEmpty(holiday.getDetail())) { |
||||
HolidayDTO holidayDTO = new HolidayDTO(); |
||||
holidayDTO.setHolidayFlag(holiday.getHolidayFlag()); |
||||
holidayDTO.setDetail(holiday.getDetail()); |
||||
holidayDTO.setDate(holiday.getDate()); |
||||
result.add(holidayDTO); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,49 @@
|
||||
package com.biutag.outeradmin.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.biutag.outeradmin.dto.TokenDTO; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import com.biutag.outeradmin.service.UserService; |
||||
import com.biutag.outeradmin.util.JwtUtil; |
||||
import io.jsonwebtoken.Claims; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@Slf4j |
||||
@RestController |
||||
@RequiredArgsConstructor |
||||
public class JwtController { |
||||
private final UserService userService; |
||||
|
||||
|
||||
@RequestMapping("/refresh-token") |
||||
public TokenDTO refreshToken(@RequestBody String reToken) { |
||||
TokenDTO tokenDTOReceived = JSON.parseObject(reToken, TokenDTO.class); |
||||
String token = tokenDTOReceived.getRefreshToken(); |
||||
log.info("refresh_token:{}", token); |
||||
try { |
||||
Claims claims = JwtUtil.parseJwtToken(token).getPayload(); |
||||
log.info("refresh token:{}", token); |
||||
log.info("claims:{}", claims); |
||||
String phone = claims.get("username", String.class); |
||||
TokenDTO tokenDTO = new TokenDTO(); |
||||
|
||||
User user = userService.getOne(new QueryWrapper<User>().eq("phone", phone)); |
||||
// 如果用户存在,就生成一个新的令牌
|
||||
if (user != null) { |
||||
String refreshToken = JwtUtil.getNewRefreshToken(token); |
||||
String accessToken = JwtUtil.getNewAccessToken(token); |
||||
tokenDTO.setRefreshToken(refreshToken); |
||||
tokenDTO.setAccessToken(accessToken); |
||||
} |
||||
log.info("refresh token success:{}", tokenDTO.toString()); |
||||
return tokenDTO; |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,74 @@
|
||||
package com.biutag.outeradmin.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.biutag.enums.ErrorEnum; |
||||
import com.biutag.outeradmin.dto.LoginFormData; |
||||
import com.biutag.outeradmin.dto.TokenDTO; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import com.biutag.outeradmin.mapper.UserMapper; |
||||
import com.biutag.outeradmin.service.UserService; |
||||
import com.biutag.outeradmin.util.JwtUtil; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import lombok.RequiredArgsConstructor; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
@RequiredArgsConstructor |
||||
@RestController |
||||
@Slf4j |
||||
public class LoginController { |
||||
private final UserService userService; |
||||
private final UserMapper userMapper; |
||||
|
||||
private static String randomCaptcha = ""; |
||||
|
||||
|
||||
@RequestMapping("/login") |
||||
public TokenDTO login(@RequestBody String formData, HttpServletRequest request) { |
||||
LoginFormData data = JSON.parseObject(formData, LoginFormData.class); |
||||
TokenDTO tokens = new TokenDTO(); |
||||
if (!data.getCaptcha().equals(randomCaptcha)) { |
||||
tokens.setStateCode(ErrorEnum.CAPTCHA_ERROR.getCode()); |
||||
return tokens; |
||||
} else { |
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("phone", data.getAccount()); |
||||
User user = userService.getOne(queryWrapper, false); |
||||
if (user == null) { |
||||
tokens.setStateCode(ErrorEnum.LOGIN_ACCOUNT_ERROR.getCode()); |
||||
return tokens; |
||||
} else { |
||||
tokens.setAccessToken(JwtUtil.buildJwtToken(data.getAccount(), data.getCaptcha(), false)); |
||||
tokens.setRefreshToken(JwtUtil.buildJwtToken(data.getAccount(), data.getCaptcha(), true)); |
||||
log.info("refresh_token:{}", tokens.getRefreshToken()); |
||||
tokens.setStateCode(ErrorEnum.SUCCESS.getCode()); |
||||
return tokens; |
||||
} |
||||
} |
||||
} |
||||
|
||||
@RequestMapping("/captcha") |
||||
public String captcha(@RequestBody String formData) { |
||||
LoginFormData data = JSON.parseObject(formData, LoginFormData.class); |
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
||||
queryWrapper.eq("phone", data.getAccount()); |
||||
User user = userService.getOne(queryWrapper, false); |
||||
if (user == null) { |
||||
return Integer.toString(ErrorEnum.LOGIN_ACCOUNT_ERROR.getCode()); |
||||
} else { |
||||
randomCaptcha = Integer.toString((int) ((Math.random() * 9 + 1) * 100000)); |
||||
System.out.println(randomCaptcha); |
||||
return randomCaptcha; |
||||
} |
||||
|
||||
} |
||||
|
||||
@RequestMapping("/logout") |
||||
public int logout() { |
||||
log.info("用户已登出"); |
||||
return ErrorEnum.SUCCESS.getCode(); |
||||
} |
||||
} |
||||
@ -0,0 +1,149 @@
|
||||
package com.biutag.outeradmin.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.outeradmin.dto.*; |
||||
import com.biutag.outeradmin.entity.*; |
||||
import com.biutag.outeradmin.mapper.MailMapper; |
||||
import com.biutag.outeradmin.service.MailService; |
||||
import com.biutag.outeradmin.util.DesensitizedUtil; |
||||
import com.biutag.outeradmin.util.ExcelUtil; |
||||
import com.biutag.util.StringUtils; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
@RequiredArgsConstructor |
||||
@RequestMapping("/mailbox") |
||||
@RestController |
||||
public class MailController { |
||||
private final MailService mailService; |
||||
private final MailMapper mailMapper; |
||||
|
||||
/** |
||||
* 查询所有信件 |
||||
* |
||||
* @return 信件列表json |
||||
*/ |
||||
@RequestMapping("/list") |
||||
public MailPageInfo list(@RequestBody String req) { |
||||
PageSet pageSet = JSON.parseObject(req, PageSet.class); |
||||
Page<Mail> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); |
||||
List<Mail> mailPage = mailMapper.selectPage(page, null).getRecords(); |
||||
pageSet.setTotalSize((int) page.getTotal()); |
||||
MailPageInfo result = new MailPageInfo(); |
||||
result.setMails(mailPage); |
||||
result.setPageSet(pageSet); |
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 根据前端表格数据查询指定信件 |
||||
* |
||||
* @param form 前端信件表单数据 |
||||
* @return 指定信件json |
||||
*/ |
||||
@RequestMapping("/list-submit") |
||||
public MailPageInfo siftList(@RequestBody String form) { |
||||
MailFormPage mailFormPage = JSON.parseObject(form, MailFormPage.class); |
||||
QueryWrapper<Mail> queryWrapper = new QueryWrapper<>(); |
||||
if (mailFormPage != null && mailFormPage.getFormData() != null && mailFormPage.getPageData() != null) { |
||||
MailFormData mailFormData = mailFormPage.getFormData(); |
||||
if (StringUtils.isNotEmpty(mailFormData.getEvaluate())) { |
||||
switch (mailFormData.getEvaluate()) { |
||||
case "不满意": |
||||
mailFormData.setEvaluate("NOT_SATISFIED"); |
||||
break; |
||||
case "基本满意": |
||||
mailFormData.setEvaluate("BASICALLY_SATISFIED"); |
||||
break; |
||||
case "满意": |
||||
mailFormData.setEvaluate("SATISFIED"); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
queryWrapper.lambda().like(StringUtils.isNotEmpty(mailFormData.getContactName()), Mail::getContactName, mailFormData.getContactName()) |
||||
.like(StringUtils.isNotEmpty(mailFormData.getContactPhone()), Mail::getContactPhone, mailFormData.getContactPhone()) |
||||
.like(StringUtils.isNotEmpty(mailFormData.getContactIdCard()), Mail::getContactIdCard, mailFormData.getContactIdCard()) |
||||
.like(StringUtils.isNotEmpty(mailFormData.getId()), Mail::getId, mailFormData.getId()) |
||||
.like(StringUtils.isNotEmpty(mailFormData.getContent()), Mail::getContent, mailFormData.getContent()) |
||||
.eq(StringUtils.isNotEmpty(mailFormData.getEvaluate()), Mail::getSatisfaction, mailFormData.getEvaluate()); |
||||
if (CollectionUtils.isNotEmpty(mailFormData.getDate()) && mailFormData.getDate().size() == 2) { |
||||
queryWrapper.lambda().between(Mail::getCreateTime, mailFormData.getDate().get(0), mailFormData.getDate().get(1)); |
||||
} |
||||
} |
||||
PageSet pageSet = mailFormPage.getPageData(); |
||||
|
||||
Page<Mail> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); |
||||
List<Mail> mailPage = mailMapper.selectPage(page, queryWrapper).getRecords(); |
||||
for (Mail mail : mailPage) { |
||||
mail.setContactIdCard(DesensitizedUtil.encryptIDCard(mail.getContactIdCard())); |
||||
mail.setContactPhone(DesensitizedUtil.encryptPhone(mail.getContactPhone())); |
||||
if (StringUtils.isNotEmpty(mail.getSatisfaction())) { |
||||
switch (mail.getSatisfaction()) { |
||||
case "SATISFIED": |
||||
mail.setSatisfaction("满意"); |
||||
break; |
||||
case "NOT_SATISFIED": |
||||
mail.setSatisfaction("不满意"); |
||||
break; |
||||
case "BASICALLY_SATISFIED": |
||||
mail.setSatisfaction("基本满意"); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
pageSet.setTotalSize((int) page.getTotal()); |
||||
MailPageInfo result = new MailPageInfo(); |
||||
result.setMails(mailPage); |
||||
result.setPageSet(pageSet); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 查询指定信件详情 |
||||
* |
||||
* @param id 信件ID |
||||
* @return 指定信件详情json |
||||
*/ |
||||
@RequestMapping("/detail") |
||||
public String detail(@RequestBody String id) { |
||||
MailID mailID = JSON.parseObject(id, MailID.class); |
||||
//TODO 这里根据ID查询数据库,记得删掉
|
||||
Mail mail = mailService.getById(mailID.getID()); |
||||
mail.setContactIdCard(DesensitizedUtil.encryptIDCard(mail.getContactIdCard())); |
||||
mail.setContactPhone(DesensitizedUtil.encryptPhone(mail.getContactPhone())); |
||||
return JSON.toJSONString(mail); |
||||
} |
||||
|
||||
@RequestMapping("/exportexcel") |
||||
public void exportexcel(HttpServletResponse response, @RequestBody String form) throws IOException { |
||||
MailFormPage formPage = JSON.parseObject(form, MailFormPage.class); |
||||
QueryWrapper<Mail> queryWrapper = new QueryWrapper<>(); |
||||
if (formPage != null && formPage.getFormData() != null && formPage.getPageData() != null) { |
||||
MailFormData formData = formPage.getFormData(); |
||||
queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getContactName()), Mail::getContactName, formData.getContactName()) |
||||
.like(StringUtils.isNotEmpty(formData.getContactPhone()), Mail::getContactPhone, formData.getContactPhone()) |
||||
.like(StringUtils.isNotEmpty(formData.getContactIdCard()), Mail::getContactIdCard, formData.getContactIdCard()) |
||||
.like(StringUtils.isNotEmpty(formData.getId()), Mail::getId, formData.getId()) |
||||
.like(StringUtils.isNotEmpty(formData.getContent()), Mail::getContent, formData.getContent()); |
||||
if (CollectionUtils.isNotEmpty(formData.getDate()) && formData.getDate().size() == 2) { |
||||
queryWrapper.lambda().between(Mail::getCreateTime, formData.getDate().get(0), formData.getDate().get(1)); |
||||
} |
||||
} |
||||
|
||||
List<Mail> mailPage = mailMapper.selectList(queryWrapper); |
||||
for (Mail mail : mailPage) { |
||||
mail.setContactIdCard(DesensitizedUtil.encryptIDCard(mail.getContactIdCard())); |
||||
mail.setContactPhone(DesensitizedUtil.encryptPhone(mail.getContactPhone())); |
||||
} |
||||
ExcelUtil.exportExcel(response, mailPage); |
||||
} |
||||
} |
||||
@ -0,0 +1,90 @@
|
||||
package com.biutag.outeradmin.controller; |
||||
|
||||
import com.alibaba.fastjson2.JSON; |
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||
import com.biutag.outeradmin.dto.PageSet; |
||||
import com.biutag.outeradmin.dto.UserFormData; |
||||
import com.biutag.outeradmin.dto.UserFormPage; |
||||
import com.biutag.outeradmin.dto.UserPageInfo; |
||||
import com.biutag.outeradmin.entity.*; |
||||
import com.biutag.outeradmin.mapper.UserMapper; |
||||
import com.biutag.outeradmin.service.UserService; |
||||
import com.biutag.outeradmin.util.DesensitizedUtil; |
||||
import com.biutag.util.StringUtils; |
||||
import lombok.RequiredArgsConstructor; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.time.LocalDateTime; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.List; |
||||
|
||||
@RequestMapping("/user") |
||||
@RestController |
||||
@RequiredArgsConstructor |
||||
public class UserController { |
||||
private final UserMapper userMapper; |
||||
private final UserService userService; |
||||
|
||||
@RequestMapping("/list-submit") |
||||
public UserPageInfo siftList(@RequestBody String form) { |
||||
UserFormPage userFormPage = JSON.parseObject(form, UserFormPage.class); |
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
||||
if (userFormPage != null && userFormPage.getFormData() != null && userFormPage.getPageData() != null) { |
||||
UserFormData formData = userFormPage.getFormData(); |
||||
|
||||
queryWrapper.lambda().like(StringUtils.isNotEmpty(formData.getRealName()), User::getRealName, formData.getRealName()) |
||||
.like(StringUtils.isNotEmpty(formData.getPhone()), User::getPhone, formData.getPhone()) |
||||
.like(StringUtils.isNotEmpty(formData.getIdCard()), User::getIdCard, formData.getIdCard()); |
||||
if (CollectionUtils.isNotEmpty(formData.getDate()) && formData.getDate().size() == 2) { |
||||
queryWrapper.lambda().between(User::getCreateTime, formData.getDate().get(0), formData.getDate().get(1)); |
||||
} |
||||
} |
||||
PageSet pageSet = userFormPage.getPageData(); |
||||
|
||||
Page<User> page = new Page<>(pageSet.getCurrentPage(), pageSet.getPageSize()); |
||||
List<User> userPage = userMapper.selectPage(page, queryWrapper).getRecords(); |
||||
for (User user : userPage) { |
||||
user.setIdCard(DesensitizedUtil.encryptIDCard(user.getIdCard())); |
||||
user.setPhone(DesensitizedUtil.encryptPhone(user.getPhone())); |
||||
} |
||||
pageSet.setTotalSize((int) page.getTotal()); |
||||
UserPageInfo result = new UserPageInfo(); |
||||
result.setUsers(userPage); |
||||
result.setPageSet(pageSet); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
@RequestMapping("/add-user") |
||||
public String addUser(@RequestBody String form) { |
||||
UserFormData userForm = JSON.parseObject(form, UserFormData.class); |
||||
User user = new User(); |
||||
user.setRealName(userForm.getRealName()); |
||||
user.setPhone(userForm.getPhone()); |
||||
user.setIdCard(userForm.getIdCard()); |
||||
LocalDateTime createTime = LocalDateTime.now(); |
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
try { |
||||
user.setCreateTime(simpleDateFormat.parse(createTime.format(formatter))); |
||||
userMapper.insert(user); |
||||
return "success"; |
||||
} catch (ParseException e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
} |
||||
|
||||
@RequestMapping("/delete-user") |
||||
public String deleteUser(@RequestBody String id) { |
||||
User user = JSON.parseObject(id, User.class); |
||||
userMapper.deleteById(user.getId()); |
||||
return "success"; |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class HolidayDTO { |
||||
private String date; |
||||
private String holidayFlag; |
||||
private String detail; |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
@Data |
||||
public class HolidayRefresh { |
||||
private List<HolidayDTO> holidayList; |
||||
private String message; |
||||
} |
||||
@ -0,0 +1,8 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class HolidayYear { |
||||
private String year; |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class LoginFormData { |
||||
private String account; |
||||
private String captcha; |
||||
} |
||||
@ -0,0 +1,16 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class MailFormData { |
||||
private List<String> date; |
||||
private String contactName; |
||||
private String contactPhone; |
||||
private String contactIdCard; |
||||
private String id; |
||||
private String content; |
||||
private String evaluate; |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class MailFormPage { |
||||
private MailFormData formData; |
||||
private PageSet pageData; |
||||
|
||||
} |
||||
@ -0,0 +1,8 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class MailID { |
||||
private String ID; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import com.biutag.outeradmin.entity.Mail; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class MailPageInfo { |
||||
private List<Mail> mails; |
||||
private PageSet pageSet; |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class PageSet { |
||||
private int currentPage; |
||||
private int pageSize; |
||||
private int totalSize; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
import org.apache.poi.ss.formula.functions.T; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class TokenDTO { |
||||
private String accessToken; |
||||
private String refreshToken; |
||||
private int stateCode; |
||||
private List<T> list; |
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class UserFormData { |
||||
private List<String> date; |
||||
private String realName; |
||||
private String phone; |
||||
private String idCard; |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class UserFormPage { |
||||
private UserFormData formData; |
||||
private PageSet pageData; |
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
package com.biutag.outeradmin.dto; |
||||
|
||||
import com.biutag.outeradmin.dto.PageSet; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import lombok.Data; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Data |
||||
public class UserPageInfo { |
||||
private List<User> users; |
||||
private PageSet pageSet; |
||||
} |
||||
@ -0,0 +1,11 @@
|
||||
package com.biutag.outeradmin.entity; |
||||
|
||||
import lombok.Data; |
||||
|
||||
@Data |
||||
public class Holiday { |
||||
private Integer id; |
||||
private String date; |
||||
private String holidayFlag; |
||||
private String detail; |
||||
} |
||||
@ -0,0 +1,72 @@
|
||||
package com.biutag.outeradmin.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Data |
||||
public class Mail { |
||||
@TableId |
||||
private String id; |
||||
|
||||
/** |
||||
* 联系人姓名 |
||||
*/ |
||||
private String contactName; |
||||
|
||||
/** |
||||
* 联系人性别 |
||||
*/ |
||||
private String contactSex; |
||||
|
||||
/** |
||||
* 联系人身份证号码 |
||||
*/ |
||||
private String contactIdCard; |
||||
|
||||
/** |
||||
* 联系人手机号码 |
||||
*/ |
||||
private String contactPhone; |
||||
|
||||
/** |
||||
* 案件编号 |
||||
*/ |
||||
private String caseNumber; |
||||
|
||||
/** |
||||
* 内容 |
||||
*/ |
||||
private String content; |
||||
|
||||
/** |
||||
* 附件 |
||||
*/ |
||||
private String attachments; |
||||
|
||||
/** |
||||
* 用户ID |
||||
*/ |
||||
private Integer userId; |
||||
|
||||
/** |
||||
* 创建时间 |
||||
*/ |
||||
private Date createTime; |
||||
|
||||
/** |
||||
* 更新时间 |
||||
*/ |
||||
private Date updateTime; |
||||
|
||||
// /**
|
||||
// * 评价
|
||||
// */
|
||||
// private String evaluate;
|
||||
|
||||
/** |
||||
* 是否满意 |
||||
*/ |
||||
private String satisfaction; |
||||
} |
||||
@ -0,0 +1,22 @@
|
||||
package com.biutag.outeradmin.entity; |
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId; |
||||
import com.baomidou.mybatisplus.annotation.TableName; |
||||
import lombok.Data; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Data |
||||
@TableName("\"user\"") |
||||
public class User { |
||||
@TableId |
||||
private Integer id; |
||||
private String openid; |
||||
private String nickName; |
||||
private Date createTime; |
||||
private String idCard; |
||||
private String realName; |
||||
private String phone; |
||||
private Date updateTime; |
||||
private Date faceAuthTime; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outeradmin.exception; |
||||
|
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
||||
import org.springframework.web.bind.annotation.RestControllerAdvice; |
||||
|
||||
@RestControllerAdvice |
||||
public class GlobalExceptionHandler { |
||||
@ExceptionHandler(TokenException.class) |
||||
public String handleTokenException(TokenException e, HttpServletResponse response) { |
||||
response.setStatus(e.getCode()); |
||||
return e.getMessage(); |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outeradmin.exception; |
||||
|
||||
public class TokenException extends RuntimeException{ |
||||
private int code; |
||||
|
||||
public TokenException(int code, String message) { |
||||
super(message); |
||||
this.code = code; |
||||
} |
||||
|
||||
public int getCode() { |
||||
return code; |
||||
} |
||||
} |
||||
@ -0,0 +1,68 @@
|
||||
package com.biutag.outeradmin.interceptor; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import com.biutag.outeradmin.service.UserService; |
||||
import com.biutag.outeradmin.util.JwtUtil; |
||||
import io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.ExpiredJwtException; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Component; |
||||
import org.springframework.web.servlet.HandlerInterceptor; |
||||
|
||||
import java.util.Date; |
||||
|
||||
@Slf4j |
||||
@Component |
||||
public class UserLoginInterceptor implements HandlerInterceptor { |
||||
|
||||
@Autowired |
||||
private UserService userService; |
||||
|
||||
@Override |
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
||||
String token = request.getHeader("Authorization"); |
||||
if (token != null && token.startsWith("Bearer ")) { |
||||
token = token.substring(7); |
||||
try { |
||||
Claims claims = JwtUtil.parseJwtToken(token).getPayload(); |
||||
String name = claims.get("username", String.class); |
||||
Date date = claims.getExpiration(); |
||||
if (name != null && date != null && date.after(new Date())) { |
||||
log.info("用户{}已登录", name); |
||||
return true; |
||||
} |
||||
} catch (Exception e) { |
||||
if (e instanceof ExpiredJwtException) { |
||||
response.setStatus(401); |
||||
log.info("用户未登录或长时间未操作导致登陆失效"); |
||||
return false; |
||||
} |
||||
throw new RuntimeException("Token无效或过期"); |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { |
||||
if (ex == null) { |
||||
String token = request.getHeader("Authorization"); |
||||
token = token.substring(7); |
||||
Claims claims = JwtUtil.parseJwtToken(token).getPayload(); |
||||
String phone = claims.get("username", String.class); |
||||
|
||||
User user = userService.getOne(new QueryWrapper<User>().eq("phone", phone)); |
||||
// 如果用户存在,就生成一个新的令牌
|
||||
if (user != null) { |
||||
String newToken = JwtUtil.getNewAccessToken(token); |
||||
// 将新的令牌添加到响应头中
|
||||
response.setHeader("Authorization", "Bearer " + newToken); |
||||
log.info("用户{}的令牌已更新", phone); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.mapper; |
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outeradmin.entity.Holiday; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface HolidayMapper extends BaseMapper<Holiday> { |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outeradmin.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outeradmin.entity.Mail; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface MailMapper extends BaseMapper<Mail> { |
||||
} |
||||
@ -0,0 +1,9 @@
|
||||
package com.biutag.outeradmin.mapper; |
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import org.apache.ibatis.annotations.Mapper; |
||||
|
||||
@Mapper |
||||
public interface UserMapper extends BaseMapper<User> { |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outeradmin.entity.Holiday; |
||||
import com.biutag.outeradmin.mapper.HolidayMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class HolidayService extends ServiceImpl<HolidayMapper, Holiday> { |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outeradmin.entity.Mail; |
||||
import com.biutag.outeradmin.mapper.MailMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class MailService extends ServiceImpl<MailMapper, Mail> { |
||||
} |
||||
@ -0,0 +1,10 @@
|
||||
package com.biutag.outeradmin.service; |
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
||||
import com.biutag.outeradmin.entity.User; |
||||
import com.biutag.outeradmin.mapper.UserMapper; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
@Service |
||||
public class UserService extends ServiceImpl<UserMapper, User> { |
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
package com.biutag.outeradmin.util; |
||||
|
||||
import com.biutag.util.StringUtils; |
||||
|
||||
/** |
||||
* 身份证以及手机号脱敏处理工具类 |
||||
*/ |
||||
public class DesensitizedUtil { |
||||
public static String encryptIDCard(String idCard) { |
||||
if (StringUtils.isNotBlank(idCard)) { |
||||
if (idCard.length() == 15) { |
||||
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{4})", "$1******$2"); |
||||
} |
||||
if (idCard.length() == 18) { |
||||
idCard = idCard.replaceAll("(\\w{6})\\w*(\\w{4})", "$1*********$2"); |
||||
} |
||||
} |
||||
return idCard; |
||||
} |
||||
|
||||
public static String encryptPhone(String phone) { |
||||
if (StringUtils.isNotBlank(phone)) { |
||||
phone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); |
||||
} |
||||
return phone; |
||||
} |
||||
} |
||||
@ -0,0 +1,76 @@
|
||||
package com.biutag.outeradmin.util; |
||||
|
||||
|
||||
|
||||
|
||||
import com.alibaba.excel.EasyExcel; |
||||
|
||||
import com.alibaba.excel.ExcelWriter; |
||||
import com.alibaba.excel.write.metadata.WriteSheet; |
||||
import com.alibaba.excel.write.metadata.fill.FillConfig; |
||||
import com.alibaba.excel.write.metadata.fill.FillWrapper; |
||||
import com.biutag.outeradmin.entity.Mail; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import org.springframework.core.io.ClassPathResource; |
||||
import org.springframework.core.io.Resource; |
||||
|
||||
|
||||
import java.io.IOException; |
||||
import java.io.InputStream; |
||||
|
||||
import java.text.SimpleDateFormat; |
||||
import java.util.*; |
||||
|
||||
|
||||
public class ExcelUtil { |
||||
public static void exportExcel(HttpServletResponse response,List<Mail> mailPage) throws IOException { |
||||
// 模板文件
|
||||
// String templateFile = "/excelmodel.xlsx";
|
||||
Resource resource = new ClassPathResource("excelmodel.xlsx"); |
||||
InputStream is = resource.getInputStream(); |
||||
// long date = new Date().getTime();
|
||||
Calendar calendar = Calendar.getInstance(); |
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
System.out.println(formatter.format(calendar.getTime())); |
||||
String name = formatter.format(calendar.getTime())+".xlsx"; |
||||
String fileName = new String(name.getBytes()); |
||||
response.setContentType("application/octet-stream"); |
||||
response.setCharacterEncoding("utf8"); |
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName); |
||||
// 根据模板文件生成目标文件
|
||||
ExcelWriter excelWriter = EasyExcel |
||||
.write(response.getOutputStream(), Mail.class) |
||||
.withTemplate(is) |
||||
// 单独设置单元格格式
|
||||
// .registerWriteHandler(new CellStyleHandler())
|
||||
.build(); |
||||
WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
||||
// 每次都会重新生成新的一行,而不是使用下面的空行
|
||||
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
||||
// 第一种占位符替换
|
||||
// Map<String, Object> map = new HashMap<String, Object>();
|
||||
// map.put("reportDate", reportDate);
|
||||
// excelWriter.fill(map, writeSheet);
|
||||
// 第二种占位符替换,这里定义了 hisData
|
||||
System.out.println(mailPage); |
||||
excelWriter.fill(new FillWrapper("mailPage",mailPage),fillConfig, writeSheet); |
||||
excelWriter.finish(); |
||||
} |
||||
|
||||
//
|
||||
// private static List<MailDto> mailData(){
|
||||
// List<MailDto> resList = new ArrayList<>();
|
||||
// MailDto mailData = MailDto.builder()
|
||||
// .contactName("today")
|
||||
// .contactIdCard("34.211")
|
||||
// .contactPhone("1.222")
|
||||
// .caseNumber("34.211")
|
||||
// .createTime(new Date())
|
||||
// .build();
|
||||
// resList.add(mailData);
|
||||
// return resList;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,161 @@
|
||||
package com.biutag.outeradmin.util; |
||||
|
||||
import com.biutag.outeradmin.entity.Holiday; |
||||
import com.fasterxml.jackson.databind.ObjectMapper; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.IOException; |
||||
import java.io.InputStreamReader; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.time.DayOfWeek; |
||||
import java.time.LocalDate; |
||||
import java.time.format.DateTimeFormatter; |
||||
import java.util.*; |
||||
|
||||
public class HolidayUtil { |
||||
|
||||
/** |
||||
* 发送get请求 |
||||
*/ |
||||
private static String get(String url){ |
||||
StringBuilder inputLine = new StringBuilder(); |
||||
String read; |
||||
try { |
||||
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); |
||||
urlConnection.setReadTimeout(30 * 1000); |
||||
urlConnection.setConnectTimeout(30 * 1000); |
||||
urlConnection.setRequestProperty("Charset", "UTF-8"); |
||||
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36)"); |
||||
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(), StandardCharsets.UTF_8)); |
||||
while ((read = in.readLine()) != null) { |
||||
inputLine.append(read); |
||||
} |
||||
in.close(); |
||||
} catch (IOException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
return inputLine.toString(); |
||||
} |
||||
|
||||
|
||||
public static List<Holiday> getAllHolidayByYear(String year) throws IOException { |
||||
List<Holiday> allDateDayList = new ArrayList<>(); |
||||
|
||||
// SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// ArrayList<HolidayVo> holidayVoList = new ArrayList<>();
|
||||
// HashMap<String, HolidayVo> hashMap = new HashMap<>();
|
||||
|
||||
//查询全年日历包含周末
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
||||
List<String> allDateList = new ArrayList<>(); |
||||
LocalDate startDate = LocalDate.of(Integer.parseInt(year.trim()), 1, 1); |
||||
LocalDate endDate = startDate; |
||||
|
||||
while (Integer.parseInt(year) == endDate.getYear()) { |
||||
Holiday holiday = new Holiday(); |
||||
DayOfWeek week = endDate.getDayOfWeek(); |
||||
if(week == DayOfWeek.SATURDAY ) { |
||||
holiday.setHolidayFlag("Y"); |
||||
holiday.setDate(endDate.format(formatter)); |
||||
holiday.setDetail("周六"); |
||||
allDateDayList.add(holiday); |
||||
}else if(week == DayOfWeek.SUNDAY){ |
||||
holiday.setHolidayFlag("Y"); |
||||
holiday.setDate(endDate.format(formatter)); |
||||
holiday.setDetail("周日"); |
||||
allDateDayList.add(holiday); |
||||
}else{ |
||||
holiday.setHolidayFlag("N"); |
||||
holiday.setDate(endDate.format(formatter)); |
||||
allDateDayList.add(holiday); |
||||
} |
||||
|
||||
endDate = endDate.plusDays(1L); |
||||
} |
||||
|
||||
|
||||
//查询全年节假日、调休
|
||||
String holidayJson = HolidayUtil.get("https://timor.tech/api/holiday/year/"+year + "/"); |
||||
ObjectMapper mapper = new ObjectMapper(); |
||||
Map holidayMap = mapper.readValue(holidayJson,Map.class); |
||||
LinkedHashMap holidayList = (LinkedHashMap)holidayMap.get("holiday"); |
||||
// if(holidayList == null){
|
||||
//
|
||||
// }
|
||||
holidayList.forEach((key,value) -> { |
||||
Holiday holiday = new Holiday(); |
||||
Map value1 = (Map) value; |
||||
String dateTime = value1.get("date").toString(); |
||||
holiday.setDate(dateTime); |
||||
if(value1.get("name").toString().contains("补班")){ |
||||
holiday.setDetail("正常上班"); |
||||
holiday.setHolidayFlag("N"); |
||||
}else { |
||||
holiday.setDetail(value1.get("name").toString()); |
||||
holiday.setHolidayFlag("Y"); |
||||
} |
||||
|
||||
for(int i = 0;i<allDateDayList.size();i++){ |
||||
if (allDateDayList.get(i).getDate().equals(holiday.getDate())){ |
||||
String detail = holiday.getDetail(); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int j = 0; j < detail.length(); j++) { |
||||
char c = detail.charAt(j); |
||||
if (sb.indexOf(String.valueOf(c)) == -1) { |
||||
sb.append(c); |
||||
} |
||||
} |
||||
String result = sb.toString(); |
||||
allDateDayList.remove(allDateDayList.get(i)); |
||||
holiday.setDetail(result); |
||||
allDateDayList.add(holiday); |
||||
} |
||||
} |
||||
|
||||
|
||||
}); |
||||
Collections.sort(allDateDayList, (o1, o2) -> { |
||||
Integer i = o1.getDate().compareTo(o2.getDate()); |
||||
return i; |
||||
}); |
||||
for(Holiday holiday : allDateDayList){ |
||||
System.out.println(holiday); |
||||
} |
||||
|
||||
return allDateDayList; |
||||
} |
||||
|
||||
// public static Map<String,List<HolidayVo>> HolidayHandle(List<Holiday> list){
|
||||
// Map<String,List<HolidayVo>> map = new HashMap<String,List<HolidayVo>>();
|
||||
// for(Holiday holiday : list){
|
||||
// HolidayVo holidayVo = new HolidayVo();
|
||||
//
|
||||
// if (holiday.getDetail()==null){
|
||||
// continue;
|
||||
// }else if(holiday.getDetail().contains("初")||holiday.getDetail().contains("元旦")||holiday.getDetail().contains("节")||holiday.getDetail().contains("周")){
|
||||
// holidayVo.setContent(holiday.getDetail());
|
||||
// }else if(holiday.getDetail().contains("正常上班")){
|
||||
// holidayVo.setContent(holiday.getDetail());
|
||||
// }
|
||||
// String mouth = holiday.getDate().substring(5,7);
|
||||
// holidayVo.setWorkingday(holiday.getDate().substring(8,10));
|
||||
//
|
||||
// if (map.containsKey("mouth"+mouth)){
|
||||
// List<HolidayVo> listofmap = map.get("mouth"+mouth);
|
||||
// listofmap.add(holidayVo);
|
||||
// }else {
|
||||
// List<HolidayVo> listHolidayVo = new ArrayList<>();
|
||||
// listHolidayVo.add(holidayVo);
|
||||
// map.put("mouth"+mouth,listHolidayVo);
|
||||
// }
|
||||
// System.out.println(holidayVo);
|
||||
// }
|
||||
// return map;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,107 @@
|
||||
package com.biutag.outeradmin.util; |
||||
|
||||
import io.jsonwebtoken.Claims; |
||||
import io.jsonwebtoken.Jws; |
||||
import io.jsonwebtoken.JwsHeader; |
||||
import io.jsonwebtoken.Jwts; |
||||
import io.jsonwebtoken.security.Keys; |
||||
import io.jsonwebtoken.security.SecureDigestAlgorithm; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import javax.crypto.SecretKey; |
||||
import java.time.Instant; |
||||
import java.util.Date; |
||||
|
||||
@Slf4j |
||||
public class JwtUtil { |
||||
// TODO 正式上线以后需要修改accessToken持续时间
|
||||
public static final long EXPIRATION_TIME = 5; // 1h
|
||||
public static final long REFRESH_TIME = 60 * 60 * 24 * 7; |
||||
public static final String APP_SECRET = "5FtX1OpGWKBVyaIh3dwRl04gkAzLro6U"; |
||||
public static final SecretKey KEY = Keys.hmacShaKeyFor(APP_SECRET.getBytes()); |
||||
public static final SecureDigestAlgorithm<SecretKey, SecretKey> ALGORITHM = Jwts.SIG.HS256; |
||||
private final static String JWT_ISS = "admin"; |
||||
|
||||
private final static String SUBJECT = "Peripherals"; |
||||
|
||||
/** |
||||
* 构建双Token |
||||
* |
||||
* @param phone 用户手机号 |
||||
* @param captcha 验证码 |
||||
* @param ifRefresh 是否refreshToken控制参数 |
||||
* @return |
||||
*/ |
||||
|
||||
public static String buildJwtToken(String phone, String captcha, boolean ifRefresh) { |
||||
Date exprireDate = Date.from(Instant.now().plusSeconds(EXPIRATION_TIME)); |
||||
if (ifRefresh) |
||||
exprireDate = Date.from(Instant.now().plusSeconds(REFRESH_TIME)); |
||||
return Jwts.builder() |
||||
.header().add("typ", "JWT").add("alg", "HS256") |
||||
.and() |
||||
.claim("username", phone).id(captcha) |
||||
.expiration(exprireDate) |
||||
.issuedAt(new Date()) |
||||
.subject(SUBJECT) |
||||
.issuer(JWT_ISS) |
||||
.signWith(KEY, ALGORITHM) |
||||
.compact(); |
||||
} |
||||
|
||||
/** |
||||
* 在accessToken发送过来时刷新refreshToken |
||||
* |
||||
* @param Token |
||||
* @return |
||||
*/ |
||||
public static String getNewRefreshToken(String Token) { |
||||
Jws<Claims> data = parseJwtToken(Token); |
||||
String name = data.getPayload().get("username", String.class); |
||||
String captcha = data.getPayload().getId(); |
||||
return buildJwtToken(name, captcha, true); |
||||
} |
||||
|
||||
/** |
||||
* accessToken过期时依据未过期的refreshToken刷新accessToken |
||||
* |
||||
* @param refreshToken |
||||
* @return |
||||
*/ |
||||
public static String getNewAccessToken(String refreshToken) { |
||||
Jws<Claims> data = parseJwtToken(refreshToken); |
||||
String name = data.getPayload().get("username", String.class); |
||||
String captcha = data.getPayload().getId(); |
||||
return buildJwtToken(name, captcha, true); |
||||
} |
||||
|
||||
/** |
||||
* 解析Token |
||||
* |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public static Jws<Claims> parseJwtToken(String token) { |
||||
return Jwts.parser().verifyWith(KEY).build().parseSignedClaims(token); |
||||
} |
||||
|
||||
/** |
||||
* 解析Token中的header |
||||
* |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public static JwsHeader parseTokenHeader(String token) { |
||||
return parseJwtToken(token).getHeader(); |
||||
} |
||||
|
||||
/** |
||||
* 解析Token中的payload |
||||
* |
||||
* @param token |
||||
* @return |
||||
*/ |
||||
public static Claims parsePayload(String token) { |
||||
return parseJwtToken(token).getPayload(); |
||||
} |
||||
} |
||||
@ -0,0 +1,22 @@
|
||||
package com.biutag.outeradmin.util; |
||||
|
||||
import cn.hutool.crypto.SecureUtil; |
||||
import cn.hutool.crypto.symmetric.AES; |
||||
|
||||
public class PhoneEncryptUtil { |
||||
private static final String KEY = "D9ioYl2WCeVRfLXvg4FrqZ51UtT8Ewcz"; |
||||
|
||||
private static AES init() { |
||||
String result = ""; |
||||
byte[] key = SecureUtil.generateKey(KEY).getEncoded(); |
||||
return new AES(key); |
||||
} |
||||
|
||||
public static String encrypt(String phone) { |
||||
return init().encryptHex(phone); |
||||
} |
||||
|
||||
public static String decrypt(String phone) { |
||||
return init().decryptStr(phone); |
||||
} |
||||
} |
||||
Binary file not shown.
Loading…
Reference in new issue