欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

根据对应规格更新规格对应数量,库存

程序员文章站 2022-04-14 15:40:59
/** * 减库存 * @param json 商品规格id 和 数量 json [{"standardid":"79","count":"5"},{"standardid":"81","count":"3"},{"standardid":"82","count":"2"},{"standardid ......
/**
* 减库存
* @param json 商品规格id 和 数量 json [{"standardid":"79","count":"5"},{"standardid":"81","count":"3"},{"standardid":"82","count":"2"},{"standardid":"83","count":"2"}]
**/
@requestmapping(value = "/updatereducestocks.json", method = requestmethod.get)
@responsebody
public integer updatereducestocks(string json) {
hashmap<string , object> map = new hashmap<>();
net.sf.json.jsonarray jsonarr = net.sf.json.jsonarray.fromobject(json);
string standardid[] = new string[jsonarr.size()];
string count[] = new string[jsonarr.size()];
for (int i = 0; i < jsonarr.size(); i++) {
standardid[i] = jsonarr.getjsonobject(i).getstring("standardid");
count[i] = jsonarr.getjsonobject(i).getstring("count");
}
for (int i = 0; i < standardid.length; i++) {
system.out.print("规格id "+standardid[i]+" ");
system.out.print("数量 "+count[i]);
system.out.println();
integer result = groupgoodsservice.updatereducestocks(parseint(standardid[i]), parseint(count[i]));
}

return 1;
}

service:
//减库存
integer updatereducestocks(integer standardid,integer count);

mapper.xml
<!--减库存-->1,0表示按顺序插入,不然不能插入多个或者改配置
<update id="updatereducestocks" parametertype="map">
update standard set stock = stock-#{1} where standard_id = #{0}
</update>