123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package service
- import (
- "ulink-admin/frame"
- "ulink-admin/modules/stock/dao"
- "ulink-admin/modules/stock/models/model"
- "ulink-admin/modules/stock/models/req"
- "ulink-admin/pkg/base"
- "xorm.io/xorm"
- )
- type StockService struct {
- stockDao dao.StockDao
- stockDetailDao dao.StockDetailDao
- }
- // List 查询所有大盘走势业务方法
- func (this StockService) List(query *req.StockQuery, list interface{}) {
- this.stockDao.List(query, list)
- }
- // Page 查询大盘走势分页列表
- func (this StockService) Page(query *req.StockQuery) ([]*model.Stock, int64) {
- return this.stockDao.Page(query)
- }
- // Insert 添加大盘走势
- func (this StockService) Insert(stock *model.Stock) {
- //检查站点标识唯一性
- if this.stockDao.Exist(stock.TableName(), "create_date=? and type=?", stock.CreateDate, stock.Type) {
- frame.Throw(frame.BUSINESS_CODE, "当天记录已存在,新增失败")
- }
- base.Transaction(func(session *xorm.Session) {
- this.stockDao.Insert(stock)
- for _, detail := range stock.Details {
- detail.StockId = stock.Id
- }
- this.stockDetailDao.Insert(stock.Details)
- })
- }
- // Get 查询
- func (this StockService) Get(id int64) *model.Stock {
- model := &model.Stock{}
- this.stockDao.GetById(id, model)
- return model
- }
- // Delete 批量删除
- func (this StockService) Delete(list []int64) {
- base.Transaction(func(session *xorm.Session) {
- this.stockDao.Delete(&model.Stock{}, list)
- this.stockDetailDao.GetSession().In("stock_id", list).Delete(&model.StockDetail{})
- })
- }
- // Edit 修改
- func (this StockService) Edit(stock *model.Stock, cols []string) {
- if this.stockDao.Exist(stock.TableName(), "create_date=? and type=? and id!=?", stock.CreateDate, stock.Type, stock.Id) {
- frame.Throw(frame.BUSINESS_CODE, "当天记录已存在,新增失败")
- }
- base.Transaction(func(session *xorm.Session) {
- this.stockDao.Update(stock, cols...)
- for _, detail := range stock.Details {
- this.stockDetailDao.Update(detail)
- }
- })
- }
|