Prechádzať zdrojové kódy

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

humingfen 5 rokov pred
rodič
commit
aee8758d7e

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

@ -81,6 +81,8 @@ public class IotDeviceDO extends UuidIdentityEntityWithOperator implements Seria
    @Column(name = "del")
    private Integer del;//删除标志(1有效,0删除)
    @Column(name = "is_grant")
    private Integer isGrant;//是否发放(0否1是)
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
@ -346,4 +348,12 @@ public class IotDeviceDO extends UuidIdentityEntityWithOperator implements Seria
    public void setInventoryLogId(String inventoryLogId) {
        this.inventoryLogId = inventoryLogId;
    }
    public Integer getIsGrant() {
        return isGrant;
    }
    public void setIsGrant(Integer isGrant) {
        this.isGrant = isGrant;
    }
}

+ 70 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/device/IotDeviceOverhaulDO.java

@ -0,0 +1,70 @@
package com.yihu.jw.entity.iot.device;
import com.yihu.jw.entity.UuidIdentityEntity;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * 设备调拨记录表
 *
 * @author humingfen on 2020.5.6.
 */
@Entity
@Table(name = "iot_device_overhaul")
public class IotDeviceOverhaulDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "patient_device_id")
    private String patientDeviceId;//居民设备表id
    @Column(name = "time")
    private String time;//计划检修时间
    @Column(name = "status")
    private Integer status;//检修状态(-1删除 0未检修 1已检修正常 2已检修回收)
    @Column(name = "remark")
    private String remark;//检修备注
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getPatientDeviceId() {
        return patientDeviceId;
    }
    public void setPatientDeviceId(String patientDeviceId) {
        this.patientDeviceId = patientDeviceId;
    }
    public String getTime() {
        return time;
    }
    public void setTime(String time) {
        this.time = time;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}

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

@ -150,6 +150,12 @@ public class IotRequestMapping {
        public static final String getRepairDeviceList = "getRepairDeviceList";
        public static final String getDeviceInfoByDeviceSn = "getDeviceInfoByDeviceSn";
        public static final String deleteRepairDevice = "deleteRepairDevice";
        //设备检修
        public static final String getOverhaulDeviceList = "getOverhaulDeviceList";
        public static final String getOverhaulListByPatientDeviceId = "getOverhaulListByPatientDeviceId";
        public static final String delOverhaulByPatientDeviceId = "delOverhaulByPatientDeviceId";
        public static final String updateOverhaulStatusById = "updateOverhaulStatusById";
    }

+ 7 - 0
common/common-util/src/main/java/com/yihu/jw/util/date/DateUtil.java

@ -414,6 +414,13 @@ public class DateUtil {
        return dateToStrShort(c.getTime());
    }
    public static Date getNextDay1(Date d, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(Calendar.DATE, days);
        return c.getTime();
    }
    public static String getNextMonth(Date d, int months) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);

+ 94 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceOverhaulController.java

@ -0,0 +1,94 @@
package com.yihu.iot.controller.device;
import com.yihu.iot.service.device.IotDeviceOverhaulService;
import com.yihu.iot.service.device.IotPatientDeviceService;
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
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.*;
import java.util.List;
/**
 * @author humingfen on 2020/5/7
 */
