All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ajaxjs.cms.app.attachment.Attachment_pictureServiceImpl Maven / Gradle / Ivy

The newest version!
package com.ajaxjs.cms.app.attachment;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import com.ajaxjs.framework.BaseService;
import com.ajaxjs.framework.Repository;
import com.ajaxjs.ioc.Bean;
import com.ajaxjs.util.io.FileUtil;

@Bean("Attachment_pictureService")
public class Attachment_pictureServiceImpl extends BaseService implements Attachment_pictureService {
	public Attachment_pictureDao dao = new Repository().bind(Attachment_pictureDao.class);
	
	{
		setUiName("图片");
		setShortName("attachment_picture");
		setDao(dao);
	}

	@Override
	public boolean delete(Attachment_picture bean) {
		new FileUtil().setFilePath(bean.getPath()).delete(); // 删除文件
		return dao.delete(bean);
	}

	@Override
	public List findByOwner(Long owner) {
		List list = dao.findByOwner(owner);
		if (null != list) {
			Collections.sort(list, new Comparator() {
				@Override
				public int compare(Attachment_picture pic1, Attachment_picture pic2) {
					if (pic1.getIndex() == null)
						return -1;
					if (pic2.getIndex() == null)
						return -1;

					if (pic1.getIndex() > pic2.getIndex())
						return 1;

					if (pic1.getIndex() == pic2.getIndex())
						return 0;

					return -1;
				}
			});
		}

		return list;
	}

	@Override
	public boolean saveImgIndex(Map map) {
		boolean isOk = true;

		for (String str : map.keySet()) {
			int index = (int) map.get(str);
			Long imgId = Long.parseLong(str);

			if (dao.saveImgIndex(index, imgId) < 0) {
				isOk = false;
			}
		}

		return isOk;
	}

	@Override
	public boolean deleteByOwnerId(Long OwnerId) {
		return dao.deleteByOwnerId(OwnerId);
	}

	@Override
	public List findAttachmentPictureByOwner(Long owner) {
		return dao.findAttachmentPictureByOwner(owner);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy