初始化库存

思路

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

转载于:https://my.oschina.net/LYQ19941105/blog/753068

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值