|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSON; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.mapper.Wrapper; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.*; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.common.CodeRes; | 
|---|
|  |  |  | import com.zy.common.entity.Parameter; | 
|---|
|  |  |  | import com.zy.common.model.PowerDto; | 
|---|
|  |  |  | import com.zy.common.model.enums.HtmlNavIconType; | 
|---|
|  |  |  | import com.zy.common.properties.OSinfo; | 
|---|
|  |  |  | import com.zy.common.properties.SystemProperties; | 
|---|
|  |  |  | import com.zy.common.utils.RandomValidateCodeUtil; | 
|---|
|  |  |  | import com.zy.system.entity.*; | 
|---|
|  |  |  | import com.zy.system.entity.license.LicenseVerify; | 
|---|
|  |  |  | import com.zy.system.service.*; | 
|---|
|  |  |  | import com.core.annotations.ManagerAuth; | 
|---|
|  |  |  | import com.core.common.Cools; | 
|---|
|  |  |  | import com.core.common.R; | 
|---|
|  |  |  | import com.core.exception.CoolException; | 
|---|
|  |  |  | import com.zy.system.timer.LicenseTimer; | 
|---|
|  |  |  | import com.zy.system.timer.LoadingConfigTimer; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Value; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PathVariable; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | private PermissionService permissionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RolePermissionService rolePermissionService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LicenseTimer licenseTimer; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private LoadingConfigTimer loadingConfigTimer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/login.action") | 
|---|
|  |  |  | @PostMapping("/login.action") | 
|---|
|  |  |  | @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "登录") | 
|---|
|  |  |  | public R loginAction(String mobile, String password){ | 
|---|
|  |  |  | if (mobile.equals("super") && password.equals(Cools.md5(superPwd))) { | 
|---|
|  |  |  | Map<String, Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("username", mobile); | 
|---|
|  |  |  | res.put("token", Cools.enToken(System.currentTimeMillis() + mobile, superPwd)); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | public R loginAction(@RequestBody Map<String, String> param) { | 
|---|
|  |  |  | //验证许可证是否有效 | 
|---|
|  |  |  | if (!licenseTimer.getSystemSupport()) { | 
|---|
|  |  |  | return R.parse(CodeRes.SYSTEM_20001); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | EntityWrapper<User> userWrapper = new EntityWrapper<>(); | 
|---|
|  |  |  | userWrapper.eq("mobile", mobile); | 
|---|
|  |  |  | userWrapper.eq("username", param.get("username")); | 
|---|
|  |  |  | User user = userService.selectOne(userWrapper); | 
|---|
|  |  |  | if (Cools.isEmpty(user)){ | 
|---|
|  |  |  | if (Cools.isEmpty(user)) { | 
|---|
|  |  |  | if (param.get("username").equals("super") && param.get("password").equals(Cools.md5(superPwd))) { | 
|---|
|  |  |  | Map<String, Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("username", param.get("username")); | 
|---|
|  |  |  | res.put("token", Cools.enToken(System.currentTimeMillis() + param.get("username"), superPwd)); | 
|---|
|  |  |  | return R.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10001); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (user.getStatus()!=1){ | 
|---|
|  |  |  | if (user.getStatus() != 1) { | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10002); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!user.getPassword().equals(password)){ | 
|---|
|  |  |  | if (!user.getPassword().equals(param.get("password"))) { | 
|---|
|  |  |  | return R.parse(CodeRes.USER_10003); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String token = Cools.enToken(System.currentTimeMillis() + mobile, user.getPassword()); | 
|---|
|  |  |  | userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId())); | 
|---|
|  |  |  | UserLogin userLogin = new UserLogin(); | 
|---|
|  |  |  | String token = Cools.enToken(System.currentTimeMillis() + param.get("username"), user.getPassword()); | 
|---|
|  |  |  | if (loadingConfigTimer.getTokenNumber() == 1) { | 
|---|
|  |  |  | userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()).eq("system", "WMS")); | 
|---|
|  |  |  | }        UserLogin userLogin = new UserLogin(); | 
|---|
|  |  |  | userLogin.setUserId(user.getId()); | 
|---|
|  |  |  | userLogin.setToken(token); | 
|---|
|  |  |  | userLogin.setCreateTime(new Date()); | 
|---|
|  |  |  | userLogin.setSystem("WMS"); | 
|---|
|  |  |  | userLoginService.insert(userLogin); | 
|---|
|  |  |  | Map<String, Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("username", user.getUsername()); | 
|---|
|  |  |  | 
|---|
|  |  |  | int time = 0; | 
|---|
|  |  |  | while (time < 3000) { | 
|---|
|  |  |  | code = RandomValidateCodeUtil.code.get(sd); | 
|---|
|  |  |  | if (!Cools.isEmpty(code)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(code)) { | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Thread.sleep(10); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/user/detail/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R userDetail(){ | 
|---|
|  |  |  | public R userDetail() { | 
|---|
|  |  |  | return R.ok(userService.selectById(getUserId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/menu/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R menu(){ | 
|---|
|  |  |  | public R menu() { | 
|---|
|  |  |  | // 获取所有一级菜单 | 
|---|
|  |  |  | List<Resource> oneLevel = resourceService.selectList(new EntityWrapper<Resource>().eq("level", 1).eq("status", 1).orderBy("sort")); | 
|---|
|  |  |  | List<Resource> oneLevel; | 
|---|
|  |  |  | User user = null; | 
|---|
|  |  |  | Wrapper<Resource> resourceWrapper; | 
|---|
|  |  |  | if (getUserId() == 9527) { | 
|---|
|  |  |  | oneLevel = resourceService.selectList(new EntityWrapper<Resource>().eq("level", 1).orderBy("sort")); | 
|---|
|  |  |  | resourceWrapper = new EntityWrapper<Resource>().eq("level", 2).eq("status", 1).orderBy("sort"); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | // 激活码验证 | 
|---|
|  |  |  | if (!SystemProperties.SYSTEM_ACTIVATION) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oneLevel = resourceService.selectList(new EntityWrapper<Resource>().eq("level", 1).eq("status", 1).orderBy("sort")); | 
|---|
|  |  |  | // 获取当前用户的所有二级菜单 | 
|---|
|  |  |  | user = userService.selectById(getUserId()); | 
|---|
|  |  |  | List<RoleResource> roleResources = roleResourceService.selectList(new EntityWrapper<RoleResource>().eq("role_id", user.getRoleId())); | 
|---|
|  |  |  | List<Long> resourceIds = new ArrayList<>(); | 
|---|
|  |  |  | roleResources.forEach(roleResource -> resourceIds.add(roleResource.getResourceId())); | 
|---|
|  |  |  | if (resourceIds.isEmpty()){ | 
|---|
|  |  |  | if (resourceIds.isEmpty()) { | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | resourceWrapper = new EntityWrapper<Resource>().in("id", resourceIds).eq("level", 2).eq("status", 1).orderBy("sort"); | 
|---|
|  |  |  | 
|---|
|  |  |  | // 是否拥有查看权限 | 
|---|
|  |  |  | if (getUserId() != 9527) { | 
|---|
|  |  |  | Resource view = resourceService.selectOne(new EntityWrapper<Resource>().eq("resource_id", resource.getId()).like("code", "#view")); | 
|---|
|  |  |  | if (!Cools.isEmpty(view)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(view)) { | 
|---|
|  |  |  | RoleResource param = new RoleResource(); | 
|---|
|  |  |  | param.setResourceId(view.getId()); | 
|---|
|  |  |  | param.setRoleId(user.getRoleId()); | 
|---|
|  |  |  | if (null == roleResourceService.selectOne(new EntityWrapper<>(param))){ | 
|---|
|  |  |  | if (null == roleResourceService.selectOne(new EntityWrapper<>(param))) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping("/power/list/auth") | 
|---|
|  |  |  | @ManagerAuth | 
|---|
|  |  |  | public R powerList(){ | 
|---|
|  |  |  | public R powerList() { | 
|---|
|  |  |  | List<Resource> oneLevels = resourceService.selectList(new EntityWrapper<Resource>().eq("level", 1).eq("status", 1).orderBy("sort")); | 
|---|
|  |  |  | List<Map> result = new ArrayList<>(); | 
|---|
|  |  |  | // 一级 | 
|---|
|  |  |  | for (Resource oneLevel : oneLevels){ | 
|---|
|  |  |  | for (Resource oneLevel : oneLevels) { | 
|---|
|  |  |  | List<Map> twoLevelsList = new ArrayList<>(); | 
|---|
|  |  |  | Map<String, Object> oneLevelMap = new HashMap<>(); | 
|---|
|  |  |  | oneLevelMap.put("title", oneLevel.getName()); | 
|---|
|  |  |  | 
|---|
|  |  |  | oneLevelMap.put("children", twoLevelsList); | 
|---|
|  |  |  | List<Resource> twoLevels = resourceService.selectList(new EntityWrapper<Resource>().eq("resource_id", oneLevel.getId()).eq("level", 2).eq("status", 1).orderBy("sort")); | 
|---|
|  |  |  | // 二级 | 
|---|
|  |  |  | for (Resource twoLevel : twoLevels){ | 
|---|
|  |  |  | for (Resource twoLevel : twoLevels) { | 
|---|
|  |  |  | Map<String, Object> twoLevelMap = new HashMap<>(); | 
|---|
|  |  |  | twoLevelMap.put("title", twoLevel.getName()); | 
|---|
|  |  |  | twoLevelMap.put("id", twoLevel.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | twoLevelMap.put("children", threeLevelsList); | 
|---|
|  |  |  | // 三级 | 
|---|
|  |  |  | List<Resource> threeLevels = resourceService.selectList(new EntityWrapper<Resource>().eq("resource_id", twoLevel.getId()).eq("level", 3).eq("status", 1).orderBy("sort")); | 
|---|
|  |  |  | for (Resource threeLevel : threeLevels){ | 
|---|
|  |  |  | for (Resource threeLevel : threeLevels) { | 
|---|
|  |  |  | Map<String, Object> threeLevelMap = new HashMap<>(); | 
|---|
|  |  |  | threeLevelMap.put("title", threeLevel.getName()); | 
|---|
|  |  |  | threeLevelMap.put("id", threeLevel.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | List<Object> result = new ArrayList<>(); | 
|---|
|  |  |  | // 菜单 | 
|---|
|  |  |  | List<RoleResource> roleResources = roleResourceService.selectList(new EntityWrapper<RoleResource>().eq("role_id", roleId)); | 
|---|
|  |  |  | for (RoleResource roleResource : roleResources){ | 
|---|
|  |  |  | for (RoleResource roleResource : roleResources) { | 
|---|
|  |  |  | Resource resource = resourceService.selectById(roleResource.getResourceId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(resource)){ | 
|---|
|  |  |  | if (resource.getLevel() == 3){ | 
|---|
|  |  |  | if (!Cools.isEmpty(resource)) { | 
|---|
|  |  |  | if (resource.getLevel() == 3) { | 
|---|
|  |  |  | result.add(resource.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | // 功能 | 
|---|
|  |  |  | List<RolePermission> rolePermissions = rolePermissionService.selectList(new EntityWrapper<RolePermission>().eq("role_id", roleId)); | 
|---|
|  |  |  | for (RolePermission rolePermission : rolePermissions){ | 
|---|
|  |  |  | for (RolePermission rolePermission : rolePermissions) { | 
|---|
|  |  |  | Permission permission = permissionService.selectById(rolePermission.getPermissionId()); | 
|---|
|  |  |  | if (!Cools.isEmpty(permission)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(permission)) { | 
|---|
|  |  |  | result.add(permission.getAction()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @RequestMapping("/power/auth") | 
|---|
|  |  |  | @ManagerAuth(memo = "授权") | 
|---|
|  |  |  | @Transactional | 
|---|
|  |  |  | public R power(Long roleId, String powers){ | 
|---|
|  |  |  | public R power(Long roleId, String powers) { | 
|---|
|  |  |  | Role role = roleService.selectById(roleId); | 
|---|
|  |  |  | Long leaderId = role.getLeader(); | 
|---|
|  |  |  | roleResourceService.delete(new EntityWrapper<RoleResource>().eq("role_id", roleId)); | 
|---|
|  |  |  | rolePermissionService.delete(new EntityWrapper<RolePermission>().eq("role_id", roleId)); | 
|---|
|  |  |  | if (!Cools.isEmpty(powers)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(powers)) { | 
|---|
|  |  |  | List<PowerDto> dtos = JSON.parseArray(powers, PowerDto.class); | 
|---|
|  |  |  | for (PowerDto dto : dtos) { | 
|---|
|  |  |  | Resource resource = resourceService.selectOne(new EntityWrapper<Resource>().eq("id", dto.getTwo()).eq("level", 2)); | 
|---|
|  |  |  | 
|---|
|  |  |  | roleResourceService.insert(roleResource); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | Permission permission = permissionService.selectOne(new EntityWrapper<Permission>().eq("action", dto.getTwo())); | 
|---|
|  |  |  | if (!Cools.isEmpty(permission)){ | 
|---|
|  |  |  | if (!Cools.isEmpty(permission)) { | 
|---|
|  |  |  | RolePermission rolePermission = new RolePermission(); | 
|---|
|  |  |  | rolePermission.setRoleId(roleId); | 
|---|
|  |  |  | rolePermission.setPermissionId(permission.getId()); | 
|---|
|  |  |  | rolePermissionService.insert(rolePermission); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (String three : dto.getThree()){ | 
|---|
|  |  |  | for (String three : dto.getThree()) { | 
|---|
|  |  |  | Resource resource1 = resourceService.selectOne(new EntityWrapper<Resource>().eq("id", three).eq("level", 3)); | 
|---|
|  |  |  | if (!Cools.isEmpty(resource1)) { | 
|---|
|  |  |  | // 校验上级权限 | 
|---|
|  |  |  | 
|---|
|  |  |  | return R.ok(resources); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    @GetMapping(value = "/system/activation/auth") | 
|---|
|  |  |  | //    public R activation() { | 
|---|
|  |  |  | //        if (SystemProperties.SYSTEM_ACTIVATION) { | 
|---|
|  |  |  | //            String activationCode = SystemProperties.getActivationCode(OSinfo.getOSname().getActivationCodePath()); | 
|---|
|  |  |  | //            String timeStr = AesUtils.decrypt(activationCode, SystemProperties.SALT); | 
|---|
|  |  |  | //            if (null == timeStr) { | 
|---|
|  |  |  | //                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE; | 
|---|
|  |  |  | //                return R.error(); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //            Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss); | 
|---|
|  |  |  | //            if (new Date().getTime() < exprTime.getTime()) { | 
|---|
|  |  |  | //                return R.ok().add(DateUtils.convert(exprTime)); | 
|---|
|  |  |  | //            } else { | 
|---|
|  |  |  | //                SystemProperties.SYSTEM_ACTIVATION = Boolean.FALSE; | 
|---|
|  |  |  | //                return R.error(); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | //        } else { | 
|---|
|  |  |  | //            return R.error(); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  | // | 
|---|
|  |  |  | //    @PostMapping(value = "/system/secret/auth") | 
|---|
|  |  |  | //    @ManagerAuth | 
|---|
|  |  |  | //    public R systemSecret(@RequestParam(value = "secret") String secret) { | 
|---|
|  |  |  | //        if (Cools.isEmpty(secret)) { | 
|---|
|  |  |  | //            return R.error("请输入激活码"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        // 验证激活码 | 
|---|
|  |  |  | //        String timeStr = AesUtils.decrypt(secret, SystemProperties.SALT); | 
|---|
|  |  |  | //        if (null == timeStr) { | 
|---|
|  |  |  | //            return R.error("激活码错误"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        Date exprTime = DateUtils.convert(timeStr, DateUtils.yyyyMMddHHmmss); | 
|---|
|  |  |  | //        if (new Date().getTime() >= exprTime.getTime()) { | 
|---|
|  |  |  | //            return R.error("激活码已失效"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        boolean result = SystemProperties.saveActivationCode(OSinfo.getOSname().getActivationCodePath(), secret); | 
|---|
|  |  |  | //        if (!result) { | 
|---|
|  |  |  | //            return R.error("激活失败"); | 
|---|
|  |  |  | //        } | 
|---|
|  |  |  | //        SystemProperties.SYSTEM_ACTIVATION = Boolean.TRUE; | 
|---|
|  |  |  | //        return R.ok("激活成功,有效期至" + DateUtils.convert(exprTime)); | 
|---|
|  |  |  | //    } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|