package com.hzs.system.home.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzs.common.core.utils.StringUtils;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.ext.HoEnterpriseMissionExt;
import com.hzs.common.domain.system.home.HoEnterpriseNews;
import com.hzs.system.home.service.IHoEnterpriseNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 公司新闻 前端控制器
 * </p>
 *
 * @author hzs
 * @since 2022-11-19
 */
@RestController
@RequestMapping("/api/ho-enterprise-news")
public class ApiHoEnterpriseNewsController extends BaseController {
    @Autowired
    private IHoEnterpriseNewsService enterpriseNewsService;

    /**
     * @description: 查询公司新闻列表
     * @author: zhang jing
     * @date: 2022/8/30 10:20
     * @param: [enterpriseNews]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @GetMapping("/list")
    public TableDataInfo list(HoEnterpriseMissionExt enterpriseNews) {
        QueryWrapper<HoEnterpriseNews> queryWrapper = new QueryWrapper();
        if(null!=enterpriseNews.getLanguageType()){
            if(enterpriseNews.getLanguageType()!=1){
                queryWrapper.ne("PK_COUNTRY",enterpriseNews.getPkCountry());
            }else{
                queryWrapper.eq("PK_COUNTRY",enterpriseNews.getPkCountry());
            }
        }
        queryWrapper.lt("EFFECTIVE_DATE",new Date());
        queryWrapper.orderByAsc("SORT");
        List<HoEnterpriseNews> list = enterpriseNewsService.list(queryWrapper);
        return getDataTable(list);
    }


    /**
     * @description: 查询单条个公司新闻
     * @author: zhang jing
     * @date: 2022/8/30 10:21
     * @param: [pkId]
     * @return: com.hzs.common.core.web.domain.AjaxResult
     **/
    @GetMapping("/getOne/{pkId}")
    public AjaxResult getOne(@PathVariable Long pkId) {
        HoEnterpriseNews enterpriseNews = enterpriseNewsService.getById(pkId);
        return AjaxResult.success(enterpriseNews);
    }


}
