Quellcode durchsuchen

delete booktype

胡轶钦 vor 6 Jahren
Ursprung
Commit
f2ce85b137

+ 9
- 0
controllers/book/book.go Datei anzeigen

@@ -261,3 +261,12 @@ func (c *BookController) GetRecordList() {
261 261
 	}
262 262
 	c.ResponseJSON(list)
263 263
 }
264
+
265
+func (c *BookController) CancelReserve() {
266
+	recordId := c.GetString(":recordId")
267
+	err := c.serv.CancelReserve(recordId)
268
+	if err != nil {
269
+		c.ResponseError(err)
270
+	}
271
+	c.ResponseJSON("取消成功")
272
+}

+ 10
- 0
controllers/booktype/booktype.go Datei anzeigen

@@ -60,3 +60,13 @@ func (c *BooktypeController) SaveBookType() {
60 60
 	}
61 61
 	c.ResponseJSON(newbooktype)
62 62
 }
63
+
64
+func (c *BooktypeController) DeleteBookType() {
65
+	bookTypeId := c.GetString(":bookTypeId")
66
+	err := c.serv.DeleteBookType(bookTypeId)
67
+	if err != nil {
68
+		c.ResponseError(err)
69
+	}
70
+	c.ResponseJSON("删除成功")
71
+
72
+}

+ 39
- 4
models/book/book.go Datei anzeigen

@@ -9,6 +9,8 @@ import (
9 9
 	"strings"
10 10
 	"time"
11 11
 
12
+	"github.com/astaxie/beego"
13
+
12 14
 	"github.com/go-xorm/xorm"
13 15
 )
14 16
 
@@ -105,6 +107,15 @@ func (m *BookDAO) AddBookRecord(record model.TaBookBorrowRecord) (*model.TaBookB
105 107
 	_, err := m.db.Insert(record)
106 108
 	return &record, err
107 109
 }
