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; } }
浙公网安备 33010602011771号