@RestController
@RequestMapping(IotRequestMapping.Common.patientDevice)
@Api(tags = "居民设备检修管理相关操作", description = "居民设备检修管理相关操作")
public class IotDeviceOverhaulController extends EnvelopRestEndpoint {
    @Autowired
    private IotPatientDeviceService patientDeviceService;
    @Autowired
    private IotDeviceOverhaulService deviceOverhaulService;
    @GetMapping(value = IotRequestMapping.PatientDevice.getOverhaulDeviceList)
    @ApiOperation(value = "获取检修管理列表", notes = "获取检修管理列表")
    public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> getOverhaulDeviceList(
            @ApiParam(name = "deviceSn", value = "sn码", defaultValue = "")
            @RequestParam(value = "deviceSn", required = false) String deviceSn,
            @ApiParam(name = "patientName", value = "领用人")
            @RequestParam(value = "patientName", required = false) String patientName,
            @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 patientDeviceService.getOverhaulDeviceList(deviceSn, patientName, page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.PatientDevice.getOverhaulListByPatientDeviceId)
    @ApiOperation(value = "根据居民设备id获取检修详情列表", notes = "根据居民设备id获取检修详情列表")
    public MixEnvelop<IotDeviceOverhaulDO, IotDeviceOverhaulDO> getOverhaulListByPatientDeviceId(
            @ApiParam(name = "patientDeviceId", value = "居民设备id", defaultValue = "")
            @RequestParam(value = "patientDeviceId", required = true) String patientDeviceId) {
        try {
            List<IotDeviceOverhaulDO> list = deviceOverhaulService.getOverhaulListByPatientDeviceId(patientDeviceId);
            return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, list);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.PatientDevice.updateOverhaulStatusById)
    @ApiOperation(value = "删除或更新检修状态", notes = "删除或更新检修状态")
    public MixEnvelop<IotDeviceOverhaulDO, IotDeviceOverhaulDO> updateOverhaulStatusById(
            @ApiParam(name = "id", value = "检修记录id", defaultValue = "")
            @RequestParam(value = "id", required = true) String id,
            @ApiParam(name = "status", value = "检修状态(-1删除 0未检修 1已检修正常 2已检修回收)")
            @RequestParam(value = "status", required = true) Integer status,
            @ApiParam(name = "remark", value = "检修备注")
            @RequestParam(value = "remark", required = false) String  remark) {
        try {
            IotDeviceOverhaulDO deviceOverhaulDO = deviceOverhaulService.updateOverhaulStatusById(id, status, remark);
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_update, deviceOverhaulDO);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.PatientDevice.delOverhaulByPatientDeviceId)
    @ApiOperation(value = "根据居民设备id删除检修记录", notes = "根据居民设备id删除检修记录")
    public MixEnvelop<IotDeviceOverhaulDO, IotDeviceOverhaulDO> delOverhaulByPatientDeviceId(
            @ApiParam(name = "patientDeviceId", value = "居民设备id", defaultValue = "")
            @RequestParam(value = "patientDeviceId", required = true) String patientDeviceId) {
        try {
            deviceOverhaulService.delOverhaulByPatientDeviceId(patientDeviceId);
            return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_delete);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

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

@ -305,6 +305,22 @@ public class IotPatientDeviceController extends EnvelopRestEndpoint {
        }
    }
    @PostMapping(value = IotRequestMapping.PatientDevice.delPatientDevice)
    @ApiOperation(value = "设备回收", notes = "设备回收")
    public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> delPatientDevice(@ApiParam(name = "id", value = "居民设备id", defaultValue = "")
                                                                                  @RequestParam String id,
                                                                               @ApiParam(name = "del", value = "删除标志(1正常 0回收纳入库存 -1回收核销)", defaultValue = "")
                                                                               @RequestParam Integer del) {
        try {
            //设备回收
            iotPatientDeviceService.delPatientDevice(id, del);
            return MixEnvelop.getSuccess(IotRequestMapping.Device.message_success_delete);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.PatientDevice.createRepairDevice)
    @ApiOperation(value = "新增编辑设备维修记录", notes = "新增编辑设备维修记录")
    public MixEnvelop<IotPatientDeviceVO, IotPatientDeviceVO> createRepairDevice(@ApiParam(name = "deviceSn", value = "设备sn码")

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

@ -43,4 +43,12 @@ public interface IotDeviceDao extends PagingAndSortingRepository<IotDeviceDO, St
    List<IotDeviceDO> findListByOrderId(String orderId);
    List<IotDeviceDO> findListByInventoryLogId(String id);
    @Modifying
    @Query("update IotDeviceDO w set w.isGrant = ?2 where w.id = ?1 ")
    void updateIsGrantById(String deviceId, Integer isGrant);
    @Modifying
    @Query("update IotDeviceDO w set w.del = ?2 where w.id = ?1 ")
    void updateDelById(String id, int del);
}

+ 19 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceOverhaulDao.java

@ -0,0 +1,19 @@
package com.yihu.iot.dao.device;
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface IotDeviceOverhaulDao extends PagingAndSortingRepository<IotDeviceOverhaulDO, String>, JpaSpecificationExecutor<IotDeviceOverhaulDO> {
    @Query("select o from  IotDeviceOverhaulDO o where o.patientDeviceId = ?1 and o.status <> -1 order by o.time ")
    List<IotDeviceOverhaulDO> findAllByPatientDeviceId(String patientDeviceId);
    @Modifying
    @Query("update IotDeviceOverhaulDO o set o.status = -1 where o.patientDeviceId = ?1 ")
    void delOverhaulByPatientDeviceId(String patientDeviceId);
}

+ 4 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotPatientDeviceDao.java

@ -44,4 +44,8 @@ public interface IotPatientDeviceDao extends PagingAndSortingRepository<IotPatie
    @Modifying
    @Query("update IotPatientDeviceDO t set t.deviceSn = ?3 , t.userType = ?4,t.sim=?5 where t.patient = ?1 and t.deviceSn = ?2 and t.del=1 ")
    int updatePatientDevice(String patient, String deviceSN, String newDeviceSN,String userType,String sim);
    @Modifying
    @Query("update IotPatientDeviceDO t set t.del = ?2 where t.id = ?1")
    void updateDelById(String id, int del);
}

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

@ -52,7 +52,7 @@ public class IotDeviceInventoryService extends BaseJpaService<IotDeviceInventory
     * @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  ";
        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 and is_grant=0 ";
        if (StringUtils.isNotBlank(name)) {
            sql += "and name like '%" + name + "%' ";
        }

+ 40 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceOverhaulService.java

@ -0,0 +1,40 @@
package com.yihu.iot.service.device;
import com.yihu.iot.dao.device.IotDeviceOverhaulDao;
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
 * 设备检修相关管理接口
 * create by hmf on 2020.5.7
 */
@Service
public class IotDeviceOverhaulService extends BaseJpaService<IotDeviceOverhaulDO, IotDeviceOverhaulDao> {
    @Autowired
    private IotDeviceOverhaulDao deviceOverhaulDao;
    public List<IotDeviceOverhaulDO> getOverhaulListByPatientDeviceId(String patientDeviceId) {
        return deviceOverhaulDao.findAllByPatientDeviceId(patientDeviceId);
    }
    public IotDeviceOverhaulDO updateOverhaulStatusById(String id, Integer status, String remark) {
        IotDeviceOverhaulDO deviceOverhaulDO = deviceOverhaulDao.findOne(id);
        deviceOverhaulDO.setStatus(status);
        if(StringUtils.isNotBlank(remark)){
            deviceOverhaulDO.setRemark(remark);
        }
        deviceOverhaulDO.setUpdateTime(new Date());
        deviceOverhaulDao.save(deviceOverhaulDO);
        return deviceOverhaulDO;
    }
    public void delOverhaulByPatientDeviceId(String patientDeviceId) {
        deviceOverhaulDao.delOverhaulByPatientDeviceId(patientDeviceId);
    }
}

+ 73 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -2,13 +2,19 @@ package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONObject;
import com.yihu.elasticsearch.ElasticSearchHelper;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceOverhaulDao;
import com.yihu.iot.dao.device.IotPatientDeviceDao;
import com.yihu.iot.datainput.util.ConstantUtils;
import com.yihu.iot.service.common.ElasticSearchQueryGenerator;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.jw.device.LocationDataDO;
import com.yihu.jw.entity.iot.device.IotDeviceOverhaulDO;
import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.util.common.LatitudeUtils;
import com.yihu.jw.util.date.DateUtil;
@ -22,7 +28,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.util.*;
@ -40,17 +48,48 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
    private ElasticSearchHelper elasticSearchHelper;
    @Autowired
    private ElasticSearchQueryGenerator elasticSearchQueryGenerator;
    @Autowired
    private IotDeviceDao iotDeviceDao;
    @Autowired
    private JdbcTemplate jdbcTempalte;
    @Autowired
    private IotSystemDictService iotSystemDictService;
    @Autowired
    private IotDeviceOverhaulDao deviceOverhaulDao;
    /**
     * 新增
     * @param patientDevice
     * @return
     */
    @Transactional
    public IotPatientDeviceDO create(IotPatientDeviceDO patientDevice) {
        patientDevice.setSaasId(getCode());
        patientDevice.setDel(1);
        return iotPatientDeviceDao.save(patientDevice);
        IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.save(patientDevice);
        //更新设备绑定状态,减库存
        iotDeviceDao.updateIsGrantById(patientDevice.getDeviceId(), 1);
        //生成一年检修记录
        List<IotSystemDictDO> systemDictDOS = iotSystemDictService.getListByDictName("OVERHAUL_FREQUENCY");//获取设备检修时间
        if(systemDictDOS.size() == 1){
            List<IotDeviceOverhaulDO> deviceOverhaulDOS = new ArrayList<>();
            int day = Integer.parseInt(systemDictDOS.get(0).getValue());//检修间隔天数
            int count = 365/day;
            for(int i = 0 ; i< count; i++){
                IotDeviceOverhaulDO deviceOverhaulDO = new IotDeviceOverhaulDO();
                deviceOverhaulDO.setSaasId(getCode());
                deviceOverhaulDO.setPatientDeviceId(patientDeviceDO.getId());
                deviceOverhaulDO.setStatus(0);
                deviceOverhaulDO.setTime(DateUtil.dateToStr(DateUtil.getNextDay1(new Date(), day*(i+1)), "yyyy年MM月dd日"));
                deviceOverhaulDO.setCreateTime(new Date());
                deviceOverhaulDO.setUpdateTime(new Date());
                deviceOverhaulDOS.add(deviceOverhaulDO);
            }
            deviceOverhaulDao.save(deviceOverhaulDOS);
        }
        return patientDeviceDO;
    }
    /**
@ -365,4 +404,37 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
        }
        iotPatientDeviceDao.save(patientDeviceDOList);
    }
    @Transactional
    public void delPatientDevice(String id, Integer del) {
        IotPatientDeviceDO patientDeviceDO = iotPatientDeviceDao.findOne(id);
        patientDeviceDO.setDel(del);
        iotPatientDeviceDao.save(patientDeviceDO);
        //更新设备绑定状态,加库存
        iotDeviceDao.updateIsGrantById(patientDeviceDO.getDeviceId(), 0);
        if(del == -1){
            //核销设备
            iotDeviceDao.updateDelById(patientDeviceDO.getDeviceId(), 0);
        }
    }
    public MixEnvelop<IotPatientDeviceVO,IotPatientDeviceVO> getOverhaulDeviceList(String deviceSn, String patientName, Integer page, Integer pageSize) {
        String sql = "SELECT DISTINCT d.* FROM `iot_patient_device` d , iot_device_overhaul o where d.del= 1 and  d.id = o.patient_device_id ";
        if(StringUtils.isNotBlank(deviceSn)){
            sql += "and d.device_sn like '%" + deviceSn + "'% ";
        }
        if(StringUtils.isNotBlank(patientName)){
            sql += "and d.patientName like '%" + patientName + "'% ";
        }
        //判断是否需要分页
        if (page != null && pageSize != null) {
            Long count = Long.valueOf(jdbcTempalte.queryForList(sql).size());
            sql += "limit " + (page - 1) * pageSize + "," + pageSize;
            List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
            return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find, deviceVOList, page, pageSize, count);
        } else {
            List<IotPatientDeviceVO> deviceVOList = jdbcTempalte.query(sql, new BeanPropertyRowMapper<>(IotPatientDeviceVO.class));
            return MixEnvelop.getSuccessList(IotRequestMapping.Common.message_success_find, deviceVOList);
        }
    }
}

+ 10 - 10
svr/svr-iot/src/main/java/com/yihu/iot/service/dict/IotSystemDictService.java

@ -51,18 +51,18 @@ public class IotSystemDictService extends BaseJpaService<IotSystemDictDO,IotSyst
                dictDO.setValue(value);
                dictDO.setParentCode(parentCode);
                dictDO.setUpdateTime(new Date());
            }
        }else {
            //获取最近一条添加记录的code
            List<IotSystemDictDO> dictDOList = iotSystemDictDao.getAllByDictNameAndOrderByCodeDesc(dictDO.getDictName());
            if (dictDOList.size() > 0) {
                dictDO.setCode((Long.parseLong(dictDOList.get(0).getCode()) + 1) + "");
            } else {
                //获取最近一条添加记录的code
                List<IotSystemDictDO> dictDOList = iotSystemDictDao.getAllByDictNameAndOrderByCodeDesc(dictDO.getDictName());
                if (dictDOList.size() > 0) {
                    dictDO.setCode((Long.parseLong(dictDOList.get(0).getCode()) + 1) + "");
                } else {
                    dictDO.setCode("1");
                }
                dictDO.setSaasId(getCode());
                dictDO.setDel(1);
                dictDO.setCreateTime(new Date());
                dictDO.setCode("1");
            }
            dictDO.setSaasId(getCode());
            dictDO.setDel(1);
            dictDO.setCreateTime(new Date());
        }
        iotSystemDictDao.save(dictDO);
        return dictDO;