| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- /**
- * @Author: zou.yingbin
- * @Create : 2021/1/13 11:16
- * @Modify : 2021/1/13 11:16
- */
- package models
- import (
- "fmt"
- "mtp2_if/db"
- "mtp2_if/logger"
- )
- // 现货商品表
- type ErmcpWrstandard struct {
- WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID(SEQ_WRSTANDARD)
- WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 现货商品代码
- DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种ID
- UNITID int32 `json:"unitid" xorm:"'UNITID'"` // 单位ID
- MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 最小变动值
- MINIVALUEDP int32 `json:"minivaluedp" xorm:"'MINIVALUEDP'"` // 最小变动值小数位
- REALMINIVALUE int32 `json:"realminivalue" xorm:"'REALMINIVALUE'"` // 实际最小变动值
- REALMINIVALUEDP int32 `json:"realminivaluedp" xorm:"'REALMINIVALUEDP'"` // 实际最小变动值小数位
- CREATORID int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
- CREATETIME string `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
- WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 现货商品名称
- AREAUSERID int `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
- EnumdicName string `json:"enumdicname"` // 单位名称
- ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 0-无效(停用) 1-有效(正常)
- UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
- REMARK string `json:"remark" xorm:"'REMARK'"` // 备注
- }
- func (r *ErmcpWrstandard) buildSql() string {
- str := "select WRSTANDARDID," +
- " WRSTANDARDCODE," +
- " DELIVERYGOODSID," +
- " UNITID," +
- " MINIVALUE," +
- " MINIVALUEDP," +
- " REALMINIVALUE," +
- " REALMINIVALUEDP," +
- " CREATORID," +
- " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
- " WRSTANDARDNAME," +
- " ISVALID," +
- " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
- " REMARK," +
- " AREAUSERID" +
- " from wrstandard t" +
- " where t.AREAUSERID=%v"
- sqlId := fmt.Sprintf(str, r.AREAUSERID)
- if r.WRSTANDARDID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
- }
- if r.ISVALID >= 0{
- sqlId = sqlId + fmt.Sprintf(" and t.ISVALID=%v", r.ISVALID)
- }
- return sqlId
- }
- // 查询现货商品
- func (r *ErmcpWrstandard) GetData() ([]ErmcpWrstandard, error) {
- sData := make([]ErmcpWrstandard, 0)
- e := db.GetEngine()
- if err := e.SQL(r.buildSql()).Find(&sData); err != nil {
- logger.GetLogger().Errorf("query wrstardard fail, %v", err)
- return sData, err
- }
- return sData, nil
- }
- // 商品型号表
- type GoodsTypeModel struct {
- MODELID int `json:"modelid" xorm:"'MODELID'"` // 型号ID
- MODELNAME string `json:"modelname" xorm:"'MODELNAME'"` // 型号名称
- WRSTANDARDID int64 `json:"-" xorm:"'WRSTANDARDID'"` // 现货商品ID
- DELIVERYGOODSID int32 `json:"-" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
- AREAUSERID int `json:"-" xorm:"'AREAUSERID'"` // 所属机构
- ISVALID int32 `json:"-" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
- CREATORSRC int32 `json:"-" xorm:"'CREATORSRC'"` // 创建人来源 - 1:管理端 2:终端
- CREATORID int32 `json:"-" xorm:"'CREATORID'"` // 创建人
- CREATETIME string `json:"-" xorm:"'CREATETIME'"` // SYSDATE 创建时间
- UPDATORSRC int32 `json:"-" xorm:"'UPDATORSRC'"` // 更新人来源 - 1:管理端 2:终端
- UPDATORID int32 `json:"-" xorm:"'UPDATORID'"` // 更新人
- UPDATETIME string `json:"updatetime" xorm:"'UPDATETIME'"` // 更新时间
- }
- // 获取商品型号表数据
- func (r *GoodsTypeModel) GetData() ([]GoodsTypeModel, error) {
- sData := make([]GoodsTypeModel, 0)
- if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
- logger.GetLogger().Errorf("query goodsTypeModel fail, %v", err)
- return nil, err
- }
- return sData, nil
- }
- func (r *GoodsTypeModel) buildSql() string {
- sqlId := "select MODELID," +
- " MODELNAME," +
- " WRSTANDARDID," +
- " DELIVERYGOODSID," +
- " AREAUSERID," +
- " ISVALID," +
- " CREATORSRC," +
- " CREATORID," +
- " to_char(CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
- " UPDATORSRC," +
- " UPDATORID," +
- " to_char(UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME" +
- " from spotgoodsmodel where ISVALID=1"
- if r.AREAUSERID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and AREAUSERID=%v", r.AREAUSERID)
- }
- if r.WRSTANDARDID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
- }
- return sqlId
- }
- // 商品品牌
- type GoodsBrand struct {
- BRANDID int `json:"brandid" xorm:"'bRANDID'"` // 品牌ID
- BRANDNAME string `json:"brandname" xorm:"'BRANDNAME'"` // 品牌名称
- WRSTANDARDID int64 `json:"-" xorm:"'WRSTANDARDID'"` // 现货商品ID
- DELIVERYGOODSID int32 `json:"-" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
- AREAUSERID int `json:"-" xorm:"'AREAUSERID'"` // 所属机构
- ISVALID int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
- }
- func (r *GoodsBrand) buildSql() string {
- sqlId := "select BRANDID," +
- " BRANDNAME," +
- " WRSTANDARDID," +
- " DELIVERYGOODSID," +
- " AREAUSERID," +
- " ISVALID" +
- " from spotgoodsbrand" +
- " where ISVALID = 1"
- if r.AREAUSERID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and AREAUSERID=%v", r.AREAUSERID)
- }
- if r.WRSTANDARDID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and WRSTANDARDID=%v", r.WRSTANDARDID)
- }
- return sqlId
- }
- // 获取品牌数据
- func (r *GoodsBrand) GetData() ([]GoodsBrand, error) {
- sData := make([]GoodsBrand, 0)
- if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
- logger.GetLogger().Errorf("query GoodsBrand fail, %v", err)
- return nil, err
- }
- return sData, nil
- }
- // 现货商品折算配置明细表
- type WRSConverTDetail struct {
- WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 现货商品ID
- DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID
- MIDDLEGOODSID int64 `json:"middlegoodsid" xorm:"'MIDDLEGOODSID'"` // 套保品种ID
- CONVERTRATIO float64 `json:"convertratio" xorm:"'CONVERTRATIO'"` // 套保系数
- MODIFYTIME string `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
- MIDDLEGOODSNAME string `json:"middlegoodsname" xorm:"'middlegoodsname'"` // 套保品种名称
- MIDDLEGOODSCODE string `json:"middlegoodscode" xorm:"'middlegoodscode'"` // 套保品种代码
- }
- func (r *WRSConverTDetail) buildSql() string {
- sqlId := "select t.WRSTANDARDID," +
- " t.DELIVERYGOODSID," +
- " t.MIDDLEGOODSID," +
- " t.CONVERTRATIO," +
- " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
- " m.middlegoodsname," +
- " m.middlegoodscode" +
- " from Erms2_Wrsconvertdetail t" +
- " left join erms_middlegoods m" +
- " on t.middlegoodsid = m.middlegoodsid" +
- " where 1=1"
- if r.WRSTANDARDID > 0 {
- sqlId = sqlId + fmt.Sprintf(" and t.wrstandardid=%v", r.WRSTANDARDID)
- }
- return sqlId
- }
- // 获取现货商品折算配置明细表数据
- func (r *WRSConverTDetail) GetData() ([]WRSConverTDetail, error) {
- sData := make([]WRSConverTDetail, 0)
- if err := db.GetEngine().SQL(r.buildSql()).Find(&sData); err != nil {
- logger.GetLogger().Errorf("query WRSConverTDetail fail, %v", err)
- return nil, err
- }
- return sData, nil
- }
- // 现货商品详细
- type ErmcpWrstandDetail struct {
- Wrd ErmcpWrstandard `json:"wrd"` // 基本信息
- GtList []GoodsTypeModel `json:"gtList"` // 型号列表
- GbList []GoodsBrand `json:"gbList"` // 品牌列表
- WrsList []WRSConverTDetail `json:"wrsList"` // 套保信息列表
- }
- // 查询现货商品详细
- func (r *ErmcpWrstandDetail) GetData() (ErmcpWrstandDetail, error) {
- // 获取基本信息
- m := ErmcpWrstandard{AREAUSERID: r.Wrd.AREAUSERID, WRSTANDARDID: r.Wrd.WRSTANDARDID, ISVALID: -1}
- d, err := m.GetData()
- if err != nil {
- return ErmcpWrstandDetail{}, err
- }
- if d == nil || len(d) == 0 {
- return ErmcpWrstandDetail{}, fmt.Errorf("no record")
- }
- rsp := ErmcpWrstandDetail{}
- rsp.Wrd = d[0]
- // 获取型号信息
- gt := GoodsTypeModel{AREAUSERID: rsp.Wrd.AREAUSERID, WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
- if val, err := gt.GetData(); err == nil {
- rsp.GtList = val
- }
- // 获取品牌信息
- gb := GoodsBrand{AREAUSERID: rsp.Wrd.AREAUSERID, WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
- if val, err := gb.GetData(); err == nil {
- rsp.GbList = val
- }
- // 获取套保信息
- wrs := WRSConverTDetail{WRSTANDARDID: rsp.Wrd.WRSTANDARDID}
- if val, err := wrs.GetData(); err == nil {
- rsp.WrsList = val
- }
- return rsp, nil
- }
|