| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package platform.modules.government.service;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import platform.common.Constant;
- import platform.common.base.service.BaseService;
- import platform.modules.build.DTO.HomeSlideDto;
- import platform.modules.government.dao.AttachmentDao;
- import platform.modules.government.entity.Attachment;
- import platform.modules.government.entity.FileDown;
- import platform.modules.government.entity.Slides;
- import tk.mybatis.mapper.entity.Example;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 幻灯片管理Service
- *
- * @author lhf
- * @version 2017-10-26
- */
- @Service
- @Transactional
- public class SlidesService extends BaseService<Slides> {
- @Autowired
- private AttachmentService attachmentService;
- @Autowired
- private AttachmentDao attachmentDao;
- @Transactional(readOnly = true)
- public PageInfo<Slides> findPage(Integer pageNum, Integer pageSize) throws Exception {
- Example example = new Example(Slides.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", "0");
- /*
- * if(StringUtils.isNotBlank(param)) { criteria.andLike("title", "%" +
- * param + "%"); }
- */
- // 倒序
- example.orderBy("create_time").desc();
- PageHelper.startPage(pageNum, pageSize);
- List<Slides> Slides = this.selectByExample(example);
- for (Slides slide : Slides) {
- Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES);
- slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()));
- }
- return new PageInfo<>(Slides);
- }
- @Transactional(readOnly = true)
- public PageInfo<Slides> findFrontPage(Integer pageNum, Integer pageSize) throws Exception {
- Example example = new Example(Slides.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", "0");
- criteria.andEqualTo("is_start", "1");
- // 倒序
- example.orderBy("create_time").desc();
- PageHelper.startPage(pageNum, pageSize);
- List<Slides> Slides = this.selectByExample(example);
- for (Slides slide : Slides) {
- Attachment attachment = attachmentService.findByBizIdAndBizType(slide.getId(), Constant.Attachment.SLIDES);
- if(attachment!=null){
- slide.setFileDown(new FileDown(attachment.getId(), attachment.getFile_name(), attachment.getFile_url(), attachment.getDownload_uri()));
- }
- }
- return new PageInfo<>(Slides);
- }
- public Boolean saveSlides(Slides slides) throws Exception {
- if (this.saveSelective(slides) == 1) {
- attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
- slides.getFileDown().getFile_id());
- return true;
- }
- return false;
- }
- public Boolean updateSlides(Slides slides) throws Exception {
- if (this.updateSelective(slides) == 1) {
- if(null!=slides.getFileDown().getFile_id()) {
- attachmentDao.deleteByBusiness(Constant.Attachment.SLIDES, slides.getId());
- attachmentDao.updateAttachment(Constant.Attachment.SLIDES, slides.getId(),
- slides.getFileDown().getFile_id());
- }
- return true;
- }
- return false;
- }
- public Boolean deleteSlidesByIds(String ids) throws Exception {
- if (this.deleteByIds(ids) == 1) {
- return true;
- }
- return false;
- }
- public List<HomeSlideDto> showHomeSlides() {
- Example example = new Example(Slides.class);
- Example.Criteria criteria = example.createCriteria();
- criteria.andEqualTo("del_flag", "0");
- criteria.andEqualTo("is_start", "1");
- // 倒序
- example.orderBy("sort").asc();
- List<HomeSlideDto> slideDtoList = new ArrayList<>();
- List<Slides> Slides = this.selectByExample(example);
- if (Slides.size() > 0) {
- for (Slides slides : Slides) {
- HomeSlideDto homeSlideDto = new HomeSlideDto();
- List<Attachment> attashMemtList = attachmentDao.selectByIdAndBusinessId(Constant.Attachment.SLIDES,
- slides.getId(), null);
- if (attashMemtList.size() > 0) {
- homeSlideDto.setImagUrl(attashMemtList.get(0).getFile_url());
- }
- homeSlideDto.setIsLink(slides.getIs_link());
- if(slides.getIs_link()){
- homeSlideDto.setLinkLocation(slides.getHref());
- }else{
- homeSlideDto.setLinkLocation("javascript:return false;");
- }
- slideDtoList.add(homeSlideDto);
- }
- }
- return slideDtoList;
- }
- }
|