初始化库存

原创
2016/09/29 10:22
阅读数 272

思路

  • 先来理一下思路哈~~~
  • 大概就是,新增商品之后,要设置初始库存,添加商品部分已经写好,我只负责初始化库存,以及将没有入库的商品添加进去
  • 进行判断,如果已经入库,则不需要重复添加,只添加不存在的
  • 输入数字设置为初始库存,没有初始则设置为0

前端页面:

<div class="xuanz">
                        <div class="xuanz_in_in">
                            <span class="cx" ng-click="initInventory()">初始化库存&nbsp;<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)
    @ResponseBody
    public 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

@Override
    public 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

@Override
    public ProductInventory selectByProid(long proid) {
        return sqlSessionTemplate.selectOne(getSqlName("selectByProid"),proid);
    }
展开阅读全文
加载中
点击加入讨论🔥(2) 发布并加入讨论🔥
打赏
2 评论
1 收藏
0
分享
返回顶部
顶部