DengBiao před 1 rokem
rodič
revize
bdb31656a9
6 změnil soubory, kde provedl 287 přidání a 28 odebrání
  1. +125
    -0
      app/admin/hdl/hdl_device.go
  2. +17
    -0
      app/admin/md/md_device.go
  3. +103
    -0
      app/db/db_device.go
  4. +11
    -0
      app/db/model/device.go
  5. +24
    -28
      app/db/model/self_support_for_school_ord.go
  6. +7
    -0
      app/router/admin_router.go

+ 125
- 0
app/admin/hdl/hdl_device.go Zobrazit soubor

@@ -0,0 +1,125 @@
package hdl

import (
"applet/app/admin/lib/validate"
"applet/app/admin/md"
"applet/app/db"
model2 "applet/app/db/model"
"applet/app/e"
"github.com/gin-gonic/gin"
"time"
)

func DeviceList(c *gin.Context) {
var req md.DeviceListReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
if req.Limit == 0 {
req.Limit = 10
}
if req.Page == 0 {
req.Page = 10
}

sess := db.Db.Desc("id")
if req.Name != "" {
sess.And("device.name like ?", "%"+req.Name+"%")
}
if req.EnterpriseName != "" {
sess.And("enterprise.name like ?", "%"+req.EnterpriseName+"%")
}
if req.StartDate != "" {
sess.And("device.create_at >=?", req.StartDate)
}
if req.EndDate != "" {
sess.And("device.create_at <=?", req.EndDate)
}
var m []*db.DeviceWithEnterprise
total, err := sess.Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}

e.OutSuc(c, map[string]interface{}{
"list": m,
"total": total,
}, nil)
return
}

func DeviceSave(c *gin.Context) {
var req md.DeviceSaveReq
err := c.ShouldBindJSON(&req)
if err != nil {
err = validate.HandleValidateErr(err)
err1 := err.(e.E)
e.OutErr(c, err1.Code, err1.Error())
return
}
deviceDd := db.Device{}
deviceDd.Set(req.DeviceSn)
//查找 device_sn
device, err := deviceDd.GetDevice()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if device == nil {
insertAffected, err1 := deviceDd.DeviceInsert(&model2.Device{
Name: req.Name,
DeviceSn: req.DeviceSn,
EnterpriseId: req.EnterpriseId,
Memo: req.Memo,
CreateAt: time.Now().Format("2006-01-02 15:04:05"),
UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
})
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if insertAffected <= 0 {
e.OutErr(c, e.ERR_DB_ORM, "新增数据失败")
return
}
} else {
device.EnterpriseId = req.EnterpriseId
device.Name = req.Name
device.Memo = req.Memo
device.UpdateAt = time.Now().Format("2006-01-02 15:04:05")
updateAffected, err1 := deviceDd.DeviceUpdate(device, "enterprise_id", "name", "memo", "update_at")
if err1 != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if updateAffected <= 0 {
e.OutErr(c, e.ERR_DB_ORM, "更新数据失败")
return
}
}

e.OutSuc(c, "success", nil)
return
}

func DeviceDelete(c *gin.Context) {
deviceSn := c.Param("device_sn")
deviceDd := db.Device{}
deviceDd.Set(deviceSn)
deviceDdAffected, err := deviceDd.DeviceDelete()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if deviceDdAffected <= 0 {
e.OutErr(c, e.ERR_DB_ORM, "删除数据失败")
return
}
e.OutSuc(c, "success", nil)
return
}

+ 17
- 0
app/admin/md/md_device.go Zobrazit soubor

@@ -0,0 +1,17 @@
package md

type DeviceListReq struct {
Page int `json:"page" label:"页码"`
Limit int `json:"limit" label:"每页数量"`
EnterpriseName string `json:"enterprise_name" label:"校企名称"`
Name string `json:"name" label:"档口名称"`
StartDate string `json:"start_date" label:"起始时间"`
EndDate string `json:"end_date" label:"截止时间"`
}

type DeviceSaveReq struct {
Name string `json:"name" binding:"required"`
DeviceSn string `json:"device_sn" binding:"required"`
EnterpriseId int `json:"enterprise_id" binding:"required"`
Memo string `json:"memo"`
}

+ 103
- 0
app/db/db_device.go Zobrazit soubor

@@ -0,0 +1,103 @@
package db

import (
"applet/app/db/model"
"applet/app/utils/logx"
"reflect"
"xorm.io/xorm"
)

type Device struct {
Db *xorm.Engine `json:"db"`
DeviceSn string `json:"device_sn"`
}

func (deviceOrdDb *Device) Set(deviceSn string) { // set方法
deviceOrdDb.Db = Db
deviceOrdDb.DeviceSn = deviceSn
}

