/** * @Author: zou.yingbin * @Create : 2021/4/14 11:11 * @Modify : 2021/4/14 11:11 */ package models import ( "mtp2_if/db" "mtp2_if/mtpcache" "mtp2_if/utils" ) // ErmcpDeliveryGoods 现货品种(交割品种) type ErmcpDeliveryGoods struct { DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID(SEQ_DELIVERYGOODS) DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码 DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称 GOODSUNITID int32 `json:"goodsunitid" xorm:"'GOODSUNITID'"` // 现货品种单位ID DELIVERYGOODSTYPE int32 `json:"deliverygoodstype" xorm:"'DELIVERYGOODSTYPE'"` // 现货品种类型: 1-整装不拆分 2-散装记录明细 3:整装拆分 4:散装不记录明细 STANDARDQTY int32 `json:"standardqty" xorm:"'STANDARDQTY'"` // 标准数量(库位数量) [标准品特有] STANDARDQTYRANGE int32 `json:"standardqtyrange" xorm:"'STANDARDQTYRANGE'"` // 标准数量偏差范围 [标准品特有] AUDITFLAG int32 `json:"auditflag" xorm:"'AUDITFLAG'"` // 交割是否需要审核 - 0:不需要 1:需要审核 默认为0 ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效 AGREEUNIT int32 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位[散货时默认为1, 整装时默认为标准数量] QTYDECIMALPLACE int32 `json:"qtydecimalplace" xorm:"'QTYDECIMALPLACE'"` // 成交量小数位 CATEGORYID int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(SEQ_WRCATEGORY) DGSTATUS int32 `json:"dgstatus" xorm:"'DGSTATUS'"` // 品种状态 - 作废 - 0:未激活 1:正常 AREAUSERID int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构 EnumdicName string `json:"enumdicname"` // 现货品种单位名称 ExcludeCfg int32 `json:"-"` // 排除已配置项 1-排除 } func (r *ErmcpDeliveryGoods) calc() { r.EnumdicName = mtpcache.GetEnumDicitemName(r.GOODSUNITID) } func (r *ErmcpDeliveryGoods) buildSql() string { var sqlId utils.SQLVal = "SELECT t.DELIVERYGOODSID," + " t.DELIVERYGOODSCODE," + " t.DELIVERYGOODSNAME," + " t.GOODSUNITID," + " t.DELIVERYGOODSTYPE," + " t.STANDARDQTY," + " t.STANDARDQTYRANGE," + " t.AUDITFLAG," + " t.ISVALID," + " t.ISSPLIT," + " t.AGREEUNIT," + " t.QTYDECIMALPLACE," + " t.CATEGORYID," + " t.DGSTATUS," + " t.AREAUSERID" + " FROM DELIVERYGOODS t" + " WHERE 1 = 1" sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) if r.ExcludeCfg == 1 { sqlId.Join(" and t.deliverygoodsid not in(select distinct deliverygoodsid from ermcp_bizgroupspotgoods)") } return sqlId.String() } // GetDataEx 获取现货商品(交割商品) func (r *ErmcpDeliveryGoods) GetDataEx() (interface{}, error) { return r.GetData() } // GetData func (r *ErmcpDeliveryGoods) GetData() ([]ErmcpDeliveryGoods, error) { sData := make([]ErmcpDeliveryGoods, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) for i := range sData { sData[i].calc() } return sData, err } // ErmcpDGFactoryItem 品种选择项定义表 type ErmcpDGFactoryItem struct { DGFACTORYITEMID int64 // 选择项ID(SEQ_DGFACTORYITEM) DELIVERYGOODSID int32 // 品种ID DGFACTORYITEMTYPEID int64 // 要素项类型 DGFACTORYITEMVALUE string // 要素项值(类型为仓库时填写仓库名称) WAREHOUSEID int64 // 仓库ID(类型为仓库时填写) ISVALID int32 // 是否有效 - 0:无效 1:有效 ORDERINDEX int32 // 顺序 } func (r *ErmcpDGFactoryItem) buildSql() string { var sqlId utils.SQLVal = "SELECT DGFACTORYITEMID," + " t.DELIVERYGOODSID," + " to_char(t.DGFACTORYITEMTYPEID) DGFACTORYITEMTYPEID," + " t.DGFACTORYITEMVALUE," + " to_char(t.WAREHOUSEID) WAREHOUSEID," + " t.ISVALID," + " t.ORDERINDEX" + " FROM DGFACTORYITEM t" + " WHERE ISVALID = 1" sqlId.AndEx("t.DGFACTORYITEMID", r.DGFACTORYITEMID, r.DGFACTORYITEMID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) sqlId.AndEx("t.DGFACTORYITEMTYPEID", r.DGFACTORYITEMTYPEID, r.DGFACTORYITEMTYPEID > 0) sqlId.AndEx("t.ORDERINDEX", r.ORDERINDEX, r.ORDERINDEX > 0) return sqlId.String() } // GetDataEx 获取品种选择项定义 func (r *ErmcpDGFactoryItem) GetDataEx() (interface{}, error) { return r.GetData() } // GetData func (r *ErmcpDGFactoryItem) GetData() (interface{}, error) { sData := make([]ErmcpDGFactoryItem, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) return sData, err } // ErmcpBrand 品牌(从品种选择项定义表中查) type ErmcpBrand struct { BRANDID int64 `json:"brandid"` // 品牌id BRANDNAME string `json:"brandname"` // 品牌名称 DELIVERYGOODSID int32 `json:"deliverygoodsid"` // 品种ID } // 获取品牌数据 func (r *ErmcpBrand) GetData() ([]ErmcpBrand, error) { m := ErmcpDGFactoryItem{ DELIVERYGOODSID: r.DELIVERYGOODSID, DGFACTORYITEMTYPEID: 2, ORDERINDEX: 1, } sData := make([]ErmcpBrand, 0) if d, err := m.GetDataEx(); err == nil { if dgLst, ok := d.([]ErmcpDGFactoryItem); ok { for _, val := range dgLst { sData = append(sData, ErmcpBrand{BRANDID: val.DGFACTORYITEMID, BRANDNAME: val.DGFACTORYITEMVALUE, DELIVERYGOODSID: val.DELIVERYGOODSID}) } } } return sData, nil } // ErmcpRelatedGoods 现货品种的关联交易商品 type ErmcpRelatedGoods struct { GoodsId int `json:"goodsid" xorm:"'GoodsId'"` // 商品id GoodsCode string `json:"goodscode" xorm:"'GoodsCode'"` // 商品代码 GoodsName string `json:"goodsname" xorm:"'GoodsName'"` // 商品名称 DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID AREAUSERID int64 `json:"-"` // 所属机构 } func (r *ErmcpRelatedGoods) buildSql() string { var sqlId utils.SQLVal = "select distinct t.deliverygoodsid, g.goodsid, g.goodscode, g.goodsname" + " from deliverygoods t" + " inner join ERMS2_WRSConvertDetail w" + " on t.deliverygoodsid = w.deliverygoodsid" + " inner join erms_middlegoods m" + " on w.middlegoodsid = m.middlegoodsid" + " inner join ERMCP_GGConvertConfig gc" + " on m.goodsgroupid = gc.destgoodsgroupid" + " inner join goods g" + " on gc.srcgoodsgroupid = g.goodsgroupid" + " where 1 = 1" sqlId.AndEx("t.AREAUSERID", r.AREAUSERID, r.AREAUSERID > 0) sqlId.AndEx("t.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0) return sqlId.String() } // GetDataEx 获取现货关联交易商品 func (r *ErmcpRelatedGoods) GetDataEx() (interface{}, error) { return r.GetData() } // GetData 获取现货关联交易商品 func (r *ErmcpRelatedGoods) GetData() ([]ErmcpRelatedGoods, error) { sData := make([]ErmcpRelatedGoods, 0) err := db.GetEngine().SQL(r.buildSql()).Find(&sData) return sData, err } // ErmcpDeliveryGoodsDetail 现货商品详情 type ErmcpDeliveryGoodsDetail struct { Data ErmcpDeliveryGoods `json:"data"` // 现货商品基本信息(交割品种) GmList []ErmcpWrstandard `json:"gmlist"` // 品类列表(仓单标准) GbList []ErmcpBrand `json:"gblist"` // 品牌列表 WrsList []WRSConverTDetail `json:"wrslist"` // 套保信息列表 GoodsList []ErmcpRelatedGoods `json:"goodslist"` // 关联交易商品列表 QryTradeGoods int32 `json:"-"` // 是否查询关联交易商品 1-查询 } func (r *ErmcpDeliveryGoodsDetail) addGmList(lst []ErmcpWrstandard) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GmList = append(r.GmList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addGbList(lst []ErmcpBrand) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GbList = append(r.GbList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addWrsList(lst []WRSConverTDetail) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.WrsList = append(r.WrsList, lst[i]) } } } func (r *ErmcpDeliveryGoodsDetail) addGoodsList(lst []ErmcpRelatedGoods) { for i := range lst { if lst[i].DELIVERYGOODSID == r.Data.DELIVERYGOODSID { r.GoodsList = append(r.GoodsList, lst[i]) } } } // GetDataEx func (r *ErmcpDeliveryGoodsDetail) GetDataEx() (interface{}, error) { sData := make([]ErmcpDeliveryGoodsDetail, 0) m := ErmcpDeliveryGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID} data, err := m.GetData() if err != nil { return sData, err } if data == nil || len(data) == 0 { return sData, nil } // 基本信息 for i := range data { val := ErmcpDeliveryGoodsDetail{Data: data[i], GmList: make([]ErmcpWrstandard, 0), GbList: make([]ErmcpBrand, 0), WrsList: make([]WRSConverTDetail, 0), GoodsList: make([]ErmcpRelatedGoods, 0), } sData = append(sData, val) } //品类 gm := ErmcpWrstandard{AREAUSERID: int(r.Data.AREAUSERID), DELIVERYGOODSID: r.Data.DELIVERYGOODSID, ISVALID: 1} gb := ErmcpBrand{DELIVERYGOODSID: r.Data.DELIVERYGOODSID} WrsC := WRSConverTDetail{DELIVERYGOODSID: r.Data.DELIVERYGOODSID} gmLst, _ := gm.GetData() gbLst, _ := gb.GetData() wrsLst, _ := WrsC.GetData() var goodLst []ErmcpRelatedGoods if r.QryTradeGoods == 1 { goodsM := ErmcpRelatedGoods{AREAUSERID: r.Data.AREAUSERID, DELIVERYGOODSID: r.Data.DELIVERYGOODSID} goodLst, _ = goodsM.GetData() } for i := range sData { sData[i].addGmList(gmLst) sData[i].addGbList(gbLst) sData[i].addWrsList(wrsLst) sData[i].addGoodsList(goodLst) } return sData, nil }