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.government.dao.AttachmentDao; import platform.modules.government.dao.LogoDao; import platform.modules.government.entity.Attachment; import platform.modules.government.entity.FileDown; import platform.modules.government.entity.Logo; import tk.mybatis.mapper.entity.Example; import java.util.List; /** * 首页logService * * @author lhf * @version 2017-10-26 */ @Service @Transactional public class LogoService extends BaseService { @Autowired LogoDao logoDao; @Autowired private AttachmentDao attachmentDao; @Autowired private AttachmentService attachmentService; @Transactional(readOnly = true) public PageInfo findPage(Integer pageNum, Integer pageSize) throws Exception { Example example = new Example(Logo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); // 倒序 example.orderBy("is_start").desc(); example.orderBy("create_time").desc(); PageHelper.startPage(pageNum, pageSize); List Logo = this.selectByExample(example); for (Logo logo : Logo) { List attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.LOGO, logo.getId(), null); if (null != attachments && attachments.size() > 0) { FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(),attachments.get(0).getDownload_uri()); logo.setFileDown(fileDown); } } return new PageInfo(Logo); } public Logo findLogo() { Example example = new Example(Logo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("is_start", 1); example.orderBy("create_time").desc(); List logo = this.selectByExample(example); if (null != logo) { Logo lo = logo.get(0); List attachments = attachmentService.selectByIdAndBusinessId(Constant.Attachment.LOGO, lo.getId(), null); if (null != attachments && attachments.size() > 0) { FileDown fileDown = new FileDown(attachments.get(0).getId(), attachments.get(0).getFile_name(), attachments.get(0).getFile_url(),attachments.get(0).getDownload_uri()); lo.setFileDown(fileDown); } return lo; } return null; } public Boolean saveLogo(Logo logo) throws Exception { if (this.insertAndGetId(logo) > 0) { //更新其他logo if(null!=logo.getIs_start()&&logo.getIs_start()){ logoDao.updateOtherLogo(logo.getId()); } attachmentDao.deleteByBusiness(Constant.Attachment.LOGO, logo.getId()); attachmentDao.updateAttachment(Constant.Attachment.LOGO, logo.getId(), logo.getFileDown().getFile_id()); return true; } return false; } public Boolean updateLogo(Logo logo) throws Exception { if (this.updateSelective(logo) == 1) { //更新其他logo if(null!=logo.getIs_start()&&logo.getIs_start()){ logoDao.updateOtherLogo(logo.getId()); } if(null!=logo.getFileDown().getFile_id()) { attachmentDao.deleteByBusiness(Constant.Attachment.LOGO, logo.getId()); attachmentDao.updateAttachment(Constant.Attachment.LOGO, logo.getId(), logo.getFileDown().getFile_id()); } return true; } return false; } public Boolean deleteLogoByIds(String ids) throws Exception { if (this.deleteByIds(ids) == 1) { return true; } return false; } public int findStartLogo() { Example example = new Example(Logo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("del_flag", 0); criteria.andEqualTo("is_start", 1); List Logo = this.selectByExample(example); return Logo == null ? 0 : Logo.size(); } public void updateOtherLogo(Integer id) throws Exception { logoDao.updateOtherLogo(id); } public Integer countLogo(Integer id) throws Exception { return logoDao.countLogo(id); } }