| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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<Logo> {
- @Autowired
- LogoDao logoDao;
- @Autowired
- private AttachmentDao attachmentDao;
- @Autowired
- private AttachmentService attachmentService;
- @Transactional(readOnly = true)
- public PageInfo<Logo> 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> Logo = this.selectByExample(example);
- for (Logo logo : Logo) {
- List<Attachment> 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>(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> logo = this.selectByExample(example);
- if (null != logo) {
- Logo lo = logo.get(0);
- List<Attachment> 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> 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);
- }
- }
|