Browse Source

节假日模块完善优化,同步节假日数据修复

dev_ycq
21819 2 years ago
parent
commit
c26c537771
  1. 6
      mailbox-outer-admin/pom.xml
  2. 61
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/HolidayController.java
  3. 37
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java
  4. 22
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/domain/Holiday.java
  5. 10
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/HolidayRefresh.java
  6. 8
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/HolidayYear.java
  7. 2
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/MailID.java
  8. 14
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/model/vo/HolidayVo.java
  9. 76
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/ExcelUtil.java
  10. 68
      mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/HolidayUtil.java
  11. BIN
      mailbox-outer-admin/src/main/resources/excelmodel.xlsx

6
mailbox-outer-admin/pom.xml

@ -64,6 +64,12 @@
<artifactId>mailbox-common</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.3.2</version>
</dependency>
</dependencies>
</project>

61
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/HolidayController.java

@ -1,16 +1,23 @@
package com.biutag.outeradmin.controller;
import com.biutag.outeradmin.entity.Holiday;
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;
@ -22,39 +29,33 @@ public class HolidayController {
private final HolidayService holidayService;
private final HolidayMapper holidayMapper;
// @RequestMapping("/getholiday")
// @ApiOperation("查询节假日")
// public AjaxResult getlist(@RequestParam("search") String search) throws Exception {
//
// //判断年份
// LocalDateTime currentDate = LocalDateTime.now();
// int currentyear = currentDate.getYear();
// if (Integer.parseInt(search) != currentyear) {
// return AjaxResult.success();
// }
// Map<String, List<HolidayVo>> map = holidayService.showholiday();
// return AjaxResult.success(map);
//
// }
//
//
// @PostMapping("/saveholiday")
// @ApiOperation("节假日")
// public AjaxResult setlist(@RequestBody String search) throws Exception {
// LocalDateTime currentDate = LocalDateTime.now();
// int currentyear = currentDate.getYear();
// if (Integer.parseInt(search) != currentyear) {
// return AjaxResult.success();
// }
// holidayService.saveholiday(search);
// return AjaxResult.success();
//
// }
@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)) {
System.out.println("年份相同");
holidayRefresh.setMessage("success");
} else {
holidayMapper.delete(null);
List<Holiday> holidays = HolidayUtil.getAllHolidayByYear(getYear.getYear());
holidayService.saveBatch(holidays);
holidayRefresh.setMessage("success");
System.out.println("年份不同,重写数据库");
}
holidayRefresh.setHolidayList(getlist());
return holidayRefresh;
}
@RequestMapping("/show-holiday")
@ApiOperation("进入页面显示节假日")
public List<HolidayDTO> getlist() throws Exception {
public List<HolidayDTO> getlist() {
List<Holiday> holidayList = holidayService.list();
List<HolidayDTO> result = new ArrayList<>();
for (Holiday holiday : holidayList) {

37
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/controller/MailController.java

@ -4,18 +4,18 @@ 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.MailFormData;
import com.biutag.outeradmin.dto.MailFormPage;
import com.biutag.outeradmin.dto.MailPageInfo;
import com.biutag.outeradmin.dto.PageSet;
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
@ -121,6 +121,33 @@ public class MailController {
MailID mailID = JSON.parseObject(id, MailID.class);
//TODO 这里根据ID查询数据库,记得删掉
System.out.println(mailID.getID());
return JSON.toJSONString(mailService.getById(mailID.getID()));
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);
}
}

22
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/domain/Holiday.java

@ -1,22 +0,0 @@
package com.biutag.outeradmin.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 管理员
*/
@Data
@TableName("holiday")
@NoArgsConstructor
@AllArgsConstructor
public class Holiday implements Serializable {
@TableId(type = IdType.AUTO)
private Integer id;
private String date;
private String holiday_flag;
private String detail;
}

10
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/HolidayRefresh.java

@ -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;
}

8
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/HolidayYear.java

@ -0,0 +1,8 @@
package com.biutag.outeradmin.dto;
import lombok.Data;
@Data
public class HolidayYear {
private String year;
}

2
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/entity/MailID.java → mailbox-outer-admin/src/main/java/com/biutag/outeradmin/dto/MailID.java

@ -1,4 +1,4 @@
package com.biutag.outeradmin.entity;
package com.biutag.outeradmin.dto;
import lombok.Data;

14
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/model/vo/HolidayVo.java

@ -1,14 +0,0 @@
package com.biutag.outeradmin.model.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HolidayVo {
private String workingday;//日期
private String content;//描述
}

76
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/ExcelUtil.java

@ -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;
// }
}

68
mailbox-outer-admin/src/main/java/com/biutag/outeradmin/util/HolidayUtil.java

@ -1,8 +1,6 @@
package com.biutag.outeradmin.util;
import com.biutag.outeradmin.domain.Holiday;
import com.biutag.outeradmin.model.vo.HolidayVo;
import com.biutag.outeradmin.entity.Holiday;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.BufferedReader;
@ -60,17 +58,17 @@ public class HolidayUtil {
Holiday holiday = new Holiday();
DayOfWeek week = endDate.getDayOfWeek();
if(week == DayOfWeek.SATURDAY ) {
holiday.setHoliday_flag("Y");
holiday.setHolidayFlag("Y");
holiday.setDate(endDate.format(formatter));
holiday.setDetail("周六");
allDateDayList.add(holiday);
}else if(week == DayOfWeek.SUNDAY){
holiday.setHoliday_flag("Y");
holiday.setHolidayFlag("Y");
holiday.setDate(endDate.format(formatter));
holiday.setDetail("周日");
allDateDayList.add(holiday);
}else{
holiday.setHoliday_flag("N");
holiday.setHolidayFlag("N");
holiday.setDate(endDate.format(formatter));
allDateDayList.add(holiday);
}
@ -94,10 +92,10 @@ public class HolidayUtil {
holiday.setDate(dateTime);
if(value1.get("name").toString().contains("补班")){
holiday.setDetail("正常上班");
holiday.setHoliday_flag("N");
holiday.setHolidayFlag("N");
}else {
holiday.setDetail(value1.get("name").toString());
holiday.setHoliday_flag("Y");
holiday.setHolidayFlag("Y");
}
for(int i = 0;i<allDateDayList.size();i++){
@ -130,33 +128,33 @@ public class HolidayUtil {
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;
}
// 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;
// }

BIN
mailbox-outer-admin/src/main/resources/excelmodel.xlsx

Binary file not shown.
Loading…
Cancel
Save