Explorar el Código

booktype searchby

bc_zhang hace 4 años
padre
commit
c217b02243

+ 1 - 1
src/main/java/com/zglc/fm/controller/AircraftTypeController.java

@@ -64,7 +64,7 @@ public class AircraftTypeController {
             @ApiResponse(code = 0, message = "成功")
             @ApiResponse(code = 0, message = "成功")
     })
     })
     @PostMapping("add")
     @PostMapping("add")
-    public Result<String> add(@RequestBody AircraftTypeEntity data){return  AircraftTypeService.add(data);}
+    public Result<String> add(@RequestBody AircraftTypeEntity data){return  AircraftTypeService.addAndCheck(data);}
 
 
     @ApiOperation("删除")
     @ApiOperation("删除")
     @ApiResponses({
     @ApiResponses({

+ 23 - 0
src/main/java/com/zglc/fm/controller/BookController.java

@@ -91,6 +91,29 @@ public class BookController {
         return Result.success(bookService.listAll());
         return Result.success(bookService.listAll());
     }
     }
 
 
+//    @ApiOperation("按书籍类型id列出所有")
+//    @ApiResponses({
+//            @ApiResponse(code = 0, message = "成功")
+//    })
+//    @GetMapping("listByType")
+//    public Result<List<BookEntity>> listBy(Integer typeId) {
+//        return Result.success(userService.searchAllUser(departmentId,roleId,null,null));
+//    }
+
+    @ApiOperation("分页按书籍类型id筛选")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("searchByType")
+    public Result<PageInfo<BookEntity>> searchData(Integer typeId,String name,Integer page, Integer size) {
+        PageHelper.startPage(page, size, "id desc");
+        return Result.success(new PageInfo<>( bookService.searchAllBook(typeId,name)));
+    }
+
+
+
+
+
     @ApiOperation("ID查找")
     @ApiOperation("ID查找")
     @ApiResponses({
     @ApiResponses({
             @ApiResponse(code = 0, message = "成功")
             @ApiResponse(code = 0, message = "成功")

+ 87 - 0
src/main/java/com/zglc/fm/controller/BookTypeController.java

@@ -0,0 +1,87 @@
+package com.zglc.fm.controller;
+
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.zglc.fm.base.Result;
+import com.zglc.fm.entity.DeleteEntity;
+import com.zglc.fm.entity.BookTypeEntity;
+import com.zglc.fm.service.BookTypeService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Api(tags = "教材类型接口")
+@RequestMapping("api/booktype")
+@CrossOrigin(allowCredentials = "true")
+@RestController
+public class BookTypeController {
+
+    @Resource
+    private final BookTypeService bookTypeService;
+    @Autowired(required = false)
+    public BookTypeController(BookTypeService bookTypeService){
+        this.bookTypeService = bookTypeService;
+    }
+
+
+    @ApiOperation("列出所有")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("listAll")
+    public Result<List<BookTypeEntity>> listAll() {
+        return Result.success(bookTypeService.listAll());
+    }
+
+    @ApiOperation("ID查找")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("get")
+    public  Result<BookTypeEntity> get(@RequestParam Integer id){return  Result.success(bookTypeService.getBookType(id));}
+
+    @ApiOperation("按名称查询")
+    @GetMapping("getByName")
+    public Result<List<BookTypeEntity>> findByName(@RequestParam("name") String name){
+        return bookTypeService.findByName(name);
+    }
+
+    @ApiOperation("增添")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @PostMapping("add")
+    public Result<String> add(@RequestBody BookTypeEntity data){return  bookTypeService.addAndCheck(data);}
+
+    @ApiOperation("删除")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @PostMapping("delete")
+    public Result<String> delete(@RequestBody DeleteEntity deleteEntity){return  bookTypeService.delete(deleteEntity.getIds());}
+
+    @ApiOperation("修改")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @PostMapping("edit")
+    public Result<String> edit( @RequestBody BookTypeEntity data){return  bookTypeService.edit(data);}
+
+    @ApiOperation("分页列出所有")
+    @ApiResponses({
+            @ApiResponse(code = 0, message = "成功")
+    })
+    @GetMapping("listpage")
+    public Result<PageInfo<BookTypeEntity>> listpage(Integer page, Integer size) {
+        PageHelper.startPage(page, size, "id desc");
+        return Result.success(new PageInfo<>(bookTypeService.getAllBookType()));
+    }
+
+}

+ 1 - 1
src/main/java/com/zglc/fm/controller/MajorController.java

@@ -58,7 +58,7 @@ public class MajorController {
             @ApiResponse(code = 0, message = "成功")
             @ApiResponse(code = 0, message = "成功")
     })
     })
     @PostMapping("add")
     @PostMapping("add")
-    public Result<String> add(@RequestBody MajorEntity data){return  majorService.add(data);}
+    public Result<String> add(@RequestBody MajorEntity data){return  majorService.addAndCheck(data);}
 
 
     @ApiOperation("删除")
     @ApiOperation("删除")
     @ApiResponses({
     @ApiResponses({

+ 1 - 1
src/main/java/com/zglc/fm/controller/UserController.java

@@ -105,7 +105,7 @@ public class UserController {
             @ApiResponse(code = 0, message = "成功")
             @ApiResponse(code = 0, message = "成功")
     })
     })
     @PostMapping("add")
     @PostMapping("add")
-    public Result<String> add( @RequestBody UserEntity data){return  userService.add(data);}
+    public Result<String> add( @RequestBody UserEntity data){return  userService.addAndCheck(data);}
 
 
     @ApiOperation("删除")    
     @ApiOperation("删除")    
 	@ApiResponses({
 	@ApiResponses({

+ 18 - 0
src/main/java/com/zglc/fm/dao/BookTypeDao.java

@@ -0,0 +1,18 @@
+package com.zglc.fm.dao;
+
+import com.zglc.fm.entity.BookTypeEntity;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+import tk.mybatis.mapper.common.Mapper;
+
+import java.util.List;
+
+@Repository
+public interface BookTypeDao extends Mapper<BookTypeEntity> {
+
+    List<BookTypeEntity> listAll();
+
+    Integer getCount();
+
+    List<BookTypeEntity> findByName(@Param("type_name") String name);
+}

+ 30 - 0
src/main/java/com/zglc/fm/entity/BookEntity.java

@@ -37,18 +37,48 @@ public class BookEntity implements Serializable {
     @Column(name = "major_type")
     @Column(name = "major_type")
     private String major_type;
     private String major_type;
 
 
+    /**
+     * type_name
+     */
+    @Column(name = "type_id")
+    private String type_id;
+
+    /**
+     * type_name
+     */
+    @Column(name = "type_name")
+    private String type_name;
+
     /**
     /**
      * description
      * description
      */
      */
     @Column(name = "description")
     @Column(name = "description")
     private String description;
     private String description;
 
 
+    /**
+     * description
+     */
+    @Column(name = "author")
+    private String author;
+
+    /**
+     * description
+     */
+    @Column(name = "publish_time")
+    private String publish_time;
+
     /**
     /**
      * file_path
      * file_path
      */
      */
     @Column(name = "file_path")
     @Column(name = "file_path")
     private String file_path;
     private String file_path;
 
 
+    /**
+     * img
+     */
+    @Column(name = "img")
+    private String img;
+
     /**
     /**
      * input_time
      * input_time
      */
      */

+ 33 - 0
src/main/java/com/zglc/fm/entity/BookTypeEntity.java

@@ -0,0 +1,33 @@
+package com.zglc.fm.entity;
+
+import lombok.Data;
+
+import javax.persistence.*;
+
+
+@Data
+@Table(name = "t_book_type")
+public class BookTypeEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     *id
+     */
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private Integer id;
+
+    /**
+     * 专业名
+     */
+    @Column(name = "type_name")
+    private String type_name;
+
+    /**
+     * 备注
+     */
+    @Column(name = "remarks")
+    private String remarks;
+
+}

+ 21 - 0
src/main/java/com/zglc/fm/service/AircraftTypeService.java

@@ -40,6 +40,27 @@ public class AircraftTypeService {
         return Result.result(flag, msg, msg);
         return Result.result(flag, msg, msg);
     }
     }
 
 
+    public Result<String> addAndCheck(AircraftTypeEntity data){
+        boolean flag = true;
+        String msg = "";
+        Example example = new Example(AircraftTypeEntity.class);
+        example.createCriteria().andEqualTo("aircraft_type", data.getAircraft_type());
+        List<AircraftTypeEntity> lst = aircraftTypeDao.selectByExample(example);
+        if (lst.size() > 0) {
+            flag = false;
+            msg = "机型已存在!";
+        } else {
+            int index = aircraftTypeDao.insertSelective(data);
+            if (index == 0) {
+                flag = false;
+                msg = "添加机型失败!";
+            } else {
+                msg = "添加机型成功!";
+            }
+        }
+        return Result.result(flag, msg, msg);
+    }
+
     public Result<String> delete(List<Integer> ids) {
     public Result<String> delete(List<Integer> ids) {
         boolean flag = true;
         boolean flag = true;
         String msg = "";
         String msg = "";

+ 16 - 0
src/main/java/com/zglc/fm/service/BookService.java

@@ -98,5 +98,21 @@ public class BookService {
         return bookDao.selectByExample(example);
         return bookDao.selectByExample(example);
     }
     }
 
 
+    public List<BookEntity> searchAllBook(Integer typeId, String name) {
+
+        Example example = new Example(BookEntity.class);
+        Example.Criteria criteria = example.createCriteria();
+        if (typeId != 0)
+            criteria.andEqualTo("type_id", typeId);
+        if(name != null)
+        {
+            criteria.andLike("book_name", "%" + name + "%");
+        }
+        if (criteria.isValid())
+            return bookDao.selectByExample(example);
+        else
+            return getAllBook();
+    }
+
 
 
 }
 }

+ 121 - 0
src/main/java/com/zglc/fm/service/BookTypeService.java

@@ -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);
+    }
+
+}

+ 21 - 0
src/main/java/com/zglc/fm/service/MajorService.java

@@ -43,6 +43,27 @@ public class MajorService {
         return Result.result(flag, msg, msg);
         return Result.result(flag, msg, msg);
     }
     }
 
 
+    public Result<String> addAndCheck(MajorEntity data){
+        boolean flag = true;
+        String msg = "";
+        Example example = new Example(MajorEntity.class);
+        example.createCriteria().andEqualTo("major_name", data.getMajor_name());
+        List<MajorEntity> lst = majorDao.selectByExample(example);
+        if (lst.size() > 0) {
+            flag = false;
+            msg = "专业已存在!";
+        } else {
+            int index = majorDao.insertSelective(data);
+            if (index == 0) {
+                flag = false;
+                msg = "添加专业失败!";
+            } else {
+                msg = "添加专业成功!";
+            }
+        }
+        return Result.result(flag, msg, msg);
+    }
+
     public Result<String> delete(List<Integer> ids) {
     public Result<String> delete(List<Integer> ids) {
         boolean flag = true;
         boolean flag = true;
         String msg = "";
         String msg = "";

+ 15 - 8
src/main/java/com/zglc/fm/service/UserService.java

@@ -2,6 +2,7 @@ package com.zglc.fm.service;
 
 
 import com.zglc.fm.entity.UserEntity;
 import com.zglc.fm.entity.UserEntity;
 import com.zglc.fm.dao.UserDao;
 import com.zglc.fm.dao.UserDao;
+import com.zglc.fm.utils.DigestUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import com.zglc.fm.base.Result;
 import com.zglc.fm.base.Result;
 import tk.mybatis.mapper.entity.Example;
 import tk.mybatis.mapper.entity.Example;
@@ -61,6 +62,11 @@ public class UserService {
     }
     }
 
 
     public UserEntity getUser(Integer id) {
     public UserEntity getUser(Integer id) {
+//        if (id == 1) {
+//            return null;
+//        } else {
+//            return userDao.selectByPrimaryKey(id);
+//        }
         return userDao.selectByPrimaryKey(id);
         return userDao.selectByPrimaryKey(id);
     }
     }
 
 
@@ -92,14 +98,16 @@ public class UserService {
     public Result<String> addAndCheck(UserEntity data) {
     public Result<String> addAndCheck(UserEntity data) {
         boolean flag = true;
         boolean flag = true;
         String msg = "";
         String msg = "";
-        UserEntity tmpData = null;
         Example example = new Example(UserEntity.class);
         Example example = new Example(UserEntity.class);
-        example.createCriteria().andEqualTo("id", data.getId());
-        tmpData = userDao.selectOneByExample(example);
-        if (tmpData != null) {
+        example.createCriteria().andEqualTo("userName", data.getUserName());
+        List<UserEntity> lst = userDao.selectByExample(example);
+        if (lst.size() > 0) {
             flag = false;
             flag = false;
             msg = "用户已存在!";
             msg = "用户已存在!";
         } else {
         } else {
+//            UserEntity userEntity = new UserEntity();
+            String digestPassword = DigestUtil.getMD5Str(data.getPassword());
+            data.setPassword(digestPassword);
             int index = userDao.insertSelective(data);
             int index = userDao.insertSelective(data);
             if (index == 0) {
             if (index == 0) {
                 flag = false;
                 flag = false;
@@ -149,8 +157,8 @@ public class UserService {
         while (iter.hasNext()) {
         while (iter.hasNext()) {
             Integer id = (Integer) iter.next();
             Integer id = (Integer) iter.next();
             UserEntity userEntity = userDao.selectByPrimaryKey(id);
             UserEntity userEntity = userDao.selectByPrimaryKey(id);
-           if (getImg(userEntity))
-                    files.add("image/" + userEntity.getImg());
+            if (getImg(userEntity))
+                files.add("image/" + userEntity.getImg());
             int index = userDao.deleteByPrimaryKey(id);
             int index = userDao.deleteByPrimaryKey(id);
             if (index == 0) {
             if (index == 0) {
                 flag = false;
                 flag = false;
@@ -176,5 +184,4 @@ public class UserService {
         return Result.success(list);
         return Result.success(list);
 
 
     }
     }
-}
-
+}

+ 1 - 1
src/main/resources/logback-spring.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration debug="true">
 <configuration debug="true">
-    <property name="logDir" value="/usr/local/etc/tr/logs"/>
+    <property name="logDir" value="/usr/local/etc/fm/logs"/>
 
 
     <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
     <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
         <layout class="ch.qos.logback.classic.PatternLayout">
         <layout class="ch.qos.logback.classic.PatternLayout">

+ 7 - 2
src/main/resources/mapping/BookDao.xml

@@ -9,14 +9,19 @@
         <result property="book_name" column="book_name"/>
         <result property="book_name" column="book_name"/>
         <result property="aircraft_type" column="aircraft_type"/>
         <result property="aircraft_type" column="aircraft_type"/>
         <result property="major_type" column="major_type"/>
         <result property="major_type" column="major_type"/>
+        <result property="type_id" column="type_id"/>
+        <result property="type_name" column="type_name"/>
         <result property="description" column="description"/>
         <result property="description" column="description"/>
+        <result property="author" column="author"/>
+        <result property="publish_time" column="publish_time"/>
         <result property="file_path" column="file_path"/>
         <result property="file_path" column="file_path"/>
+        <result property="img" column="img"/>
         <result property="input_time" column="input_time"/>
         <result property="input_time" column="input_time"/>
         <result property="remarks" column="remarks"/>
         <result property="remarks" column="remarks"/>
     </resultMap>
     </resultMap>
 
 
     <select id="listAll" resultMap="bookMap">
     <select id="listAll" resultMap="bookMap">
-        select id,book_name,aircraft_type,major_type,description,file_path,input_time,remarks
+        select id,book_name,aircraft_type,major_type,type_id,type_name,description,author,publish_time,file_path,img,input_time,remarks
         from t_book
         from t_book
         where id > 0
         where id > 0
     </select>
     </select>
@@ -36,7 +41,7 @@
 <!--    </insert>-->
 <!--    </insert>-->
 
 
     <select id="findByName" parameterType="String" resultMap="bookMap">
     <select id="findByName" parameterType="String" resultMap="bookMap">
-        select id,book_name,aircraft_type,major_type,description,file_path,input_time,remarks from t_book where book_name
+        select id,book_name,aircraft_type,major_type,type_id,type_name,description,author,publish_time,file_path,img,input_time,remarks from t_book where book_name
         like #{book_name}
         like #{book_name}
     </select>
     </select>
 
 

+ 38 - 0
src/main/resources/mapping/BookTypeDao.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.zglc.fm.dao.BookTypeDao">
+
+	<!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.zglc.fm.entity.BookTypeEntity" id="bookTypeMap">
+        <result property="id" column="id"/>
+        <result property="type_name" column="type_name"/>
+        <result property="remarks" column="remarks"/>
+    </resultMap>
+
+    <select id="listAll" resultMap="bookTypeMap">
+        select id,type_name,remarks
+        from t_book_type
+        where id > 0
+    </select>
+
+    <select id="getCount" resultType="java.lang.Integer">
+        select count(1)
+        from t_book_type
+        where id > 1
+    </select>
+
+<!--    <insert id="batchAdd" parameterType="java.util.List">-->
+<!--        <foreach collection="list" item="equ" separator=";">-->
+<!--            insert into t_equipment (equipment_type)-->
+<!--            SELECT #{equ.equipment_type}-->
+<!--            FROM DUAL WHERE NOT EXISTS (SELECT equipment_type FROM  t_equipment WHERE equipment_type = #{equ.equipment_type})-->
+<!--        </foreach>-->
+<!--    </insert>-->
+
+    <select id="findByName" parameterType="String" resultMap="bookTypeMap">
+        select id,type_name,remarks from t_book_type where type_name
+        like #{type_name}
+    </select>
+
+</mapper>