Exemple #1
0
func (this *ItemController) Add() {
	item, ok := this.Ctx.Input.Params[":hi"]
	//	beego.Debug("params", this.Ctx.Input.Params, this.Ctx.Input)
	if !ok {
		beego.Error(stat.ParamItemError)
		this.Data["json"] = JsonResult{stat.ParamItemError, stat.ParamItemError}
		this.ServeJson()
		return
	}
	oEntityDef, ok := itemDef.EntityDefMap[item]
	if !ok {
		beego.Error(fmt.Sprintf("Item %s not define", item))
		this.Data["json"] = JsonResult{stat.ItemNotDefine, stat.ItemNotDefine}
		this.ServeJson()
		return
	}
	curUserSn := this.GetSessionString(SessionUserSn)
	svcParams := this.GetFormValues(oEntityDef)
	svcParams[s.Creater] = curUserSn
	for _, field := range oEntityDef.Fields {
		if strings.EqualFold(field.Model, s.Upload) {
			delete(svcParams, field.Name)
		}
	}
	beego.Debug("ItemController.Add:", svcParams)
	status, reason := svc.Add(item, svcParams)
	this.Data["json"] = &JsonResult{status, reason}
	this.ServeJson()
}
Exemple #2
0
func UpdateSupplierRels(product string, suppliers []string) string {
	beego.Debug("UpdateSupplierRels:", product, " ", suppliers)
	query := `SELECT * FROM supplier_product WHERE product = ?`
	st, vs := wbo.DbQueryValues(query, product)
	if st != stat.Success {
		return st
	}
	oldRelMaps := make(map[string]map[string]interface{})
	for _, v := range vs {
		supplier, _ := v[s.Supplier]
		beego.Debug("UpdateSupplierRels oldRels:", supplier)
		oldRelMaps[supplier.(string)] = v
	}
	for _, supplier := range suppliers {
		if _, ok := oldRelMaps[supplier]; ok {
			delete(oldRelMaps, supplier)
		} else {
			// 新增
			beego.Debug("UpdateSupplierRels", t.Params{s.Supplier: supplier, s.Product: product})
			svc.Add("supplier_product", t.Params{s.Supplier: supplier, s.Product: product})
		}
	}
	for _, oldRel := range oldRelMaps {
		if sn, ok := oldRel[s.Sn]; ok {
			DelSupplierRel(sn.(string))
		}
	}
	return stat.Success
}
Exemple #3
0
func AddSupplierRels(product string, suppliers []string) string {
	beego.Debug("AddSuppliers suppliers:", suppliers)
	for _, supplier := range suppliers {
		params := t.Params{s.Supplier: supplier, s.Product: product}
		beego.Debug("AddSuppliers", params)
		svc.Add("supplier_product", params)
	}
	return stat.Success
}
Exemple #4
0
func (this *ProductController) Add() {
	item := s.Product
	oItemDef, _ := itemDef.EntityDefMap[item]
	svcParams, exParams := this.GetExFormValues(oItemDef)
	beego.Debug("ProductController.Add:", svcParams)
	suppliers, ok := exParams["supplierlist"]
	if !ok {
		this.JsonError(stat.Failed, "添加至少一个供应商!")
		return
	}
	sn := u.TUId()
	supplierMgr.AddSupplierRels(sn, suppliers.([]string))
	svcParams[s.Sn] = sn
	status, reason := svc.Add(item, svcParams)
	this.Data["json"] = &JsonResult{status, reason}
	this.ServeJson()
}