Merge branch 'master' of http://118.89.139.230:10101/r/~whyclxw/CadDrawManager
| | |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.pojo.DocUser; |
| | | import com.whyc.service.DocUserService; |
| | | import com.whyc.service.LoginService; |
| | | import com.whyc.util.ActionUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | @Autowired |
| | | private DocUserMapper userMapper; |
| | | |
| | | @Autowired |
| | | private LoginService service; |
| | | |
| | | @PostMapping("/") |
| | | @ApiOperation(value ="登录") |
| | | public Response login(@RequestParam String name, String snId, HttpServletRequest request){ |
| | |
| | | return true; |
| | | } |
| | | |
| | | @PostMapping("logout") |
| | | @ApiOperation(value ="退出登录") |
| | | public void logout(){ |
| | | service.logout(); |
| | | } |
| | | |
| | | } |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | |
| | | @Api(tags = "产品管理") |
| | | @RestController |
| | |
| | | |
| | | @ApiOperation(value = "历史版本可用性设定",notes = "8.31修改后使用") |
| | | @GetMapping("setpHistoryEnable") |
| | | public Response setpHistoryEnable( @RequestParam String parentCode, @RequestParam String customCode, @RequestParam int version,@RequestParam int enabled,@RequestParam(required = false) String reason) { |
| | | return historyService.setpHistoryEnable(parentCode, customCode, version, enabled,reason); |
| | | public Response setpHistoryEnable( @RequestParam String parentCode, @RequestParam String customCode, @RequestParam int version,@RequestParam int enabled,@RequestParam(required = false) String reason,@RequestParam String versionTime) { |
| | | return historyService.setpHistoryEnable(parentCode, customCode, version, enabled,reason,versionTime); |
| | | } |
| | | @PostMapping("zipParse") |
| | | @ApiOperation(value = "zip解析",notes = "返回结果中,追加data3为对比结果,为key-value集合,key为diffList,addList,deleteList") |
| | |
| | | private String parentCode; |
| | | private String customCode; |
| | | private Integer version; |
| | | private String versionTime; |
| | | @ApiModelProperty("1锁定,2解锁") |
| | | private Integer lockFlag; |
| | | private String reason; |
| | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | public String getVersionTime() { |
| | | return versionTime; |
| | | } |
| | | |
| | | public void setVersionTime(String versionTime) { |
| | | this.versionTime = versionTime; |
| | | } |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Page; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.DocUserMapper; |
| | | import com.whyc.pojo.DocDepart; |
| | |
| | | import org.apache.shiro.authc.UsernamePasswordToken; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.system.ApplicationHome; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | |
| | | return response.set(1,false,"密码错误"); |
| | | } |
| | | //登录成功 |
| | | ServletContext servletContext = request.getServletContext(); |
| | | servletContext.setAttribute(name, request.getSession().getId()); |
| | | //Session存储当前用户及权限组列表 |
| | | DocUser userDB = (DocUser) subject.getPrincipal(); |
| | | userDB.setSnId(null); |
New file |
| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.DocUser; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.apache.shiro.subject.Subject; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | | @Service |
| | | public class LoginService { |
| | | |
| | | public Response checkUserWebSocket(HttpSession httpSession){ |
| | | Response model = new Response(); |
| | | try { |
| | | DocUser user = (DocUser) httpSession.getAttribute("user"); |
| | | //System.out.println("webSocket:"+user); |
| | | if(user!=null){ |
| | | String sessionId = (String) httpSession.getServletContext().getAttribute(user.getName()); |
| | | if(httpSession.getId().equals(sessionId)){ |
| | | model.set(1,user,null); |
| | | }else{ |
| | | model.set(1,false,"不同主机登录"); |
| | | //用户在其他主机登录,强迫用户在本机的session失效 |
| | | httpSession.invalidate(); |
| | | } |
| | | } |
| | | else { |
| | | model.set(1,false,"用户信息失效,请重新登录"); |
| | | } |
| | | |
| | | }catch (Exception e){ |
| | | model.set(1,false,"登录信息失效,重新登录"); |
| | | } |
| | | return model; |
| | | } |
| | | |
| | | public void logout() { |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | subject.logout(); |
| | | } |
| | | } |
| | |
| | | } |
| | | //历史版本可用性设定 |
| | | @Transactional |
| | | public Response setpHistoryEnable(String parentCode, String customCode, int version, int enabled, String reason) { |
| | | public Response setpHistoryEnable(String parentCode, String customCode, int version, int enabled, String reason, String versionTime) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("parent_code",parentCode); |
| | | wrapper.eq("custom_code",customCode); |
| | |
| | | lockLog.setParentCode(parentCode); |
| | | lockLog.setCustomCode(customCode); |
| | | lockLog.setVersion(version); |
| | | lockLog.setVersionTime(versionTime); |
| | | lockLog.setReason(reason); |
| | | lockLog.setOwner(ActionUtil.getUser().getName()); |
| | | lockLog.setCreateTime(new Date()); |
| | |
| | | |
| | | public List<ProductLockLog> getListByParentCodeAndCustomCode(String parentCode, String customCode) { |
| | | QueryWrapper<ProductLockLog> query = Wrappers.query(); |
| | | query.eq("parent_code",parentCode).eq("custom_code",customCode); |
| | | query.eq("parent_code",parentCode).eq("custom_code",customCode).orderByDesc("id"); |
| | | return mapper.selectList(query); |
| | | } |
| | | } |
New file |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.LoginService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 账号重复登录检查 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/loginCheck",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class LoginCheckSocket { |
| | | |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | private static LoginService loginService; |
| | | |
| | | @Autowired |
| | | public void setLoginService(LoginService loginService) { |
| | | LoginCheckSocket.loginService = loginService; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session, EndpointConfig config){ |
| | | this.session = session; |
| | | HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | if(httpSession == null){ |
| | | Map<String, Response> res = new HashMap<>(); |
| | | Response resp1 = new Response().set(1, false, "登录信息失效,重新登录"); |
| | | res.put("checkLogin", resp1); |
| | | try { |
| | | session.getBasicRemote().sendObject(new Response().set(1,res)); |
| | | } catch (IOException | EncodeException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }else { |
| | | Thread thread = new Thread() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | Map<String, Response> res = new HashMap<>(); |
| | | Response sessionRes = new Response().set(1, httpSession.getId()); |
| | | while (!currentThread().isInterrupted()) { |
| | | Response response = loginService.checkUserWebSocket(httpSession); |
| | | res.put("checkLogin", response); |
| | | res.put("session", sessionRes); |
| | | session.getBasicRemote().sendObject(new Response().set(1, res)); |
| | | if (response.getData() instanceof Boolean) { |
| | | if(response.getData().equals(false)) { |
| | | this.interrupt(); |
| | | } |
| | | } |
| | | sleep(4000); |
| | | } |
| | | } catch (Exception e) { |
| | | this.interrupt(); |
| | | } |
| | | } |
| | | }; |
| | | thread.start(); |
| | | this.thread = thread; |
| | | } |
| | | } |
| | | |
| | | @OnClose |
| | | public void onClose(CloseReason closeReason) throws IOException { |
| | | System.err.println("closeReason = " + closeReason); |
| | | if(session.isOpen()){ |
| | | session.close(); |
| | | } |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable error) throws IOException { |
| | | error.printStackTrace(); |
| | | thread.isInterrupted(); |
| | | if(session.isOpen()){ |
| | | session.close(); |
| | | } |
| | | } |
| | | |
| | | } |