Browse Source

Merge branch 'dev' of humingfen/wlyy2.0 into dev

humingfen 5 years ago
parent
commit
78df0ec8ef
18 changed files with 584 additions and 6 deletions
  1. 31 0
      common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceDO.java
  2. 129 0
      common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceInventoryLogDO.java
  3. 51 0
      common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotPatientDeviceDO.java
  4. 20 0
      common/common-entity/src/main/java/com/yihu/jw/entity/iot/product/IotProductBaseInfoDO.java
  5. 8 2
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java
  6. 30 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceVO.java
  7. 1 1
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotPatientDeviceVO.java
  8. 20 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/product/IotProductBaseInfoVO.java
  9. 15 0
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java
  10. 58 0
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceInventoryController.java
  11. 15 0
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotPatientDeviceController.java
  12. 2 2
      svr/svr-iot/src/main/java/com/yihu/iot/controller/dict/HospitalController.java
  13. 15 0
      svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java
  14. 8 0
      svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceInventoryLogDao.java
  15. 2 0
      svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceOrderDao.java
  16. 1 1
      svr/svr-iot/src/main/java/com/yihu/iot/dao/product/IotProductBaseInfoDao.java
  17. 152 0
      svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceInventoryService.java
  18. 26 0
      svr/svr-iot/src/main/java/com/yihu/iot/service/product/IotProductBaseInfoService.java

+ 31 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceDO.java

@ -82,6 +82,13 @@ public class IotDeviceDO extends UuidIdentityEntityWithOperator implements Seria
    @Column(name = "del")
    private Integer del;//删除标志(1有效,0删除)
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
    @Column(name = "category_name")
    private String categoryName;//设备类型名称
    @Column(name = "inventory_log_id")
    private String inventoryLogId;//出入库记录id
    public enum DeviceStatus {
        normal("正常", "1"),
        scrap("报废", "2"),
@ -315,4 +322,28 @@ public class IotDeviceDO extends UuidIdentityEntityWithOperator implements Seria
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    public String getInventoryLogId() {
        return inventoryLogId;
    }
    public void setInventoryLogId(String inventoryLogId) {
        this.inventoryLogId = inventoryLogId;
    }
}

+ 129 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceInventoryLogDO.java

@ -0,0 +1,129 @@
package com.yihu.jw.entity.iot.device;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * 设备表
 * @author humingfen on 2020.4.29.
 */
@Entity
@Table(name = "iot_device_inventory_log")
public class IotDeviceInventoryLogDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "product_id")
    private String productId;//产品id
    @Column(name = "name")
    private String name;//设备名称
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
    @Column(name = "category_name")
    private String categoryName;//设备类型名称
    @Column(name = "hospital")
    private String hospital;//归属社区
    @Column(name = "hospital_name")
    private String hospitalName;//归属社区名称
    @Column(name = "order_id")
    private String orderId;//订单id
    @Column(name = "order_no")
    private String orderNo;//订单编号
//    @Column(name = "num")
//    private Integer num;//数量
    @Column(name = "type")
    private String type;//调拨类型(1入库 2设备调拨出库 3核销出库)
    @Column(name = "remark")
    private String remark;//备注
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public String getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}

+ 51 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotPatientDeviceDO.java

@ -23,8 +23,12 @@ public class IotPatientDeviceDO extends UuidIdentityEntityWithOperator implement
    private String patientName;//居民姓名
    @Column(name = "idcard")
    private String idcard;//居民身份证
    @Column(name = "mobile")
    private String mobile;//联系方式
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
    @Column(name = "category_name")
    private String categoryName;//设备类型名称
    @Column(name = "device_id")
    private String deviceId;//设备id
    @Column(name = "device_name")
