随笔 - 32,  文章 - 0,  评论 - 3,  阅读 - 39209
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;
    }
}
复制代码

 

posted on   大黑.的博客  阅读(180)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示