大屏项目初始化
This commit is contained in:
89
src/main/java/com/mini/mybigscreen/Job/erpJobs.java
Normal file
89
src/main/java/com/mini/mybigscreen/Job/erpJobs.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.mini.mybigscreen.Job;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mini.mybigscreen.biz.domain.ErpTransactionFlow;
|
||||
import com.mini.mybigscreen.biz.domain.IndexInfo;
|
||||
import com.mini.mybigscreen.biz.service.ErpTransactionFlowService;
|
||||
import com.mini.mybigscreen.biz.service.IndexInfoService;
|
||||
import com.mini.mybigscreen.utils.DateUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class erpJobs {
|
||||
|
||||
|
||||
@Resource
|
||||
private IndexInfoService infoService;
|
||||
|
||||
@Resource
|
||||
private ErpTransactionFlowService flowService;
|
||||
|
||||
@Scheduled(cron = "0 0 2 * * ?")
|
||||
public void updateErpIndex() {
|
||||
final BigDecimal BUDGET_AMOUNT = new BigDecimal("3000");
|
||||
QueryWrapper<ErpTransactionFlow> query = new QueryWrapper<>();
|
||||
query.eq("year_date", DateUtils.getCurrentYear())
|
||||
.eq("month_date", DateUtils.getCurrentMonth());
|
||||
List<ErpTransactionFlow> flowList = flowService.list(query);
|
||||
BigDecimal incomeAmount = flowList.stream()
|
||||
.filter(flow -> flow.getTransactionType().equals("1"))
|
||||
.map(ErpTransactionFlow::getAmount)
|
||||
.filter(amount -> amount != null)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal expenseAmount = flowList.stream()
|
||||
.filter(flow -> flow.getTransactionType().equals("2"))
|
||||
.map(ErpTransactionFlow::getAmount)
|
||||
.filter(amount -> amount != null)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
//净利润
|
||||
BigDecimal netProfit = incomeAmount.subtract(expenseAmount);
|
||||
//利润率
|
||||
BigDecimal profitRate = netProfit.divide(incomeAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
//占比
|
||||
BigDecimal expenseIncomeRatio = expenseAmount.divide(incomeAmount, 4, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal("100"))
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
boolean isOverBudget = expenseAmount.compareTo(BUDGET_AMOUNT) > 0;
|
||||
String budgetStatusName = isOverBudget ? "超出" : "正常";
|
||||
BigDecimal overBudgetAmount = isOverBudget ? expenseAmount.subtract(BUDGET_AMOUNT) : BigDecimal.ZERO;
|
||||
String[] indexList = {
|
||||
"ERP_001",
|
||||
"ERP_002",
|
||||
"ERP_003",
|
||||
"ERP_004",
|
||||
"ERP_006",
|
||||
};
|
||||
for (String index : indexList) {
|
||||
QueryWrapper<IndexInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("module_code", index);
|
||||
IndexInfo indexInfo = infoService.getOne(queryWrapper);
|
||||
if (index.equals("ERP_001")) {
|
||||
indexInfo.setValue(incomeAmount);
|
||||
}
|
||||
if (index.equals("ERP_002")) {
|
||||
indexInfo.setValue(expenseAmount);
|
||||
}
|
||||
if (index.equals("ERP_003")) {
|
||||
indexInfo.setValue(profitRate);
|
||||
}
|
||||
if (index.equals("ERP_004")) {
|
||||
indexInfo.setValue(expenseIncomeRatio);
|
||||
}
|
||||
if (index.equals("ERP_006")) {
|
||||
indexInfo.setModule(budgetStatusName);
|
||||
indexInfo.setValue(overBudgetAmount);
|
||||
}
|
||||
infoService.update(indexInfo, queryWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ package com.mini.mybigscreen;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.mini.mybigscreen.biz.mapper")
|
||||
public class MyBigScreenApplication {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mini.mybigscreen.biz.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mini.mybigscreen.Model.Result;
|
||||
import com.mini.mybigscreen.biz.domain.IndexInfo;
|
||||
import com.mini.mybigscreen.biz.service.IndexInfoService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页指标数据表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2026-03-02
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/biz/indexInfo")
|
||||
public class IndexInfoController {
|
||||
|
||||
|
||||
@Resource
|
||||
private IndexInfoService infoService;
|
||||
|
||||
|
||||
@GetMapping("list")
|
||||
public Result<?> getList(String indexCode) {
|
||||
QueryWrapper<IndexInfo> query = new QueryWrapper<>();
|
||||
query.eq(StrUtil.isNotBlank(indexCode), "index_code", indexCode)
|
||||
.orderByAsc("sort");
|
||||
return Result.success(infoService.list(query));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mini.mybigscreen.Model.Result;
|
||||
import com.mini.mybigscreen.biz.domain.ItemInfo;
|
||||
import com.mini.mybigscreen.biz.service.ItemInfoService;
|
||||
import com.mini.mybigscreen.utils.DateUtil;
|
||||
import com.mini.mybigscreen.utils.DateUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -35,7 +35,7 @@ public class ItemInfoController {
|
||||
QueryWrapper<ItemInfo> query = new QueryWrapper<>();
|
||||
query.eq("item_code", itemCode)
|
||||
.eq(StrUtil.isNotBlank(reqParam), "req_param", reqParam)
|
||||
.eq("ym", DateUtil.dsValue())
|
||||
.eq("ym", DateUtils.dsValue())
|
||||
;
|
||||
return Result.success(infoService.list(query));
|
||||
}
|
||||
|
||||
87
src/main/java/com/mini/mybigscreen/biz/domain/IndexInfo.java
Normal file
87
src/main/java/com/mini/mybigscreen/biz/domain/IndexInfo.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package com.mini.mybigscreen.biz.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页指标数据表
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2026-03-02
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("biz_index_info")
|
||||
public class IndexInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableField("create_time")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
@TableField("module")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 模块编码
|
||||
*/
|
||||
@TableField("module_code")
|
||||
private String moduleCode;
|
||||
|
||||
/**
|
||||
* 说明描述
|
||||
*/
|
||||
@TableField("title")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 数值
|
||||
*/
|
||||
@TableField("value")
|
||||
private BigDecimal value;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField("label")
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* 图片路径
|
||||
*/
|
||||
@TableField("icon_img")
|
||||
private String iconImg;
|
||||
|
||||
/**
|
||||
* 图标颜色
|
||||
*/
|
||||
@TableField("icon_filter")
|
||||
private String iconFilter;
|
||||
|
||||
/**
|
||||
* 序号
|
||||
*/
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 指标编号
|
||||
*/
|
||||
@TableField("index_code")
|
||||
private String indexCode;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mini.mybigscreen.biz.mapper;
|
||||
|
||||
import com.mini.mybigscreen.biz.domain.IndexInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页指标数据表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2026-03-02
|
||||
*/
|
||||
public interface IndexInfoMapper extends BaseMapper<IndexInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.mini.mybigscreen.biz.service;
|
||||
|
||||
import com.mini.mybigscreen.biz.domain.IndexInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页指标数据表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2026-03-02
|
||||
*/
|
||||
public interface IndexInfoService extends IService<IndexInfo> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.mini.mybigscreen.biz.service.impl;
|
||||
|
||||
import com.mini.mybigscreen.biz.domain.IndexInfo;
|
||||
import com.mini.mybigscreen.biz.mapper.IndexInfoMapper;
|
||||
import com.mini.mybigscreen.biz.service.IndexInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 首页指标数据表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author gaoxq
|
||||
* @since 2026-03-02
|
||||
*/
|
||||
@Service
|
||||
public class IndexInfoServiceImpl extends ServiceImpl<IndexInfoMapper, IndexInfo> implements IndexInfoService {
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class demo {
|
||||
.pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/src/main/resources/mapper"));
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
builder.addInclude("biz_home_menu")
|
||||
builder.addInclude("erp_transaction_flow_view")
|
||||
.addTablePrefix("biz_")
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.mini.mybigscreen.utils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
public class DateUtil {
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
|
||||
public static String dsValue() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
return currentDate.format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public static String dsValueDaysAgo(long days) {
|
||||
LocalDate targetDate = LocalDate.now().minusDays(days);
|
||||
return targetDate.format(DATE_FORMATTER);
|
||||
}
|
||||
}
|
||||
39
src/main/java/com/mini/mybigscreen/utils/DateUtils.java
Normal file
39
src/main/java/com/mini/mybigscreen/utils/DateUtils.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.mini.mybigscreen.utils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class DateUtils {
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
private static final DateTimeFormatter YEAR_FORMATTER = DateTimeFormatter.ofPattern("yyyy");
|
||||
private static final DateTimeFormatter MONTH_FORMATTER = DateTimeFormatter.ofPattern("MM");
|
||||
|
||||
public static String dsValue() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
return currentDate.format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public static String dsValueDaysAgo(long days) {
|
||||
LocalDate targetDate = LocalDate.now().minusDays(days);
|
||||
return targetDate.format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
public static String getCurrentYear() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
return currentDate.format(YEAR_FORMATTER);
|
||||
}
|
||||
|
||||
public static String getCurrentMonth() {
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
return currentDate.format(MONTH_FORMATTER);
|
||||
}
|
||||
|
||||
public static String getYear(LocalDate date) {
|
||||
return date.format(YEAR_FORMATTER);
|
||||
}
|
||||
|
||||
public static String getMonth(LocalDate date) {
|
||||
return date.format(MONTH_FORMATTER);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user