package thyyxxk.webserver.service.dictionary.wxservice;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import thyyxxk.webserver.dao.his.dictionary.wxservice.ScrollNewsDao;
import thyyxxk.webserver.entity.dictionary.wxservice.WxserviceScrollNews;
import thyyxxk.webserver.utils.TokenUtil;

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

@Service
public class ScrollNewsService {
    private final ScrollNewsDao dao;

    @Autowired
    public ScrollNewsService(ScrollNewsDao dao) {
        this.dao = dao;
    }

    public List<WxserviceScrollNews> getAll() {
        QueryWrapper<WxserviceScrollNews> wrapper = new QueryWrapper<>();
        wrapper.orderByAsc("sort_no");
        return dao.selectList(wrapper);
    }

    public WxserviceScrollNews getById(Integer id) {
        QueryWrapper<WxserviceScrollNews> wrapper = new QueryWrapper<>();
        wrapper.eq("sort_no", id);
        return dao.selectOne(wrapper);
    }

    public String update(WxserviceScrollNews body) {
        body.setUpdateTime(new Date());
        body.setUpdateStaff(TokenUtil.getInstance().getTokenUserId());
        dao.updateById(body);
        return "OK";
    }
}
