Controller
/** * @Classname GeneralReportModuleController * 报表查询通用接口 * @Date 2022/3/16 11:10 上午 * @Author wjh */ @RestController public class GeneralReportModuleController implements GeneralReportModuleApi { @Autowired private GeneralReportModuleImpl generalReportModuleService; @Override public ResponseEntity<ProcessSeccussResponse> generalReportModuleSearch(@Valid GeneralReportModulePostRequest body, String authorization) { int pageSize =body.getPageSize(); int pageNum = body.getPageNum() ; String contractId = body.getContractId(); String reportName = body.getReportName(); int year = body.getYear(); int month = body.getMonth() ; List<Map<Object, Object>> result = generalReportModuleService.generalReportModuleSearch(reportName,contractId, year,month,pageSize,pageNum); return ResponseEntity.ok(ResponseUtils.ok(result)); } }
Service
@Service("generalReportModule") @Slf4j public class GeneralReportModuleImpl implements GeneralReportModuleService { @Autowired private HttpServletRequest httpRequest; @Autowired private GeneralReportModuleMapper generalReportModuleMapper; private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static final String DEFAULT_CURRENCY = "CNY"; public List<Map<Object, Object>> generalReportModuleSearch(String reportName,String contractId, int year, int month, int pageSize, int pageNum) { List<Map<Object, Object>> result = this.generalReportModuleMapper.generalReportModuleSearch(reportName,contractId, year, month,pageSize,pageNum); return result; } }
mapper
@Mapper public interface GeneralReportModuleMapper { @SelectProvider(type = GeneralReportModuleSqlProvider.class, method = "generalReportModuleSearch") List<Map<Object, Object>> generalReportModuleSearch(@Param("reportName") String reportName, @Param("contractId") String contractId, @Param("year") int year, @Param("month") int month, @Param("pageSize") int pageSize, @Param("pageNum") int pageNum); }
通用模块封装
/* 通用报表模块封装 */ public class GeneralReportModuleSqlProvider { private Logger logger = LoggerFactory.getLogger(GeneralReportModuleSqlProvider.class); public String generalReportModuleSearch(Map<String, Object> params) { //int pageSize = Integer.valueOf(params.get("pageSize").toString()); //int pageNum = Integer.valueOf(params.get("pageNum").toString()) ; String contractId = params.get("contractId").toString(); int year = Integer.valueOf(params.get("year").toString()); int month = Integer.valueOf(params.get("month").toString()) ; String reportName = params.get("reportName").toString(); if (StringUtils.isBlank(contractId) || year == 0 || month == 0) { this.logger.error("无效的入参contractId:{}, year: {}, month: {}", contractId, year, month); throw new ICostException(500, "无效的入参"); } String sql = "select * from "+reportName+ " where uuid= '" + contractId + "'"; String firstDayOfMonth = null; String lastDayOfMonth = null; firstDayOfMonth = getFirstDayOfMonth(year, month); lastDayOfMonth = getLastDayOfMonth(year, month); /* if (StringUtils.isNotBlank(firstDayOfMonth) && StringUtils.isNotBlank(lastDayOfMonth)) { sql += " and update_date >= '" + firstDayOfMonth + "' "; sql += " and update_date < '" + lastDayOfMonth + "' "; }*/ logger.info("通用报表查询sql---"+sql); return sql; } public static String getFirstDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); //设置年份 cal.set(Calendar.YEAR, year); //设置月份 cal.set(Calendar.MONTH, month - 1); //获取某月最小天数 int firstDay = cal.getActualMinimum(Calendar.DAY_OF_MONTH); //设置日历中月份的最小天数 cal.set(Calendar.DAY_OF_MONTH, firstDay); //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String firstDayOfMonth = sdf.format(cal.getTime()); return firstDayOfMonth; } public static String getLastDayOfMonth(int year, int month) { Calendar cal = Calendar.getInstance(); //设置年份 cal.set(Calendar.YEAR, year); //设置月份 cal.set(Calendar.MONTH, month - 1); //获取某月最大天数 int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); //设置日历中月份的最大天数 cal.set(Calendar.DAY_OF_MONTH, lastDay); //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String lastDayOfMonth = sdf.format(cal.getTime()); return lastDayOfMonth; } }
分类:
方法笔记
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix