Bladeren bron

增加接口:查仓库信息、查库存申请

zou.yingbin 4 jaren geleden
bovenliggende
commit
37b5286a52
10 gewijzigde bestanden met toevoegingen van 9376 en 8688 verwijderingen
  1. 61 0
      controllers/ermcp/qryAreaStock.go
  2. 38 0
      controllers/ermcp/qryWarehouse.go
  3. 3153 3021
      docs/docs.go
  4. 3153 3021
      docs/swagger.json
  5. 2644 2644
      docs/swagger.yaml
  6. 173 0
      models/ermcpAreaStock.go
  7. 66 0
      models/ermcpWarehouseInfo.go
  8. 84 0
      mtpcache/systemmanager.go
  9. 2 2
      mtpcache/username.go
  10. 2 0
      routers/router.go

+ 61 - 0
controllers/ermcp/qryAreaStock.go

@@ -0,0 +1,61 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/3/10 15:30
+* @Modify  : 2021/3/10 15:30
+ */
+
+package ermcp
+
+import (
+	"github.com/gin-gonic/gin"
+	"mtp2_if/global/app"
+	"mtp2_if/models"
+)
+
+// QryAreaStockApplyReq 查询库存申请请求
+type QryAreaStockApplyReq struct {
+	USERID           string `form:"userid" binding:"required"` // 用户id
+	INOUTTYPE        string `form:"inouttype"`                 // 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
+	SPOTCONTRACTID   string `form:"spotcontractid"`            // 合同ID
+	WRSTANDARDID     string `form:"wrstandardid"`              // 现货商品ID
+	SPOTGOODSBRANDID int32  `form:"spotgoodsbrandid"`          // 品牌ID
+	SPOTGOODSMODELID int32  `form:"spotgoodsmodelid"`          // 型号ID
+	WAREHOUSEINFOID  string `form:"warehouseinfoid"`           // 仓库ID
+	APPLYSTATUS      string `form:"applystatus"`               // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
+}
+
+// QryAreaStockApplyRsp 查询库存申请响应
+type QryAreaStockApplyRsp models.ErmcpAreaStockApply
+
+// QueryAreaStockApply
+// @Summary 查询库存申请(出入库记录|库存审核)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户ID"
+// @Param inouttype query string false "出入库类型(可多项,逗号隔开) 1:采购入库 2:销售出库 3:生产入库 4:生产出库"
+// @Param spotcontractid query int false "合同ID"
+// @Param wrstandardid query int false "现货商品ID"
+// @Param spotgoodsbrandid query int false "品牌ID"
+// @Param spotgoodsmodelid query int false "型号ID"
+// @Param warehouseinfoid query int false "仓库ID"
+// @Param applystatus query string false "申请状态(可多项,逗号隔开)1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回"
+// @Success 200 {array} QryAreaStockApplyRsp
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/QueryAreaStockApply [get]
+// @Tags 企业风险管理(app)
+func QueryAreaStockApply(c *gin.Context) {
+	a := app.NewGinUtils(c)
+	req := QryAreaStockApplyReq{}
+	a.DoBindReq(&req)
+	m := models.ErmcpAreaStockApply{
+		USERID: req.USERID,
+		FilterType: req.INOUTTYPE,
+		SPOTCONTRACTID: req.SPOTCONTRACTID,
+		WRSTANDARDID: req.WRSTANDARDID,
+		SPOTGOODSBRANDID: req.SPOTGOODSBRANDID,
+		SPOTGOODSMODELID: req.SPOTGOODSMODELID,
+		WAREHOUSEINFOID: req.WAREHOUSEINFOID,
+		FilterStatus: req.APPLYSTATUS,
+	}
+	a.DoGetDataEx(&m)
+}

+ 38 - 0
controllers/ermcp/qryWarehouse.go

@@ -0,0 +1,38 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/3/10 15:04
+* @Modify  : 2021/3/10 15:04
+ */
+
+package ermcp
+
+import (
+	"github.com/gin-gonic/gin"
+	"mtp2_if/global/app"
+	"mtp2_if/models"
+)
+
+// QryWarehouseReq 仓库查询请求参数
+type QryWarehouseReq struct {
+	UserId    int64  `form:"userid" binding:"required"`    //用户ID
+}
+
+// QryWarehouseRsp 仓库查询响应
+type QryWarehouseRsp models.ErmcpWareHouseInfo
+
+// QryWarehouseInfo
+// @Summary 查询仓库信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int true "用户ID"
+// @Success 200 {array} QryWarehouseRsp
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/QueryWarehouseInfo [get]
+// @Tags 企业风险管理(app)
+func QueryWarehouseInfo(c *gin.Context) {
+	a := app.NewGinUtils(c)
+	req := QryWarehouseReq{}
+	a.DoBindReq(&req)
+	m := models.ErmcpWareHouseInfo{AREAUSERID: req.UserId}
+	a.DoGetDataEx(&m)
+}

File diff suppressed because it is too large
+ 3153 - 3021
docs/docs.go


File diff suppressed because it is too large
+ 3153 - 3021
docs/swagger.json


File diff suppressed because it is too large
+ 2644 - 2644
docs/swagger.yaml


+ 173 - 0
models/ermcpAreaStock.go