@ -42,6 +46,13 @@ public class IotPatientDeviceDO extends UuidIdentityEntityWithOperator implement
    @Column(name = "del")
    private Integer del;//删除标志
    @Column(name = "hospital")
    private String hospital;//归属社区
    @Column(name = "hospital_name")
    private String hospitalName;//归属社区名称
    @Column(name = "imgs")
    private String imgs;//领用协议,多个用逗号隔开
    public String getSaasId() {
        return saasId;
@ -146,4 +157,44 @@ public class IotPatientDeviceDO extends UuidIdentityEntityWithOperator implement
    public void setSim(String sim) {
        this.sim = sim;
    }
    public String getMobile() {
        return mobile;
    }
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getHospitalName() {
        return hospitalName;
    }
    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }
    public String getImgs() {
        return imgs;
    }
    public void setImgs(String imgs) {
        this.imgs = imgs;
    }
}

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

@ -77,6 +77,10 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    private String categoryName;//设备类型标识
    @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;
@ -317,4 +321,20 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    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;
    }
}

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

@ -115,6 +115,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";
    }
@ -141,7 +142,7 @@ public class IotRequestMapping {
        public static final String deleteLocation= "deteleLocation";
        public static final String updateLocation= "updateLocation";
        public static final String createPatientDevice = "createPatientDevice";
    }
