From 57b79b4f0e33bf984b22b8f4c11473b2ba3af60c Mon Sep 17 00:00:00 2001 From: yanyang Date: Thu, 2 Mar 2023 13:22:49 +0800 Subject: [PATCH 1/5] f --- .../java/com/cnbm/admin/base/BaseSupport.java | 155 ++++++++++++++++++ .../src/main/resources/application-dev.yml | 18 +- .../WoPackagingBoxSubstrateController.java | 4 +- .../WoPackagingBoxSubstrateServiceBiz.java | 2 +- ...angePackagingBoxHistoryServiceBizImpl.java | 8 + .../impl/PrintModelServiceBizImpl.java | 5 + .../WoCompensationPowerServiceBizImpl.java | 5 + .../impl/WoPackagingBoxServiceBizImpl.java | 6 + ...WoPackagingBoxSubstrateServiceBizImpl.java | 46 ++++-- ...WoPackagingPrintHistoryServiceBizImpl.java | 7 + .../impl/WoPowerLevelServiceBizImpl.java | 5 + 11 files changed, 232 insertions(+), 29 deletions(-) create mode 100644 ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java diff --git a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java new file mode 100644 index 0000000..64738e3 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2018. + * http://www.ulabcare.com + */ + +package com.cnbm.admin.base; + +import com.cnbm.admin.entity.LoginUser; +import com.cnbm.admin.enums.WhetherEnum; +import lombok.Builder; +import lombok.Data; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.NamedThreadLocal; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * 接口支持基类 + * + * @author jiff + * @date 2018/11/1 + * @since 1.0 + */ +@Service +public class BaseSupport { + + /** + * 获取当前登录用户信息 + * + * @return + */ + protected LoginUser getLoginUser() { + UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + + if (Objects.isNull(authentication)) { + LoginUser loginUser = (LoginUser) authentication.getPrincipal(); + return loginUser; + } + return null; + } + + + /** + * 设置公共字段值,一般用于创建新记录,包含以下字段: + * + *

