Bläddra i källkod

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

wangzhinan 4 år sedan
förälder
incheckning
51f265a73c

+ 24 - 12
svr/svr-base/src/main/java/com/yihu/jw/base/service/user/UserService.java

@ -35,6 +35,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.util.*;
import java.util.logging.Logger;
@ -765,14 +766,18 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
                "\t\tbase_role ROLE\n" +
                "\tWHERE\n" +
                "\t\tusr .saas_id = saas. ID\n" +
                "\tAND usr .role_id = ROLE . ID\n" +
                "\tAND (usr . NAME LIKE '%%' OR '' = '%%')\n" +
                "\tAND (saas. ID = '' OR '' = '')\n" +
                "\tAND (usr .role_id = '' OR '' = '')\n" +
                "\tORDER BY\n" +
                "\t\tusr .create_time DESC";
                "\tAND usr .role_id = ROLE . ID\n" ;
                if(!realName.equals(null) && !realName.equals("")){
                    finalSql = finalSql + " and usr . NAME LIKE '%"+realName+"%'";
                }
                if(!saasidValue.equals(null) && !saasidValue.equals("")){
                    finalSql = finalSql + " and saas. id = '"+saasidValue+"'";
                }
                if(!roleIdValue.equals(null) && !roleIdValue.equals("")){
                    finalSql = finalSql + " and usr .role_id = '"+roleIdValue+"'";
                }
                finalSql = finalSql + " ORDER BY usr .create_time DESC";
        Logger.getAnonymousLogger().info("finalSql="+finalSql);
        String sql = finalSql
                .replace("{realName}","%" + realName + "%")
                .replace("{saasid}",saasidValue)
@ -823,10 +828,17 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
                "WHERE " +
                "  usr.saas_id = saas.id " +
                "  AND " +
                "  usr.role_id = role.id " +
                " and (usr.name like '{realName}' or '' ='{realName}') " +
                "  and (saas.id = '{saasid}' or '' = '{saasid}') " +
                "  and ( usr.role_id = '{roleId}' or '' = '{roleId}') ";
                "  usr.role_id = role.id " ;
                if(!realName.equals(null) && !realName.equals("")){
                    countSql = countSql + " and usr . NAME LIKE '%"+realName+"%'";
                }
                if(!saasidValue.equals(null) && !saasidValue.equals("")){
                    countSql = countSql + " and saas. id = '"+saasidValue+"'";
                }
                if(!roleIdValue.equals(null) && !roleIdValue.equals("")){
                    countSql = countSql + " and usr .role_id = '"+roleIdValue+"'";
                }
        Logger.getAnonymousLogger().info("countSql="+countSql);
        String finalCountSql = countSql
                .replace("{realName}", "%" + realName + "%")
                .replace("{saasid}",  saasidValue )

+ 72 - 51
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/WlyyDeviceController.java

