package com.jzdsh.auto.biz;

import com.jzdsh.auto.model.Notice;
import lombok.extern.log4j.Log4j2;

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

/**
 * @ProjectName: auto
 * @Package: com.jzdsh.auto.biz
 * @ClassName: NoticeService
 * @Author: Jzdsh
 * @Description: 公告信息
 * @Date: 2020/3/21 11:17
 * @Version: 1.0
 */
@Log4j2
public class NoticeService {

    /**
     * 根据城市查询该公告信息  > 按时间倒叙
     * code: listByProvinceCityPageSize("上海市","上海市",10)
     *
     * @param province 省份
     * @param city     城市
     * @param pageSize 显示数量
     * @return
     */
    public List< Notice > listByProvinceCityPageSize(String province, String city, Integer pageSize) {
        try {
            return Notice.dao.paginate(1, pageSize, "select *", "from notice where province = ? and city = ? order by createTime desc", province, city).getList( );
        } catch (Exception e) {
            log.info("com.jzdsh.auto.biz.NoticeService.listByProvinceCityPageSize " + e);
        }
        return null;
    }

    /**
     * 公告信息 保存
     * @param shopId 商家id
     * @param name  商家名称
     * @param province  省份
     * @param city 城市
     * @param district 县城
     */
    public void save(int shopId,String name, String province, String city, String district){
        try {
            Notice notice = new Notice( );
            notice.setShopId(shopId);
            notice.setProvince(province);
            notice.setCity(city);
            notice.setDistrict(district);
            notice.setCreateTime(new Date( ));
            notice.setTitle(name);
            notice.save();
        } catch (Exception e) {
            log.info(e);
        }
    }
}