+ * {@link CommonField#enabled}
+ * {@link CommonField#valid}
+ * {@link CommonField#creatorId}
+ * {@link CommonField#creatorName}
+ * {@link CommonField#createTime}
+ * {@link CommonField#updaterId}
+ * {@link CommonField#updaterName}
+ * {@link CommonField#updateTime}
+ *

+ * + * @param t 需要设置的对象 + * @param ignoreProperties 忽略的字段 + * @param + */ + public T setCommonField(T t, String... ignoreProperties) { + + CommonField commonField = CommonField.builder() + .enabled(WhetherEnum.YES.getValue()) + .valid(WhetherEnum.YES.getValue()) + .createTime(LocalDateTime.now()) + .creatorId(getLoginUser().getSysUserEntity().getId()) + .creatorName(getLoginUser().getUsername()) + .updateTime(LocalDateTime.now()) + .updaterId(getLoginUser().getSysUserEntity().getId()) + .updaterName(getLoginUser().getUsername()) + .build(); + BeanUtils.copyProperties(commonField, t, ignoreProperties); + return t; + } + + /** + * 设置更新的公共字段值,一般用于更新记录,包含以下字段: + * + *

+ * {@link CommonField#updaterId}
+ * {@link CommonField#updaterName}
+ * {@link CommonField#updateTime}
+ *

+ * + * @param t 需要设置的对象 + * @param + */ + public T setUpdateCommonField(T t) { + CommonField commonField = CommonField.builder() + .updaterId(getLoginUser().getSysUserEntity().getId()) + .updaterName(getLoginUser().getUsername()) + .updateTime(LocalDateTime.now()) + .build(); + BeanUtils.copyProperties(commonField, t, "enabled", "valid"); + return t; + } + + @Data + @Builder + private static class CommonField implements Serializable { + /** + * 启用状态:0 、停用,1、启用 + */ + private Integer enabled; + /** + * 删除标志,是否有效:1 可用 0不可用 + */ + private Integer valid; + + /** + * 创建人 + */ + private Long creatorId; + /** + * 创建人 + */ + private String creatorName; + /** + * 创建时间 + */ + private LocalDateTime createTime; + + + /** + * 更新人 + */ + private Long updaterId; + /** + * 更新人 + */ + private String updaterName; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + } +} diff --git a/ym-gateway/src/main/resources/application-dev.yml b/ym-gateway/src/main/resources/application-dev.yml index d85aabd..3bbe591 100644 --- a/ym-gateway/src/main/resources/application-dev.yml +++ b/ym-gateway/src/main/resources/application-dev.yml @@ -61,14 +61,14 @@ dynamic: # username: root # password: 1qaz@WSX3edc$RFV ## camline系统 -# camline: -# driver-class-name: com.mysql.cj.jdbc.Driver -# url: jdbc:mysql://mysql.picaiba.com:30307/mt_cigs4?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true -# username: root -# password: 1qaz@WSX3edc$RFV -# camline: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://10.0.1.23:3306/synapse?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true - username: offline_data - password: tpvmfab4 \ No newline at end of file + url: jdbc:mysql://mysql.picaiba.com:30307/mt_cigs4?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true + username: root + password: 1qaz@WSX3edc$RFV +# +# camline: +# driver-class-name: com.mysql.cj.jdbc.Driver +# url: jdbc:mysql://10.0.1.23:3306/synapse?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true +# username: offline_data +# password: tpvmfab4 \ No newline at end of file diff --git a/ym-packing/src/main/java/com/cnbm/packing/controller/WoPackagingBoxSubstrateController.java b/ym-packing/src/main/java/com/cnbm/packing/controller/WoPackagingBoxSubstrateController.java index fd5aebb..add9f87 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/controller/WoPackagingBoxSubstrateController.java +++ b/ym-packing/src/main/java/com/cnbm/packing/controller/WoPackagingBoxSubstrateController.java @@ -210,9 +210,9 @@ public class WoPackagingBoxSubstrateController { @PostMapping("insertSubstrateManual") @ApiOperation("手动装箱") @LogOperation("手动装箱") - public Result insertSubstrateManual(@RequestBody ChangePackingBoxDTO dto){ + public Result insertSubstrateManual(@RequestBody ChangePackingBoxDTO[] dtos){ - woPackagingBoxSubstrateService.insertSubstrateManual(dto); + woPackagingBoxSubstrateService.insertSubstrateManual(dtos); return new Result(); } diff --git a/ym-packing/src/main/java/com/cnbm/packing/service/WoPackagingBoxSubstrateServiceBiz.java b/ym-packing/src/main/java/com/cnbm/packing/service/WoPackagingBoxSubstrateServiceBiz.java index ad4a4ed..8668a9f 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/service/WoPackagingBoxSubstrateServiceBiz.java +++ b/ym-packing/src/main/java/com/cnbm/packing/service/WoPackagingBoxSubstrateServiceBiz.java @@ -32,7 +32,7 @@ public interface WoPackagingBoxSubstrateServiceBiz extends CrudService implements ChangePackagingBoxHistoryServiceBiz { + @Autowired + private BaseSupport baseSupport; + @Override public QueryWrapper getWrapper(Map params){ LocalDateTime startTime = (LocalDateTime) params.get("startTime"); @@ -65,6 +71,7 @@ public class ChangePackagingBoxHistoryServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -69,6 +72,7 @@ public class PrintModelServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -66,6 +69,7 @@ public class WoCompensationPowerServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -83,6 +87,7 @@ public class WoPackagingBoxServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -75,6 +78,7 @@ public class WoPackagingBoxSubstrateServiceBizImpl extends CrudServiceImpl wrapper = new UpdateWrapper<>(); @@ -126,10 +132,12 @@ public class WoPackagingBoxSubstrateServiceBizImpl extends CrudServiceImpl wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(dto.getWoSubstrateId()),WoPackagingBoxSubstrate.WO_SUBSTRATE_ID,dto.getWoSubstrateId()); - if(mapper.selectCount(wrapper)>0 && StringUtils.isNotBlank(dto.getWoSubstrateId())) { - WoPackagingBoxSubstrate substrate = mapper.selectList(wrapper).get(0); - substrate.setPackagingBoxId(dto.getPackagingBoxId()); - updateById(substrate); - } - else{ - //模组ID有时为空,用户会输入”无码“ - if(dto.getWoSubstrateId()==null) { - dto.setWoSubstrateId("无码"); + public void insertSubstrateManual(ChangePackingBoxDTO[] dtos) { + for(ChangePackingBoxDTO dto : dtos) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq(StringUtils.isNotBlank(dto.getWoSubstrateId()), WoPackagingBoxSubstrate.WO_SUBSTRATE_ID, dto.getWoSubstrateId()); + if (mapper.selectCount(wrapper) > 0 && StringUtils.isNotBlank(dto.getWoSubstrateId())) { + WoPackagingBoxSubstrate substrate = mapper.selectList(wrapper).get(0); + substrate.setPackagingBoxId(dto.getPackagingBoxId()); + baseSupport.setUpdateCommonField(substrate); + updateById(substrate); + } else { + //模组ID有时为空,用户会输入”无码“ + if (dto.getWoSubstrateId() == null) { + dto.setWoSubstrateId("无码"); + } + //效验数据 + ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); + WoPackagingBoxSubstrate entity = ConvertUtils.sourceToTarget(dto, WoPackagingBoxSubstrate.class); + baseSupport.setCommonField(entity); + insert(entity); } - //效验数据 - ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - WoPackagingBoxSubstrate entity = ConvertUtils.sourceToTarget(dto, WoPackagingBoxSubstrate.class); - insert(entity); } } diff --git a/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingPrintHistoryServiceBizImpl.java b/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingPrintHistoryServiceBizImpl.java index 704a680..55f8909 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingPrintHistoryServiceBizImpl.java +++ b/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingPrintHistoryServiceBizImpl.java @@ -3,6 +3,7 @@ package com.cnbm.packing.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.cnbm.admin.base.BaseSupport; import com.cnbm.admin.enums.WhetherEnum; import com.cnbm.common.page.PageData; import com.cnbm.common.service.impl.CrudServiceImpl; @@ -42,6 +43,8 @@ public class WoPackagingPrintHistoryServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -64,6 +67,7 @@ public class WoPowerLevelServiceBizImpl extends CrudServiceImpl Date: Thu, 2 Mar 2023 15:12:54 +0800 Subject: [PATCH 2/5] common --- ym-admin/pom.xml | 5 ++ .../java/com/cnbm/admin/base/BaseSupport.java | 62 +++++++++++------- .../java/com/cnbm/admin/dto/LoginUserDTO.java | 65 +++++++++++++++++++ 3 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java diff --git a/ym-admin/pom.xml b/ym-admin/pom.xml index 132653d..54a505d 100644 --- a/ym-admin/pom.xml +++ b/ym-admin/pom.xml @@ -43,6 +43,11 @@ ym-common 1.0-SNAPSHOT + + com.alibaba + fastjson + 1.2.75 + diff --git a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java index 64738e3..6779778 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java +++ b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java @@ -5,18 +5,13 @@ package com.cnbm.admin.base; -import com.cnbm.admin.entity.LoginUser; +import com.alibaba.fastjson.JSON; +import com.cnbm.admin.dto.LoginUserDTO; import com.cnbm.admin.enums.WhetherEnum; import lombok.Builder; import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.NamedThreadLocal; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; @@ -26,10 +21,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.Serializable; import java.time.LocalDateTime; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.TimeUnit; /** * 接口支持基类 @@ -41,19 +32,40 @@ import java.util.concurrent.TimeUnit; @Service public class BaseSupport { + protected LoginUserDTO getLoginUser() { + // 后续完善拦截器再使用该方式 +// LoginUser loginUser = loginUserHolder.get(); +// if (loginUser != null) { +// return loginUser; +// } + HttpSession session = getHttpServletRequest().getSession(false); + LoginUserDTO loginUser = null; + if (session != null) { + String loginUserJson = (String) session.getAttribute(LoginUserDTO.HTTP_HEADER_NAME); + if (StringUtils.isNotBlank(loginUserJson)) { + loginUser = JSON.parseObject(loginUserJson, LoginUserDTO.class); + return loginUser; + } + } + return null; + } + /** - * 获取当前登录用户信息 + * 获取当前http请求对象 * * @return */ - protected LoginUser getLoginUser() { - UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); + protected HttpServletRequest getHttpServletRequest() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); + } - if (Objects.isNull(authentication)) { - LoginUser loginUser = (LoginUser) authentication.getPrincipal(); - return loginUser; - } - return null; + /** + * 获取当前http响应对象 + * + * @return + */ + protected HttpServletResponse getHttpServletResponse() { + return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); } @@ -81,11 +93,11 @@ public class BaseSupport { .enabled(WhetherEnum.YES.getValue()) .valid(WhetherEnum.YES.getValue()) .createTime(LocalDateTime.now()) - .creatorId(getLoginUser().getSysUserEntity().getId()) - .creatorName(getLoginUser().getUsername()) + .creatorId(getLoginUser().getUserId()) + .creatorName(getLoginUser().getUserName()) .updateTime(LocalDateTime.now()) - .updaterId(getLoginUser().getSysUserEntity().getId()) - .updaterName(getLoginUser().getUsername()) + .updaterId(getLoginUser().getUserId()) + .updaterName(getLoginUser().getUserName()) .build(); BeanUtils.copyProperties(commonField, t, ignoreProperties); return t; @@ -105,8 +117,8 @@ public class BaseSupport { */ public T setUpdateCommonField(T t) { CommonField commonField = CommonField.builder() - .updaterId(getLoginUser().getSysUserEntity().getId()) - .updaterName(getLoginUser().getUsername()) + .updaterId(getLoginUser().getUserId()) + .updaterName(getLoginUser().getUserName()) .updateTime(LocalDateTime.now()) .build(); BeanUtils.copyProperties(commonField, t, "enabled", "valid"); diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java new file mode 100644 index 0000000..46f4177 --- /dev/null +++ b/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018. + * http://www.ulabcare.com + */ + +package com.cnbm.admin.dto; + +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * @author jiff + * @date 2018/11/1 + * @since 1.0 + */ +@EqualsAndHashCode(callSuper = false) +@Builder +@Data +@Accessors(chain = true) +public class LoginUserDTO implements Serializable { + public static final String HTTP_HEADER_NAME = "loginUser"; + public static final int USER_TYPE_PLATFORM = 1; + public static final int USER_TYPE_PARTNER = 2; + public static final int USER_TYPE_HOSPITAL = 3; + public static final int USER_TYPE_PATIENT = 4; + /** + * 会话ID + */ + private String sessionId; + private Long passportUserId; + private Long userId; + private Long partnerId; + private Long hospitalId; + private Long orgId; + private String mobile; + private String userName; + /** + * 用户类型 + */ + private int userType; + /** + * 应用类型 + */ + private int appType; + /** + * 应用代码 + */ + private int appCode; + /** + * 登录类型:1、自主登录,2、漫游登录 + */ + private int loginType; + /** + * 微信appId + */ + private String wechatAppId; + /** + * 微信openId + */ + private String openId; +} From e405dcb06aaf338416f64e2d41acbb7043aa396e Mon Sep 17 00:00:00 2001 From: yanyang Date: Thu, 2 Mar 2023 17:02:10 +0800 Subject: [PATCH 3/5] commonfield --- .../java/com/cnbm/admin/base/BaseSupport.java | 21 ++++++++++--------- .../java/com/cnbm/admin/entity/LoginUser.java | 2 ++ .../admin/service/impl/LoginServiceImpl.java | 10 +++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java index 6779778..4211d71 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java +++ b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java @@ -7,6 +7,7 @@ package com.cnbm.admin.base; import com.alibaba.fastjson.JSON; import com.cnbm.admin.dto.LoginUserDTO; +import com.cnbm.admin.entity.LoginUser; import com.cnbm.admin.enums.WhetherEnum; import lombok.Builder; import lombok.Data; @@ -32,18 +33,18 @@ import java.time.LocalDateTime; @Service public class BaseSupport { - protected LoginUserDTO getLoginUser() { + protected LoginUser getLoginUser() { // 后续完善拦截器再使用该方式 // LoginUser loginUser = loginUserHolder.get(); // if (loginUser != null) { // return loginUser; // } HttpSession session = getHttpServletRequest().getSession(false); - LoginUserDTO loginUser = null; + LoginUser loginUser = null; if (session != null) { - String loginUserJson = (String) session.getAttribute(LoginUserDTO.HTTP_HEADER_NAME); + String loginUserJson = (String) session.getAttribute(LoginUser.HTTP_HEADER_NAME); if (StringUtils.isNotBlank(loginUserJson)) { - loginUser = JSON.parseObject(loginUserJson, LoginUserDTO.class); + loginUser = JSON.parseObject(loginUserJson, LoginUser.class); return loginUser; } } @@ -93,11 +94,11 @@ public class BaseSupport { .enabled(WhetherEnum.YES.getValue()) .valid(WhetherEnum.YES.getValue()) .createTime(LocalDateTime.now()) - .creatorId(getLoginUser().getUserId()) - .creatorName(getLoginUser().getUserName()) + .creatorId(getLoginUser().getSysUserEntity().getId()) + .creatorName(getLoginUser().getUsername()) .updateTime(LocalDateTime.now()) - .updaterId(getLoginUser().getUserId()) - .updaterName(getLoginUser().getUserName()) + .updaterId(getLoginUser().getSysUserEntity().getId()) + .updaterName(getLoginUser().getUsername()) .build(); BeanUtils.copyProperties(commonField, t, ignoreProperties); return t; @@ -117,8 +118,8 @@ public class BaseSupport { */ public T setUpdateCommonField(T t) { CommonField commonField = CommonField.builder() - .updaterId(getLoginUser().getUserId()) - .updaterName(getLoginUser().getUserName()) + .updaterId(getLoginUser().getSysUserEntity().getId()) + .updaterName(getLoginUser().getUsername()) .updateTime(LocalDateTime.now()) .build(); BeanUtils.copyProperties(commonField, t, "enabled", "valid"); diff --git a/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java b/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java index 6d1b4f4..7812267 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java +++ b/ym-admin/src/main/java/com/cnbm/admin/entity/LoginUser.java @@ -24,6 +24,8 @@ public class LoginUser implements UserDetails{ private static final long serialVersionUID = 1L; + public static final String HTTP_HEADER_NAME = "loginUser"; + private SysUserEntity sysUserEntity; private List permissions; diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java index cdf977c..3e5fbda 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java @@ -1,5 +1,7 @@ package com.cnbm.admin.service.impl; +import com.alibaba.fastjson.JSON; +import com.cnbm.admin.dto.LoginUserDTO; import com.cnbm.admin.entity.LoginUser; import com.cnbm.admin.entity.SysLogLoginEntity; import com.cnbm.admin.enums.LoginOperationEnum; @@ -22,8 +24,11 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -81,6 +86,11 @@ public class LoginServiceImpl implements LoginService { map.put("token",jwt); //把完整的用户信息存入redis userid作为key redisTemplate.opsForValue().set("login:"+userid,loginUser,1, TimeUnit.DAYS); + + //当前登录用户信息存入session中 + HttpSession session = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession(); + session.setAttribute(loginUser.HTTP_HEADER_NAME, JSON.toJSONString(loginUser)); + //登录成功 log.setStatus(LoginStatusEnum.SUCCESS.value()); log.setCreator(loginUser.getSysUserEntity().getId()); From 8fa7a486fdcd4d87ee8dea28cb9ec26874f61aab Mon Sep 17 00:00:00 2001 From: yanyang Date: Thu, 2 Mar 2023 20:05:41 +0800 Subject: [PATCH 4/5] m --- .../java/com/cnbm/admin/base/BaseSupport.java | 1 - .../java/com/cnbm/admin/dto/LoginUserDTO.java | 65 ------------------- .../admin/service/impl/LoginServiceImpl.java | 2 - .../impl/WoPackagingBoxServiceBizImpl.java | 2 +- 4 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java diff --git a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java index 4211d71..79c0cce 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java +++ b/ym-admin/src/main/java/com/cnbm/admin/base/BaseSupport.java @@ -6,7 +6,6 @@ package com.cnbm.admin.base; import com.alibaba.fastjson.JSON; -import com.cnbm.admin.dto.LoginUserDTO; import com.cnbm.admin.entity.LoginUser; import com.cnbm.admin.enums.WhetherEnum; import lombok.Builder; diff --git a/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java b/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java deleted file mode 100644 index 46f4177..0000000 --- a/ym-admin/src/main/java/com/cnbm/admin/dto/LoginUserDTO.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2018. - * http://www.ulabcare.com - */ - -package com.cnbm.admin.dto; - -import lombok.Builder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import java.io.Serializable; - -/** - * @author jiff - * @date 2018/11/1 - * @since 1.0 - */ -@EqualsAndHashCode(callSuper = false) -@Builder -@Data -@Accessors(chain = true) -public class LoginUserDTO implements Serializable { - public static final String HTTP_HEADER_NAME = "loginUser"; - public static final int USER_TYPE_PLATFORM = 1; - public static final int USER_TYPE_PARTNER = 2; - public static final int USER_TYPE_HOSPITAL = 3; - public static final int USER_TYPE_PATIENT = 4; - /** - * 会话ID - */ - private String sessionId; - private Long passportUserId; - private Long userId; - private Long partnerId; - private Long hospitalId; - private Long orgId; - private String mobile; - private String userName; - /** - * 用户类型 - */ - private int userType; - /** - * 应用类型 - */ - private int appType; - /** - * 应用代码 - */ - private int appCode; - /** - * 登录类型:1、自主登录,2、漫游登录 - */ - private int loginType; - /** - * 微信appId - */ - private String wechatAppId; - /** - * 微信openId - */ - private String openId; -} diff --git a/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java index 3e5fbda..064314a 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java +++ b/ym-admin/src/main/java/com/cnbm/admin/service/impl/LoginServiceImpl.java @@ -1,7 +1,6 @@ package com.cnbm.admin.service.impl; import com.alibaba.fastjson.JSON; -import com.cnbm.admin.dto.LoginUserDTO; import com.cnbm.admin.entity.LoginUser; import com.cnbm.admin.entity.SysLogLoginEntity; import com.cnbm.admin.enums.LoginOperationEnum; @@ -11,7 +10,6 @@ import com.cnbm.admin.service.CaptchaService; import com.cnbm.admin.service.SysLogLoginService; import com.cnbm.admin.utils.JwtUtil; import com.cnbm.admin.service.LoginService; -import com.cnbm.admin.utils.ResponseResult; import com.cnbm.common.exception.ErrorCode; import com.cnbm.common.utils.IpUtils; import com.cnbm.common.utils.Result; diff --git a/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingBoxServiceBizImpl.java b/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingBoxServiceBizImpl.java index a5aba1e..7f21dc1 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingBoxServiceBizImpl.java +++ b/ym-packing/src/main/java/com/cnbm/packing/service/impl/WoPackagingBoxServiceBizImpl.java @@ -86,8 +86,8 @@ public class WoPackagingBoxServiceBizImpl extends CrudServiceImpl Date: Fri, 3 Mar 2023 09:51:54 +0800 Subject: [PATCH 5/5] BaseSupportUtils --- ...angePackagingBoxHistoryServiceBizImpl.java | 9 ++++---- .../impl/PrintModelServiceBizImpl.java | 9 ++++---- .../WoCompensationPowerServiceBizImpl.java | 9 ++++---- .../impl/WoPackagingBoxServiceBizImpl.java | 9 ++++---- ...WoPackagingBoxSubstrateServiceBizImpl.java | 23 ++++++++++--------- ...WoPackagingPrintHistoryServiceBizImpl.java | 13 ++++++----- .../impl/WoPowerLevelServiceBizImpl.java | 9 ++++---- 7 files changed, 44 insertions(+), 37 deletions(-) diff --git a/ym-packing/src/main/java/com/cnbm/packing/service/impl/ChangePackagingBoxHistoryServiceBizImpl.java b/ym-packing/src/main/java/com/cnbm/packing/service/impl/ChangePackagingBoxHistoryServiceBizImpl.java index 9ec9c0a..a71cc81 100644 --- a/ym-packing/src/main/java/com/cnbm/packing/service/impl/ChangePackagingBoxHistoryServiceBizImpl.java +++ b/ym-packing/src/main/java/com/cnbm/packing/service/impl/ChangePackagingBoxHistoryServiceBizImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.cnbm.admin.base.BaseSupport; import com.cnbm.admin.base.BaseSupport; +import com.cnbm.admin.utils.BaseSupportUtils; import com.cnbm.common.page.PageData; import com.cnbm.common.service.impl.CrudServiceImpl; import com.cnbm.common.utils.ConvertUtils; @@ -33,8 +34,8 @@ import java.util.Map; @Service public class ChangePackagingBoxHistoryServiceBizImpl extends CrudServiceImpl implements ChangePackagingBoxHistoryServiceBiz { - @Autowired - private BaseSupport baseSupport; +// @Autowired +// private BaseSupport baseSupport; @Override public QueryWrapper getWrapper(Map params){ @@ -71,7 +72,7 @@ public class ChangePackagingBoxHistoryServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -72,7 +73,7 @@ public class PrintModelServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -69,7 +70,7 @@ public class WoCompensationPowerServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -86,7 +87,7 @@ public class WoPackagingBoxServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -78,7 +79,7 @@ public class WoPackagingBoxSubstrateServiceBizImpl extends CrudServiceImpl wrapper = new UpdateWrapper<>(); @@ -132,12 +133,12 @@ public class WoPackagingBoxSubstrateServiceBizImpl extends CrudServiceImpl 0 && StringUtils.isNotBlank(dto.getWoSubstrateId())) { WoPackagingBoxSubstrate substrate = mapper.selectList(wrapper).get(0); substrate.setPackagingBoxId(dto.getPackagingBoxId()); - baseSupport.setUpdateCommonField(substrate); + BaseSupportUtils.setUpdateCommonField(substrate); updateById(substrate); } else { //模组ID有时为空,用户会输入”无码“ @@ -183,7 +184,7 @@ public class WoPackagingBoxSubstrateServiceBizImpl extends CrudServiceImpl getWrapper(Map params){ @@ -67,7 +68,7 @@ public class WoPowerLevelServiceBizImpl extends CrudServiceImpl