@ -122,61 +122,82 @@ public class WlyyDeviceController extends BaseController {
    private IotPatientDeviceService iotPatientDeviceService;
    /**
     * 设备删除
     * 设备删除     屏蔽部分为患者端解绑设备
     */
    @ApiOperation("设备删除")
    @RequestMapping(value = "DeletePatientDevice",method = {RequestMethod.GET,RequestMethod.POST})
    @RequestMapping(value = "deletePatientDevice",method = {RequestMethod.POST})
    @ResponseBody
    public String delete(@ApiParam(name = "id", value = "删除设备关联ID")
                         @RequestParam(value = "id", required = true) String id) {
        try {
            PatientDevice pd = iotPatientDeviceService.findId(id);
            if (pd != null) {
                if (!StringUtils.equals(pd.getUser(), getRepUID())) {
                    return error(1,"只允许删除自己的设备!");
                }
                iotPatientDeviceService.deleteDevice(id, getRepUID());
                //居民自主解绑设备时发送消息给医生
                Patient patient = iotPatientDeviceService.findByCode(pd.getUser());   //getRepUID()
                SignFamily signFamily = iotPatientDeviceService.findDoctor(patient.getCode());
                String messageContent =  "您的居民"+patient.getName()+"解绑了";
                if ("1".equals(pd.getCategoryCode())){
                    messageContent +="血糖仪,点击下方查看居民详情";
                }else if ("2".equals(pd.getCategoryCode())){
                    messageContent +="血压计,点击下方查看居民详情";
                }else if ("4".equals(pd.getCategoryCode())){
                    messageContent +="智能手表,点击下方查看居民详情";
                }
                Message message = new Message();
                message.setCzrq(new Date());
                message.setCreateTime(new Date());
                message.setContent(messageContent);
                message.setRead(1);//设置未读
                message.setReceiver(signFamily.getDoctor());//设置接受医生的code
                message.setSender("admin");//设置发送的用户
                message.setSenderName("系统");
                message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
                message.setSenderPhoto("");
                message.setTitle("解绑设备消息");
                message.setType(301);//解绑设备消息
                message.setReadonly(1);//是否只读消息
                message.setSex(1);
                message.setRelationCode(patient.getCode());
                message.setOver("1");//未处理
                message.setData("");
                message.setDel("1");
                iotPatientDeviceService.saveMessage(message);
                //全部解绑后去判断就更新设备表中是否绑定字段
                iotPatientDeviceService.savePatientDeviceLog(pd,pd.getDeviceSn(),2,2);
                iotPatientDeviceService.unBindUpdateIsBinding(pd.getDeviceSn());
                return success("设备已删除!");
            } else {
                return error(-1, "不存在该设备!");
    public String delete(
            @ApiParam(name="deviceSn",value="设备SN")
            @RequestParam(value="deviceSn",required = true) String deviceSn,
            @ApiParam(name="type",value="设备类型")
            @RequestParam(value="type",required = true) String type
//            @ApiParam(name = "id", value = "删除设备关联ID")
//                         @RequestParam(value = "id", required = true) String id
    ) {
//        try {
//            PatientDevice pd = iotPatientDeviceService.findId(id);
//            if (pd != null) {
//                if (!StringUtils.equals(pd.getDoctor(), getRepUID())) {//user:915f019b-5b1d-11e6-8344-fa163e8aee56
//                    return error(1,"只允许删除自己的设备!");
//                }
//                iotPatientDeviceService.deleteDevice(id, getRepUID());
//                //居民自主解绑设备时发送消息给医生
//                Patient patient = iotPatientDeviceService.findByCode(pd.getUser());   //getRepUID()
//
//                SignFamily signFamily = iotPatientDeviceService.findDoctor(patient.getCode());
//                String messageContent =  "您的居民"+patient.getName()+"解绑了";
//                if ("1".equals(pd.getCategoryCode())){
//                    messageContent +="血糖仪,点击下方查看居民详情";
//                }else if ("2".equals(pd.getCategoryCode())){
//                    messageContent +="血压计,点击下方查看居民详情";
//                }else if ("4".equals(pd.getCategoryCode())){
//                    messageContent +="智能手表,点击下方查看居民详情";
//                }
//                Message message = new Message();
//                message.setCzrq(new Date());
//                message.setCreateTime(new Date());
//                message.setContent(messageContent);
//                message.setRead(1);//设置未读
//                message.setReceiver(signFamily.getDoctor());//设置接受医生的code
//                message.setSender("admin");//设置发送的用户
//                message.setSenderName("系统");
//                message.setCode(UUID.randomUUID().toString().replaceAll("-", ""));
//                message.setSenderPhoto("");
//                message.setTitle("解绑设备消息");
//                message.setType(301);//解绑设备消息
//                message.setReadonly(1);//是否只读消息
//                message.setSex(1);
//                message.setRelationCode(patient.getCode());
//                message.setOver("1");//未处理
//                message.setData("");
//                message.setDel("1");
//                iotPatientDeviceService.saveMessage(message);
//                //全部解绑后去判断就更新设备表中是否绑定字段
//                iotPatientDeviceService.savePatientDeviceLog(pd,pd.getDeviceSn(),2,2);
//                iotPatientDeviceService.unBindUpdateIsBinding(pd.getDeviceSn());
//                return success("设备已删除!");
//            } else {
//                return error(-1, "不存在该设备!");
//            }
//        } catch (Exception ex) {
//            error(ex);
//            return invalidUserException(ex, -1, ex.getMessage());
//        }
        try{
            List<PatientDevice> patientDevices = iotPatientDeviceService.findByDeviceSnAndCategory(deviceSn, type);
            PatientDevice patientDevice = new PatientDevice();
            if (patientDevices!=null && patientDevices.size()>0){
                patientDevice = patientDevices.get(0);
            }
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, ex.getMessage());
            iotPatientDeviceService.deleteDevices(deviceSn,type);
            //全部解绑后去判断就更新设备表中是否绑定字段
            iotPatientDeviceService.savePatientDeviceLog(patientDevice,deviceSn,1,2);
            iotPatientDeviceService.unBindUpdateIsBinding(deviceSn);
            return write(200,"解绑成功!");
        }catch (Exception e){
            error(e);
            return write(-1,e.getMessage());
        }
    }
}

+ 18 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -775,4 +775,22 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
            //deviceDetailDao.updateUnbindAll(2,deviceSn);
        }
    }
    public List<PatientDevice> findByDeviceSnAndCategory(String deviceSn, String categoryCode){
        String sqlFind = "select * from wlyy.wlyy_patient_device where device_sn='"+deviceSn +"' and category_code="+categoryCode;
        List<PatientDevice> patientDevices = jdbcTempalte.query(sqlFind , new BeanPropertyRowMapper<>(PatientDevice.class));
        return patientDevices;
    }
    public void deleteDevices(String deviceSn, String type) {
        String sqlFind = "select * from wlyy.wlyy_patient_device where device_sn='"+deviceSn +"' and category_code="+type;
        List<PatientDevice> patientDevices = jdbcTempalte.query(sqlFind , new BeanPropertyRowMapper<>(PatientDevice.class));
        if (patientDevices == null || patientDevices.size() == 0) {
            throw new RuntimeException("设备未被绑定!");
        }
        for (PatientDevice patientDevice : patientDevices) {
            String sqlDel = "delete from wlyy.wlyy_patient_device where id="+patientDevice.getId() ;
            jdbcTempalte.execute(sqlDel);
        }
    }
}