func (deviceOrdDb *Device) GetDeviceById(id int) (m *model.Device, err error) {
m = new(model.Device)
has, err := deviceOrdDb.Db.Where("id =?", id).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (deviceOrdDb *Device) GetDevice() (m *model.Device, err error) {
m = new(model.Device)
has, err := deviceOrdDb.Db.Where("device_sn =?", deviceOrdDb.DeviceSn).Get(m)
if err != nil {
return nil, logx.Error(err)
}
if has == false {
return nil, nil
}
return m, nil
}

func (deviceOrdDb *Device) DeviceInsert(m *model.Device) (int, error) {
_, err := deviceOrdDb.Db.InsertOne(m)
if err != nil {
return 0, err
}
return m.Id, nil
}

func (deviceOrdDb *Device) DeviceInsertBySession(session *xorm.Session, m *model.Device) (int, error) {
_, err := session.InsertOne(m)
if err != nil {
return 0, err
}
return m.Id, nil
}

func (deviceOrdDb *Device) BatchAddDevices(mm []*model.Device) (int64, error) {
affected, err := deviceOrdDb.Db.Insert(mm)
if err != nil {
return 0, err
}
return affected, nil
}

func (deviceOrdDb *Device) DeviceDeleteById(id interface{}) (int64, error) {
if reflect.TypeOf(id).Kind() == reflect.Slice {
return Db.In("id", id).Delete(model.Device{})
} else {
return Db.Where("id = ?", id).Delete(model.Device{})
}
}

func (deviceOrdDb *Device) DeviceDelete() (int64, error) {
return Db.Where("device_sn = ?", deviceOrdDb.DeviceSn).Delete(model.Device{})
}

func (deviceOrdDb *Device) DeviceUpdate(m *model.Device, forceColums ...string) (int64, error) {
var (
affected int64
err error
)
if forceColums != nil {
affected, err = deviceOrdDb.Db.Where("device_sn=?", deviceOrdDb.DeviceSn).Cols(forceColums...).Update(m)
} else {
affected, err = deviceOrdDb.Db.Where("device_sn=?", deviceOrdDb.DeviceSn).Update(m)
}
if err != nil {
return 0, err
}
return affected, nil
}

type DeviceWithEnterprise struct {
model.Device `xorm:"extends"`
model.Enterprise `xorm:"extends"`
}

func (DeviceWithEnterprise) TableName() string {
return "device"
}

+ 11
- 0
app/db/model/device.go Zobrazit soubor

@@ -0,0 +1,11 @@
package model

type Device struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Name string `json:"name" xorm:"not null default '' comment('档口名称') VARCHAR(255)"`
DeviceSn string `json:"device_sn" xorm:"not null default '' comment('设备编号') unique VARCHAR(255)"`
EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('校企id') INT(11)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注信息') VARCHAR(255)"`
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
}

+ 24
- 28
app/db/model/self_support_for_school_ord.go Zobrazit soubor

@@ -1,32 +1,28 @@
package model

import (
"time"
)

