Browse Source

物联网添加根据产品id设置库存上下限预警值

humingfen 5 years ago
parent
commit
b86f435102

+ 20 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/product/IotProductBaseInfoDO.java

@ -75,6 +75,10 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    private Double retailPrice;//零售价格
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
    @Column(name = "inventory_upper")
    private Integer inventoryUpper;//库存上限提醒值
    @Column(name = "inventory_floor")
    private Integer inventoryFloor;//库存下限提醒值
    public String getSaasId() {
        return saasId;
@ -307,4 +311,20 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public Integer getInventoryUpper() {
        return inventoryUpper;
    }
    public void setInventoryUpper(Integer inventoryUpper) {
        this.inventoryUpper = inventoryUpper;
    }
    public Integer getInventoryFloor() {
        return inventoryFloor;
    }
    public void setInventoryFloor(Integer inventoryFloor) {
        this.inventoryFloor = inventoryFloor;
    }
}

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java

@ -112,6 +112,7 @@ public class IotRequestMapping {
        public static final String updProduct = "updProduct";
        public static final String delProduct = "delProduct";
        public static final String maintenanceUnitById = "maintenanceUnitById";
        public static final String setInventoryById = "setInventoryById";
    }

+ 15 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java

@ -201,4 +201,19 @@ public class IotProductController extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = IotRequestMapping.Product.setInventoryById)
    @ApiOperation(value = "根据产品id设置库存上下限预警值")
    public MixEnvelop<IotProductVO, IotProductVO> setInventoryById(@ApiParam(name = "jsonData", value = "设置库存预警提醒json数组", defaultValue = "[]")
                                                                       @RequestParam(value = "jsonData", required = true)String jsonData) {
        try {
            List<IotProductBaseInfoDO> productBaseInfoDOList = iotProductBaseInfoService.setInventoryById(jsonData);
            //DO转VO
            List<IotProductBaseInfoVO> productVOList = convertToModels(productBaseInfoDOList,new ArrayList<>(productBaseInfoDOList.size()),IotProductBaseInfoVO.class);
            iotProductBaseInfoService.translateDictForList(productVOList);
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, productVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/dao/product/IotProductBaseInfoDao.java

@ -11,6 +11,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public interface IotProductBaseInfoDao extends PagingAndSortingRepository<IotProductBaseInfoDO,String>,
        JpaSpecificationExecutor<IotProductBaseInfoDO> {
    @Query("from IotProductBaseInfoDO w where w.id =?1")
    @Query("from IotProductBaseInfoDO w where w.id =?1 and w.del = 1")
    IotProductBaseInfoDO findById(String id);
}

+ 26 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/product/IotProductBaseInfoService.java

@ -1,5 +1,7 @@
package com.yihu.iot.service.product;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.device.IotOrderPurchaseDao;
import com.yihu.iot.dao.product.*;
import com.yihu.iot.service.dict.IotSystemDictService;
@ -330,4 +332,28 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
        }
    }
    /**
     * 设置库存上下限提醒值
     * @param jsonData
     * @return
     */
    public List<IotProductBaseInfoDO> setInventoryById(String jsonData) {
        List<IotProductBaseInfoDO> list = new ArrayList();
        JSONArray jsonArray = JSONArray.parseArray(jsonData);
        for (Object object : jsonArray){
            JSONObject jsonObject = (JSONObject) object;
            String id  = jsonObject.getString("id");
            Integer inventoryUpper = jsonObject.getInteger("inventoryUpper");
            Integer inventoryFloor = jsonObject.getInteger("inventoryFloor");
            //根据id查找对应产品
            IotProductBaseInfoDO productBaseInfoDO = iotProductBaseInfoDao.findById(id);
            if (productBaseInfoDO != null){
                productBaseInfoDO.setInventoryUpper(inventoryUpper);
                productBaseInfoDO.setInventoryFloor(inventoryFloor);
                list.add(productBaseInfoDO);
            }
        }
        iotProductBaseInfoDao.save(list);
        return list;
    }
}