新增预警页面
This commit is contained in:
@@ -7,60 +7,5 @@ import java.util.Date;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
// 日期格式化器(线程安全,复用提升性能)
|
||||
private static final DateTimeFormatter DAY_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE; // yyyy-MM-dd
|
||||
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM"); // yyyy-MM
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
|
||||
public static String calculateStartCycleCode(String cycleType) {
|
||||
// 默认使用当前日期计算,留参便于测试时指定日期
|
||||
return calculateStartCycleCode(cycleType, LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载方法:支持指定基准日期计算起始cycleCode(便于测试)
|
||||
*
|
||||
* @param cycleType 周期类型(D:日, M:月, Q:季度, Y:年)
|
||||
* @param baseDate 基准日期(以此日期为起点计算时间范围)
|
||||
* @return 起始cycleCode(符合对应格式),未识别类型返回null
|
||||
*/
|
||||
public static String calculateStartCycleCode(String cycleType, LocalDate baseDate) {
|
||||
if (baseDate == null) {
|
||||
throw new IllegalArgumentException("基准日期不能为null");
|
||||
}
|
||||
if (cycleType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return switch (cycleType) {
|
||||
case "D" ->
|
||||
// 日:最近30天,格式 yyyy-MM-dd
|
||||
baseDate.minusDays(30).format(DAY_FORMATTER);
|
||||
case "M" ->
|
||||
// 月:最近1年,格式 yyyy-MM
|
||||
baseDate.minusYears(1).format(MONTH_FORMATTER);
|
||||
case "Q" ->
|
||||
// 季度:最近3年,格式 yyyy-Qx
|
||||
getQuarterCycleCode(baseDate.minusYears(3));
|
||||
case "Y" ->
|
||||
// 年:最近6年,格式 yyyy
|
||||
String.valueOf(baseDate.minusYears(6).getYear());
|
||||
default ->
|
||||
// 未识别的周期类型,返回null
|
||||
null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算指定日期对应的季度cycleCode(格式:yyyy-Qx)
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 季度cycleCode(如2023-Q3)
|
||||
*/
|
||||
private static String getQuarterCycleCode(LocalDate date) {
|
||||
int month = date.getMonthValue(); // 1-12月
|
||||
int quarter = (month - 1) / 3 + 1;
|
||||
return String.format("%d-Q%d", date.getYear(), quarter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +111,56 @@ public class vDate {
|
||||
result.append(seconds).append("秒");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String calculateStartCycleCode(String cycleType) {
|
||||
// 默认使用当前日期计算,留参便于测试时指定日期
|
||||
return calculateStartCycleCode(cycleType, LocalDate.now());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载方法:支持指定基准日期计算起始cycleCode(便于测试)
|
||||
*
|
||||
* @param cycleType 周期类型(D:日, M:月, Q:季度, Y:年)
|
||||
* @param baseDate 基准日期(以此日期为起点计算时间范围)
|
||||
* @return 起始cycleCode(符合对应格式),未识别类型返回null
|
||||
*/
|
||||
public static String calculateStartCycleCode(String cycleType, LocalDate baseDate) {
|
||||
if (baseDate == null) {
|
||||
throw new IllegalArgumentException("基准日期不能为null");
|
||||
}
|
||||
if (cycleType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return switch (cycleType) {
|
||||
case "D" ->
|
||||
// 日:最近30天,格式 yyyy-MM-dd
|
||||
baseDate.minusDays(30).format(DAY_FORMATTER);
|
||||
case "M" ->
|
||||
// 月:最近1年,格式 yyyy-MM
|
||||
baseDate.minusYears(1).format(MONTH_FORMATTER);
|
||||
case "Q" ->
|
||||
// 季度:最近3年,格式 yyyy-Qx
|
||||
getQuarterCycleCode(baseDate.minusYears(3));
|
||||
case "Y" ->
|
||||
// 年:最近6年,格式 yyyy
|
||||
String.valueOf(baseDate.minusYears(6).getYear());
|
||||
default ->
|
||||
// 未识别的周期类型,返回null
|
||||
null;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算指定日期对应的季度cycleCode(格式:yyyy-Qx)
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 季度cycleCode(如2023-Q3)
|
||||
*/
|
||||
private static String getQuarterCycleCode(LocalDate date) {
|
||||
int month = date.getMonthValue(); // 1-12月
|
||||
int quarter = (month - 1) / 3 + 1;
|
||||
return String.format("%d-Q%d", date.getYear(), quarter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.jeesite.modules.erp.dao;
|
||||
|
||||
import com.jeesite.common.dao.CrudDao;
|
||||
import com.jeesite.common.mybatis.annotation.MyBatisDao;
|
||||
import com.jeesite.modules.erp.entity.ErpSummaryAll;
|
||||
|
||||
/**
|
||||
* 汇总信息DAO接口
|
||||
* @author gaoxq
|
||||
* @version 2025-12-09
|
||||
*/
|
||||
@MyBatisDao(dataSourceName="work")
|
||||
public interface ErpSummaryAllDao extends CrudDao<ErpSummaryAll> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.jeesite.modules.erp.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jeesite.common.entity.DataEntity;
|
||||
import com.jeesite.common.mybatis.annotation.Column;
|
||||
import com.jeesite.common.mybatis.annotation.Table;
|
||||
import com.jeesite.common.mybatis.mapper.query.QueryType;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Align;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelFields;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 汇总信息Entity
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-09
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table(name = "erp_summary_all", alias = "a", label = "汇总信息信息", columns = {
|
||||
@Column(name = "create_time", attrName = "createTime", label = "记录时间", isQuery = false, isUpdateForce = true),
|
||||
@Column(name = "id", attrName = "id", label = "主键ID", isPK = true),
|
||||
@Column(name = "c_date", attrName = "cdate", label = "汇总日期"),
|
||||
@Column(name = "c_type", attrName = "ctype", label = "交易类型", isQuery = false),
|
||||
@Column(name = "this_value", attrName = "thisValue", label = "当期金额", isQuery = false, isUpdateForce = true),
|
||||
@Column(name = "prev_value", attrName = "prevValue", label = "上期金额", isQuery = false, isUpdateForce = true),
|
||||
@Column(name = "mom_rate", attrName = "momRate", label = "环比", isQuery = false, isUpdateForce = true),
|
||||
@Column(name = "f_cycle", attrName = "fcycle", label = "周期类型"),
|
||||
}, orderBy = "a.c_date"
|
||||
)
|
||||
@Data
|
||||
public class ErpSummaryAll extends DataEntity<ErpSummaryAll> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Date createTime; // 记录时间
|
||||
private String cdate; // 汇总日期
|
||||
private String ctype; // 交易类型
|
||||
private Double thisValue; // 当期金额
|
||||
private Double prevValue; // 上期金额
|
||||
private Double momRate; // 环比
|
||||
private String fcycle; // 周期类型
|
||||
|
||||
@ExcelFields({
|
||||
@ExcelField(title = "记录时间", attrName = "createTime", align = Align.CENTER, sort = 10, dataFormat = "yyyy-MM-dd hh:mm"),
|
||||
@ExcelField(title = "主键ID", attrName = "id", align = Align.CENTER, sort = 20),
|
||||
@ExcelField(title = "汇总日期", attrName = "cdate", align = Align.CENTER, sort = 30, dataFormat = "yyyy-MM-dd"),
|
||||
@ExcelField(title = "交易类型", attrName = "ctype", dictType = "transaction_type", align = Align.CENTER, sort = 40),
|
||||
@ExcelField(title = "当期金额", attrName = "thisValue", align = Align.CENTER, sort = 50),
|
||||
@ExcelField(title = "上期金额", attrName = "prevValue", align = Align.CENTER, sort = 60),
|
||||
@ExcelField(title = "环比", attrName = "momRate", align = Align.CENTER, sort = 70),
|
||||
@ExcelField(title = "周期类型", attrName = "fcycle", dictType = "report_cycle", align = Align.CENTER, sort = 80),
|
||||
})
|
||||
public ErpSummaryAll() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ErpSummaryAll(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public String getCdate_gte() {
|
||||
return sqlMap.getWhere().getValue("c_date", QueryType.GTE);
|
||||
}
|
||||
|
||||
public void setCdate_gte(String cdate) {
|
||||
sqlMap.getWhere().and("c_date", QueryType.GTE, cdate);
|
||||
}
|
||||
|
||||
public String getCdate_lte() {
|
||||
return sqlMap.getWhere().getValue("c_date", QueryType.LTE);
|
||||
}
|
||||
|
||||
public void setCdate_lte(String cdate) {
|
||||
sqlMap.getWhere().and("c_date", QueryType.LTE, cdate);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.jeesite.modules.erp.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.service.CrudService;
|
||||
import com.jeesite.modules.erp.entity.ErpSummaryAll;
|
||||
import com.jeesite.modules.erp.dao.ErpSummaryAllDao;
|
||||
import com.jeesite.common.service.ServiceException;
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.validator.ValidatorUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelImport;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import jakarta.validation.ConstraintViolation;
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 汇总信息Service
|
||||
* @author gaoxq
|
||||
* @version 2025-12-09
|
||||
*/
|
||||
@Service
|
||||
public class ErpSummaryAllService extends CrudService<ErpSummaryAllDao, ErpSummaryAll> {
|
||||
|
||||
/**
|
||||
* 获取单条数据
|
||||
* @param erpSummaryAll 主键
|
||||
*/
|
||||
@Override
|
||||
public ErpSummaryAll get(ErpSummaryAll erpSummaryAll) {
|
||||
return super.get(erpSummaryAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分页数据
|
||||
* @param erpSummaryAll 查询条件
|
||||
* @param erpSummaryAll page 分页对象
|
||||
*/
|
||||
@Override
|
||||
public Page<ErpSummaryAll> findPage(ErpSummaryAll erpSummaryAll) {
|
||||
return super.findPage(erpSummaryAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
* @param erpSummaryAll 查询条件
|
||||
*/
|
||||
@Override
|
||||
public List<ErpSummaryAll> findList(ErpSummaryAll erpSummaryAll) {
|
||||
return super.findList(erpSummaryAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据(插入或更新)
|
||||
* @param erpSummaryAll 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void save(ErpSummaryAll erpSummaryAll) {
|
||||
super.save(erpSummaryAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
* @param file 导入的数据文件
|
||||
*/
|
||||
@Transactional
|
||||
public String importData(MultipartFile file) {
|
||||
if (file == null){
|
||||
throw new ServiceException(text("请选择导入的数据文件!"));
|
||||
}
|
||||
int successNum = 0; int failureNum = 0;
|
||||
StringBuilder successMsg = new StringBuilder();
|
||||
StringBuilder failureMsg = new StringBuilder();
|
||||
try(ExcelImport ei = new ExcelImport(file, 2, 0)){
|
||||
List<ErpSummaryAll> list = ei.getDataList(ErpSummaryAll.class);
|
||||
for (ErpSummaryAll erpSummaryAll : list) {
|
||||
try{
|
||||
ValidatorUtils.validateWithException(erpSummaryAll);
|
||||
this.save(erpSummaryAll);
|
||||
successNum++;
|
||||
successMsg.append("<br/>" + successNum + "、编号 " + erpSummaryAll.getId() + " 导入成功");
|
||||
} catch (Exception e) {
|
||||
failureNum++;
|
||||
String msg = "<br/>" + failureNum + "、编号 " + erpSummaryAll.getId() + " 导入失败:";
|
||||
if (e instanceof ConstraintViolationException){
|
||||
ConstraintViolationException cve = (ConstraintViolationException)e;
|
||||
for (ConstraintViolation<?> violation : cve.getConstraintViolations()) {
|
||||
msg += Global.getText(violation.getMessage()) + " ("+violation.getPropertyPath()+")";
|
||||
}
|
||||
}else{
|
||||
msg += e.getMessage();
|
||||
}
|
||||
failureMsg.append(msg);
|
||||
logger.error(msg, e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
failureMsg.append(e.getMessage());
|
||||
return failureMsg.toString();
|
||||
}
|
||||
if (failureNum > 0) {
|
||||
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
||||
throw new ServiceException(failureMsg.toString());
|
||||
}else{
|
||||
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
||||
}
|
||||
return successMsg.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param erpSummaryAll 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateStatus(ErpSummaryAll erpSummaryAll) {
|
||||
super.updateStatus(erpSummaryAll);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
* @param erpSummaryAll 数据对象
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void delete(ErpSummaryAll erpSummaryAll) {
|
||||
erpSummaryAll.sqlMap().markIdDelete(); // 逻辑删除时标记ID值
|
||||
super.delete(erpSummaryAll);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.jeesite.modules.erp.web;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jeesite.modules.app.utils.vDate;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.jeesite.common.config.Global;
|
||||
import com.jeesite.common.collect.ListUtils;
|
||||
import com.jeesite.common.entity.Page;
|
||||
import com.jeesite.common.lang.DateUtils;
|
||||
import com.jeesite.common.utils.excel.ExcelExport;
|
||||
import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.jeesite.common.web.BaseController;
|
||||
import com.jeesite.modules.erp.entity.ErpSummaryAll;
|
||||
import com.jeesite.modules.erp.service.ErpSummaryAllService;
|
||||
|
||||
/**
|
||||
* 汇总信息Controller
|
||||
*
|
||||
* @author gaoxq
|
||||
* @version 2025-12-09
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "${adminPath}/erp/summaryAll")
|
||||
public class ErpSummaryAllController extends BaseController {
|
||||
|
||||
private final ErpSummaryAllService erpSummaryAllService;
|
||||
|
||||
public ErpSummaryAllController(ErpSummaryAllService erpSummaryAllService) {
|
||||
this.erpSummaryAllService = erpSummaryAllService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据
|
||||
*/
|
||||
@ModelAttribute
|
||||
public ErpSummaryAll get(String id, boolean isNewRecord) {
|
||||
return erpSummaryAllService.get(id, isNewRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:view")
|
||||
@RequestMapping(value = {"list", ""})
|
||||
public String list(ErpSummaryAll erpSummaryAll, Model model) {
|
||||
model.addAttribute("erpSummaryAll", erpSummaryAll);
|
||||
return "modules/erp/erpSummaryAllList";
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表数据
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:view")
|
||||
@RequestMapping(value = "listData")
|
||||
@ResponseBody
|
||||
public Page<ErpSummaryAll> listData(ErpSummaryAll erpSummaryAll, HttpServletRequest request, HttpServletResponse response) {
|
||||
erpSummaryAll.setPage(new Page<>(request, response));
|
||||
Page<ErpSummaryAll> page = erpSummaryAllService.findPage(erpSummaryAll);
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看编辑表单
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:view")
|
||||
@RequestMapping(value = "form")
|
||||
public String form(ErpSummaryAll erpSummaryAll, Model model) {
|
||||
model.addAttribute("erpSummaryAll", erpSummaryAll);
|
||||
return "modules/erp/erpSummaryAllForm";
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:edit")
|
||||
@PostMapping(value = "save")
|
||||
@ResponseBody
|
||||
public String save(@Validated ErpSummaryAll erpSummaryAll) {
|
||||
erpSummaryAllService.save(erpSummaryAll);
|
||||
return renderResult(Global.TRUE, text("保存汇总信息成功!"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:view")
|
||||
@RequestMapping(value = "exportData")
|
||||
public void exportData(ErpSummaryAll erpSummaryAll, HttpServletResponse response) {
|
||||
List<ErpSummaryAll> list = erpSummaryAllService.findList(erpSummaryAll);
|
||||
String fileName = "汇总信息" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("汇总信息", ErpSummaryAll.class)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载模板
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:view")
|
||||
@RequestMapping(value = "importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
ErpSummaryAll erpSummaryAll = new ErpSummaryAll();
|
||||
List<ErpSummaryAll> list = ListUtils.newArrayList(erpSummaryAll);
|
||||
String fileName = "汇总信息模板.xlsx";
|
||||
try (ExcelExport ee = new ExcelExport("汇总信息", ErpSummaryAll.class, Type.IMPORT)) {
|
||||
ee.setDataList(list).write(response, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*/
|
||||
@ResponseBody
|
||||
@RequiresPermissions("erp:summaryAll:edit")
|
||||
@PostMapping(value = "importData")
|
||||
public String importData(MultipartFile file) {
|
||||
try {
|
||||
String message = erpSummaryAllService.importData(file);
|
||||
return renderResult(Global.TRUE, "posfull:" + message);
|
||||
} catch (Exception ex) {
|
||||
return renderResult(Global.FALSE, "posfull:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据
|
||||
*/
|
||||
@RequiresPermissions("erp:summaryAll:edit")
|
||||
@RequestMapping(value = "delete")
|
||||
@ResponseBody
|
||||
public String delete(ErpSummaryAll erpSummaryAll) {
|
||||
erpSummaryAllService.delete(erpSummaryAll);
|
||||
return renderResult(Global.TRUE, text("删除汇总信息成功!"));
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "listAll")
|
||||
@ResponseBody
|
||||
public List<ErpSummaryAll> listAll(ErpSummaryAll erpSummaryAll) {
|
||||
erpSummaryAll.setCdate_gte(vDate.calculateStartCycleCode(erpSummaryAll.getFcycle()));
|
||||
return erpSummaryAllService.findList(erpSummaryAll);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user