type SelfSupportForSchoolOrd struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('所属单位id') INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"`
OutOrderNo string `json:"out_order_no" xorm:"not null default '' comment('外部订单号,设备端产生') VARCHAR(255)"`
TradeNo string `json:"trade_no" xorm:"not null default '' comment('第三方交易号,支付宝,微信,ISV渠道等') VARCHAR(255)"`
Consumer string `json:"consumer" xorm:"not null default '' comment('消费人(花名册名称)') CHAR(100)"`
BuyerId string `json:"buyer_id" xorm:"not null default '' comment('云校园定义买家标识(支付宝刷脸用户id)') CHAR(100)"`
SellerId string `json:"seller_id" xorm:"not null default '' comment('卖家支付宝uid') CHAR(100)"`
DeviceSn string `json:"device_sn" xorm:"not null default '' comment('设备编号') CHAR(100)"`
SchoolName string `json:"school_name" xorm:"not null default '' comment('学校名称') CHAR(100)"`
SchoolCode string `json:"school_code" xorm:"not null default '' comment('学校内标') CHAR(100)"`
StoreBusinessScenario string `json:"store_business_scenario" xorm:"not null default '' comment('门店经营场景') CHAR(100)"`
StoreName string `json:"store_name" xorm:"not null default '' comment('门店名称') CHAR(100)"`
CpStoreId string `json:"cp_store_id" xorm:"not null default '' comment('门店编号') CHAR(100)"`
MerchantName string `json:"merchant_name" xorm:"not null default '' comment('商户名称') CHAR(100)"`
CpMerchantId string `json:"cp_merchant_id" xorm:"not null default '' comment('商户编码') CHAR(100)"`
TradeAmount string `json:"trade_amount" xorm:"not null default 0.00 comment('交易总金额') DECIMAL(8,2)"`
FaceTime string `json:"face_time" xorm:"not null default '' comment('刷脸时间') CHAR(100)"`
OrderStatus int `json:"order_status" xorm:"not null default 0 comment('支付状态 (1:待支付 2:支付成功)') TINYINT(1)"`
DebtBusinessCode string `json:"debt_business_code" xorm:"not null default '' comment('欠费订单异常渠道异常码(欠费返回)') CHAR(100)"`
DebtBusinessMsg string `json:"debt_business_msg" xorm:"not null default '' comment('欠费订单欠费原因(欠费返回)') VARCHAR(255)"`
CreateAt time.Time `json:"create_at" xorm:"not null pk default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('所属单位id') INT(11)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
UserIdentityId int `json:"user_identity_id" xorm:"not null default 0 comment('用户身份id') INT(11)"`
OutOrderNo string `json:"out_order_no" xorm:"not null default '' comment('外部订单号,设备端产生') VARCHAR(255)"`
TradeNo string `json:"trade_no" xorm:"not null default '' comment('第三方交易号,支付宝,微信,ISV渠道等') VARCHAR(255)"`
Consumer string `json:"consumer" xorm:"not null default '' comment('消费人(花名册名称)') CHAR(100)"`
BuyerId string `json:"buyer_id" xorm:"not null default '' comment('云校园定义买家标识(支付宝刷脸用户id)') CHAR(100)"`
SellerId string `json:"seller_id" xorm:"not null default '' comment('卖家支付宝uid') CHAR(100)"`
DeviceSn string `json:"device_sn" xorm:"not null default '' comment('设备编号') CHAR(100)"`
SchoolName string `json:"school_name" xorm:"not null default '' comment('学校名称') CHAR(100)"`
SchoolCode string `json:"school_code" xorm:"not null default '' comment('学校内标') CHAR(100)"`
StoreBusinessScenario string `json:"store_business_scenario" xorm:"not null default '' comment('门店经营场景') CHAR(100)"`
StoreName string `json:"store_name" xorm:"not null default '' comment('门店名称') CHAR(100)"`
CpStoreId string `json:"cp_store_id" xorm:"not null default '' comment('门店编号') CHAR(100)"`
MerchantName string `json:"merchant_name" xorm:"not null default '' comment('商户名称') CHAR(100)"`
CpMerchantId string `json:"cp_merchant_id" xorm:"not null default '' comment('商户编码') CHAR(100)"`
TradeAmount string `json:"trade_amount" xorm:"not null default 0.00 comment('交易总金额') DECIMAL(8,2)"`
FaceTime string `json:"face_time" xorm:"not null default '' comment('刷脸时间') CHAR(100)"`
OrderStatus int `json:"order_status" xorm:"not null default 0 comment('支付状态 (1:待支付 2:支付成功)') TINYINT(1)"`
DebtBusinessCode string `json:"debt_business_code" xorm:"not null default '' comment('欠费订单异常渠道异常码(欠费返回)') CHAR(100)"`
DebtBusinessMsg string `json:"debt_business_msg" xorm:"not null default '' comment('欠费订单欠费原因(欠费返回)') VARCHAR(255)"`
CreateAt string `json:"create_at" xorm:"not null pk default 'CURRENT_TIMESTAMP' DATETIME"`
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
}

+ 7
- 0
app/router/admin_router.go Zobrazit soubor

@@ -101,6 +101,12 @@ func rFinanceManage(r *gin.RouterGroup) {
r.POST("/nursingHome/ordRefund", hdl.NursingHomeOrdRefund) //财务管理-(养老院)订单退款
}

func rDeviceManage(r *gin.RouterGroup) {
r.POST("/save", hdl2.DeviceSave) //设备管理-编辑/新增
r.POST("/list", hdl2.DeviceList) //设备管理-列表
r.DELETE("/delete/:device_sn", hdl2.DeviceDelete) //设备管理-删除
}

func rDataStatistics(r *gin.RouterGroup) {
r.POST("/centralKitchenForSchool/export", hdl2.CentralKitchenForSchoolDataStatisticsExport) //数据统计-(央厨-学校)-导出
r.POST("/centralKitchenForSchool/list", hdl2.CentralKitchenForSchoolDataStatisticsList) //数据统计-(央厨-学校)-列表
@@ -271,5 +277,6 @@ func AdminRoute(r *gin.RouterGroup) {
rUser(r.Group("/user")) //用户管理
rAuditCenter(r.Group("/auditCenter")) //审核中心
rFinanceManage(r.Group("/financeManage")) //财务管理
rDeviceManage(r.Group("/deviceManage")) //设备管理
rDataStatistics(r.Group("/dataStatistics")) //数据统计
}

Načítá se…
Zrušit
Uložit