@ -174,6 +175,11 @@ public class IotRequestMapping {
        public static final String api_update = "updDevice";
        public static final String api_queryPage = "queryDevicePage";
        public static final String api_getList = "getDeviceList";
        public static final String api_findByDeviceSn = "findByDeviceSn";
        //设备库存
        public static final String getDeviceInventoryList = "getDeviceInventoryList";
        public static final String updateInventory = "updateInventory";
        public static final String isSnExist = "isSnExist";
        public static final String isSimExist = "isSimExist";
@ -189,7 +195,7 @@ public class IotRequestMapping {
        public static final String del_message_fail = "该设备已绑定居民,不允许删除";
        public static final String message_success_create = "device create success";
        public static final String message_success_find_functions = "device find success";
        public static final String message_success_updateInventory = "device inventory update success";
    }
    /**

+ 30 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceVO.java

@ -68,6 +68,12 @@ public class IotDeviceVO extends BaseVO implements Serializable {
    private List<IotProductDataTransmissionVO> dataTransmissionVOList;
    @ApiModelProperty("关联居民")
    private List<IotPatientDeviceVO> patientDeviceVOList;
    @ApiModelProperty("库存数")
    private Integer inventoryCount;
    @ApiModelProperty("设备类型")
    private String categoryCode;//设备类型标识
    @ApiModelProperty("设备类型名称")
    private String categoryName;//设备类型名称
    public String getName() {
        return name;
@ -260,4 +266,28 @@ public class IotDeviceVO extends BaseVO implements Serializable {
    public void setPatientDeviceVOList(List<IotPatientDeviceVO> patientDeviceVOList) {
        this.patientDeviceVOList = patientDeviceVOList;
    }
    public Integer getInventoryCount() {
        return inventoryCount;
    }
    public void setInventoryCount(Integer inventoryCount) {
        this.inventoryCount = inventoryCount;
    }
    public String getCategoryCode() {
        return categoryCode;
    }
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
}

+ 1 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotPatientDeviceVO.java

@ -37,7 +37,7 @@ public class IotPatientDeviceVO extends BaseVO implements Serializable {
    private String categoryCode;
    @ApiModelProperty("地址")
    private String address;
    @ApiModelProperty("社区地址")
    @ApiModelProperty("社区")
    private String hospitalName;
    @ApiModelProperty("病情:0绿标,1黄标,2红标")
    private Integer diseaseCondition;

+ 20 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/product/IotProductBaseInfoVO.java

@ -84,6 +84,10 @@ public class IotProductBaseInfoVO extends BaseVO implements Serializable {
    private Double retailPrice;
    @ApiModelProperty("设备类型标识")
    private String categoryCode;
    @ApiModelProperty("库存上限提醒值")
    private Double inventoryUpper;
    @ApiModelProperty("库存下限提醒值")
    private String inventoryFloor;
    public String getParentId() {
        return parentId;
@ -340,4 +344,20 @@ public class IotProductBaseInfoVO extends BaseVO implements Serializable {
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }
    public Double getInventoryUpper() {
        return inventoryUpper;
    }
    public void setInventoryUpper(Double inventoryUpper) {
        this.inventoryUpper = inventoryUpper;
    }
    public String getInventoryFloor() {
        return inventoryFloor;
    }
    public void setInventoryFloor(String inventoryFloor) {
        this.inventoryFloor = inventoryFloor;
    }
}

+ 15 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java

@ -256,4 +256,19 @@ public class IotDeviceController extends EnvelopRestEndpoint {
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.api_findByDeviceSn)
    @ApiOperation(value = "根据sn查找设备", notes = "根据sn查找设备")
    public MixEnvelop<IotDeviceVO, IotDeviceVO> findByDeviceSn(@ApiParam(name = "deviceSn", value = "设备sn码")
                                                           @RequestParam(value = "deviceSn", required = true) String deviceSn
    ) {
        try {
            IotDeviceDO iotDeviceDO = iotDeviceService.findByDeviceSn(deviceSn);
            IotDeviceVO iotDeviceVO = convertToModel(iotDeviceDO,IotDeviceVO.class);
            return MixEnvelop.getSuccess(IotRequestMapping.Device.message_success_find, iotDeviceVO);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 58 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceInventoryController.java

@ -0,0 +1,58 @@
package com.yihu.iot.controller.device;
import com.yihu.iot.service.device.IotDeviceInventoryService;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author humingfen on 2020.4.29
 */
@RestController
@RequestMapping(IotRequestMapping.Common.device)
@Api(tags = "设备库存管理相关操作", description = "设备库存管理相关操作")
public class IotDeviceInventoryController extends EnvelopRestEndpoint {
    @Autowired
    private IotDeviceInventoryService deviceInventoryService;
    @GetMapping(value = IotRequestMapping.Device.getDeviceInventoryList)
    @ApiOperation(value = "获取设备库存列表", notes = "获取设备库存列表")
    public MixEnvelop<IotDeviceVO, IotDeviceVO> getDeviceInventoryList(@ApiParam(name = "name", value = "设备名称")
                                                           @RequestParam(value = "name", required = false) String name,
                                                                       @ApiParam(name = "categoryCode", value = "设备类型标识")
                                                                       @RequestParam(value = "categoryCode", required = false) String categoryCode,
                                                                       @ApiParam(name = "hospitalName", value = "单位名称")
                                                                           @RequestParam(value = "hospitalName", required = false) String hospitalName,
                                                                       @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                                                                           @RequestParam(value = "page", required = false) Integer page,
                                                                       @ApiParam(name = "pageSize", value = "每页记录数")
                                                                           @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            return deviceInventoryService.getDeviceInventoryList(name, categoryCode, hospitalName, page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Device.updateInventory)
    @ApiOperation(value = "设备库存出入库", notes = "设备库存出入库")
    public MixEnvelop<IotDeviceVO, IotDeviceVO> updateInventory(@ApiParam(name = "jsonData", value = "设备出入库json",defaultValue = "")
                                                                       @RequestParam(value = "jsonData", required = true) String jsonData) {
        try {
            Integer count = deviceInventoryService.updateInventory(jsonData);
            return MixEnvelop.getSuccess(IotRequestMapping.Device.message_success_updateInventory, count);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 15 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotPatientDeviceController.java

@ -289,4 +289,19 @@ public class IotPatientDeviceController extends EnvelopRestEndpoint {
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.PatientDevice.createPatientDevice)
    @ApiOperation(value = "设备发放", notes = "设备发放")
    public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> createPatientDevice(@ApiParam(name = "jsonData", value = "", defaultValue = "")
                                                                     @RequestParam String jsonData) {
        try {
            //设备绑定
            IotPatientDeviceDO patientDevice = toEntity(jsonData, IotPatientDeviceDO.class);
            iotPatientDeviceService.create(patientDevice);
            return MixEnvelop.getSuccess(IotRequestMapping.Device.message_success_create);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 2 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/dict/HospitalController.java

@ -24,8 +24,8 @@ public class HospitalController extends EnvelopRestEndpoint {
    @PostMapping(value = IotRequestMapping.Hospital.create)
    @ApiOperation(value = "创建编辑单位字典")
    public MixEnvelop create(
            @ApiParam(name = "jsonData", value = "设备体征字典json数据")
            @RequestParam(value = "jsonData", required = false) String jsonData){
            @ApiParam(name = "jsonData", value = "单位json数据")
            @RequestParam(value = "jsonData", required = true) String jsonData){
        try {
            IotHospitalDO hospitalDO = toEntity(jsonData, IotHospitalDO.class);
            return MixEnvelop.getSuccess(IotRequestMapping.Company.message_success_create, hospitalService.create(hospitalDO));

+ 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_update, productVOList);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 8 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceInventoryLogDao.java

@ -0,0 +1,8 @@
package com.yihu.iot.dao.device;
import com.yihu.jw.entity.iot.device.IotDeviceInventoryLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface IotDeviceInventoryLogDao extends PagingAndSortingRepository<IotDeviceInventoryLogDO, String>, JpaSpecificationExecutor<IotDeviceInventoryLogDO> {
}

+ 2 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceOrderDao.java

@ -17,4 +17,6 @@ public interface IotDeviceOrderDao extends PagingAndSortingRepository<IotDeviceO
    @Query("from IotDeviceOrderDO w where w.ymd =?1")
    List<IotDeviceOrderDO> findByYmd(String ymd);
    IotDeviceOrderDO findByOrderNoAndDel(String orderNo, Integer del);
}

+ 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);
}

+ 152 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceInventoryService.java

@ -0,0 +1,152 @@
package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonObject;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceInventoryLogDao;
import com.yihu.iot.dao.device.IotDeviceOrderDao;
import com.yihu.jw.entity.iot.device.IotDeviceDO;
import com.yihu.jw.entity.iot.device.IotDeviceInventoryLogDO;
import com.yihu.jw.entity.iot.device.IotDeviceOrderDO;
import com.yihu.jw.entity.specialist.rehabilitation.RehabilitationTemplateDetailDO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
//create by hmf on 2020.4.29
@Service
public class IotDeviceInventoryService extends BaseJpaService<IotDeviceInventoryLogDO, IotDeviceInventoryLogDao> {
    @Autowired
    private JdbcTemplate jdbcTempalte;
    @Autowired
    private IotDeviceDao iotDeviceDao;
    @Autowired
    private IotDeviceInventoryLogDao deviceInventoryLogDao;
    @Autowired
    private IotDeviceOrderDao deviceOrderDao;
    @Autowired
    private ObjectMapper objectMapper;
    /**
     * 获取库存列表接口
     *
     * @param name
     * @param categoryCode
     * @param hospitalName
     * @param page
     * @param pageSize
     * @return
     */
    public MixEnvelop<IotDeviceVO, IotDeviceVO> getDeviceInventoryList(String name, String categoryCode, String hospitalName, Integer page, Integer pageSize) {
        String sql = "select d.id,d.product_id,d.`name`,d.category_code,d.category_name,d.manufacturer_id,d.manufacturer_name,d.hospital,d.hospital_name,count(id) inventoryCount FROM `iot_device` d where del=1  ";
        if (StringUtils.isNotBlank(name)) {
            sql += "and name like '%" + name + "%' ";
        }
        if (StringUtils.isNotBlank(categoryCode)) {
            sql += "and category_code = '" + categoryCode + "' ";
        }
        if (StringUtils.isNotBlank(hospitalName)) {
            sql += "and hospital_name like '%" + hospitalName + "%' ";
        }
        sql += "GROUP BY d.product_id, d.manufacturer_id, d.hospital, d.category_code ";
        //判断是否需要分页
        if (page != null && pageSize != null) {
            Long count = Long.valueOf(jdbcTempalte.queryForList(sql).size());
            sql += "limit " + (page - 1) * pageSize + "," + pageSize;
            List<IotDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotDeviceVO.class));
            return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find, deviceVOList, page, pageSize, count);
        } else {
            List<IotDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotDeviceVO.class));
            return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, deviceVOList);
        }
    }
    public Integer updateInventory(String jsonData) {
        List<IotDeviceDO> deviceDOList = new ArrayList<>();
        JSONArray jsonArray = JSONArray.parseArray(jsonData);
        for (Object object : jsonArray) {
            JSONObject jsonObject = (JSONObject) object;
            String orderId = null;
            if (jsonObject.containsKey("orderNo") && StringUtils.isNotBlank(jsonObject.getString("orderNo"))) {
                String orderNo = jsonObject.getString("orderNo");//订单编号
                //根据订单编号获取订单id
                IotDeviceOrderDO deviceOrderDO = deviceOrderDao.findByOrderNoAndDel(orderNo, 1);
                orderId = deviceOrderDO.getId();
            }
            String deviceList = jsonObject.getString("deviceList");//需进行操作的设备列表
            IotDeviceInventoryLogDO deviceInventoryLogDO = null;
            List<IotDeviceDO> deviceDOS = new ArrayList<>();
            try {
                deviceInventoryLogDO = objectMapper.readValue(jsonObject.toString(), IotDeviceInventoryLogDO.class);
                deviceDOS = new ObjectMapper().readValue(deviceList, new TypeReference<List<IotDeviceDO>>() {
                });
            } catch (IOException e) {
                e.printStackTrace();
            }
            //保存出入库日志
            deviceInventoryLogDO.setSaasId(getCode());
            deviceInventoryLogDO.setOrderId(orderId);
            deviceInventoryLogDO.setCreateTime(new Date());
            deviceInventoryLogDO.setUpdateTime(new Date());
//            deviceInventoryLogDO.setNum(deviceDOS.size());
            deviceInventoryLogDao.save(deviceInventoryLogDO);
            //根据类型处理出入库
            for (IotDeviceDO deviceDO : deviceDOS) {
                String deviceSn = deviceDO.getDeviceSn();
                String type = deviceInventoryLogDO.getType();//调拨类型(1入库 2设备调拨出库 3核销出库)
                //设备出库,更换相关信息
                if(type.equals("1")){
                    deviceDO.setSaasId(getCode());
                }else {
                    deviceDO = iotDeviceDao.findByDeviceSn(deviceSn);
                    if(type.equals("3")){
                        deviceDO.setDel(0);
                        deviceDO.setStatus("2");
                        deviceDO.setInventoryLogId(deviceInventoryLogDO.getId());
                        deviceDO.setUpdateTime(new Date());
                        deviceDOList.add(deviceDO);
                        continue;
                    }
                }
                deviceDO.setProductId(jsonObject.getString("productId"));
                deviceDO.setName(jsonObject.getString("name"));
                deviceDO.setCategoryCode(jsonObject.getString("categoryCode"));
                deviceDO.setCategoryName(jsonObject.getString("categoryName"));
                deviceDO.setManufacturerId(jsonObject.getString("manufacturerId"));
                deviceDO.setManufacturerName(jsonObject.getString("manufacturerName"));
                deviceDO.setHospital(jsonObject.getString("hospital"));
                deviceDO.setHospitalName(jsonObject.getString("hospitalName"));
                if (StringUtils.isNotBlank(orderId)) {
                    deviceInventoryLogDO.setOrderId(orderId);
                }
                if (jsonObject.containsKey("orderNo") && StringUtils.isNotBlank(jsonObject.getString("orderNo"))) {
                    deviceInventoryLogDO.setOrderNo(jsonObject.getString("orderNo"));
                }
                deviceDO.setDel(1);
                deviceDO.setStatus("1");
                deviceDO.setInventoryLogId(deviceInventoryLogDO.getId());
                deviceDO.setCreateTime(new Date());
                deviceDO.setUpdateTime(new Date());
                deviceDOList.add(deviceDO);
            }
        }
        iotDeviceDao.save(deviceDOList);
        return deviceDOList.size();
    }
}

+ 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;
@ -331,4 +333,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;
    }
}