110
+func (m *BookDAO) GetRecordById(recordId string) (*model.TaBookBorrowRecord, error) {
111
+	var record []model.TaBookBorrowRecord
112
+	sql := `select * from ta_book_borrow_record where book_borrow_record_id = '` + recordId + `'`
113
+	err := m.db.Sql(sql).Find(&record)
114
+	if len(record) <= 0 {
115
+		return nil, err
116
+	}
117
+	return &record[0], err
118
+}
108 119
 func (m *BookDAO) UpdateBookRecord(record *model.TaBookBorrowRecord) (*model.TaBookBorrowRecord, error) {
109 120
 	var cols = []string{
110 121
 		"borrow_date",
@@ -124,6 +135,7 @@ type BorrowRecord struct {
124 135
 	model.TaBookBorrowRecord `xorm:"extends"`
125 136
 	BookBarcode              string
126 137
 	BookName                 string
138
+	BookImg                  string
127 139
 }
128 140
 
129 141
 func (m *BookDAO) GetRecordList(borrowStatus, caseid, customerName, customerPhone, bookName, barcode string, page, pageSize int) ([]BorrowRecord, error) {
@@ -131,7 +143,8 @@ func (m *BookDAO) GetRecordList(borrowStatus, caseid, customerName, customerPhon
131 143
 	sql := `SELECT
132 144
 	a.*,
133 145
 	b.book_name,
134
-	b.book_barcode
146
+	b.book_barcode,
147
+	b.book_img
135 148
 FROM
136 149
 	ta_book_borrow_record a
137 150
 	INNER JOIN ta_book b ON a.book_id = b.book_id
@@ -152,6 +165,7 @@ FROM
152 165
 		sql += ` and b.book_barcode = '` + barcode + `'`
153 166
 	}
154 167
 	sql += ` order by a.create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
168
+	beego.Error(sql)
155 169
 	err := m.db.Sql(sql).Find(&record)
156 170
 	return record, err
157 171
 
@@ -416,10 +430,31 @@ func (m *BookDAO) GetCustomerByCustomerInfo(customerInfo string) (*model.TaCusto
416 430
 	return &customer[0], err
417 431
 
418 432
 }
419
-func (m *BookDAO) GetAllRecord() ([]model.TaBookBorrowRecord, error) {
433
+
434
+// GetAllOneWeekRecord
435
+func (m *BookDAO) GetAllOneWeekRecord() ([]model.TaBookBorrowRecord, error) {
420 436
 	var record []model.TaBookBorrowRecord
421
-	sql := `select * from ta_book_borrow_record where 
422
-	a.borrow_status IN ( '` + models.BORROW_TYPE_BORROWED + `', '` + models.BORROW_TYPE_LATE + `' )`
437
+	sql := `SELECT
438
+	a.* 
439
+FROM
440
+	ta_book_borrow_record a 
441
+WHERE
442
+	DATE_FORMAT( a.end_date, "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( now( ), INTERVAL 1 WEEK ) ), "%Y-%m-%d" )
443
+	and a.borrow_status = '` + models.BORROW_TYPE_BORROWED + `'`
444
+	err := m.db.Sql(sql).Find(&record)
445
+	return record, err
446
+}
447
+
448
+// GetAllLateRecord
449
+func (m *BookDAO) GetAllLateRecord() ([]model.TaBookBorrowRecord, error) {
450
+	var record []model.TaBookBorrowRecord
451
+	sql := `SELECT
452
+	a.* 
453
+FROM
454
+	ta_book_borrow_record a 
455
+WHERE
456
+	DATE_FORMAT( now(), "%Y-%m-%d" ) = DATE_FORMAT( ( SELECT date_add( a.end_date, INTERVAL 2 DAY ) ), "%Y-%m-%d" )
457
+	and a.borrow_status = '` + models.BORROW_TYPE_LATE + `'`
423 458
 	err := m.db.Sql(sql).Find(&record)
424 459
 	return record, err
425 460
 }

+ 19
- 0
models/booktype/booktype.go Datei anzeigen

@@ -66,3 +66,22 @@ func (m *BooktypeDAO) EditBookType(booktype model.TaBookType) (*model.TaBookType
66 66
 	return &booktype, err
67 67
 
68 68
 }
69
+func (m *BooktypeDAO) DeleteBookType(bookTypeId string) error {
70
+	var booktype = model.TaBookType{
71
+		BookTypeId: bookTypeId,
72
+		Status:     models.STATUS_DEL,
73
+	}
74
+	var cols = []string{
75
+		"status",
76
+	}
77
+	_, err := m.db.Cols(cols...).Where("book_type_id = ?", booktype.BookTypeId).Update(booktype)
78
+	return err
79
+}
80
+
81
+func (m *BooktypeDAO) IsExistBook(bookTypeId string) (int, error) {
82
+	var book []model.TaBook
83
+	sql := `select * from ta_book where book_type_id = '` + bookTypeId + `' 
84
+	and status = '` + strconv.Itoa(models.STATUS_NORMAL) + `'`
85
+	err := m.db.Sql(sql).Find(&book)
86
+	return len(book), err
87
+}

+ 2
- 0
routers/common.go Datei anzeigen

@@ -360,11 +360,13 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
360 360
 		beego.NSRouter("/book/return/:customerInfo", &book.BookController{}, "get:GetCustomerReturnList"),
361 361
 		beego.NSRouter("/book/customer/:customerInfo", &book.BookController{}, "put:GetCustomerByCustomerInfo"),
362 362
 		beego.NSRouter("/book/excel", &book.BookController{}, "post:ExcelInpuData"),
363
+		beego.NSRouter("/book/cancel/:recordId", &book.BookController{}, "put:CancelReserve"),
363 364
 
364 365
 		// booktype 图书类型管理
365 366
 		beego.NSRouter("/booktype", &booktype.BooktypeController{}, "get:GetList"),
366 367
 		beego.NSRouter("/booktype/:bookTypeId", &booktype.BooktypeController{}, "get:GetBookTypeById"),
367 368
 		beego.NSRouter("/booktype", &booktype.BooktypeController{}, "post:SaveBookType"),
368 369
 		beego.NSRouter("/booktype", &booktype.BooktypeController{}, "put:SaveBookType"),
370
+		beego.NSRouter("/booktype/:bookTypeId", &booktype.BooktypeController{}, "delete:DeleteBookType"),
369 371
 	)
370 372
 }

+ 15
- 0
service/book/book.go Datei anzeigen

@@ -272,6 +272,21 @@ func (s *BookServ) ReturnBook(borrowId string) error {
272 272
 	}
273 273
 	return nil
274 274
 }
275
+func (s *BookServ) CancelReserve(recordId string) error {
276
+	record, err := s.dao.GetRecordById(recordId)
277
+	if err != nil {
278
+		utils.LogError("取消失败: " + err.Error())
279
+		return errors.New("取消失败")
280
+	}
281
+	record.BorrowStatus = models.BORROW_TYPE_CANCEL
282
+	_, err = s.dao.UpdateBookRecord(record)
283
+	if err != nil {
284
+		utils.LogError("取消失败: " + err.Error())
285
+		return errors.New("取消失败")
286
+	}
287
+	return nil
288
+
289
+}
275 290
 
276 291
 func (s *BookServ) GetCustomerReturnList(customerInfo, caseId string, page, pageSize int) (map[string]interface{}, error) {
277 292
 	if pageSize == 0 {

+ 17
- 0
service/booktype/booktype.go Datei anzeigen

@@ -70,3 +70,20 @@ func (s *BooktypeServ) SaveBookType(booktype model.TaBookType) (*model.TaBookTyp
70 70
 
71 71
 	return bookType, nil
72 72
 }
73
+
74
+func (s *BooktypeServ) DeleteBookType(bookTypeId string) error {
75
+	num, err := s.dao.IsExistBook(bookTypeId)
76
+	if err != nil {
77
+		utils.LogError("删除图书失败: " + err.Error())
78
+		return errors.New("删除图书失败")
79
+	}
80
+	if num > 0 {
81
+		return errors.New("该类型下有图书,不能删除")
82
+	}
83
+	err = s.dao.DeleteBookType(bookTypeId)
84
+	if err != nil {
85
+		utils.LogError("删除图书失败: " + err.Error())
86
+		return errors.New("删除图书失败")
87
+	}
88
+	return nil
89
+}