screen-api/src/main/java/com/moral/api/controller/AppDevicController.java
New file @@ -0,0 +1,66 @@ package com.moral.api.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.List; import java.util.Map; import com.moral.api.entity.Device; import com.moral.api.entity.Organization; import com.moral.api.service.DeviceService; import com.moral.api.service.OrganizationService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.sun.org.apache.regexp.internal.RE; @Slf4j @Api(tags = {"小程序设备管理"}) @RestController @RequestMapping("/AppDevice") public class AppDevicController { @Autowired private OrganizationService organizationService; @Autowired private DeviceService deviceService; @GetMapping("selectOrganization") @ApiOperation(value = "小程序获取组织") public ResultMessage selectOrganization(){ List<Organization> organizations = organizationService.getOrganizations(); return ResultMessage.ok(organizations); } @GetMapping("selectDevice") @ApiOperation(value = "小程序获取设备") public ResultMessage selectDevice(@RequestParam @ApiParam(value = "organizationId",name = "组织ID") Integer organizationId){ List<Device> organizationDevice = deviceService.getOrganizationDevice(organizationId); if (ObjectUtils.isEmpty(organizationDevice)){ return ResultMessage.fail(ResponseCodeEnum.TARGET_IS_NULL.getCode(), ResponseCodeEnum.TARGET_IS_NULL.getMsg()); } return ResultMessage.ok(organizationDevice); } @GetMapping("fuzzySearch") @ApiOperation(value = "小程序模糊搜索") public ResultMessage fuzzySearch(@RequestParam @ApiParam(value = "mac",name = "设备mac号") String mac){ List<Device> devices = deviceService.getFuzzySearch(mac); return ResultMessage.ok(devices); } } screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -364,13 +364,6 @@ map.put("date2",params.get("date2").toString()); // map.put("data",params.get("data").toString()); compile.render(map); // response.addHeader("Access-Contro1-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Origin","*");//允许所有请求跨域 response.setHeader("Access-Control-Allow-Methods", "*");//允许跨域的请求方法GET, POST, HEAD 等 response.setHeader("Access-Control-Allow-Headers", "*");//允许跨域的请求头 response.setHeader("Access-Control-Allow-Credentials", "true");//是否携带cooki compile.write(response.getOutputStream()); compile.close(); } catch (IOException e) { screen-api/src/main/java/com/moral/api/pojo/vo/device/OrganizationVO.java
New file @@ -0,0 +1,14 @@ package com.moral.api.pojo.vo.device; import lombok.Data; import java.io.Serializable; @Data public class OrganizationVO implements Serializable { private Integer id; private String name; } screen-api/src/main/java/com/moral/api/pojo/vo/user/QxUser.java
@@ -31,4 +31,9 @@ * 所属部门责任单位 */ private Integer unitId; /** * 组织id */ private Integer organizationId; } screen-api/src/main/java/com/moral/api/service/DeviceService.java
@@ -51,4 +51,18 @@ */ Device getDeviceUnitAlramInforByMac(String mac); /** * 模糊查询 * @param mac * @return */ List<Device> getFuzzySearch(String mac); /** * 根据组织查询设备 * @param id * @return */ List<Device> getOrganizationDevice(Integer id); } screen-api/src/main/java/com/moral/api/service/OrganizationService.java
@@ -33,4 +33,13 @@ */ Organization getOrganizationById(Integer id); /** * 根据用户查询组织 * @return */ List<Organization> getOrganizations(); } screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.config.mybatis.MybatisPlusConfig; import com.moral.api.entity.*; @@ -495,6 +496,40 @@ return device; } /** * 模糊查询 * * @param mac * @return */ @Override public List<Device> getFuzzySearch(String mac) { LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(); if (ObjectUtils.isEmpty(mac)){ return null; } wrapper.eq(Device::getIsDelete,Constants.NOT_DELETE); wrapper.like(Device::getMac,mac); List<Device> devices = deviceMapper.selectList(wrapper); return devices; } /** * 根据组织查询设备 * * @param id * @return */ @Override public List<Device> getOrganizationDevice(Integer id) { LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Device::getOrganizationId,id); wrapper.eq(Device::getIsDelete,Constants.NOT_DELETE); wrapper.orderByAsc(Device::getCreateTime); List<Device> devices = deviceMapper.selectList(wrapper); return devices; } private Device getDeviceUnitAlramInforByMacFromDb(String mac){ QueryWrapper<Device> wrapper = new QueryWrapper<>(); wrapper.eq("mac",mac); screen-api/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -1,8 +1,10 @@ package com.moral.api.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.moral.api.config.Interceptor.UserHelper; import com.moral.api.entity.Organization; import com.moral.api.mapper.OrganizationMapper; import com.moral.api.pojo.vo.user.QxUser; import com.moral.api.service.OrganizationService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.constant.Constants; @@ -40,6 +42,25 @@ return organizationMapper.selectById(id); } /** * 根据用户查询组织 * * @return */ @Override public List<Organization> getOrganizations() { QueryWrapper<Organization> wrapper = new QueryWrapper<>(); wrapper.select("id","name"); QxUser user = UserHelper.getCurrentUser(); Integer organizationId = user.getOrganizationId(); if (organizationId!=24){ wrapper.eq("id",user.getOrganizationId()); } wrapper.eq("is_delete",Constants.NOT_DELETE); List<Organization> organizations = organizationMapper.selectList(wrapper); return organizations; } /** * @Description: 通过父组织查询下面所有的子组织放到children中 screen-api/src/main/java/com/moral/api/service/impl/UserServiceImpl.java
@@ -105,6 +105,7 @@ userInfo.put("wechat", userBo.getWechat()); userInfo.put("expireTime", DateUtils.dateToDateString(userBo.getExpireTime())); userInfo.put("isAdmin", userBo.getIsAdmin()); userInfo.put("organizationId",userBo.getOrganizationId()); userInfo.put("openid", openId); try { @@ -173,6 +174,7 @@ userInfo.put("mobile", user.getMobile()); userInfo.put("unitId",user.getUnitId()); // userInfo.put("unName",user.getAreaName()); userInfo.put("organizationId",user.getOrganizationId()); userInfo.put("wechat", user.getWechat()); userInfo.put("expireTime", DateUtils.dateToDateString(user.getExpireTime())); userInfo.put("isAdmin", user.getIsAdmin());