Commit f15cabc1 authored by “yiyousong”'s avatar “yiyousong”
parents 9ee5eec9 0ae3f311
......@@ -26,7 +26,7 @@ public interface IAreaFeign extends IFeign {
* @param areaPdu
* @return
*/
@PostMapping(value = "/area/list")
@PostMapping(value = "/area/interlist")
String list(@RequestBody AreaPdu areaPdu);
......@@ -36,7 +36,7 @@ public interface IAreaFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/area/info")
@GetMapping(value = "/area/interinfo")
String info(@RequestParam(value = "id") Long id);
/**
......
......@@ -29,7 +29,7 @@ public interface ISiteFeign extends IFeign {
* @param sitePdu
* @return
*/
@PostMapping(value = "/site/list")
@PostMapping(value = "/site/interlist")
Rest<RespData<List<SitePdu>>> list(@RequestBody SitePdu sitePdu);
......@@ -39,7 +39,7 @@ public interface ISiteFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/site/info")
@GetMapping(value = "/site/interinfo")
Rest<SitePdu> info(@RequestParam(value = "id") Long id);
/**
......
......@@ -28,7 +28,7 @@ public interface ISiteHallFeign extends IFeign {
* @param siteHallPdu
* @return
*/
@PostMapping(value = "/site/hall/list")
@PostMapping(value = "/site/hall/interlist")
Rest<RespData<List<SiteHallPdu>>> list(@RequestBody SiteHallPdu siteHallPdu);
......@@ -38,7 +38,7 @@ public interface ISiteHallFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/site/hall/info")
@GetMapping(value = "/site/hall/interinfo")
Rest<SiteHallPdu> info(@RequestParam(value = "id") Long id);
/**
......
package com.mortals.xhx.feign.skin;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.skin.SkinBasePdu;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.feign.IFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 系统基础皮肤 Feign接口
......@@ -25,7 +26,7 @@ public interface ISkinBaseFeign extends IFeign {
* @param skinBasePdu
* @return
*/
@PostMapping(value = "/skin/base/list")
@PostMapping(value = "/skin/base/interlist")
Rest<RespData<List<SkinBasePdu>>> list(@RequestBody SkinBasePdu skinBasePdu);
......@@ -35,7 +36,7 @@ public interface ISkinBaseFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/skin/base/info")
@GetMapping(value = "/skin/base/interinfo")
Rest<SkinBasePdu> info(@RequestParam(value = "id") Long id);
/**
......
......@@ -26,7 +26,7 @@ public interface ISmsSetFeign extends IFeign {
* @param smsSetPdu
* @return
*/
@PostMapping(value = "/sms/set/list")
@PostMapping(value = "/sms/set/interlist")
Rest<RespData<List<SmsSetPdu>>> list(@RequestBody SmsSetPdu smsSetPdu);
......@@ -36,7 +36,7 @@ public interface ISmsSetFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/sms/set/info")
@GetMapping(value = "/sms/set/interinfo")
Rest<SmsSetPdu> info(@RequestParam(value = "id") Long id);
/**
......
......@@ -38,7 +38,7 @@ public interface IUserFeign extends IFeign {
* @param id
* @return
*/
@GetMapping(value = "/user/info")
@GetMapping(value = "/user/interinfo")
Rest<UserPdu> info(@RequestParam(value = "id") Long id);
/**
......
......@@ -8,7 +8,7 @@
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
<el-row>
<Field label="产品类型" :span="20" prop="productId" type="select" :enumData="dict.productId" v-model="form.productId" placeholder="请选择产品"/>
<Field label="文件地址" :span="20" prop="filePath"><fileUpload ref="fileUpload" v-model="form.filePath" prePath="/file/uploadfile"/></Field>
<Field label="文件地址" :span="20" prop="filePath"><fileUpload ref="fileUpload" v-model="form.filePath" :prePath="'/file/uploadfile/'+siteid"/></Field>
<Field label="版本号" :span="20" prop="version" type="num" v-model="form.version" placeholder="请输入版本号"/>
<Field label="备注信息" :span="20" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注信息"/>
......@@ -22,6 +22,7 @@
<script>
import form from "@/assets/mixins/formdialog";
import session from "@/assets/utils/session";
export default {
name: "ProductVersionDetail",
mixins: [form],
......@@ -30,9 +31,11 @@
},
created() {
this.changePath("product/version")
this.siteid= session.getSession("siteid")
},
data() {
return {
siteid:"",
// 遮罩层
loading: true,
// 弹出层标题
......
......@@ -59,7 +59,7 @@ ALTER TABLE mortals_xhx_device_module_distribute ADD COLUMN `siteId` bigint(20
ALTER TABLE mortals_xhx_device_module_distribute ADD COLUMN `siteCode` varchar(256) default '' COMMENT '站点编号,来源基础服务平台';
ALTER TABLE mortals_xhx_device_module_distribute ADD COLUMN `siteName` varchar(256) default '' COMMENT '站点名称';
ALTER TABLE mortals_xhx_product_version ADD COLUMN `siteId` bigint(20) COMMENT '站点Id,来源基础服务平台';
ALTER TABLE mortals_xhx_product_version ADD COLUMN `siteId` bigint(20) default '1' COMMENT '站点Id,来源基础服务平台';
ALTER TABLE mortals_xhx_product_version ADD COLUMN `siteCode` varchar(256) default '' COMMENT '站点编号,来源基础服务平台';
ALTER TABLE mortals_xhx_product_version ADD COLUMN `siteName` varchar(256) default '' COMMENT '站点名称';
......@@ -67,3 +67,14 @@ ALTER TABLE mortals_xhx_product_version ADD COLUMN `siteName` varchar(256) de
2023-08-21
-- ----------------------------
ALTER TABLE mortals_xhx_device_module_distribute ADD COLUMN `selected` tinyint(2) NOT NULL default '0' COMMENT '是否默认选择分辨率(0.否,1.是)';
ALTER TABLE mortals_xhx_role_auth ADD COLUMN `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE mortals_xhx_role_user ADD COLUMN `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间';
ALTER TABLE mortals_xhx_idgenerator ADD COLUMN `createTime` datetime(0) NULL DEFAULT NULL COMMENT '创建时间';
......@@ -7,10 +7,12 @@ import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.PlatformTypeEnum;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
......@@ -25,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* token验证处理
......@@ -61,6 +64,9 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
@Value("${platform.type:cloud}")
private String platFormType;//版本,默认云服务版本
@Autowired
private ResourceService resourceService;
@Autowired
private UserService userService;
......@@ -74,7 +80,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
protected static final Long SECOND_WEEK = 7 * SECOND_DAY;
private static final Long SECOND_MINUTE_TEN = 1 * SECOND_MINUTE;
private static final Long SECOND_MINUTE_TEN = 20 * SECOND_MINUTE;
@Autowired
private ICacheService cacheService;
......@@ -91,15 +97,23 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
String token = getToken(request);
if (StringUtils.isNotEmpty(token)) {
try {
boolean signed = Jwts.parser().isSigned(token);
if (!signed) {
log.error("token非法!=>{}", token);
return null;
}
Claims claims = parseToken(token);
String uuid = (String) claims.get(SysConstains.LOGIN_USER_KEY);
String userKey = getTokenKey(uuid);
// Rest<String> rest = userFeign.getToken(userKey);
// String userStr = rest.getData();
String userStr = "";
if (platFormType.equalsIgnoreCase(PlatformTypeEnum.CLOUD.getValue())) {
cacheService.select(portalDb);
userStr = cacheService.get(userKey);
//刷新token时间
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
if (!ObjectUtils.isEmpty(userEntity)) {
verifyToken(userEntity);
}
cacheService.select(db);
} else {
userStr = cacheService.get(userKey);
......@@ -108,10 +122,19 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
UserEntity userEntity = JSONObject.parseObject(userStr, UserEntity.class);
userEntity.setToken(token);
//更新portal 中的id 为 device中的id
UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
if(!ObjectUtils.isEmpty(temp)){
// UserEntity temp = userService.selectOne(new UserQuery().loginName(userEntity.getLoginName()));
UserEntity temp = userService.getExtCache(userEntity.getLoginName());
if (!ObjectUtils.isEmpty(temp)) {
userEntity.setId(temp.getId());
}
//更新resource 路径
String menuUrlCode = cacheService.hget(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), String.class);
if (ObjectUtils.isEmpty(menuUrlCode)) {
Set<String> urls = resourceService.findUrlSetByUserId(userEntity.getId());
menuUrlCode = MenuEncodeUtil.generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userEntity.getId().toString(), menuUrlCode);
}
userEntity.setMenuUrl(menuUrlCode);
return userEntity;
}
} catch (Exception e) {
......@@ -169,7 +192,7 @@ public class AuthTokenServiceImpl implements IAuthTokenService {
public void verifyToken(IUser user) {
long expireTime = user.getExpireTime();
long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= SECOND_MINUTE_TEN) {
if (expireTime - currentTime <= SECOND_MINUTE_TEN*1000) {
log.info("不足十分钟,刷新过期时间");
refreshToken(user);
}
......
......@@ -9,7 +9,6 @@ import com.mortals.framework.util.AESUtil;
import com.mortals.framework.utils.ServletUtils;
import com.mortals.framework.web.interceptor.BaseInterceptor;
import com.mortals.xhx.base.framework.config.InterceptorConfig;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
......@@ -21,7 +20,6 @@ import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import static com.mortals.xhx.common.key.ErrorCode.*;
import static com.mortals.xhx.common.key.ErrorCode.ERROR_USER_OPERATION_CONTENT;
/**
* 用户权限验证,基于token
......@@ -74,7 +72,8 @@ public class AuthUserInterceptor extends BaseInterceptor {
if (ObjectUtils.isEmpty(loginUser)) {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_TOKEN_EXPIRED, ERROR_TOKEN_EXPIRED_CONTENT)));
return false;
} else if (loginUser.isAdmin() || loginUser.getUserType() == 1) {
// } else if (loginUser.isAdmin() || loginUser.getUserType() == 1) {
} else if (loginUser.isAdmin()) {
return super.preHandle(request, response, handler);
} else {
ServletUtils.renderString(response, JSONObject.toJSONString(Rest.fail(ERROR_USER_OPERATION, ERROR_USER_OPERATION_CONTENT)));
......
......@@ -3,14 +3,10 @@ package com.mortals.xhx.base.login.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.ap.CookieService;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.service.IAuthTokenService;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.IUser;
import com.mortals.framework.util.AESUtil;
import com.mortals.framework.util.HttpUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
......@@ -21,6 +17,7 @@ import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.base.system.valid.service.ValidCodeService;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.common.utils.MenuEncodeUtil;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
......@@ -171,56 +168,14 @@ public class LoginController extends BaseCRUDJsonBodyMappingController<UserServi
data.put("id", user.getId());
data.put("userType", user.getUserType());
ret.put(KEY_RESULT_DATA, data);
generateMenuUrlCode(urls);
// this.generateBlackCookie(request, response, user.getLoginName(), urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, user.getId().toString(), MenuEncodeUtil.generateMenuUrlCode(urls));
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "用户登录系统成功!");
ret.put("resources", urls);
return ret.toJSONString();
}
private void generateBlackCookie(HttpServletRequest request, HttpServletResponse response, String loginName, Set<String> urls) {
try {
String cacheKey = RedisKey.KEY_MENU_CACHE + loginName;
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
//应为Cookie会超长,所以改为仅存储key将值放入redis
//CookieService.setCookieForAuth(request, response, securityKey, null);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
menuUrl = AESUtil.encrypt(menuUrl, securityKey);
cacheService.set(cacheKey, menuUrl, 604800);
HttpUtil.setCookieValue(request, response, SysConstains.COOKIE_MENU, cacheKey, -1);
} catch (Throwable e) {
}
}
private String generateMenuUrlCode(Set<String> urls) {
try {
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
return AESUtil.encrypt(menuUrl, securityKey);
} catch (Throwable e) {
log.error("编码异常", e);
return null;
}
}
@RequestMapping("validcode")
public String validCode(HttpServletRequest request, HttpServletResponse response, LoginForm loginForm) {
......
/**
* 文件:MenuForm.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.menu.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.menu.model.MenuQuery;
/**
* <p>Title: 菜单信息</p>
* <p>Description: MenuForm </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
public class MenuForm extends BaseCRUDFormLong<MenuEntity> {
private MenuEntity entity = new MenuEntity();
private MenuQuery query = new MenuQuery();
public MenuForm(){
}
@Override
public MenuEntity getEntity() {
return entity;
}
public void setEntity(MenuEntity entity) {
this.entity = entity;
}
@Override
public MenuQuery getQuery() {
return query;
}
public void setQuery(MenuQuery query) {
this.query = query;
}
}
\ No newline at end of file
......@@ -8,7 +8,6 @@
package com.mortals.xhx.base.system.oper.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.OrderCol;
......@@ -16,15 +15,9 @@ import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.oper.model.OperLogEntity;
import com.mortals.xhx.base.system.oper.service.OperLogService;
import com.mortals.xhx.common.code.OperTypeEnum;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
......@@ -43,7 +36,6 @@ import java.util.Map;
public class OperLogController extends BaseCRUDJsonBodyMappingController<OperLogService, OperLogEntity, Long> {
public OperLogController() {
super.setFormClass(OperLogForm.class);
super.setModuleDesc("操作日志");
}
......
/**
* 文件:OperLogForm.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.oper.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.base.system.oper.model.OperLogEntity;
import com.mortals.xhx.base.system.oper.model.OperLogQuery;
/**
* <p>Title: 操作日志</p>
* <p>Description: OperLogForm </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
public class OperLogForm extends BaseCRUDFormLong<OperLogEntity> {
private OperLogEntity entity = new OperLogEntity();
private OperLogQuery query = new OperLogQuery();
public OperLogForm(){
}
@Override
public OperLogEntity getEntity() {
return entity;
}
public void setEntity(OperLogEntity entity) {
this.entity = entity;
}
@Override
public OperLogQuery getQuery() {
return query;
}
public void setQuery(OperLogQuery query) {
this.query = query;
}
}
\ No newline at end of file
/**
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:ResourceServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.resource.dao.ResourceDao;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
/**
* <p>Title: 资源信息</p>
* <p>Description: ResourceServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
@Service("resourceService")
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,ResourceEntity,Long> implements ResourceService {
public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao, ResourceEntity, Long> implements ResourceService {
@Autowired
private ICacheService cacheService;
@Autowired
private RoleAuthService roleAuthService;
@Override
public List<ResourceEntity> findAllEnable() throws AppException {
......@@ -69,5 +87,39 @@ public class ResourceServiceImpl extends AbstractCRUDServiceImpl<ResourceDao,Res
public List<ResourceEntity> findAll(int userType) {
return dao.getAll(userType);
}
@Override
protected void updateAfter(ResourceEntity entity, Context context) throws AppException {
updateUserMenuUrlCache();
}
@Override
protected void saveAfter(ResourceEntity entity, Context context) throws AppException {
updateUserMenuUrlCache();
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
//删除关联表中数据
if (!ObjectUtils.isEmpty(ids)) {
RoleAuthQuery query = new RoleAuthQuery();
query.setResourceIdList(Arrays.asList(ids));
List<RoleAuthEntity> roleAuthEntities = roleAuthService.find(query);
if (!ObjectUtils.isEmpty(roleAuthEntities)) {
roleAuthService.remove(roleAuthEntities.stream().map(m -> m.getId()).toArray(Long[]::new), context);
updateUserMenuUrlCache();
}
}
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = this.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
package com.mortals.xhx.base.system.resource.web;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.common.code.AuthType;
import com.mortals.xhx.common.code.SourceType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.common.code.AuthType;
import com.mortals.xhx.common.code.SourceType;
import java.util.HashMap;
import java.util.Map;
/**
* 资源信息
......@@ -35,7 +30,6 @@ import com.mortals.xhx.common.code.SourceType;
public class ResourceController extends BaseCRUDJsonBodyMappingController<ResourceService,ResourceEntity,Long> {
public ResourceController(){
super.setFormClass(ResourceForm.class);
super.setModuleDesc("资源信息");
}
......
/**
* 文件:ResourceForm.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.resource.web;
import com.mortals.framework.web.BaseCRUDFormLong;
import com.mortals.xhx.base.system.resource.model.ResourceEntity;
import com.mortals.xhx.base.system.resource.model.ResourceQuery;
/**
* <p>Title: 资源信息</p>
* <p>Description: ResourceForm </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @version 1.0.0
*/
public class ResourceForm extends BaseCRUDFormLong<ResourceEntity> {
private ResourceEntity entity = new ResourceEntity();
private ResourceQuery query = new ResourceQuery();
public ResourceForm(){
}
@Override
public ResourceEntity getEntity() {
return entity;
}
public void setEntity(ResourceEntity entity) {
this.entity = entity;
}
@Override
public ResourceQuery getQuery() {
return query;
}
public void setQuery(ResourceQuery query) {
this.query = query;
}
}
\ No newline at end of file
/**
* 文件:RoleAuthServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:RoleAuthServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.role.service.impl;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleAuthDao;
import com.mortals.xhx.base.system.role.model.RoleAuthEntity;
import com.mortals.xhx.base.system.role.model.RoleAuthQuery;
import com.mortals.xhx.base.system.role.service.RoleAuthService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
/**
* <p>Title: 角色资源权限</p>
* <p>Description: RoleAuthServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
@Service("roleAuthService")
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao,RoleAuthEntity,Long> implements RoleAuthService {
public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao, RoleAuthEntity, Long> implements RoleAuthService {
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
@Override
public void doDistributionSource(RoleAuthQuery query) {
......@@ -49,6 +56,18 @@ public class RoleAuthServiceImpl extends AbstractCRUDServiceImpl<RoleAuthDao,Rol
list.add(entity);
}
this.dao.insertBatch(list);
this.updateUserMenuUrlCache();
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = resourceService.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
/**
* 文件:RoleUserServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
* 文件:RoleUserServiceImpl.java
* 版本:1.0.0
* 日期:
* Copyright &reg;
* All right reserved.
*/
package com.mortals.xhx.base.system.role.service.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.xhx.base.system.resource.service.ResourceService;
import com.mortals.xhx.base.system.role.dao.RoleUserDao;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
import com.mortals.xhx.base.system.role.model.RoleUserQuery;
import com.mortals.xhx.base.system.role.service.RoleUserService;
import com.mortals.xhx.common.key.RedisKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import static com.mortals.xhx.common.utils.MenuEncodeUtil.generateMenuUrlCode;
/**
* <p>Title: 角色用户</p>
* <p>Description: RoleUserServiceImpl service接口 </p>
* <p>Copyright: Copyright &reg; </p>
* <p>Company: </p>
* @author
* @author
* @version 1.0.0
*/
@Service("roleUserService")
public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao,RoleUserEntity,Long> implements RoleUserService {
public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao, RoleUserEntity, Long> implements RoleUserService {
@Autowired
private ICacheService cacheService;
@Autowired
private ResourceService resourceService;
@Override
public void doDistributionUser(RoleUserQuery query) {
......@@ -50,6 +61,7 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao,Rol
list.add(rolseUser);
}
this.dao.insertBatch(list);
updateUserMenuUrlCache();
}
@Override
......@@ -68,8 +80,22 @@ public class RoleUserServiceImpl extends AbstractCRUDServiceImpl<RoleUserDao,Rol
list.add(rolseUser);
}
this.dao.insertBatch(list);
updateUserMenuUrlCache();
}
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
updateUserMenuUrlCache();
}
private void updateUserMenuUrlCache() {
//更新用户菜单
Set<String> hkeys = cacheService.hkeys(RedisKey.KEY_USER_MENU_CACHE);
for (String userId : hkeys) {
Set<String> urls = resourceService.findUrlSetByUserId(DataUtil.converStr2Long(userId, 0L));
String menuUrlCode = generateMenuUrlCode(urls);
cacheService.hset(RedisKey.KEY_USER_MENU_CACHE, userId, menuUrlCode);
}
}
}
\ No newline at end of file
......@@ -8,9 +8,10 @@
package com.mortals.xhx.base.system.user.service;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.ICRUDCacheService;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
import com.mortals.xhx.base.system.user.dao.UserDao;
......@@ -28,7 +29,7 @@ import java.util.Set;
* @version 1.0.0
*/
public interface UserService extends ICRUDService<UserEntity,Long> {
public interface UserService extends ICRUDCacheService<UserEntity,Long> {
/**
* 用户登录
*
......@@ -116,6 +117,10 @@ public interface UserService extends ICRUDService<UserEntity,Long> {
Rest<Void> refreshUser();
UserDao getUserDao();
}
\ No newline at end of file
......@@ -9,13 +9,14 @@
package com.mortals.xhx.base.system.user.service.impl;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.service.IUser;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.SecurityUtil;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.base.system.menu.model.MenuEntity;
......@@ -30,8 +31,12 @@ import com.mortals.xhx.base.system.user.dao.UserDao;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
......@@ -49,7 +54,8 @@ import java.util.stream.Collectors;
* @version 1.0.0
*/
@Service("userService")
public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Slf4j
public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserEntity, Long> implements UserService {
@Autowired
......@@ -61,6 +67,14 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
@Autowired
private RoleUserService roleUserService;
@Autowired
private IUserFeign userFeign;
@Override
protected String getExtKey(UserEntity data) {
return data.getLoginName();
}
private void doHandlerUser(UserEntity entity) throws AppException {
if (StringUtils.isNotEmpty(entity.getLoginPwd())) {
try {
......@@ -92,7 +106,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
entity.setLoginPwd(null);
this.doHandlerUser(entity);
//更新角色
if(entity.getId().longValue() != SysConstains.ADMIN_ID &&!ObjectUtils.isEmpty(entity.getRoleIds())){
if (entity.getId().longValue() != SysConstains.ADMIN_ID && !ObjectUtils.isEmpty(entity.getRoleIds())) {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
......@@ -104,7 +118,7 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
@Override
protected void saveAfter(UserEntity entity, Context context) throws AppException {
//更新角色
if(!ObjectUtils.isEmpty(entity.getId())&&entity.getId().longValue() != SysConstains.ADMIN_ID &&!ObjectUtils.isEmpty(entity.getRoleIds())){
if (!ObjectUtils.isEmpty(entity.getId()) && entity.getId().longValue() != SysConstains.ADMIN_ID && !ObjectUtils.isEmpty(entity.getRoleIds())) {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(entity.getId());
List<Long> idList = Arrays.asList(entity.getRoleIds().split(",")).stream().map(Long::parseLong).collect(Collectors.toList());
......@@ -316,6 +330,57 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
return true;
}
@Override
public Rest<Void> refreshUser() {
UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
if (resp.getCode() == YesNoEnum.YES.getValue()) {
List<UserPdu> userPduList = resp.getData().getData();
log.info("用户总数量:{}", userPduList.size());
if (!ObjectUtils.isEmpty(userPduList)) {
List<UserEntity> newUserList = userPduList.stream().map(newUser -> {
UserEntity userEntity = new UserEntity();
userEntity.initAttrValue();
BeanUtils.copyProperties(newUser, userEntity, new String[]{"id","lastLoginTime", "lastLoginAddress"});
return userEntity;
}).collect(Collectors.toList());
List<UserEntity> oldUserList = this.find(new UserQuery());
log.info(" oldUserList size:{}", oldUserList.size());
Map<String, UserEntity> oldUserMap = oldUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
Map<String, UserEntity> newUserMap = newUserList.stream().collect(Collectors.toMap(x -> x.getLoginName(), y -> y, (o, n) -> n));
List<UserEntity> saveUserList = newUserList.stream().map(item -> {
if (!oldUserMap.containsKey(item.getLoginName())) {
item.setCreateUserId(1L);
item.setCreateUserName("系统管理员");
item.setCreateTime(new Date());
return item;
}
return null;
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(saveUserList)) {
saveUserList.stream().forEach(item->{
this.getUserDao().insert(item);
});
//userService.save(saveUserList);
}
}
//查找新增 与更新
}
return Rest.ok();
}
@Override
public UserDao getUserDao() {
return getDao();
......@@ -323,11 +388,11 @@ public class UserServiceImpl extends AbstractCRUDServiceImpl<UserDao, UserEntity
@Override
protected void removeAfter(Long[] ids, Context context, int result) throws AppException {
Arrays.asList(ids).stream().peek(userId->{
Arrays.asList(ids).stream().peek(userId -> {
RoleUserQuery roleUserQuery = new RoleUserQuery();
roleUserQuery.setUserId(userId);
Long[] userIds = roleUserService.find(roleUserQuery).stream().map(RoleUserEntity::getId).toArray(Long[]::new);
roleUserService.remove(userIds,context);
roleUserService.remove(userIds, context);
}).count();
super.removeAfter(ids, context, result);
......
......@@ -2,12 +2,13 @@ package com.mortals.xhx.base.system.user.web;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.IBaseEnum;
import com.mortals.framework.common.Rest;
import com.mortals.framework.common.code.UserType;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.framework.web.BaseCRUDJsonMappingController;
import com.mortals.xhx.base.framework.annotation.Operlog;
import com.mortals.xhx.base.system.role.model.RoleQuery;
import com.mortals.xhx.base.system.role.model.RoleUserEntity;
......@@ -20,17 +21,10 @@ import com.mortals.xhx.common.code.UserStatus;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -56,8 +50,8 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model,"userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model,"status", UserStatus.getEnumMap());
this.addDict(model, "userType", IBaseEnum.getEnumMap(UserType.class));
this.addDict(model, "status", UserStatus.getEnumMap());
this.addDict(model, "roleIds", roleService.find(new RoleQuery()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getName())));
}
......@@ -117,6 +111,15 @@ public class UserController extends BaseCRUDJsonBodyMappingController<UserServic
}
@PostMapping({"refreshUser"})
@UnAuth
public Rest<Object> refreshUser() {
log.info("刷新用户");
this.service.refreshUser();
return Rest.ok("用户同步刷新操作成功");
}
public static void main(String[] args) {
String token = "eyJhbGciOiJIUzI1NiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIzNGE5NDA5ZDVhOTQ3MWNhMzdkYjZkYmMwY2JjZTc5In0.MWyQW40HYDxyUz7PJRf_nRsFPWx3Hr811Ime984nixs";
......
......@@ -38,7 +38,7 @@ public class ApiSubmitInterceptor extends BaseInterceptor {
Method method = handlerMethod.getMethod();
ApiUserAuth annotation = method.getAnnotation(ApiUserAuth.class);
if (annotation != null) {
//校验
//校验 校验路径是否允许
if (!this.verifyApiUser(request)) {
JSONObject ret = new JSONObject();
ret.put("code", TOKEN_AUTH_FAIL);
......
......@@ -21,7 +21,6 @@ import com.mortals.framework.service.ILogService;
import com.mortals.framework.service.impl.FileLogServiceImpl;
import com.mortals.framework.util.DataUtil;
import com.mortals.framework.util.DateUtils;
import com.mortals.xhx.base.framework.annotation.ApiUserAuth;
import com.mortals.xhx.base.login.web.LoginForm;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.base.system.user.model.UserEntity;
......@@ -78,6 +77,7 @@ import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.Constant.*;
import static com.mortals.xhx.common.key.ErrorCode.*;
import static com.mortals.xhx.common.key.RedisKey.KEY_DEVICE_DOWN_MSG_QUEUE;
import static com.mortals.xhx.common.key.RedisKey.KEY_TOKEN_API_CACHE;
/**
......@@ -146,6 +146,7 @@ public class DeviceApiController {
* @return
*/
@PostMapping("register")
@UnAuth
public String register(HttpServletRequest request, @RequestBody DeviceReq req) {
log.info("【设备注册】【请求体】--> " + JSONObject.toJSONString(req));
String serverName = request.getHeader("server-name");
......@@ -185,7 +186,7 @@ public class DeviceApiController {
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (ObjectUtils.isEmpty(productEntity)) {
throw new AppException(PRODUCT_IS_EMPTY, PRODUCT_IS_EMPTY_CONTENT);
throw new AppException(PRODUCT_IS_EMPTY, PRODUCT_IS_EMPTY_CONTENT+"productId:"+deviceEntity.getProductId());
}
if (ObjectUtils.isEmpty(productEntity.getPlatformId())) {
......@@ -282,6 +283,7 @@ public class DeviceApiController {
* @return
*/
@PostMapping("getToken")
@UnAuth
public String getToken(@RequestBody LoginForm loginForm) {
ApiResp<String> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
......@@ -313,6 +315,7 @@ public class DeviceApiController {
* @return
*/
@RequestMapping(value = "deviceInit", method = {RequestMethod.POST, RequestMethod.GET})
@UnAuth
public String deviceInit() {
ApiResp<DeviceInitResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
......@@ -388,6 +391,7 @@ public class DeviceApiController {
* @return
*/
@PostMapping("deviceUpdate")
@UnAuth
public String deviceUpdateApi(HttpServletRequest request, @RequestBody DeviceReq req) {
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
......@@ -517,6 +521,7 @@ public class DeviceApiController {
* @return
*/
@PostMapping("checkVersion")
@UnAuth
public String checkVersion(HttpServletRequest request, @RequestBody DeviceReq req) {
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
......@@ -560,6 +565,57 @@ public class DeviceApiController {
return JSON.toJSONString(rsp);
}
/**
* 检查设备最新版本信息
*
* @param req
* @return
*/
@PostMapping("checkVersionbak")
@UnAuth
public String checkVersionbak(HttpServletRequest request, @RequestBody DeviceReq req) {
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
// String serverName = request.getServerName();
// int serverPort = request.getServerPort();
log.info("【检查设备最新版本信息】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp();
try {
DeviceEntity deviceEntity = checkDeviceExist(req);
//查找版本号最大的.
ProductVersionQuery productVersionQuery = new ProductVersionQuery();
productVersionQuery.setProductId(deviceEntity.getProductId());
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version", OrderCol.DESCENDING)));
//productVersionQuery.setOrderKind(OrderCol.DESCENDING);
ProductVersionEntity productVersionEntity = productVersionService.selectOne(productVersionQuery);
if (ObjectUtils.isEmpty(productVersionEntity)) {
throw new AppException(DEVICE_VERSION_UNEXIST, DEVICE_VERSION_UNEXIST_CONTENT);
}
ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity, productVersionInfo, serverName, serverPort);
String content = EncryptUtil.myEnscrt(JSON.toJSONString(productVersionInfo), 9, DES_STR, ENCRYPT_STR);
log.info("响应【设备版本检查】【响应体】--> " + JSONObject.toJSONString(productVersionInfo));
deviceResp.setContent(content);
rsp.setData(deviceResp);
} catch (AppException e) {
rsp.setCode(e.getCode());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
} catch (Exception e) {
log.error("接收数据失败", e);
rsp.setCode(ApiRespCodeEnum.FAILED.getValue());
rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp);
}
return JSON.toJSONString(rsp);
}
private void saveDevice(DeviceReq req, PlatformEntity platformEntity, ProductEntity productEntity, DeviceEntity deviceEntity) {
BeanUtils.copyProperties(req, deviceEntity, BeanUtil.getNullPropertyNames(req));
......@@ -611,8 +667,12 @@ public class DeviceApiController {
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
try {
DownMsgTask downMsgTask = new DownMsgTask(list, platformService, productService, deviceService, deviceLogService, messageProducer);
sendTaskThreadPool.execute(downMsgTask);
List<DeviceMsgReq> collect = list.stream().sorted(Comparator.comparing(DeviceMsgReq::getTimestamp)).collect(Collectors.toList());
collect.forEach(item->{
cacheService.lpush(KEY_DEVICE_DOWN_MSG_QUEUE,item);
});
// DownMsgTask downMsgTask = new DownMsgTask(list, platformService, productService, deviceService, deviceLogService, messageProducer);
// sendTaskThreadPool.execute(downMsgTask);
} catch (AppException e) {
log.error("接收数据失败", e);
rsp.setCode(e.getCode());
......@@ -625,7 +685,7 @@ public class DeviceApiController {
return JSON.toJSONString(rsp);
}
log.debug("响应【设备数据消息接收】【响应体】--> " + JSONObject.toJSONString(rsp));
log.info("响应【设备数据消息接收】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp);
}
......@@ -680,6 +740,7 @@ public class DeviceApiController {
* @return
*/
@PostMapping("upload")
@UnAuth
public String upload(@RequestBody UploadDeviceReq req) {
log.info("【设备数据上报】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<String> rsp = new ApiResp<>();
......@@ -738,7 +799,6 @@ public class DeviceApiController {
* @return
*/
@PostMapping("receive")
@ApiUserAuth
public String receive(HttpServletRequest request, @RequestBody DeviceReq req) {
log.info("【设备接收】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<String> rsp = new ApiResp<>();
......@@ -984,8 +1044,7 @@ public class DeviceApiController {
query.setSelected(YesNoEnum.NO.getValue());
deviceModuleDistributeEntity = deviceModuleDistributeService.selectOne(query);
if (!ObjectUtils.isEmpty(deviceModuleDistributeEntity)) {
deviceModuleDistributeService.active(deviceModuleDistributeEntity, null);
//deviceModuleDistributeService.active(deviceModuleDistributeEntity, null);
homeUrl = String.format("/homeDeviceUrl/%s/%s/%s", deviceModuleDistributeEntity.getSiteId(), deviceModuleDistributeEntity.getProductCode(), deviceModuleDistributeEntity.getImageResolutionValue());
//根据部署的资源 生成homeurl
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11078");
......
......@@ -25,6 +25,11 @@ public class RedisKey {
*/
public static final String KEY_DEVICE_THIRDPARTY_QUEUE = "device:thirdparty:queue";
/**
* 下发消息队列
*/
public static final String KEY_DEVICE_DOWN_MSG_QUEUE = "device:down:msg:queue";
public static final String KEY_SITE_CACHE = "siteDict";
public static final String KEY_PLATFORM_CACHE = "platformDict";
......@@ -32,4 +37,7 @@ public class RedisKey {
public static final String KEY_PRODUCT_CACHE = "productDict";
public static final String KEY_TOKEN_API_CACHE = "token:api:";
public static final String KEY_USER_MENU_CACHE = "user:menu";
}
package com.mortals.xhx.common.utils;
import com.mortals.framework.ap.GlobalSysInfo;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.util.AESUtil;
import lombok.extern.slf4j.Slf4j;
import java.util.Set;
@Slf4j
public class MenuEncodeUtil {
public static String generateMenuUrlCode(Set<String> urls) {
try {
String securityKey = GlobalSysInfo.getPropertyValue(SysConstains.PROP_COOKIE_SECURITY_KEY);
StringBuilder sb = new StringBuilder();
if (urls != null && urls.size() > 0) {
for (String url : urls) {
int index = url.hashCode() & (Integer.MAX_VALUE - 1);
sb.append(index).append(",");
}
}
String menuUrl = sb.toString();
return AESUtil.encrypt(menuUrl, securityKey);
} catch (Throwable e) {
log.error("编码异常",e);
return null;
}
}
}
package com.mortals.xhx.daemon.applicationservice;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.service.ICacheService;
import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.base.system.message.impl.MessageProducer;
import com.mortals.xhx.busiz.req.DeviceMsgReq;
import com.mortals.xhx.common.code.LogTypeEnum;
import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceLogEntity;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.queue.DefaultTbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsg;
import com.mortals.xhx.queue.TbQueueMsgHeaders;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import static com.mortals.xhx.common.key.RedisKey.KEY_DEVICE_DOWN_MSG_QUEUE;
/**
* 下发消息
*
* @author: zxfei
* @date: 2023/11/8 23:45
*/
@Component
@Slf4j
public class DeviceDownMsgService implements IApplicationStartedService {
protected Boolean stopped = false;
@Autowired
private ICacheService cacheService;
@Autowired
private DeviceService deviceService;
@Autowired
private DeviceLogService deviceLogService;
@Autowired
private MessageProducer messageProducer;
@Override
public void start() {
log.info("DeviceDownMsgService start");
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
int waitTime = 1;
while (!stopped) {
try {
DeviceMsgReq deviceMsgReq = cacheService.blpop(KEY_DEVICE_DOWN_MSG_QUEUE,10, DeviceMsgReq.class);
if (!ObjectUtils.isEmpty(deviceMsgReq)) {
log.info("下发消息:{}",deviceMsgReq.getDeviceCode());
//根据设备编码查询设备
DeviceEntity deviceEntity = null;
try {
deviceEntity = deviceService.getExtCache(deviceMsgReq.getDeviceCode());
} catch (Exception e) {
log.error("redis 获取设备异常!", e);
continue;
}
if (!ObjectUtils.isEmpty(deviceEntity)) {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, deviceMsgReq.getMessageType());
header.put(MessageHeader.DEVICECODE, deviceMsgReq.getDeviceCode());
header.put(MessageHeader.TIMESTAMP, deviceMsgReq.getTimestamp().toString());
TbQueueMsg queueMsg = new DefaultTbQueueMsg(IdUtil.fastUUID(), deviceMsgReq.getData(), header);
messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg));
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
deviceLogEntity.initAttrValue();
deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID());
deviceLogEntity.setSiteId(deviceEntity.getSiteId());
deviceLogEntity.setDeviceId(deviceEntity.getId());
deviceLogEntity.setDeviceName(deviceEntity.getDeviceName());
deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode());
deviceLogEntity.setMessageHead(deviceMsgReq.getMessageType());
deviceLogEntity.setContent(deviceMsgReq.getData());
deviceLogEntity.setLogType(LogTypeEnum.下发服务.getValue());
deviceLogEntity.setCreateUserId(1L);
deviceLogEntity.setCreateTime(new Date());
deviceLogService.save(deviceLogEntity, null);
} else {
log.info("未找到设备,deviceCode:{}", deviceMsgReq.getDeviceCode());
}
}
try {
Thread.sleep(waitTime);
} catch (InterruptedException e2) {
}
} catch (Exception e) {
log.error("异常", e);
try {
Thread.sleep(waitTime);
} catch (InterruptedException e2) {
}
}
}
}
});
sendThread.start();
}
@Override
public void stop() {
log.info("停止服务..");
this.stopped = true;
}
@Override
public int getOrder() {
return 50;
}
}
......@@ -8,7 +8,6 @@ import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.pdu.DeviceReq;
import com.mortals.xhx.common.utils.SendTaskThreadPool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -23,9 +22,6 @@ import static com.mortals.xhx.common.key.RedisKey.KEY_DEVICE_THIRDPARTY_QUEUE;
@Slf4j
public class DeviceSendThirdPartyService implements IApplicationStartedService {
@Autowired
private SendTaskThreadPool sendTaskThreadPool;
protected Boolean stopped = false;
@Autowired
private ICacheService cacheService;
......@@ -73,33 +69,6 @@ public class DeviceSendThirdPartyService implements IApplicationStartedService {
sendThread.start();
//启动短信发送响应更新线程
/* sendTaskThreadPool.execute(() -> {
int waitTime = SEND_INTEVEL;
while (!stopped) {
try {
// DeviceReq deviceReq = cacheService.lpop(KEY_DEVICE_THIRDPARTY_QUEUE, DeviceReq.class);
// if (!ObjectUtils.isEmpty(deviceReq)) {
// String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
// ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(phpInUrl).addPath(thirdPartyPath).build(), deviceReq);
// log.info("sendThirty resp ==>{}", JSON.toJSONString(resp));
// }
// try {
// Thread.sleep(waitTime);
// } catch (InterruptedException e2) {
// }
} catch (Exception e) {
log.error("异常", e);
try {
Thread.sleep(waitTime);
} catch (InterruptedException e2) {
}
}
}
});*/
}
......
package com.mortals.xhx.daemon.task;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ITask;
import com.mortals.framework.service.ITaskExcuteService;
import com.mortals.xhx.base.system.user.model.UserEntity;
import com.mortals.xhx.base.system.user.model.UserQuery;
import com.mortals.xhx.base.system.user.service.UserService;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.RespData;
import com.mortals.xhx.common.pdu.user.UserPdu;
import com.mortals.xhx.feign.user.IUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 同步用户,唯一标识为用户名。
......@@ -39,7 +26,10 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
@Override
public void excuteTask(ITask task) throws AppException {
log.info("同步用户任务");
UserPdu userPdu = new UserPdu();
userService.refreshUser();
/* UserPdu userPdu = new UserPdu();
userPdu.setPage(1);
userPdu.setSize(-1);
Rest<RespData<List<UserPdu>>> resp = userFeign.list(userPdu);
......@@ -86,7 +76,7 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
//同步更新用户,以loginname为唯一标识,密码默认与用户相同
/* resp.getData().getData().forEach(user -> {
*//* resp.getData().getData().forEach(user -> {
log.info("loginName:{}", user.getLoginName());
UserEntity tempEntity = userService.selectOne(new UserQuery().loginName(user.getLoginName()));
if (ObjectUtils.isEmpty(tempEntity)) {
......@@ -101,8 +91,8 @@ public class SyncUserTaskImpl implements ITaskExcuteService {
log.info("更新:{}", JSON.toJSONString(userEntity));
userService.getUserDao().update(userEntity);
}
});*/
}
});*//*
}*/
// log.info("syncUserResp:{}", JSON.toJSONString(resp));
}
......
package com.mortals.xhx.module.device.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
......@@ -50,6 +51,17 @@ public class DeviceAlarmInfoController extends BaseCRUDJsonBodyMappingController
super.init(model, context);
}
@Override
@UnAuth
public Rest<Object> list(DeviceAlarmInfoEntity query) {
return super.list(query);
}
@Override
@UnAuth
public String info(Long id) {
return super.info(id);
}
@Override
protected void doListBefore(DeviceAlarmInfoEntity query, Map<String, Object> model, Context context) throws AppException {
......
......@@ -83,6 +83,12 @@ public class DeviceController extends BaseCRUDJsonBodyMappingController<DeviceSe
super.setModuleDesc("设备");
}
@Override
@UnAuth
public Rest<Object> list(DeviceEntity query) {
return super.list(query);
}
@Override
protected void init(Map<String, Object> model, Context context) {
this.addDict(model, "platformId", platformService.find(new PlatformEntity()).stream().collect(Collectors.toMap(x -> x.getId().toString(), y -> y.getPlatformName())));
......
package com.mortals.xhx.module.device.web;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.module.device.model.DeviceModuleUseEntity;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceModuleUseService;
import com.mortals.xhx.module.device.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.device.model.DeviceModuleUseEntity;
import com.mortals.xhx.module.device.service.DeviceModuleUseService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import java.util.Arrays;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 设备模块使用频率
......@@ -50,5 +41,15 @@ public class DeviceModuleUseController extends BaseCRUDJsonBodyMappingController
super.init(model, context);
}
@Override
@UnAuth
public Rest<Object> list(DeviceModuleUseEntity query) {
return super.list(query);
}
@Override
@UnAuth
public String info(Long id) {
return super.info(id);
}
}
\ No newline at end of file
......@@ -81,8 +81,8 @@ mybatis:
application:
auth:
unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/device/*,/api/*
uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*,/device/*,/api/*
unloginUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*
uncheckUrl: /refresh,/error,/login/login,/login/index,/login/logout,/securitycode/createCode,/file/common/*,/test*
registerApiPath: /api/register
deviceInitApiPath: /api/deviceInit
deviceUpdateApiPath: /api/deviceUpdate
......
......@@ -24,6 +24,14 @@ Content-Type: application/json
{}
###首页
POST {{baseUrl}}//api/callback
Authorization: {{authToken}}
Content-Type: application/json
[{"deviceCode":"26-55-E7-3F-B1-AF","messageType":"waitqueue","timestamp":"1699428063250","data":"W10="}]
###站点树
GET {{baseUrl}}/site/siteTree
Authorization: {{authToken}}
......
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