|
@@ -0,0 +1,121 @@
|
|
|
+package com.zglc.fm.service;
|
|
|
+
|
|
|
+import com.zglc.fm.base.Result;
|
|
|
+import com.zglc.fm.dao.BookTypeDao;
|
|
|
+import com.zglc.fm.entity.BookTypeEntity;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
+
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+
|
|
|
+public class BookTypeService {
|
|
|
+
|
|
|
+ private BookTypeDao bookTypeDao;
|
|
|
+
|
|
|
+ public BookTypeService(BookTypeDao bookTypeDao) {
|
|
|
+ this.bookTypeDao = bookTypeDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BookTypeEntity> listAll() {
|
|
|
+ return bookTypeDao.listAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getCount() {
|
|
|
+ return bookTypeDao.getCount();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<String> add(BookTypeEntity data) {
|
|
|
+ data.setId(null);
|
|
|
+ boolean flag = true;
|
|
|
+ String msg = "";
|
|
|
+ int index = bookTypeDao.insertSelective(data);
|
|
|
+ if (index == 0) {
|
|
|
+ flag = false;
|
|
|
+ msg = "添加书籍类型信息失败!";
|
|
|
+ } else {
|
|
|
+ msg = "添加书籍类型信息成功!";
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.result(flag, msg, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<String> addAndCheck(BookTypeEntity data){
|
|
|
+ boolean flag = true;
|
|
|
+ String msg = "";
|
|
|
+ Example example = new Example(BookTypeEntity.class);
|
|
|
+ example.createCriteria().andEqualTo("type_name", data.getType_name());
|
|
|
+ List<BookTypeEntity> lst = bookTypeDao.selectByExample(example);
|
|
|
+ if (lst.size() > 0) {
|
|
|
+ flag = false;
|
|
|
+ msg = "书籍类型已存在!";
|
|
|
+ } else {
|
|
|
+ int index = bookTypeDao.insertSelective(data);
|
|
|
+ if (index == 0) {
|
|
|
+ flag = false;
|
|
|
+ msg = "添加书籍类型失败!";
|
|
|
+ } else {
|
|
|
+ msg = "添加书籍类型成功!";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.result(flag, msg, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<String> delete(List<Integer> ids) {
|
|
|
+ boolean flag = true;
|
|
|
+ String msg = "";
|
|
|
+ Iterator iter = ids.iterator();
|
|
|
+ while(iter.hasNext()) {
|
|
|
+ Integer id = (Integer)iter.next();
|
|
|
+ int index = bookTypeDao.deleteByPrimaryKey(id);
|
|
|
+ if (index == 0) {
|
|
|
+ flag = false;
|
|
|
+ msg += "书籍类型删除失败!" + id + ";";
|
|
|
+ } else {
|
|
|
+ msg += "书籍类型删除成功!" + id + ";";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.result(flag, msg, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<String> edit(BookTypeEntity data) {
|
|
|
+ boolean flag = true;
|
|
|
+ String msg = "";
|
|
|
+ BookTypeEntity tmpData = bookTypeDao.selectByPrimaryKey(data.getId());
|
|
|
+ if (tmpData != null) {
|
|
|
+ int index = bookTypeDao.updateByPrimaryKeySelective(data);
|
|
|
+ if (index == 0) {
|
|
|
+ flag = false;
|
|
|
+ msg = "书籍类型信息修改失败";
|
|
|
+ } else {
|
|
|
+ msg = "书籍类型信息修改成功";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ flag = false;
|
|
|
+ msg = "书籍类型信息不存在!";
|
|
|
+ }
|
|
|
+ return Result.result(flag, msg, msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result<List<BookTypeEntity>> findByName(String name){
|
|
|
+ if (name == null ||"".equals(name)){
|
|
|
+ return Result.result(false, "名称不能为空" ,null);
|
|
|
+ }
|
|
|
+ List<BookTypeEntity> list = bookTypeDao.findByName("%" + name + "%");
|
|
|
+ return Result.success(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ public BookTypeEntity getBookType(Integer id) {
|
|
|
+ return bookTypeDao.selectByPrimaryKey(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BookTypeEntity> getAllBookType() {
|
|
|
+ String msg = "";
|
|
|
+ Example example = new Example(BookTypeEntity.class);
|
|
|
+ example.createCriteria();
|
|
|
+ return bookTypeDao.selectByExample(example);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|