优化商品的多属性
This commit is contained in:
@@ -429,11 +429,11 @@ CREATE TABLE `jsh_material_attribute` (
|
|||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Records of jsh_material_attribute
|
-- Records of jsh_material_attribute
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('1', 'color', '颜色', '红色|橙色|黄色|绿色|蓝色|紫色', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('1', 'manyColor', '颜色', '红色|橙色|黄色|绿色|蓝色|紫色', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('2', 'size', '尺寸', 'S|M|L|XL|XXL|XXXL', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('2', 'manySize', '尺寸', 'S|M|L|XL|XXL|XXXL', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('3', 'brand', '品牌', '品牌1|品牌2', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('3', 'other1', '自定义1', '小米|华为', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('4', 'other1', '自定义1', null, '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('4', 'other2', '自定义2', null, '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('5', 'other2', '自定义2', null, '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('5', 'other3', '自定义3', null, '63', '0');
|
||||||
|
|
||||||
-- ----------------------------
|
-- ----------------------------
|
||||||
-- Table structure for jsh_material_category
|
-- Table structure for jsh_material_category
|
||||||
|
|||||||
@@ -1143,11 +1143,11 @@ CREATE TABLE `jsh_material_attribute` (
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性';
|
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='产品属性';
|
||||||
|
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('1', 'color', '颜色', '红色|橙色|黄色|绿色|蓝色|紫色', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('1', 'manyColor', '颜色', '红色|橙色|黄色|绿色|蓝色|紫色', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('2', 'size', '尺寸', 'S|M|L|XL|XXL|XXXL', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('2', 'manySize', '尺寸', 'S|M|L|XL|XXL|XXXL', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('3', 'brand', '品牌', '品牌1|品牌2', '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('3', 'other1', '自定义1', '小米|华为', '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('4', 'other1', '自定义1', null, '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('4', 'other2', '自定义2', null, '63', '0');
|
||||||
INSERT INTO `jsh_material_attribute` VALUES ('5', 'other2', '自定义2', null, '63', '0');
|
INSERT INTO `jsh_material_attribute` VALUES ('5', 'other3', '自定义3', null, '63', '0');
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
-- --------------------------------------------------------
|
||||||
-- 时间 2021年7月22日
|
-- 时间 2021年7月22日
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.jsh.erp.controller;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jsh.erp.datasource.entities.MaterialAttribute;
|
||||||
|
import com.jsh.erp.service.materialAttribute.MaterialAttributeService;
|
||||||
|
import com.jsh.erp.utils.BaseResponseInfo;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ji sheng hua jshERP
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/materialAttribute")
|
||||||
|
public class MaterialAttributeController {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(MaterialAttributeController.class);
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MaterialAttributeService materialAttributeService;
|
||||||
|
|
||||||
|
@GetMapping("/getAll")
|
||||||
|
public BaseResponseInfo getAll(HttpServletRequest request)throws Exception {
|
||||||
|
BaseResponseInfo res = new BaseResponseInfo();
|
||||||
|
try {
|
||||||
|
JSONObject obj = materialAttributeService.getAll();
|
||||||
|
res.code = 200;
|
||||||
|
res.data = obj;
|
||||||
|
} catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
res.code = 500;
|
||||||
|
res.data = "获取数据失败";
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@ public class MaterialExtendController {
|
|||||||
item.put("id", md.getId());
|
item.put("id", md.getId());
|
||||||
item.put("barCode", md.getBarCode());
|
item.put("barCode", md.getBarCode());
|
||||||
item.put("commodityUnit", md.getCommodityUnit());
|
item.put("commodityUnit", md.getCommodityUnit());
|
||||||
|
item.put("sku", md.getSku());
|
||||||
item.put("purchaseDecimal", md.getPurchaseDecimal());
|
item.put("purchaseDecimal", md.getPurchaseDecimal());
|
||||||
item.put("commodityDecimal", md.getCommodityDecimal());
|
item.put("commodityDecimal", md.getCommodityDecimal());
|
||||||
item.put("wholesaleDecimal", md.getWholesaleDecimal());
|
item.put("wholesaleDecimal", md.getWholesaleDecimal());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jsh.erp.service.materialAttribute;
|
package com.jsh.erp.service.materialAttribute;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.jsh.erp.constants.BusinessConstants;
|
import com.jsh.erp.constants.BusinessConstants;
|
||||||
import com.jsh.erp.datasource.entities.MaterialAttribute;
|
import com.jsh.erp.datasource.entities.MaterialAttribute;
|
||||||
@@ -9,6 +10,7 @@ import com.jsh.erp.datasource.mappers.MaterialAttributeMapperEx;
|
|||||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||||
import com.jsh.erp.exception.JshException;
|
import com.jsh.erp.exception.JshException;
|
||||||
import com.jsh.erp.service.log.LogService;
|
import com.jsh.erp.service.log.LogService;
|
||||||
|
import com.jsh.erp.utils.StringUtil;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -58,13 +60,13 @@ public class MaterialAttributeService {
|
|||||||
|
|
||||||
public List<MaterialAttribute> select(String attributeField, int offset, int rows)
|
public List<MaterialAttribute> select(String attributeField, int offset, int rows)
|
||||||
throws Exception{
|
throws Exception{
|
||||||
String[] arr = {"color","size","brand","other1","other2"};
|
String[] arr = {"manyColor","manySize","other1","other2","other3"};
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
map.put("color", "颜色");
|
map.put("manyColor", "多颜色");
|
||||||
map.put("size", "尺寸");
|
map.put("manySize", "多尺寸");
|
||||||
map.put("brand", "品牌");
|
|
||||||
map.put("other1", "自定义1");
|
map.put("other1", "自定义1");
|
||||||
map.put("other2", "自定义2");
|
map.put("other2", "自定义2");
|
||||||
|
map.put("other3", "自定义3");
|
||||||
List<MaterialAttribute> list = new ArrayList<>();
|
List<MaterialAttribute> list = new ArrayList<>();
|
||||||
try{
|
try{
|
||||||
List<MaterialAttribute> maList = materialAttributeMapperEx.selectByConditionMaterialAttribute(attributeField, offset, rows);
|
List<MaterialAttribute> maList = materialAttributeMapperEx.selectByConditionMaterialAttribute(attributeField, offset, rows);
|
||||||
@@ -161,4 +163,59 @@ public class MaterialAttributeService {
|
|||||||
}
|
}
|
||||||
return list==null?0:list.size();
|
return list==null?0:list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JSONObject getAll() {
|
||||||
|
JSONObject obj = new JSONObject();
|
||||||
|
//属性名
|
||||||
|
obj.put("manyColorName", getNameByField("manyColor"));
|
||||||
|
obj.put("manySizeName", getNameByField("manySize"));
|
||||||
|
obj.put("other1Name", getNameByField("other1"));
|
||||||
|
obj.put("other2Name", getNameByField("other2"));
|
||||||
|
obj.put("other3Name", getNameByField("other3"));
|
||||||
|
//属性值
|
||||||
|
obj.put("manyColorValue", getValueArrByField("manyColor"));
|
||||||
|
obj.put("manySizeValue", getValueArrByField("manySize"));
|
||||||
|
obj.put("other1Value", getValueArrByField("other1"));
|
||||||
|
obj.put("other2Value", getValueArrByField("other2"));
|
||||||
|
obj.put("other3Value", getValueArrByField("other3"));
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MaterialAttribute getInfoByField(String field) {
|
||||||
|
MaterialAttributeExample example = new MaterialAttributeExample();
|
||||||
|
example.createCriteria().andAttributeFieldEqualTo(field).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||||
|
List<MaterialAttribute> list = materialAttributeMapper.selectByExample(example);
|
||||||
|
if(list!=null && list.size()>0) {
|
||||||
|
return list.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameByField(String field) {
|
||||||
|
MaterialAttribute ma = getInfoByField(field);
|
||||||
|
if(ma!=null) {
|
||||||
|
return ma.getAttributeName();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONArray getValueArrByField(String field) {
|
||||||
|
JSONArray valueArr = new JSONArray();
|
||||||
|
MaterialAttribute ma = getInfoByField(field);
|
||||||
|
if(ma!=null) {
|
||||||
|
String value = ma.getAttributeValue();
|
||||||
|
if(StringUtil.isNotEmpty(value)){
|
||||||
|
String[] arr = value.split("\\|");
|
||||||
|
for(String v: arr) {
|
||||||
|
JSONObject item = new JSONObject();
|
||||||
|
item.put("value",v);
|
||||||
|
item.put("name",v);
|
||||||
|
valueArr.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valueArr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,9 @@ public class MaterialExtendService {
|
|||||||
if (StringUtils.isNotEmpty(tempInsertedJson.getString("commodityUnit"))) {
|
if (StringUtils.isNotEmpty(tempInsertedJson.getString("commodityUnit"))) {
|
||||||
materialExtend.setCommodityUnit(tempInsertedJson.getString("commodityUnit"));
|
materialExtend.setCommodityUnit(tempInsertedJson.getString("commodityUnit"));
|
||||||
}
|
}
|
||||||
|
if (tempInsertedJson.get("sku")!=null) {
|
||||||
|
materialExtend.setSku(tempInsertedJson.getString("sku"));
|
||||||
|
}
|
||||||
if (StringUtils.isNotEmpty(tempInsertedJson.getString("purchaseDecimal"))) {
|
if (StringUtils.isNotEmpty(tempInsertedJson.getString("purchaseDecimal"))) {
|
||||||
materialExtend.setPurchaseDecimal(tempInsertedJson.getBigDecimal("purchaseDecimal"));
|
materialExtend.setPurchaseDecimal(tempInsertedJson.getBigDecimal("purchaseDecimal"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.MaterialExtendExample" resultMap="ResultMapList">
|
<select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.MaterialExtendExample" resultMap="ResultMapList">
|
||||||
select DISTINCT d.Id,d.bar_code,d.commodity_unit,d.commodity_decimal,d.purchase_decimal,d.wholesale_decimal,d.low_decimal
|
select DISTINCT d.Id,d.bar_code,d.commodity_unit,d.sku,d.commodity_decimal,d.purchase_decimal,d.wholesale_decimal,d.low_decimal
|
||||||
from jsh_material_extend d
|
from jsh_material_extend d
|
||||||
where d.material_id = #{materialId}
|
where d.material_id = #{materialId}
|
||||||
and ifnull(d.delete_Flag,'0') !='1'
|
and ifnull(d.delete_Flag,'0') !='1'
|
||||||
|
|||||||
Reference in New Issue
Block a user