Commit a45b1c62 by YANGYANG

用户管理 终版提交

parent 5da72e86
......@@ -16,7 +16,7 @@ import java.io.Serializable;
*/
@Data
@ApiModel(value="device对象", description="device对象")
public class device implements Serializable {
public class Device implements Serializable {
private static final long serialVersionUID = 1L;
......
package com.founder.commonutils.zdryEntity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.founder.commonutils.ZdryApiEntity.Device;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
......@@ -19,78 +11,27 @@ import java.util.Date;
* </p>
*
* @author yangyang
* @since 2021-05-30
* @since 2021-05-31
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="Users对象", description="")
@ApiModel(value="UsersAndDevice对象", description="UsersAndDevice对象")
public class UsersAndDevice implements Serializable {
private Users users;
private Device device;
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "姓名")
private String xm;
@ApiModelProperty(value = "性别 1男 2女 0未知")
private Integer xb;
@ApiModelProperty(value = "家庭住址")
private String jtZz;
@ApiModelProperty(value = "是否有前科 1是 0否")
private Integer sfyQk;
@ApiModelProperty(value = "现住址")
private String xzz;
@ApiModelProperty(value = "病史")
private String bs;
@ApiModelProperty(value = "病情等级 1低 2中 3高 4极高")
private Integer bqDj;
@ApiModelProperty(value = "监护人1姓名")
private String jhr1Xm;
@ApiModelProperty(value = "监护人1关系")
private String jhr1Gx;
@ApiModelProperty(value = "监护人1联系电话")
private String jhr1Lxdh;
@ApiModelProperty(value = "监护人1紧急电话")
private String jhr1Jjdh;
@ApiModelProperty(value = "监护人2姓名")
private String jhr2Xm;
@ApiModelProperty(value = "监护人2关系")
private String jhr2Gx;
@ApiModelProperty(value = "监护人2联系电话")
private String jhr2Lxdh;
@ApiModelProperty(value = "监护人2紧急电话")
private String jhr2Jjdh;
@ApiModelProperty(value = "设备IMEI")
@TableId(value = "sb_imei", type = IdType.ID_WORKER_STR)
private String sbImei;
@ApiModelProperty(value = "设备型号")
private String sbXh;
@ApiModelProperty(value = "登记时间")
@TableField(fill = FieldFill.INSERT)
private Date djsj;
@ApiModelProperty(value = "改写时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gxsj;
public Users getUsers() {
return users;
}
@ApiModelProperty(value = "信息删除判断标志 1删除 0未删除")
private Integer xxscPdbz;
public void setUsers(Users users) {
this.users = users;
}
public Device getDevice() {
return device;
}
public void setDevice(Device device) {
this.device = device;
}
}
......@@ -3,11 +3,13 @@ package com.founder.zdry;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = {"com.founder"})
@EnableDiscoveryClient
@EnableFeignClients
public class ZdryApplication {
......
......@@ -6,7 +6,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.publicEntity.ResultCode;
import com.founder.commonutils.zdryEntity.Users;
import com.founder.zdry.fegin.fegin.ServerZdryApi;
import com.founder.commonutils.zdryEntity.UsersAndDevice;
import com.founder.zdry.fegin.ServerZdryApi;
import com.founder.zdry.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -83,36 +84,50 @@ public class UsersController {
public MapRestResult getById(
@ApiParam(name = "sbimei", value = "设备IMEI", required = true)
@PathVariable String sbimei){
UsersAndDevice usersAndDevice = new UsersAndDevice();
Users users = usersService.getById(sbimei);
return MapRestResult.build(ResultCode.SUCCESS,"成功获取用户信息","1",users);
usersAndDevice.setUsers(users);
usersAndDevice.setDevice(serverZdryApi.getDevice(sbimei));
return MapRestResult.build(ResultCode.SUCCESS,"成功获取用户信息","1",usersAndDevice);
}
@ApiOperation(value = "新增用户")
@PostMapping("/saveUsers")
public MapRestResult saveUsers(@ApiParam(name = "users", value = "用户对象", required = true)
@RequestBody Users users) {
boolean flag = usersService.save(users);
if(flag){
return MapRestResult.build(ResultCode.SUCCESS,"成功保存用户信息","1");
public MapRestResult saveUsers(@ApiParam(name = "UsersAndDevice", value = "用户对象", required = true)
@RequestBody UsersAndDevice usersAndDevice) {
// 调用开关接口
String result = serverZdryApi.updateDevice(usersAndDevice.getDevice());
if(result.equals("success")){
boolean flag = usersService.save(usersAndDevice.getUsers());
if(flag){
return MapRestResult.build(ResultCode.SUCCESS,"成功保存用户信息","1");
}else{
return MapRestResult.build(ResultCode.ERROR,"保存用户信息失败","1");
}
}else{
return MapRestResult.build(ResultCode.ERROR,"保存用户信息失败","1");
return MapRestResult.build(ResultCode.ERROR,"保存用户开关信息失败","1");
}
}
@ApiOperation(value = "根据设备IMEI修改用户信息")
@PostMapping("/updateUsersBySbImei")
public MapRestResult savePermission(@ApiParam(name = "users", value = "用户对象", required = true)
@RequestBody Users users) {
boolean flag = usersService.updateById(users);
if(flag){
return MapRestResult.build(ResultCode.SUCCESS,"成功修改用户信息","1");
public MapRestResult savePermission(@ApiParam(name = "UsersAndDevice", value = "用户对象", required = true)
@RequestBody UsersAndDevice usersAndDevice) {
// 调用开关接口
String result = serverZdryApi.updateDevice(usersAndDevice.getDevice());
if(result.equals("success")){
boolean flag = usersService.updateById(usersAndDevice.getUsers());
if(flag){
return MapRestResult.build(ResultCode.SUCCESS,"成功修改用户信息","1");
}else{
return MapRestResult.build(ResultCode.ERROR,"修改用户开关信息失败","1");
}
}else{
return MapRestResult.build(ResultCode.ERROR,"修改用户信息失败","1");
}
}
......
package com.founder.zdry.fegin.fegin;
package com.founder.zdry.fegin;
import com.founder.commonutils.ZdryApiEntity.device;
import com.founder.zdry.fegin.fegin.fallback.FallBackZdryApi;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.zdry.fegin.fallback.FallBackZdryApi;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
/**
* Created by yyon 2021/05/31
* 调用zdryapi子系统
......@@ -16,9 +14,9 @@ import java.util.Map;
@FeignClient(value = "zdryapi", fallback = FallBackZdryApi.class)
public interface ServerZdryApi {
@RequestMapping("/zdryapi/getDevice")
public Map<String, Object> getDevice(@RequestParam(value = "deviceId") String deviceId);
@PostMapping("/zdryapi/getDevice")
Device getDevice(@RequestParam(value = "deviceId") String deviceId);
@RequestMapping("/zdryapi/updateDevice")
public Map<String, Object> updateDevice(@RequestBody device deviceParam);
@PostMapping("/zdryapi/updateDevice")
String updateDevice(@RequestBody Device deviceParam);
}
package com.founder.zdry.fegin.fallback;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.zdry.fegin.ServerZdryApi;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Created by yangyang on 2021/05/31
* 调用ZdryApi子系统异常反馈
**/
@Component
public class FallBackZdryApi implements ServerZdryApi {
@Override
public Device getDevice(@RequestParam(value = "deviceId") String deviceId) {
return null;
}
@Override
public String updateDevice(@RequestBody Device deviceParam) {
return "zdryapi服务器发生异常,断路器进行反馈";
}
}
\ No newline at end of file
package com.founder.zdry.fegin.fegin.fallback;
import com.founder.commonutils.ZdryApiEntity.device;
import com.founder.zdry.fegin.fegin.ServerZdryApi;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* Created by yyon 2021/05/31
* 调用zdryapi子系统
**/
@Component
public class FallBackZdryApi implements ServerZdryApi {
@Override
public Map<String, Object> getDevice(String deviceId) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("msg", "server-bz服务器发生异常,断路器进行反馈");
return map;
}
@Override
public Map<String, Object> updateDevice(device deviceParam) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("msg", "server-bz服务器发生异常,断路器进行反馈");
return map;
}
}
\ No newline at end of file
package com.founder.zdryapi.controller;
import com.founder.commonutils.ZdryApiEntity.device;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.zdryapi.service.ZdryApiService;
import io.swagger.annotations.Api;
......@@ -37,9 +37,9 @@ public class ZdryApiController {
@ApiOperation(value = "查看指定设备接口")
@PostMapping(value = "/getDevice")
public MapRestResult getDevice(@RequestParam(value = "deviceId") String deviceId) {
public Device getDevice(@RequestParam(value = "deviceId") String deviceId) {
long startTime=new Date().getTime();
MapRestResult result=zdryApiService.getDevice(deviceId);
Device result=zdryApiService.getDevice(deviceId);
long endTime=new Date().getTime();
long timeDiffer=endTime-startTime;
System.out.println("查看指定设备接口**请求时长**********"+timeDiffer+"毫秒");
......@@ -48,7 +48,7 @@ public class ZdryApiController {
@ApiOperation(value = "修改指定设备接口")
@PostMapping(value = "/updateDevice")
public MapRestResult updateDevice(@RequestBody device deviceParam) {
public String updateDevice(@RequestBody Device deviceParam) {
return zdryApiService.updateDevice(deviceParam);
}
}
......
package com.founder.zdryapi.service;
import com.founder.commonutils.ZdryApiEntity.device;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.commonutils.publicEntity.MapRestResult;
/**
......@@ -15,7 +15,7 @@ public interface ZdryApiService {
String getToken();
MapRestResult getDevice(String deviceId);
Device getDevice(String deviceId);
MapRestResult updateDevice(device deviceParam);
String updateDevice(Device deviceParam);
}
package com.founder.zdryapi.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.founder.commonutils.ZdryApiEntity.device;
import com.founder.commonutils.publicEntity.MapRestResult;
import com.founder.commonutils.ZdryApiEntity.Device;
import com.founder.zdryapi.service.ZdryApiService;
import org.apache.commons.lang3.StringUtils;
......@@ -49,8 +48,8 @@ public class ZdryApiServiceImpl implements ZdryApiService {
@Autowired
private RestTemplate restTemplate;
public MapRestResult getDevice(String deviceId){
device d = new device();
public Device getDevice(String deviceId){
Device device = new Device();
try {
String resultString = restTemplate.getForEntity(zdryUrl+sbxxUrl+deviceId,String.class).getBody();
if (StringUtils.isNotEmpty(resultString)) {
......@@ -61,7 +60,7 @@ public class ZdryApiServiceImpl implements ZdryApiService {
if(getToken().equals("success")){
getDevice(deviceId);
}else{
return MapRestResult.build(200,"查看设备信息失败",1);
return device;
};
}
if (result.containsKey("obj")) {
......@@ -71,35 +70,35 @@ public class ZdryApiServiceImpl implements ZdryApiService {
String track_enable = dataObject.getString("track_enable");
String heartrate_enable = dataObject.getString("heartrate_enable");
if(pedometer_enable.equals("true")){
d.setPedometer_enable(1);
device.setPedometer_enable(1);
}else{
d.setPedometer_enable(0);
device.setPedometer_enable(0);
}
if(sleep_enable.equals("true")){
d.setSleep_enable(1);
device.setSleep_enable(1);
}else{
d.setSleep_enable(0);
device.setSleep_enable(0);
}
if(track_enable.equals("true")){
d.setTrack_enable(1);
device.setTrack_enable(1);
}else{
d.setTrack_enable(0);
device.setTrack_enable(0);
}
if(heartrate_enable.equals("true")){
d.setHeartrate_enable(1);
device.setHeartrate_enable(1);
}else{
d.setHeartrate_enable(0);
device.setHeartrate_enable(0);
}
d.setSbImei(deviceId);
device.setSbImei(deviceId);
}
}
}catch (Exception e){
e.printStackTrace();
}
return MapRestResult.build(200,"查看设备信息成功",d);
return device;
}
public MapRestResult updateDevice(device deviceParam){
public String updateDevice(Device deviceParam){
try {
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json");
......@@ -108,8 +107,8 @@ public class ZdryApiServiceImpl implements ZdryApiService {
JSONObject json = new JSONObject();
json.put("heartrate_enable",deviceParam.getHeartrate_enable());
json.put("pedometer_enable",deviceParam.getPedometer_enable());
json.put("Sleep_enable",deviceParam.getSleep_enable());
json.put("Track_enable",deviceParam.getTrack_enable());
json.put("sleep_enable",deviceParam.getSleep_enable());
json.put("track_enable",deviceParam.getTrack_enable());
HttpEntity<JSONObject> params = new HttpEntity<>(json, headers);
String resultString = restTemplate.postForEntity(zdryUrl+updateSbxxUrl+deviceParam.getSbImei()+"/4g/edit/", params, String.class).getBody();
JSONObject result = JSONObject.parseObject(resultString);
......@@ -119,16 +118,16 @@ public class ZdryApiServiceImpl implements ZdryApiService {
if(getToken().equals("success")){
updateDevice(deviceParam);
}else{
return MapRestResult.build(200,"修改设备信息失败",1);
return "error";
};
}
if (result.containsKey("success")) {
return MapRestResult.build(200,"修改设备信息成功",1);
return "success";
}
}catch (Exception e){
e.printStackTrace();
}
return MapRestResult.build(200,"修改设备信息成功",1);
return "success";
}
public String getToken() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment