Commit 147b8035 authored by reedmi's avatar reedmi

完善商品分类

parent e7aeabf1
......@@ -11,6 +11,7 @@ import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.originspark.drp.models.User;
import com.originspark.drp.service.projects.invoices.StockInInvoiceService;
import com.originspark.drp.service.projects.invoices.StockOutInvoiceService;
import com.originspark.drp.service.resources.VendorService;
......@@ -72,6 +73,10 @@ public class BaseController extends HandlerInterceptorAdapter {
return request().getSession();
}
public User getCurrentUser() {
return (User)session().getAttribute("user");
}
// 一般用于create、update、delete的返回值
protected final static String ok(String message) {
Map<String, Object> modelMap = new HashMap<String, Object>(2);
......
......@@ -5,6 +5,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -30,23 +31,22 @@ public class VendorController extends BaseController {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public String create(@RequestBody Vendor vendor,HttpServletRequest request) {
public String create(@RequestBody Vendor vendor) {
String name = vendor.getName();
if (name == null || name.trim().equals("")) {
logger.warn(">添加失败:商品名称不能为空");
return failure("供应商名称不能为空");
String contactMan = vendor.getContactMan();
if (contactMan == null || contactMan.trim().equals("")) {
return failure("联系人不能为空");
}
if (vendorService.findByName(name) != null) {
logger.warn(">添加失败:该供应商已经存在,不可重复添加");
String name = vendor.getName();
if (!StringUtils.isEmpty(name) && vendorService.findByName(name) != null) {
return failure("该供应商已经存在,不可重复添加");
}
vendor.setCreatedBy(SessionUtil.getCurrentUserName(request));
vendor.setCreatedBy(getCurrentUser().getName());
vendorService.save(vendor);
logger.info(">添加成功:"+vendor.toString());
return ok("创建成功");
}
......
......@@ -44,30 +44,29 @@ public class WareController extends BaseController {
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public String create(@RequestBody Ware ware,HttpServletRequest request) {
public String create(@RequestBody Ware ware) {
//validation
String name = ware.getName();
if(name == null || name.trim().equals("")){
logger.warn(">添加失败:商品名称不能为空");
return failure("商品名称不能为空");
}
String unit = ware.getUnit();
if(unit == null || unit.trim().equals("")){
logger.warn(">添加失败:商品单位不能为空");
return failure("商品单位不能为空");
}
if(wareService.have(ware)){
logger.warn(">添加失败:该商品已存在,不能重复添加");
return failure("该商品已存在,不能重复添加");
}
//save
ware.setCreatedBy(SessionUtil.getCurrentUserName(request));
ware.setCreatedBy(SessionUtil.getCurrentUserName(request()));
Ware savedWare = wareService.save(ware);
logger.info(">添加成功:"+savedWare.toString());
return ok("创建成功");
}
......
......@@ -19,9 +19,10 @@ import com.originspark.drp.models.AbstractModel;
public class Vendor extends AbstractModel{
/**
* 名称
* 联系人
*/
private String name;
@Column(name="contactMan")
private String contactMan;
/**
* 联系电话
......@@ -29,15 +30,14 @@ public class Vendor extends AbstractModel{
private String phone;
/**
* 地址
* 公司名称
*/
private String address;
private String name;
/**
* 联系人
* 公司地址
*/
@Column(name="contactMan")
private String contactMan;
private String address;
/**
* 备注
......
......@@ -62,6 +62,9 @@ public class Ware extends AbstractModel {
*/
private String note;
@ManyToOne
private WareCategory category;
/**
* 供应商
*/
......@@ -140,6 +143,14 @@ public class Ware extends AbstractModel {
this.note = note;
}
public WareCategory getCategory() {
return category;
}
public void setCategory(WareCategory category) {
this.category = category;
}
public Vendor getVendor() {
return vendor;
}
......
......@@ -7,6 +7,7 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.originspark.drp.models.AbstractModel;
/**
......@@ -27,6 +28,10 @@ public class WareCategory extends AbstractModel {
@OneToMany(mappedBy = "parent")
private List<WareCategory> chidren;
@JsonIgnore
@OneToMany(mappedBy = "category")
private List<Ware> wares;
public String getName() {
return name;
}
......@@ -59,6 +64,14 @@ public class WareCategory extends AbstractModel {
this.chidren = chidren;
}
public List<Ware> getWares() {
return wares;
}
public void setWares(List<Ware> wares) {
this.wares = wares;
}
public boolean getLoaded() {
if (getChidren().isEmpty()) {
return true;
......
......@@ -48,7 +48,7 @@ Ext.define("drp.app.controller.resources.VendorController", {
},
showCreateVendorForm : function(btn) {
var vendorForm = Ext.widget("vendorviewform");
AlertWin.alert('新增供应商', null, vendorForm, 500, 370);
AlertWin.alert('新增供应商', null, vendorForm, 500, 220);
},
showUpdateVendorForm : function(grid, record, item, index, e, eopts) {
......@@ -58,7 +58,7 @@ Ext.define("drp.app.controller.resources.VendorController", {
return;
} else {
vendorForm.down('form').loadRecord(record);
AlertWin.alert('修改供应商', null, vendorForm, 500, 370);
AlertWin.alert('修改供应商', null, vendorForm, 500, 220);
}
},
......
......@@ -116,7 +116,7 @@ Ext.define("drp.app.controller.resources.WareController", {
showCreateWareForm : function(btn) {
var wareForm = Ext.widget("wareviewform");
AlertWin.alert('新增商品', null, wareForm, 500, 280);
AlertWin.alert('新增商品', null, wareForm, 500, 320);
},
showUpdateWareForm : function(grid, record, item, index, e, eopts) {
......@@ -126,7 +126,7 @@ Ext.define("drp.app.controller.resources.WareController", {
return;
} else {
wareForm.down('form').loadRecord(record);
AlertWin.alert('修改商品', null, wareForm, 500, 280);
AlertWin.alert('修改商品', null, wareForm, 500, 320);
}
},
......@@ -184,7 +184,7 @@ Ext.define("drp.app.controller.resources.WareController", {
if (form.isValid()) {
var formBean = form.getValues();
var model = Ext.create(modelName, formBean);
//add extra field
var vendorField = null;
if(formBean['vendor.id']){
......@@ -194,14 +194,25 @@ Ext.define("drp.app.controller.resources.WareController", {
id : formBean['vendor.id']
});
}
var categoryField = null;
if(formBean['category.id']){
categoryField = new Ext.data.Field({name:'category'});
model.fields.add(categoryField);
model.set("category",{
id : formBean['category.id']
});
}
//save model
me.saveModel(model, wareGrid);
//remove extra field
if(vendorField != null){
model.fields.remove(vendorField);
}
if(categoryField != null){
model.fields.remove(categoryField);
}
}
},
......@@ -231,8 +242,7 @@ Ext.define("drp.app.controller.resources.WareController", {
}]);
},
models : [ "drp.app.model.resources.WareModel" ],
models : [ "drp.app.model.resources.WareModel", "drp.app.model.resources.WareCategoryModel" ],
stores : [ "drp.app.store.resources.WareStore", "drp.app.store.resources.VendorStore"],
views : [ "drp.app.view.resources.WareView",
"drp.app.view.resources.WareViewForm","drp.widget.UploadFileForm" ]
views : [ "drp.app.view.resources.WareView", "drp.app.view.resources.WareViewForm","drp.widget.UploadFileForm" ]
});
\ No newline at end of file
......@@ -12,29 +12,11 @@ Ext.define("drp.app.model.resources.VendorModel", {
}, {
name : "phone",// 联系电话
type : "string"
}, {
name : "registrationNumber",//注册编号
type : "string"
}, {
name : 'registrationRange',// 承包范围
type : 'string'
}, {
name : 'registrationBank',// 开户行
type : 'string'
}, {
name : 'taxNumber',// 税号
type : 'string'
}, {
name : 'orgCodeCertificate',// 组织机构代码证
type : 'string'
}, {
name : 'note',// 备注
type : 'string'
}, {
name : 'countOfWares',// 产品供应数量
type : 'int',
persist : false
} ],
}],
proxy : {
type : 'rest',
url : 'vendor',
......
......@@ -12,6 +12,12 @@ Ext.define("drp.app.model.resources.WareModel", {
name : 'produceOn'// 生产日期
}, {
name : 'storage'// 保质期
}, {
name : "category.id",
persist : false
}, {
name : "category.name",
persist : false
}, {
name : "vendor.id",
persist : false
......
......@@ -106,39 +106,9 @@ Ext.define('drp.app.view.resources.VendorView', {
width : 100,
dataIndex : 'countOfWares',
text : '供应商品数量'
},{
xtype : 'gridcolumn',
text : '营业执照',
width : 600,
columns : [{
xtype : 'gridcolumn',
width : 125,
dataIndex : 'registrationNumber',
text : '注册编号'
}, {
xtype : 'gridcolumn',
width : 125,
dataIndex : 'registrationBank',
text : '开户行'
}, {
xtype : 'gridcolumn',
width : 125,
dataIndex : 'registrationRange',
text : '承包范围'
}, {
xtype : 'gridcolumn',
width : 125,
dataIndex : 'taxNumber',
text : '税号'
}, {
xtype : 'gridcolumn',
width : 125,
dataIndex : 'orgCodeCertificate',
text : '组织机构代码证'
}]
}, {
xtype : 'gridcolumn',
width : 150,
width : 200,
dataIndex : 'note',
text : '备注'
}, {
......
......@@ -12,65 +12,33 @@ Ext.define("drp.app.view.resources.VendorViewForm", {
}, {
xtype : 'textfield',
anchor : '60%',
margin : '5 0 0 5',
name : 'name',
allowBlank : false,
fieldLabel : '名称<font color="red">*</font>'
}, {
xtype : 'textfield',
anchor : '60%',
margin : '5 0 0 5',
name : 'address',
margin : '20 0 0 10',
name : 'contactMan',
allowBlank : false,
fieldLabel : '地址名称<font color="red">*</font>'
fieldLabel : '联系人<font color="red">*</font>'
}, {
xtype : 'textfield',
anchor : '60%',
margin : '5 0 0 5',
margin : '5 0 0 10',
name : 'phone',
allowBlank : false,
fieldLabel : '联系电话<font color="red">*</font>'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'contactMan',
allowBlank : false,
fieldLabel : '联系人名称<font color="red">*</font>'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'registrationNumber',
fieldLabel : '注册编号'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'registrationRange',
fieldLabel : '承包范围'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'registrationBank',
fieldLabel : '开户行'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'orgCodeCertificate',
fieldLabel : '组织机构代码证'
anchor : '60%',
margin : '5 0 0 10',
name : 'name',
fieldLabel : '公司名称'
}, {
xtype : 'textfield',
anchor : '75%',
margin : '5 0 0 5',
name : 'taxNumber',
fieldLabel : '税号'
anchor : '60%',
margin : '5 0 0 10',
name : 'address',
fieldLabel : '公司地址'
}, {
xtype : 'textarea',
anchor : '90%',
margin : '5 0 0 5',
margin : '5 0 0 10',
name : 'note',
fieldLabel : '备注'
}, {
......
......@@ -94,7 +94,10 @@ Ext.define('drp.app.view.resources.WareView', {
xtype : 'gridcolumn',
width : 160,
dataIndex : 'name',
text : '品名'
text : '品名',
renderer : function(value, mate, record) {
return record.data['category.name'] + '-' + value;
}
}, {
xtype : 'gridcolumn',
width : 160,
......
......@@ -12,6 +12,16 @@ Ext.define("drp.app.view.resources.WareViewForm", {
xtype : 'textfield',
hidden : true,
name : 'id'
}, {
xtype : 'treecombobox',
anchor : '60%',
margin : '5 0 0 5',
name : 'category.id',
valueField : 'id',
displayField : 'name',
editable : false,
model : 'drp.app.model.resources.WareCategoryModel',
fieldLabel : '产品种类'
}, {
xtype : 'textfield',
anchor : '60%',
......@@ -27,7 +37,8 @@ Ext.define("drp.app.view.resources.WareViewForm", {
fieldLabel : '规格'
}, {
xtype : 'combobox',
fieldLabel : '单位',
fieldLabel : '单位<font color="red">*</font>',
allowBlank : false,
anchor : '60%',
margin : '5 0 0 5',
name : 'unit',
......@@ -37,7 +48,10 @@ Ext.define("drp.app.view.resources.WareViewForm", {
fields : ['value', 'name'],
data : [{
"value" : "",
"name" : "吨/T"
"name" : ""
}, {
"value" : "",
"name" : ""
}, {
"value" : "",
"name" : ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment