package com.cweb.controller;

import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsCompany;
import com.hfkj.entity.SecRegion;
import com.hfkj.model.ResponseData;
import com.hfkj.service.BsCompanyService;
import com.hfkj.service.CmsContentService;
import com.hfkj.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@Controller
@Api(value = "内容管理 内容发布")
@RequestMapping(value = "/cmsContent")
public class CmsContentController {

    private static Logger log = LoggerFactory.getLogger(CmsContentController.class);

    @Resource
    private CommonService commonService;

    @Resource
    private CmsContentService cmsContentService;

    @Resource
    private BsCompanyService bsCompanyService;

    @RequestMapping(value = "/getCmsContent", method = RequestMethod.GET)
    @ApiOperation(value = "查询首页轮播图")
    @ResponseBody
    public ResponseData getCmsContent(@RequestParam(name = "regionId", required = true) String regionId,
                                      @RequestParam(name = "categoryCode", required = true) String categoryCode) {
        try {

            SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId));
            if (region != null) {
                BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString());
                if (bsCompany != null) {
                    Map<String,String> map = new HashMap<>();
                    map.put("companyId", bsCompany.getId().toString());
                    map.put("status", "2");
                    map.put("categoryCode", categoryCode);
                    return ResponseMsgUtil.success(cmsContentService.getListContent(map));
                }
            }
            return ResponseMsgUtil.success(new ArrayList<>());
        } catch (Exception e) {
            log.error("CmsContentController --> getCorporateAdvertising() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }
}
