初始化库存
2019獨角獸企業重金招聘Python工程師標準>>>
思路
- 先來理一下思路哈~~~
- 大概就是,新增商品之后,要設置初始庫存,添加商品部分已經寫好,我只負責初始化庫存,以及將沒有入庫的商品添加進去
- 進行判斷,如果已經入庫,則不需要重復添加,只添加不存在的
- 輸入數字設置為初始庫存,沒有初始則設置為0
前端頁面:
<div class="xuanz"><div class="xuanz_in_in"><span class="cx" ng-click="initInventory()">初始化庫存 <span class="caret"></span></span></div><input class="in_l" type="text" placeholder="請輸入初始化庫存數" ng-model="realinventory"/><span class="searchbutton in_r" ng-click="search()"></span></div>controller.js
scope.initInventory = function(){console.log(scope.realinventory);productService.initInventory(scope.realinventory,function(data){//window.location.href=ctx+'/product/index#/inventory/0';scope.list();});}service.js
initInventory:function(realinventory,callback){$http({method: "POST",url: ctx + "/productinventory/insertprotoproinventory",data:{"realinventory":realinventory}}).success(function (data, status) {callback(data);});}controller:
/** 將Product信息添加至ProductInventory* 顯示所有* */@RequestMapping(value = "insertprotoproinventory",method = RequestMethod.POST)@ResponseBodypublic Result insertProtoProInventory(@RequestBody ProductInventory productInventory){String appid = (String) SecurityUtils.getSubject().getSession().getAttribute(IConstants.APPIDSESSION);if(appid!=null){productInventory.setAppid(appid);}ShiroDbRealm.ShiroUser user = getCurrentUser();if(Commons.isNull(user)){return new Result(Result.Status.ERROR,null);}Administrator admin = administratorService.queryById(user.getId());if(Commons.isNull(admin) || Commons.isNull(admin.getType())){return new Result(Result.Status.ERROR,null);}if (admin.getType() == 3) {productInventory.setSupplierid(admin.getId());} else if (admin.getType() == 4) {if (!Commons.isNull(admin.getSupplierid())) {productInventory.setSupplierid(Long.valueOf(admin.getSupplierid()));} else {return new Result(Result.Status.ERROR, null);}}if (productInventory.getRealinventory()==null){productInventory.setRealinventory(0);}else {productInventory.getRealinventory();} // productInventory.setRealinventory(realinventory);productInventoryService.insertProductInventory(productInventory);return new Result(Result.Status.OK);}mapper
<select id="selectByProid" resultMap="BaseResultMap" parameterType="java.lang.Long">select<include refid="Base_Column_List"/>from<include refid="table"/>where proid=#{proid}</select>serviceImpl
@Overridepublic void insertProductInventory(ProductInventory productInventory) { // Map<String,Object> map = new HashMap<>(); // map.put("appid", productInventory.getAppid()); // map.put("appid", productInventory.getAppid());ProductQuery query = new ProductQuery();query.setAppid(productInventory.getAppid());query.setSupplier(productInventory.getSupplierid());List<Product> productList = productService.queryList(query);//判斷數據庫是否已經存在數據for (Product product : productList) {long proid = product.getId();if (this.selectByProid(proid) == null) {productInventory.setId(null);productInventory.setAppid(product.getAppid());productInventory.setProid(product.getId());productInventory.setProseries(product.getProductseries());productInventory.setSupplierid(product.getSupplier());productInventory.setFatherid(null);productInventory.setUserid(null);productInventory.setCreatetime(new Date());productInventory.setRealinventory(productInventory.getRealinventory());productInventory.setSupplierinventory(productInventory.getRealinventory());productInventory.setChannelinventory(0);productInventory.setTicketinventory(0);productInventoryDao.insert(productInventory);}else { continue; }}}DaoImpl
@Overridepublic ProductInventory selectByProid(long proid) {return sqlSessionTemplate.selectOne(getSqlName("selectByProid"),proid);}轉載于:https://my.oschina.net/LYQ19941105/blog/753068
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
- 上一篇: Android Studio Gradl
- 下一篇: 数据结构-直接寻址表