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

/**
* 减库存
* @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>








posted @ 2019-05-11 15:28  tomingto  阅读(235)  评论(0编辑  收藏  举报