@@ -0,0 +1,173 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/3/10 9:13
+* @Modify  : 2021/3/10 9:13
+ */
+
+package models
+
+import (
+	"fmt"
+	"mtp2_if/db"
+	"mtp2_if/mtpcache"
+	"mtp2_if/utils"
+)
+
+// ErmcpAreaStockApply 出入库申请
+type ErmcpAreaStockApply struct {
+	INOUTAPPLYID     string  `json:"inoutapplyid"  xorm:"'INOUTAPPLYID'"`         // 申请ID(607+Unix秒时间戳(10位)+xxxxxx)
+	USERID           string  `json:"userid"  xorm:"'USERID'"`                     // 机构ID
+	INOUTTYPE        int32   `json:"inouttype"  xorm:"'INOUTTYPE'"`               // 出入库类型 - 1:采购入库 2:销售出库 3:生产入库 4:生产出库
+	WRSTANDARDID     string  `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`         // 现货商品ID
+	SPOTGOODSMODELID int32   `json:"spotgoodsmodelid"  xorm:"'SPOTGOODSMODELID'"` // 现货型号ID
+	SPOTGOODSBRANDID int32   `json:"spotgoodsbrandid"  xorm:"'SPOTGOODSBRANDID'"` // 现货品牌ID
+	DELIVERYGOODSID  int64   `json:"deliverygoodsid"  xorm:"'DELIVERYGOODSID'"`   // 现货品种ID
+	SPOTCONTRACTID   string  `json:"spotcontractid"  xorm:"'SPOTCONTRACTID'"`     // 关联现货合同ID [1:采购入库 2:销售出库 ]
+	WAREHOUSEINFOID  string  `json:"warehouseinfoid"  xorm:"'WAREHOUSEINFOID'"`   // 现货仓库ID
+	QTY              float64 `json:"qty"  xorm:"'QTY'"`                           // 数量
+	APPLYSTATUS      int32   `json:"applystatus"  xorm:"'APPLYSTATUS'"`           // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
+	APPLYSRC         int32   `json:"applysrc"  xorm:"'APPLYSRC'"`                 // 申请来源 - 1:管理端 2:终端
+	APPLYID          int64   `json:"applyid"  xorm:"'APPLYID'"`                   // 申请人
+	APPLYREMARK      string  `json:"applyremark"  xorm:"'APPLYREMARK'"`           // 申请备注
+	APPLYTIME        string  `json:"applytime"  xorm:"'APPLYTIME'"`               // 申请时间
+	AUDITSRC         int32   `json:"auditsrc"  xorm:"'AUDITSRC'"`                 // 审核来源 - 1:管理端 2:终端
+	AUDITID          int64   `json:"auditid"  xorm:"'AUDITID'"`                   // 审核人
+	AUDITTIME        string  `json:"audittime"  xorm:"'AUDITTIME'"`               // 审核时间
+	AUDITREMARK      string  `json:"auditremark"  xorm:"'AUDITREMARK'"`           // 审核备注
+	AUDITTRADEDATE   string  `json:"audittradedate"  xorm:"'AUDITTRADEDATE'"`     // 审核交易日(yyyyMMdd)
+	WRSTANDARDNAME   string  `json:"wrstandardname"  xorm:"'WRSTANDARDNAME'"`     // 现货商品名称
+	WRSTANDARDCODE   string  `json:"wrstandardcode"  xorm:"'WRSTANDARDCODE'"`     // 现货商品代码
+	UNITID           int32   `json:"unitid"  xorm:"'UNITID'"`                     // 单位id
+	BRANDNAME        string  `json:"brandname"  xorm:"'BRANDNAME'"`               // 品牌名称
+	MODELNAME        string  `json:"modelname"  xorm:"'MODELNAME'"`               // 型号名称
+	WAREHOUSENAME    string  `json:"warehousename"  xorm:"'WAREHOUSENAME'"`       // 仓库名称
+	WAREHOUSECODE    string  `json:"warehousecode"  xorm:"'WAREHOUSECODE'"`       // 仓库代码
+	WAREHOUSETYPE    int32   `json:"warehousetype"  xorm:"'WAREHOUSETYPE'"`       // 仓库类型 - 1 厂库  2 自有库  3 合作库
+	CONTRACTNO       string  `json:"contractno"  xorm:"'CONTRACTNO'"`             // 合同编号
+	CONTRACTTYPE     int32   `json:"contracttype"  xorm:"'CONTRACTTYPE'"`         // 现货合同类型 - 1:采购 -1:销售
+	BUYUSERID        int64   `json:"buyuserid"  xorm:"'BUYUSERID'"`               // 采购方userid
+	SELLUSERID       int64   `json:"selluserid"  xorm:"'SELLUSERID'"`             // 销售方userid
+	PRICETYPE        int32   `json:"pricetype"  xorm:"'PRICETYPE'"`               // 定价类型 - 1:一口价 2:点价 3:暂定价
+	CONTRACTQTY      float64 `json:"contractqty"  xorm:"'CONTRACTQTY'"`           // 合同量
+	BUYUSERNAME      string  `json:"buyusername"`                                 // 采购方名称
+	SELLUSERNAME     string  `json:"sellusername"`                                // 销售方名称
+	APPLYNAME        string  `json:"applyname"`                                   // 申请人名称
+	AUDITNAME        string  `json:"auditname"`                                   // 审核人名称
+	ENUMDICNAME      string  `json:"enumdicname"`                                 // 现货商品单位名称
+
+	FilterStatus string `json:"-"` // 查询条件, 申请状态, 逗号隔开
+	FilterType string `json:"-"` // 查询条件, 出入库类型, 逗号隔开
+}
+
+func (r *ErmcpAreaStockApply) calc() {
+	// 采购方名称
+	r.BUYUSERNAME = mtpcache.GetUserNameByUserId(r.BUYUSERID)
+	// 销售方名称
+	r.SELLUSERNAME = mtpcache.GetUserNameByUserId(r.SELLUSERID)
+	// 申请人名称
+	if r.APPLYSRC == 1 {
+		r.APPLYNAME = mtpcache.GetSystemmangerLoginCode(r.APPLYID)
+	}else {
+		r.APPLYNAME = mtpcache.GetLoginCodeByLoginId(r.APPLYID)
+	}
+	// 审核人名称
+	if r.AUDITSRC == 1 {
+		r.AUDITNAME = mtpcache.GetSystemmangerLoginCode(r.AUDITID)
+	}else {
+		r.AUDITNAME = mtpcache.GetLoginCodeByLoginId(r.AUDITID)
+	}
+	// 单位名称
+	r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
+}
+
+func (r *ErmcpAreaStockApply) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT to_char(t.INOUTAPPLYID) INOUTAPPLYID," +
+		"       t.USERID," +
+		"       t.INOUTTYPE," +
+		"       t.WRSTANDARDID," +
+		"       t.SPOTGOODSMODELID," +
+		"       t.SPOTGOODSBRANDID," +
+		"       t.DELIVERYGOODSID," +
+		"       to_char(t.SPOTCONTRACTID) SPOTCONTRACTID," +
+		"       to_char(t.WAREHOUSEINFOID) WAREHOUSEINFOID," +
+		"       t.QTY," +
+		"       t.APPLYSTATUS," +
+		"       t.APPLYSRC," +
+		"       t.APPLYID," +
+		"       t.APPLYREMARK," +
+		"       to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME," +
+		"       t.AUDITSRC," +
+		"       t.AUDITID," +
+		"       to_char(t.AUDITTIME, 'yyyy-mm-dd hh24:mi:ss') AUDITTIME," +
+		"       t.AUDITREMARK," +
+		"       t.AUDITTRADEDATE," +
+		"       w.wrstandardname," +
+		"       w.wrstandardcode," +
+		"       w.unitid," +
+		"       gb.brandname," +
+		"       gm.modelname," +
+		"       h.warehousename," +
+		"       h.warehousecode," +
+		"       h.warehousetype," +
+		"       s.contractno," +
+		"       s.contracttype," +
+		"       s.buyuserid," +
+		"       s.selluserid," +
+		"       s.pricetype," +
+		"       s.qty CONTRACTQTY" +
+		"  FROM ERMCP_AREAINOUTSTOCKAPPLY t" +
+		"  left join wrstandard w" +
+		"    on t.wrstandardid = w.wrstandardid" +
+		"  left join spotgoodsbrand gb" +
+		"    on t.spotgoodsbrandid = gb.brandid" +
+		"  left join spotgoodsmodel gm" +
+		"    on t.spotgoodsmodelid = gm.modelid" +
+		"  left join warehouseinfo h" +
+		"    on t.warehouseinfoid = h.autoid" +
+		"  left join ermcp_spotcontract s" +
+		"    on t.spotcontractid = s.spotcontractid" +
+		" WHERE 1 = 1"
+	// 用户id(必要条件)
+	sqlId.And("t.USERID", r.USERID)
+	// 出入库类型
+	if r.INOUTTYPE > 0 {
+		sqlId.And("t.INOUTTYPE", r.INOUTTYPE)
+	}
+	// 合同id
+	if len(r.SPOTCONTRACTID) > 0 {
+		sqlId.And("t.SPOTCONTRACTID", r.SPOTCONTRACTID)
+	}
+	// 现货商品id
+	if len(r.WRSTANDARDID) > 0 {
+		sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
+	}
+	// 品牌id
+	if r.SPOTGOODSBRANDID > 0 {
+		sqlId.And("t.SPOTGOODSBRANDID", r.SPOTGOODSBRANDID)
+	}
+	// 型号id
+	if r.SPOTGOODSMODELID > 0 {
+		sqlId.And("t.SPOTGOODSMODELID", r.SPOTGOODSMODELID)
+	}
+	// 仓库id
+	if len(r.WAREHOUSEINFOID) > 0 {
+		sqlId.And("t.WAREHOUSEINFOID", r.WAREHOUSEINFOID)
+	}
+	// 出入库状态
+	if len(r.FilterStatus) > 0 {
+		sqlId.Join(fmt.Sprintf(" and t.APPLYSTATUS in(%v)", r.FilterStatus))
+	}
+	return sqlId.String()
+}
+
+// 查询库存申请(记录)
+func (r *ErmcpAreaStockApply) GetDataEx() (interface{}, error) {
+	sData := make([]ErmcpAreaStockApply, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	if err == nil {
+		for i := range sData {
+			sData[i].calc()
+		}
+	}
+	return sData, err
+}

+ 66 - 0
models/ermcpWarehouseInfo.go

@@ -0,0 +1,66 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/3/9 16:21
+* @Modify  : 2021/3/9 16:21
+ */
+
+package models
+
+import (
+	"mtp2_if/db"
+	"mtp2_if/utils"
+)
+
+// ErmcpWareHouseInfo 仓库信息结构
+type ErmcpWareHouseInfo struct {
+	AUTOID          int64  `json:"autoid"  xorm:"'AUTOID'"`                   // 自增ID(仓库ID)
+	WAREHOUSECODE   string `json:"warehousecode"  xorm:"'WAREHOUSECODE'"`     // 仓库代码
+	WAREHOUSENAME   string `json:"warehousename"  xorm:"'WAREHOUSENAME'"`     // 仓库名称
+	WAREHOUSETYPE   int32  `json:"warehousetype"  xorm:"'WAREHOUSETYPE'"`     // 仓库类型 - 1 厂库  2 自有库  3 合作库
+	AREAUSERID      int64  `json:"areauserid"  xorm:"'AREAUSERID'"`           // 所属机构
+	WAREHOUSESTATUS int32  `json:"warehousestatus"  xorm:"'WAREHOUSESTATUS'"` // 仓库状态 - 1:正常 2:注销 3:待审核 4:审核拒绝
+	COUNTRYID       int32  `json:"countryid"  xorm:"'COUNTRYID'"`             // 国家
+	PROVINCEID      int32  `json:"provinceid"  xorm:"'PROVINCEID'"`           // 省
+	CITYID          int32  `json:"cityid"  xorm:"'CITYID'"`                   // 市
+	DISTRICTID      int32  `json:"districtid"  xorm:"'DISTRICTID'"`           // 区
+	ADDRESS         string `json:"address"  xorm:"'ADDRESS'"`                 // 详细地址
+	REMARK          string `json:"remark"  xorm:"'REMARK'"`                   // 审核备注
+	CREATETIME      string `json:"createtime"  xorm:"'CREATETIME'"`           // 创建时间
+	HASVIDEO        int32  `json:"hasvideo"  xorm:"'HASVIDEO'"`               // 是否有视频 - 0:无 1:有
+	VIDEOURL        string `json:"videourl"  xorm:"'VIDEOURL'"`               // 视频地址
+	CONTACTNAME     string `json:"contactname"  xorm:"'CONTACTNAME'"`         // 联系人
+	CONTACTNUM      string `json:"contactnum"  xorm:"'CONTACTNUM'"`           // 联系电话
+}
+
+func (r *ErmcpWareHouseInfo) buildSql() string {
+	var sqlId utils.SQLVal = "SELECT t.AUTOID," +
+		"       t.WAREHOUSECODE," +
+		"       t.WAREHOUSENAME," +
+		"       t.WAREHOUSETYPE," +
+		"       t.AREAUSERID," +
+		"       t.WAREHOUSESTATUS," +
+		"       t.COUNTRYID," +
+		"       t.PROVINCEID," +
+		"       t.CITYID," +
+		"       t.DISTRICTID," +
+		"       t.ADDRESS," +
+		"       t.REMARK," +
+		"       to_char(t.CREATETIME,'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
+		"       t.HASVIDEO," +
+		"       t.VIDEOURL," +
+		"       t.CONTACTNAME," +
+		"       t.CONTACTNUM" +
+		"  FROM WAREHOUSEINFO t" +
+		" WHERE 1 = 1"
+	if r.AREAUSERID > 0 {
+		sqlId.And("t.AREAUSERID", r.AREAUSERID)
+	}
+	return sqlId.String()
+}
+
+// GetDataEx 获取仓库信息
+func (r *ErmcpWareHouseInfo) GetDataEx() (interface{}, error) {
+	sData := make([]ErmcpWareHouseInfo, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	return sData, err
+}

+ 84 - 0
mtpcache/systemmanager.go

@@ -0,0 +1,84 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/3/10 14:13
+* @Modify  : 2021/3/10 14:13
+ */
+
+package mtpcache
+
+import (
+	"mtp2_if/db"
+	"mtp2_if/logger"
+	"sync"
+	"time"
+)
+
+var vSysMgr sysMgr
+
+// sysMgr 管理员
+type sysMgr struct {
+	mtx  sync.RWMutex       // 锁
+	data map[int64]sysMgrData // 数据[AUTOID]sysMgrData
+	last time.Time
+}
+
+// sysMgrData 管理员数据
+type sysMgrData struct {
+	AUTOID    int64    `json:"autoid"  xorm:"'AUTOID'"`       // 管理员ID
+	LOGINCODE string `json:"logincode"  xorm:"'LOGINCODE'"` // 管理员登录代码
+	USERNAME  string `json:"username"  xorm:"'USERNAME'"`   // 管理员登录名称
+}
+
+func (r *sysMgr) load() {
+	now := time.Now()
+	// 间隔3秒以上才重新加载
+	if d := now.Sub(r.last); d.Seconds() < 3 {
+		return
+	}
+
+	r.mtx.Lock()
+	defer r.mtx.Unlock()
+	e := db.GetEngine()
+	if e == nil {
+		return
+	}
+
+	sqlId := "select t.autoid, t.logincode, t.username from systemmanager t"
+
+	sData := make([]sysMgrData, 0)
+	s := e.SQL(sqlId)
+	if err := s.Find(&sData); err != nil {
+		logger.GetLogger().Errorf("cache load usrname, %v", err)
+	} else {
+		r.data = make(map[int64]sysMgrData)
+		for i := range sData {
+			r.data[sData[i].AUTOID] = sData[i]
+		}
+		r.last = time.Now()
+	}
+}
+
+func (r *sysMgr) logincode(autoId int64) string {
+	r.mtx.RLock()
+	defer r.mtx.RUnlock()
+
+	if r.data == nil {
+		return ""
+	}
+
+	if v, ok := r.data[autoId]; ok {
+		return v.LOGINCODE
+	}
+	return ""
+}
+
+// GetSystemmangerLoginCode 获取管理员登录代码
+// 参数 autoId 管理员id
+func GetSystemmangerLoginCode(autoId int64) string {
+	if v := vSysMgr.logincode(autoId); v != "" {
+		return v
+	}else {
+		vSysMgr.load()
+	}
+	return vSysMgr.logincode(autoId)
+}

+ 2 - 2
mtpcache/username.go

@@ -89,7 +89,7 @@ func (r *userName) loginCode(loginId int64) string {
 	return ""
 }
 
-// 根据登录ID获取名称
+// GetUserNameByLoginId 根据登录ID获取名称
 func GetUserNameByLoginId(loginId int64) string {
 	if v := vUser.name(loginId); v != "" {
 		return v
@@ -100,7 +100,7 @@ func GetUserNameByLoginId(loginId int64) string {
 	return vUser.name(loginId)
 }
 
-// 根据登录ID获取登录代码
+// GetLoginCodeByLoginId 根据登录ID获取登录代码
 func GetLoginCodeByLoginId(loginId int64) string {
 	if v := vUser.loginCode(loginId); v != "" {
 		return v

+ 2 - 0
routers/router.go

@@ -361,6 +361,8 @@ func InitRouter() *gin.Engine {
 		ermcpR.GET("/QryReportMonthSpotDetail", ermcp.QryReportMonthSpotDetail)
 		ermcpR.GET("/QueryExposureHedgePositionDetail", ermcp.QueryExposureHedgePositionDetail)
 		ermcpR.GET("/QueryPendingAuditInfo", ermcp.QueryPendingAuditInfo)
+		ermcpR.GET("/QueryWarehouseInfo", ermcp.QueryWarehouseInfo)
+		ermcpR.GET("/QueryAreaStockApply", ermcp.QueryAreaStockApply)
 
 		// 期货相关
 		// 查询企业风管期货商品信息

Some files were not shown because too many files changed in this diff