Commit 46500bff by zzrdark

1.增加页面

2.系统管理大模块的修改
3.设备控制模块
parent d95f6ed4
...@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; ...@@ -4,6 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mx.cneeds.server.entity.ProductSeriesEntity; import com.mx.cneeds.server.entity.ProductSeriesEntity;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import java.util.Map;
/** /**
* *
* *
...@@ -13,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -13,5 +16,7 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface ProductSeriesDao extends BaseMapper<ProductSeriesEntity> { public interface ProductSeriesDao extends BaseMapper<ProductSeriesEntity> {
List<ProductSeriesEntity> queryList(Map<String, Object> params);
} }
...@@ -24,4 +24,9 @@ public interface SysUserDeptDao extends BaseMapper<SysUserDeptEntity> { ...@@ -24,4 +24,9 @@ public interface SysUserDeptDao extends BaseMapper<SysUserDeptEntity> {
* 根据角色ID,获取部门ID列表 * 根据角色ID,获取部门ID列表
*/ */
List<Long> queryDeptIdList(Long userId); List<Long> queryDeptIdList(Long userId);
/**
* 根据角色ID,获取部门ID列表
*/
List<Long> queryDeptId(Long userId);
} }
package com.mx.cneeds.server.entity; package com.mx.cneeds.server.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
...@@ -24,49 +25,66 @@ public class DeviceInfoEntity implements Serializable { ...@@ -24,49 +25,66 @@ public class DeviceInfoEntity implements Serializable {
*/ */
@TableId @TableId
private Long deviceId; private Long deviceId;
/** /**
* *
*/ */
private Long deptId; private Long deptId;
/** /**
* imei * imei
*/ */
private String imei; private String imei;
/** /**
* iccid * iccid
*/ */
private String iccid; private String iccid;
/** /**
* 状态0未激活,1已激活 * 状态0未激活,1已激活
*/ */
private String status; private String status;
/** /**
* 设备版本 * 设备版本
*/ */
private String deviceVersion; private String deviceVersion;
/** /**
* 产品系列 * 产品系列
*/ */
private Long seriesId; private Long seriesId;
/** /**
* 创建时间 * 创建时间
*/ */
private Date createTime; private Date createTime;
/** /**
* 激活时间 * 激活时间
*/ */
private Date activeTime; private Date activeTime;
/** /**
* 渠道号 * 渠道号
*/ */
private String channelNums; private String channelNums;
/** /**
* 渠道号提示信息 * 渠道号提示信息
*/ */
private String channelNumsMessage; private String channelNumsMessage;
/** /**
* 0:黑名单,1:白名单 * 0:黑名单,1:白名单
*/ */
private Integer channelRules; private Integer channelRules;
/**
* 产品系列号
*/
@TableField( exist=false )
private String seriesNum;
} }
...@@ -12,4 +12,12 @@ ...@@ -12,4 +12,12 @@
</resultMap> </resultMap>
<select id="queryList" resultType="com.mx.cneeds.server.entity.ProductSeriesEntity">
select t1.* from product_series t1 where
1 = 1
<if test="sql_filter != null">
and ${sql_filter}
</if>
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -23,4 +23,9 @@ ...@@ -23,4 +23,9 @@
</select> </select>
<select id="queryDeptId" resultType="long">
select dept_id from sys_user_dept where user_id = #{userId}
</select>
</mapper> </mapper>
\ No newline at end of file
package com.mx.cneeds.common.dto;
import lombok.Data;
/**
* @ClassName DataFilterDto
* @Author zzrdark
* @Date 2020-03-20 18:18
* @Description TODO
**/
@Data
public class DataFilterDto {
/** 表的别名 */
private String tableAlias;
/** true:没有本部门数据权限,也能查询本人数据 */
private boolean user;
/** true:拥有子部门数据权限 */
private boolean subDept;
/** 部门ID */
private String deptId;
/** 用户ID */
private String userId;
private String username;
}
package com.mx.cneeds.common.dto;
import lombok.Data;
import java.util.List;
/**
* @ClassName DevicesVo
* @Author zzrdark
* @Date 2020-03-19 17:20
* @Description TODO
**/
@Data
public class DevicesDto {
/**
* 产品系列Id
*/
private Long seriesId;
/**
* 设备imeis
*/
private List<String> imeis;
/**
* 部门Id
*/
private Long deptId;
}
...@@ -23,6 +23,7 @@ public class DeviceChannelVo { ...@@ -23,6 +23,7 @@ public class DeviceChannelVo {
/** /**
* 名单规则 * 名单规则
* 0:黑名单,1:白名单
*/ */
private Integer channelRules; private Integer channelRules;
......
package com.mx.cneeds.common.vo;
import lombok.Data;
import java.util.List;
/**
* @ClassName DevicesVo
* @Author zzrdark
* @Date 2020-03-19 17:20
* @Description TODO
**/
@Data
public class DevicesVo {
/**
* 产品系列Id
*/
private Long seriesId;
/**
* 设备ids
*/
private List<String> imeis;
/**
* 部门Id
*/
private Long deptId;
}
...@@ -33,5 +33,6 @@ public @interface DataFilter { ...@@ -33,5 +33,6 @@ public @interface DataFilter {
/** 用户ID */ /** 用户ID */
String userId() default "user_id"; String userId() default "user_id";
} }
package com.mx.cneeds.server.anthorization.config; package com.mx.cneeds.server.anthorization.config;
import com.mx.cneeds.server.anthorization.service.MxJwtTokenEnhancer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
...@@ -12,10 +14,15 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.A ...@@ -12,10 +14,15 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.A
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore; import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import java.util.ArrayList;
import java.util.List;
@Configuration @Configuration
@EnableAuthorizationServer @EnableAuthorizationServer
public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdapter { public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdapter {
...@@ -33,11 +40,19 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap ...@@ -33,11 +40,19 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap
@Autowired @Autowired
private PasswordEncoder passwordEncoder; private PasswordEncoder passwordEncoder;
@Override @Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.authenticationManager(authenticationManager); endpoints.authenticationManager(authenticationManager);
endpoints.userDetailsService(myUserDetailsService); endpoints.userDetailsService(myUserDetailsService);
endpoints.tokenStore(jwtTokenStore()).accessTokenConverter(jwtAccessTokenConverter());
//配置jwt
TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
List<TokenEnhancer> enhancerList = new ArrayList();
enhancerList.add(jwtTokenEnhancer());
enhancerList.add(jwtAccessTokenConverter());
tokenEnhancerChain.setTokenEnhancers(enhancerList);
endpoints.tokenStore(jwtTokenStore()).tokenEnhancer(tokenEnhancerChain).accessTokenConverter(jwtAccessTokenConverter());
} }
/** /**
...@@ -57,6 +72,16 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap ...@@ -57,6 +72,16 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap
return converter; return converter;
} }
/**
* 用于扩展JWT
* @return
*/
@Bean
@ConditionalOnMissingBean(name = "jwtTokenEnhancer")
public TokenEnhancer jwtTokenEnhancer(){
return new MxJwtTokenEnhancer();
}
@Override @Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception { public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory() clients.inMemory()
...@@ -77,4 +102,5 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap ...@@ -77,4 +102,5 @@ public class OAuth2AuthorizationServer extends AuthorizationServerConfigurerAdap
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
security.passwordEncoder(new BCryptPasswordEncoder()); security.passwordEncoder(new BCryptPasswordEncoder());
} }
} }
\ No newline at end of file
package com.mx.cneeds.server.anthorization.service;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import java.util.HashMap;
import java.util.Map;
public class MxJwtTokenEnhancer implements TokenEnhancer {
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
Map<String, Object> info = new HashMap<>();
info.put("company", "美行科技");
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(info);
return accessToken;
}
}
\ No newline at end of file
package com.mx.cneeds.server.datashow.client; package com.mx.cneeds.server.datashow.client;
import com.mx.cneeds.common.dto.DevicesDto;
import com.mx.cneeds.common.dto.PageDto; import com.mx.cneeds.common.dto.PageDto;
import com.mx.cneeds.common.dto.SeriesDto; import com.mx.cneeds.common.dto.SeriesDto;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
...@@ -24,6 +25,9 @@ public interface DeviceClient { ...@@ -24,6 +25,9 @@ public interface DeviceClient {
@RequestParam("sidx") String orderField, @RequestParam("sidx") String orderField,
@RequestParam("order") String order); @RequestParam("order") String order);
@PostMapping("/device/series/listAll")
List<SeriesDto> seriesListAll();
@PostMapping("/device/series/save") @PostMapping("/device/series/save")
void addSeries(@RequestBody SeriesDto dto); void addSeries(@RequestBody SeriesDto dto);
...@@ -33,4 +37,21 @@ public interface DeviceClient { ...@@ -33,4 +37,21 @@ public interface DeviceClient {
@PostMapping("/device/series/delete") @PostMapping("/device/series/delete")
void deleteSeries(@RequestBody List<Long> ids); void deleteSeries(@RequestBody List<Long> ids);
@PostMapping("device/info/list")
PageDto deviceList(@RequestParam Integer page,
@RequestParam("limit") Integer pageSize,
@RequestParam("sidx") String orderField,
@RequestParam("order") String order);
@PostMapping("/device/info/importDevice")
void importDevice(@RequestBody DevicesDto dto);
@PostMapping("/device/info/updateDeviceSeriesBatch")
void updateDeviceSeriesBatch(@RequestBody DevicesDto dto);
@PostMapping("/device/info/delete")
void deleteDevice(@RequestBody List<Long> ids);
} }
package com.mx.cneeds.server.datashow.web.device; package com.mx.cneeds.server.datashow.web.device;
import com.mx.cneeds.common.converter.RequestParamterConverter; import com.mx.cneeds.common.converter.RequestParamterConverter;
import com.mx.cneeds.common.dto.DepartmentDto; import com.mx.cneeds.common.dto.*;
import com.mx.cneeds.common.dto.PageDto;
import com.mx.cneeds.common.dto.SeriesDto;
import com.mx.cneeds.common.result.R; import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.vo.DeviceChannelVo; import com.mx.cneeds.common.vo.DeviceChannelVo;
import com.mx.cneeds.common.vo.DevicesVo;
import com.mx.cneeds.common.vo.SeriesVo; import com.mx.cneeds.common.vo.SeriesVo;
import com.mx.cneeds.server.datashow.client.DeviceClient; import com.mx.cneeds.server.datashow.client.DeviceClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -40,6 +39,17 @@ public class DeviceController { ...@@ -40,6 +39,17 @@ public class DeviceController {
return new R().put("data",channelVo); return new R().put("data",channelVo);
} }
@PostMapping("/saveChannel")
public R saveChannel_nums(DeviceChannelVo channelVo){
DevicesDto devicesDto = new DevicesDto();
BeanUtils.copyProperties(channelVo,devicesDto);
deviceClient.updateDeviceSeriesBatch(devicesDto);
return new R().put("data",channelVo);
}
@PostMapping("/series/list") @PostMapping("/series/list")
public R seriesList(@RequestParam(required = false) Integer page, public R seriesList(@RequestParam(required = false) Integer page,
...@@ -73,6 +83,13 @@ public class DeviceController { ...@@ -73,6 +83,13 @@ public class DeviceController {
return new R().put("data",pageDto); return new R().put("data",pageDto);
} }
@PostMapping("/series/listAll")
public R selectSeries(){
List<SeriesDto> seriesDtos = deviceClient.seriesListAll();
return new R().put("data",seriesDtos);
}
@PostMapping("/series/add") @PostMapping("/series/add")
public R addSeries(SeriesVo seriesVo){ public R addSeries(SeriesVo seriesVo){
SeriesDto seriesDto = new SeriesDto(); SeriesDto seriesDto = new SeriesDto();
...@@ -102,7 +119,62 @@ public class DeviceController { ...@@ -102,7 +119,62 @@ public class DeviceController {
} }
@PostMapping("/device/list")
public R deviceList(@RequestParam(required = false) Integer page,
@RequestParam(required = false) Integer pageSize,
@RequestParam(required = false) String sort){
String orderField = null;
String order = null;
if (page==null || page==0){
page = new Integer(1);
}
if (pageSize==null || pageSize==0){
pageSize = new Integer(10);
}
if (StringUtils.isNotEmpty(sort) && StringUtils.isNotBlank(sort.trim())){
if (sort.contains("+")){
order = new String("asc");
}
if (sort.contains("-")){
order = new String("desc");
}
orderField = sort.substring(1);
orderField = RequestParamterConverter.toLine(orderField);
}
PageDto pageDto = deviceClient.deviceList(page,pageSize,orderField,order);
return new R().put("data",pageDto);
}
@PostMapping("/device/importDevice")
public R importDevice(DevicesVo devicesVo){
DevicesDto devicesDto = new DevicesDto();
BeanUtils.copyProperties(devicesVo,devicesDto);
deviceClient.importDevice(devicesDto);
return R.ok();
}
@PostMapping("/device/updateDeviceSeriesBatch")
public R updateDeviceSeriesBatch(DevicesVo devicesVo){
DevicesDto devicesDto = new DevicesDto();
BeanUtils.copyProperties(devicesVo,devicesDto);
deviceClient.updateDeviceSeriesBatch(devicesDto);
return R.ok();
}
@PostMapping("/device/delete")
public R deleteDevice(@RequestParam(value = "ids",required = false) List<Long> ids){
deviceClient.deleteDevice(ids);
return R.ok();
}
} }
...@@ -6,6 +6,7 @@ import org.springframework.boot.WebApplicationType; ...@@ -6,6 +6,7 @@ import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/** /**
* @ClassName DeviceApplication * @ClassName DeviceApplication
...@@ -16,6 +17,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient; ...@@ -16,6 +17,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication @SpringBootApplication
@EnableEurekaClient @EnableEurekaClient
@MapperScan("com.mx.cneeds.server.dao") @MapperScan("com.mx.cneeds.server.dao")
@EnableFeignClients
public class DeviceApplication { public class DeviceApplication {
public static void main(String[] args) { public static void main(String[] args) {
new SpringApplicationBuilder(DeviceApplication.class).web(WebApplicationType.SERVLET).run(args); new SpringApplicationBuilder(DeviceApplication.class).web(WebApplicationType.SERVLET).run(args);
......
package com.mx.cneeds.server.device.client;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(name = "CNEEDS-SERVER-USER")
public interface UserClient {
@PostMapping("sys/user/genDataFilter")
String genDataFilter(@RequestBody DataFilterDto dataFilterDto);
}
\ No newline at end of file
/**
* Copyright (c) 2016-2019 人人开源 All rights reserved.
*
* https://www.renren.io
*
* 版权所有,侵权必究!
*/
package com.mx.cneeds.server.device.common;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import com.mx.cneeds.common.exception.RRException;
import com.mx.cneeds.common.pager.Constant;
import com.mx.cneeds.server.device.client.UserClient;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* 数据过滤,切面处理类
*
* @author Mark sunlightcs@gmail.com
*/
@Aspect
@Component
public class DataFilterAspect {
@Autowired
private UserClient userClient;
@Pointcut("@annotation(com.mx.cneeds.common.annotation.DataFilter)")
public void dataFilterCut() {
}
@Before("dataFilterCut()")
public void dataFilter(JoinPoint point){
Object params = point.getArgs()[0];
if(params != null && params instanceof Map){
String username = (String) ((Map) params).get("login_username");
//如果不是超级管理员,则进行数据过滤
if(!Constant.STRING_SUPER_ADMIN.equals(username)){
Map map = (Map)params;
map.put(Constant.SQL_FILTER, getSQLFilter(username, point));
}
return ;
}
throw new RRException("数据权限接口,只能是Map类型参数,且不能为NULL");
}
/**
* 获取数据过滤的SQL
*/
private String getSQLFilter(String username, JoinPoint point){
MethodSignature signature = (MethodSignature) point.getSignature();
DataFilter dataFilter = signature.getMethod().getAnnotation(DataFilter.class);
DataFilterDto dataFilterDto = new DataFilterDto();
dataFilterDto.setDeptId(dataFilter.deptId());
dataFilterDto.setUserId(dataFilter.userId());
dataFilterDto.setUser(dataFilter.user());
dataFilterDto.setSubDept(dataFilter.subDept());
dataFilterDto.setTableAlias(dataFilter.tableAlias());
dataFilterDto.setUsername(username);
String sqlFilter = userClient.genDataFilter(dataFilterDto);
return sqlFilter;
}
}
package com.mx.cneeds.server.device.config;
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class MybatisPlusConfig {
/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
@Bean
public ISqlInjector sqlInjector() {
return new LogicSqlInjector();
}
}
\ No newline at end of file
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.server.entity.DeviceInfoEntity; import com.mx.cneeds.server.entity.DeviceInfoEntity;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -16,5 +17,7 @@ import java.util.Map; ...@@ -16,5 +17,7 @@ import java.util.Map;
public interface DeviceInfoService extends IService<DeviceInfoEntity> { public interface DeviceInfoService extends IService<DeviceInfoEntity> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
void updateBatchByImei(List<DeviceInfoEntity> deviceInfoEntityList);
} }
...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.server.entity.ProductSeriesEntity; import com.mx.cneeds.server.entity.ProductSeriesEntity;
import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
...@@ -16,5 +18,9 @@ import java.util.Map; ...@@ -16,5 +18,9 @@ import java.util.Map;
public interface ProductSeriesService extends IService<ProductSeriesEntity> { public interface ProductSeriesService extends IService<ProductSeriesEntity> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
List<ProductSeriesEntity> queryListById(Collection<Long> array);
List<ProductSeriesEntity> queryList(Map<String, Object> params);
} }
...@@ -4,9 +4,17 @@ import com.mx.cneeds.common.pager.PageUtils; ...@@ -4,9 +4,17 @@ import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.pager.Query; import com.mx.cneeds.common.pager.Query;
import com.mx.cneeds.server.dao.DeviceInfoDao; import com.mx.cneeds.server.dao.DeviceInfoDao;
import com.mx.cneeds.server.device.service.DeviceInfoService; import com.mx.cneeds.server.device.service.DeviceInfoService;
import com.mx.cneeds.server.device.service.ProductSeriesService;
import com.mx.cneeds.server.entity.DeviceInfoEntity; import com.mx.cneeds.server.entity.DeviceInfoEntity;
import com.mx.cneeds.server.entity.ProductSeriesEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -15,6 +23,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -15,6 +23,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@Service("deviceInfoService") @Service("deviceInfoService")
public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfoEntity> implements DeviceInfoService { public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfoEntity> implements DeviceInfoService {
@Autowired
private ProductSeriesService productSeriesService;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<DeviceInfoEntity> page = this.page( IPage<DeviceInfoEntity> page = this.page(
...@@ -22,7 +33,31 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfo ...@@ -22,7 +33,31 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoDao, DeviceInfo
new QueryWrapper<DeviceInfoEntity>() new QueryWrapper<DeviceInfoEntity>()
); );
Set<Long> set = new HashSet<>();
page.getRecords().forEach(deviceInfoEntity -> {
set.add(deviceInfoEntity.getSeriesId());
});
if (set.size() != 0){
List<ProductSeriesEntity> seriesEntityList = productSeriesService.queryListById(set);
page.getRecords().forEach(deviceInfoEntity -> {
seriesEntityList.forEach(seriesEntity -> {
if (deviceInfoEntity.getSeriesId().equals(seriesEntity.getSeriesId())){
deviceInfoEntity.setSeriesNum(seriesEntity.getSeriesNum());
}
});
});
}
return new PageUtils(page); return new PageUtils(page);
} }
@Override
public void updateBatchByImei(List<DeviceInfoEntity> deviceInfoEntityList) {
deviceInfoEntityList.forEach(deviceInfoEntity -> {
getBaseMapper().update(deviceInfoEntity,new QueryWrapper<DeviceInfoEntity>().eq("imei",deviceInfoEntity.getImei()));
});
}
} }
package com.mx.cneeds.server.device.service.impl; package com.mx.cneeds.server.device.service.impl;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.pager.Query; import com.mx.cneeds.common.pager.Query;
import com.mx.cneeds.server.dao.ProductSeriesDao; import com.mx.cneeds.server.dao.ProductSeriesDao;
import com.mx.cneeds.server.device.service.ProductSeriesService; import com.mx.cneeds.server.device.service.ProductSeriesService;
import com.mx.cneeds.server.entity.ProductSeriesEntity; import com.mx.cneeds.server.entity.ProductSeriesEntity;
import com.mx.cneeds.server.entity.SysRoleEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
...@@ -25,4 +30,16 @@ public class ProductSeriesServiceImpl extends ServiceImpl<ProductSeriesDao, Prod ...@@ -25,4 +30,16 @@ public class ProductSeriesServiceImpl extends ServiceImpl<ProductSeriesDao, Prod
return new PageUtils(page); return new PageUtils(page);
} }
@Override
public List<ProductSeriesEntity> queryListById(Collection<Long> array){
List<ProductSeriesEntity> productSeriesEntityList = getBaseMapper().selectBatchIds(array);
return productSeriesEntityList;
}
@Override
public List<ProductSeriesEntity> queryList(Map<String, Object> params) {
return baseMapper.queryList(params);
}
} }
package com.mx.cneeds.server.device.web; package com.mx.cneeds.server.device.web;
import java.util.Arrays; import java.util.*;
import java.util.Map;
import com.mx.cneeds.common.dto.DevicesDto;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R; import com.mx.cneeds.common.result.R;
import com.mx.cneeds.common.validator.ValidatorUtils; import com.mx.cneeds.common.validator.ValidatorUtils;
...@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
* @date 2020-03-18 14:44:30 * @date 2020-03-18 14:44:30
*/ */
@RestController @RestController
@RequestMapping("sys/deviceinfo") @RequestMapping("device/info")
public class DeviceInfoController { public class DeviceInfoController {
@Autowired @Autowired
private DeviceInfoService deviceInfoService; private DeviceInfoService deviceInfoService;
...@@ -34,10 +34,10 @@ public class DeviceInfoController { ...@@ -34,10 +34,10 @@ public class DeviceInfoController {
* 列表 * 列表
*/ */
@RequestMapping("/list") @RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params){ public PageUtils list(@RequestParam Map<String, Object> params){
PageUtils page = deviceInfoService.queryPage(params); PageUtils page = deviceInfoService.queryPage(params);
return R.ok().put("page", page); return page;
} }
...@@ -82,4 +82,44 @@ public class DeviceInfoController { ...@@ -82,4 +82,44 @@ public class DeviceInfoController {
return R.ok(); return R.ok();
} }
/**
* 保存
*/
@RequestMapping("/importDevice")
public R importDevice(@RequestBody DevicesDto devicesDto){
List<DeviceInfoEntity> deviceInfoEntityList = new LinkedList<>();
if (devicesDto.getImeis() != null && devicesDto.getImeis().size() != 0) {
devicesDto.getImeis().forEach(str -> {
DeviceInfoEntity deviceInfoEntity = new DeviceInfoEntity();
deviceInfoEntity.setImei(str);
deviceInfoEntity.setSeriesId(devicesDto.getSeriesId());
deviceInfoEntity.setDeptId(devicesDto.getDeptId());
deviceInfoEntity.setCreateTime(new Date());
deviceInfoEntityList.add(deviceInfoEntity);
});
}
deviceInfoService.saveBatch(deviceInfoEntityList);
return R.ok();
}
/**
* 保存
*/
@RequestMapping("/updateDeviceSeriesBatch")
public R updateDeviceSeriesBatch(@RequestBody DevicesDto devicesDto){
List<DeviceInfoEntity> deviceInfoEntityList = new LinkedList<>();
if (devicesDto.getImeis() != null && devicesDto.getImeis().size() != 0) {
devicesDto.getImeis().forEach(str -> {
DeviceInfoEntity deviceInfoEntity = new DeviceInfoEntity();
deviceInfoEntity.setImei(str);
deviceInfoEntity.setSeriesId(devicesDto.getSeriesId());
deviceInfoEntity.setDeptId(devicesDto.getDeptId());
deviceInfoEntityList.add(deviceInfoEntity);
});
}
deviceInfoService.updateBatchByImei(deviceInfoEntityList);
return R.ok();
}
} }
...@@ -48,6 +48,20 @@ public class ProductSeriesController { ...@@ -48,6 +48,20 @@ public class ProductSeriesController {
} }
return page; return page;
} }
@RequestMapping("listAll")
public List<SeriesDto> listAll(Map<String, Object> params){
List<ProductSeriesEntity> productSeriesEntities = productSeriesService.queryList(params);
List<SeriesDto> list = new ArrayList<SeriesDto>();
for (Object entity : productSeriesEntities){
SeriesDto dto = new SeriesDto();
ProductSeriesEntity seriesEntity = (ProductSeriesEntity) entity;
BeanUtils.copyProperties(seriesEntity,dto);
list.add(dto);
}
return list;
}
/** /**
......
...@@ -11,13 +11,11 @@ package com.mx.cneeds.server.user.common; ...@@ -11,13 +11,11 @@ package com.mx.cneeds.server.user.common;
import com.mx.cneeds.common.annotation.DataFilter; import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import com.mx.cneeds.common.exception.RRException; import com.mx.cneeds.common.exception.RRException;
import com.mx.cneeds.common.pager.Constant; import com.mx.cneeds.common.pager.Constant;
import com.mx.cneeds.server.entity.SysUserEntity; import com.mx.cneeds.server.entity.SysUserEntity;
import com.mx.cneeds.server.user.service.SysDeptService; import com.mx.cneeds.server.user.service.*;
import com.mx.cneeds.server.user.service.SysRoleDeptService;
import com.mx.cneeds.server.user.service.SysUserRoleService;
import com.mx.cneeds.server.user.service.SysUserService;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
...@@ -43,12 +41,6 @@ public class DataFilterAspect { ...@@ -43,12 +41,6 @@ public class DataFilterAspect {
@Autowired @Autowired
private SysUserService sysUserService; private SysUserService sysUserService;
@Autowired
private SysDeptService sysDeptService;
@Autowired
private SysUserRoleService sysUserRoleService;
@Autowired
private SysRoleDeptService sysRoleDeptService;
@Pointcut("@annotation(com.mx.cneeds.common.annotation.DataFilter)") @Pointcut("@annotation(com.mx.cneeds.common.annotation.DataFilter)")
public void dataFilterCut() { public void dataFilterCut() {
...@@ -77,51 +69,21 @@ public class DataFilterAspect { ...@@ -77,51 +69,21 @@ public class DataFilterAspect {
private String getSQLFilter(String username, JoinPoint point){ private String getSQLFilter(String username, JoinPoint point){
MethodSignature signature = (MethodSignature) point.getSignature(); MethodSignature signature = (MethodSignature) point.getSignature();
DataFilter dataFilter = signature.getMethod().getAnnotation(DataFilter.class); DataFilter dataFilter = signature.getMethod().getAnnotation(DataFilter.class);
//获取表的别名
String tableAlias = dataFilter.tableAlias();
if(StringUtils.isNotBlank(tableAlias)){
tableAlias += ".";
}
//部门ID列表 DataFilterDto dataFilterDto = new DataFilterDto();
Set<Long> deptIdList = new HashSet<>();
SysUserEntity sysUserEntity = sysUserService.queryUserByUsername(username); dataFilterDto.setDeptId(dataFilter.deptId());
dataFilterDto.setUserId(dataFilter.userId());
//用户角色对应的部门ID列表 dataFilterDto.setUser(dataFilter.user());
Long roleId = sysUserRoleService.queryRoleId(sysUserEntity.getUserId()); dataFilterDto.setSubDept(dataFilter.subDept());
if(roleId != null){ dataFilterDto.setTableAlias(dataFilter.tableAlias());
List<Long> userDeptIdList = sysRoleDeptService.queryDeptId(roleId); dataFilterDto.setUsername(username);
deptIdList.addAll(userDeptIdList);
}
//用户子部门ID列表
if(dataFilter.subDept()){
List<Long> subDeptIdList = sysDeptService.getSubDeptIdList(sysUserEntity.getUserId());
deptIdList.addAll(subDeptIdList);
}
StringBuilder sqlFilter = new StringBuilder(); String sqlFilter = sysUserService.genDataFilter(dataFilterDto);
sqlFilter.append(" (");
if(deptIdList.size() > 0){ return sqlFilter;
sqlFilter.append(tableAlias).append(dataFilter.deptId()).append(" in(").append(StringUtils.join(deptIdList, ",")).append(")"); }
}
//没有本部门数据权限,也能查询本人数据
if(dataFilter.user()){
if(deptIdList.size() > 0){
sqlFilter.append(" or ");
}
sqlFilter.append(tableAlias).append(dataFilter.userId()).append("=").append(sysUserEntity.getUserId());
}
sqlFilter.append(")");
if(sqlFilter.toString().trim().equals("()")){
return null;
}
return sqlFilter.toString();
}
} }
...@@ -20,7 +20,6 @@ public interface SysRoleService extends IService<SysRoleEntity> { ...@@ -20,7 +20,6 @@ public interface SysRoleService extends IService<SysRoleEntity> {
PageUtils queryPage(Map<String, Object> params); PageUtils queryPage(Map<String, Object> params);
@DataFilter(subDept = true, user = false, tableAlias = "t1")
List<SysRoleEntity> queryList(Map<String, Object> params); List<SysRoleEntity> queryList(Map<String, Object> params);
void saveRole(SysRoleEntity role, List<Long> funcIdList, List<Long> deptIdList); void saveRole(SysRoleEntity role, List<Long> funcIdList, List<Long> deptIdList);
......
...@@ -24,5 +24,7 @@ public interface SysUserDeptService extends IService<SysUserDeptEntity> { ...@@ -24,5 +24,7 @@ public interface SysUserDeptService extends IService<SysUserDeptEntity> {
void saveOrUpdate(Long userId, List<Long> deptIdList); void saveOrUpdate(Long userId, List<Long> deptIdList);
List<Long> queryDeptIdList(Long userId); List<Long> queryDeptIdList(Long userId);
List<Long> queryDeptId(Long userId);
} }
package com.mx.cneeds.server.user.service; package com.mx.cneeds.server.user.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.server.entity.SysUserEntity; import com.mx.cneeds.server.entity.SysUserEntity;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -26,5 +28,7 @@ public interface SysUserService extends IService<SysUserEntity> { ...@@ -26,5 +28,7 @@ public interface SysUserService extends IService<SysUserEntity> {
void saveUser(SysUserEntity user, List<Long> funcIdList, List<Long> deptIdList, Long roleId); void saveUser(SysUserEntity user, List<Long> funcIdList, List<Long> deptIdList, Long roleId);
void update(SysUserEntity user, List<Long> funcIdList, List<Long> deptIdList); void update(SysUserEntity user, List<Long> funcIdList, List<Long> deptIdList);
String genDataFilter(DataFilterDto dataFilterDto);
} }
...@@ -60,4 +60,8 @@ public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptDao, SysUserD ...@@ -60,4 +60,8 @@ public class SysUserDeptServiceImpl extends ServiceImpl<SysUserDeptDao, SysUserD
return baseMapper.queryDeptIdList(userId); return baseMapper.queryDeptIdList(userId);
} }
@Override
public List<Long> queryDeptId(Long userId) {
return baseMapper.queryDeptId(userId);
}
} }
package com.mx.cneeds.server.user.service.impl; package com.mx.cneeds.server.user.service.impl;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.pager.Query; import com.mx.cneeds.common.pager.Query;
import com.mx.cneeds.server.dao.SysUserDao; import com.mx.cneeds.server.dao.SysUserDao;
import com.mx.cneeds.server.entity.SysUserEntity; import com.mx.cneeds.server.entity.SysUserEntity;
import com.mx.cneeds.server.user.service.*; import com.mx.cneeds.server.user.service.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
...@@ -30,6 +31,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i ...@@ -30,6 +31,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
@Autowired @Autowired
private SysUserRoleService sysUserRoleService; private SysUserRoleService sysUserRoleService;
@Autowired
private SysDeptService sysDeptService;
@Autowired
private SysRoleDeptService sysRoleDeptService;
@Override @Override
public PageUtils queryPage(Map<String, Object> params) { public PageUtils queryPage(Map<String, Object> params) {
IPage<SysUserEntity> page = this.page( IPage<SysUserEntity> page = this.page(
...@@ -91,4 +99,58 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i ...@@ -91,4 +99,58 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserDao, SysUserEntity> i
sysUserDeptService.saveOrUpdate(user.getUserId(), deptIdList); sysUserDeptService.saveOrUpdate(user.getUserId(), deptIdList);
} }
@Override
public String genDataFilter(DataFilterDto dataFilterDto) {
//获取表的别名
String tableAlias = dataFilterDto.getTableAlias();
if(StringUtils.isNotBlank(tableAlias)){
tableAlias += ".";
}
StringBuilder sqlFilter = new StringBuilder();
sqlFilter.append(" (");
//部门ID列表
Set<Long> deptIdList = new HashSet<>();
SysUserEntity sysUserEntity = queryUserByUsername(dataFilterDto.getUsername());
//用户角色对应的部门ID列表
Long roleId = sysUserRoleService.queryRoleId(sysUserEntity.getUserId());
// 查询用户关联的部门权限表
List<Long> userDeptIdList = sysUserDeptService.queryDeptId(sysUserEntity.getUserId());
deptIdList.addAll(userDeptIdList);
if(roleId != null){
List<Long> roleDeptIdList = sysRoleDeptService.queryDeptId(roleId);
deptIdList.addAll(roleDeptIdList);
}
//用户子部门ID列表
if(dataFilterDto.isSubDept()){
List<Long> subDeptIdList = sysDeptService.getSubDeptIdList(sysUserEntity.getUserId());
deptIdList.addAll(subDeptIdList);
}
if(deptIdList.size() > 0){
sqlFilter.append(tableAlias).append(dataFilterDto.getDeptId()).append(" in(").append(StringUtils.join(deptIdList, ",")).append(")");
}
//没有本部门数据权限,也能查询本人数据
if(dataFilterDto.isUser()){
if(deptIdList.size() > 0){
sqlFilter.append(" or ");
}
sqlFilter.append(tableAlias).append(dataFilterDto.getUserId()).append("=").append(sysUserEntity.getUserId());
}
sqlFilter.append(")");
if(sqlFilter.toString().trim().equals("()")){
return null;
}
return sqlFilter.toString();
}
} }
package com.mx.cneeds.server.user.web; package com.mx.cneeds.server.user.web;
import com.mx.cneeds.common.annotation.DataFilter;
import com.mx.cneeds.common.dto.DataFilterDto;
import com.mx.cneeds.common.dto.UserDto; import com.mx.cneeds.common.dto.UserDto;
import com.mx.cneeds.common.pager.PageUtils; import com.mx.cneeds.common.pager.PageUtils;
import com.mx.cneeds.common.result.R; import com.mx.cneeds.common.result.R;
...@@ -116,4 +118,15 @@ public class SysUserController { ...@@ -116,4 +118,15 @@ public class SysUserController {
return R.ok(); return R.ok();
} }
/**
* TODO 暂时通过这里去实现
* @param dataFilterDto
* @return
*/
@RequestMapping("/genDataFilter")
public String genDataFilter(@RequestBody DataFilterDto dataFilterDto){
return sysUserService.genDataFilter(dataFilterDto);
}
} }
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