package cn.huge.module.sy.controller.web;
|
|
import cn.huge.base.common.utils.DateUtils;
|
import cn.huge.base.common.utils.ReturnFailUtils;
|
import cn.huge.base.common.utils.ReturnSucUtils;
|
import cn.huge.module.sy.domain.po.SyHoliday;
|
import cn.huge.module.sy.service.SyHolidayService;
|
import com.google.common.collect.Maps;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.Sort;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* @title: 节假日日期配置表接口api-web端
|
* @description: 节假日日期配置表接口api-web端
|
* @company: hugeinfo
|
* @author: liyj
|
* @time: 2025-01-20 10:56:54
|
* @version: 1.0.0
|
*/
|
@Slf4j
|
@RestController
|
@RequestMapping("/api/web/syHoliday")
|
public class SyHolidayWebController {
|
|
@Autowired(required = false)
|
private HttpServletRequest request;
|
|
@Autowired
|
private SyHolidayService service;
|
|
/**
|
* 获取请求URL参数
|
* @return Map<String, Object>
|
*/
|
private Map<String, Object> getParameter(){
|
Map<String, Object> terms = Maps.newHashMap();
|
// id
|
String id = request.getParameter("id");
|
if (StringUtils.isNotBlank(id)){
|
terms.put("id", id);
|
}
|
// holiday_date
|
String holidayDate = request.getParameter("holidayDate");
|
if (StringUtils.isNotBlank(holidayDate)){
|
terms.put("holidayDate", holidayDate);
|
}
|
// 创建时间区间
|
String createStart = request.getParameter("createStart");
|
String createEnd = request.getParameter("createEnd");
|
if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) {
|
terms.put("createStart", createStart);
|
terms.put("createEnd", createEnd);
|
}
|
// 更新时间区间
|
String updateStart = request.getParameter("updateStart");
|
String updateEnd = request.getParameter("updateEnd");
|
if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) {
|
terms.put("updateStart", updateStart);
|
terms.put("updateEnd", updateEnd);
|
}
|
return terms;
|
}
|
|
/**
|
* 条件查询多个
|
* @url {ctx}/api/web/syHoliday/listQuery
|
* @return Object
|
*/
|
@GetMapping("/listQuery")
|
public Object listQuery() {
|
try {
|
Map<String, Object> terms = getParameter();
|
return ReturnSucUtils.getRepInfo(service.listTerms(terms));
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 条件分页查询
|
* @url {ctx}/api/web/syHoliday/pageQuery
|
* @param page 页码
|
* @param size 每页数量
|
* @return Object
|
*/
|
@GetMapping("/pageQuery")
|
public Object pageQuery(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
|
try {
|
Map<String, Object> terms = getParameter();
|
Sort sort = Sort.by(Sort.Direction.DESC, "create_time");
|
PageRequest pageRequest = PageRequest.of(page-1, size, sort);
|
Page<SyHoliday> syHolidayPage = service.pageQuery(pageRequest, terms);
|
return ReturnSucUtils.getRepInfo( "处理成功", syHolidayPage);
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 根据编号查询单个
|
* @url {ctx}/api/web/syHoliday/getById
|
* @param id 主键编号
|
* @return Object
|
*/
|
@GetMapping("/getById")
|
public Object getById(@RequestParam(value = "id") String id) {
|
try {
|
return ReturnSucUtils.getRepInfo(service.getById(id));
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 根据主键单个
|
* @url {ctx}/api/web/syHoliday/deleteById
|
* @param id 主键编号
|
* @return Object
|
*/
|
@GetMapping("/deleteById")
|
public Object deleteById(@RequestParam(value = "id") String id) {
|
try {
|
service.removeById(id);
|
return ReturnSucUtils.getRepInfo();
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* 新增或更新对象
|
* @url {ctx}/api/web/syHoliday/saveSyHoliday
|
* @param syHoliday 实体对象
|
* @return Object
|
*/
|
@PostMapping("/saveSyHoliday")
|
public Object saveSyHoliday(@RequestBody SyHoliday syHoliday) {
|
try {
|
service.saveSyHoliday(syHoliday);
|
return ReturnSucUtils.getRepInfo();
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* @url {ctx}/api/web/syHoliday/getExpiryDayTest
|
* @param daysToAdd
|
* @return
|
*/
|
@GetMapping("/getExpiryDayTest")
|
public Object getExpiryDayTest(@RequestParam(value = "daysToAdd") int daysToAdd) {
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String startTime = "2025-01-20 17:05:33";
|
Date startDate = sdf.parse(startTime);
|
Date endDate = service.getExpiryDay(startDate, daysToAdd);
|
String endTime = sdf.format(endDate);
|
return ReturnSucUtils.getRepInfo(endTime);
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
/**
|
* @url {ctx}/api/web/syHoliday/getExpiryHourTest
|
* @param hourToAdd
|
* @return
|
*/
|
@GetMapping("/getExpiryHourTest")
|
public Object getExpiryHourTest(@RequestParam(value = "hourToAdd") int hourToAdd) {
|
try {
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
String startTime = "2025-01-20 17:05:33";
|
Date startDate = sdf.parse(startTime);
|
Date endDate = service.getExpiryHour(startDate, hourToAdd);
|
String endTime = sdf.format(endDate);
|
return ReturnSucUtils.getRepInfo(endTime);
|
} catch (Exception e) {
|
return ReturnFailUtils.getRepInfo();
|
}
|
}
|
|
}
|