package com.bootdo.portal.controller;

import com.bootdo.blog.service.ContentService;
import com.bootdo.common.utils.R;
import com.bootdo.datas.domain.DataDO;
import com.bootdo.portal.common.CommonConstants;
import com.bootdo.portal.vo.PoliciesAndRegulationsVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 政策法规api
 *
 * @author Mr.xiBel
 * @date 2022/4/28
 **/
@CrossOrigin
@RestController
@RequestMapping("/portal/policiesRegulations")
public class PoliciesAndRegulationsController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 文章/轮播数据
     */
    @Resource
    private ContentService contentService;


    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public R getPoliciesAndRegulations(@RequestBody Map<String, Object> parameter) {
        // 条件获取 备案数据列表
        List<PoliciesAndRegulationsVO> portalDataList = contentService.portalPoliciesRegulations(parameter);
        Long total = contentService.portalPoliciesRegulationsCount(parameter);
        if (Objects.nonNull(portalDataList)) {
            return Objects.requireNonNull(R.ok().put(CommonConstants.DATA_FIELD_DATA, portalDataList)).
                    put(CommonConstants.DATA_FIELD_TOTAL, total);
        }

        return R.ok();
    }
}
