| | |
| | | package org.sxkj.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.log.annotation.ApiLog; |
| | | import org.springblade.core.log.logger.BladeLogger; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.sxkj.common.constant.WordOrderConstant; |
| | | import org.sxkj.common.utils.HeaderUtils; |
| | | import org.sxkj.common.utils.OrderNumUtils; |
| | | import org.sxkj.system.cache.DictCache; |
| | | import org.sxkj.system.entity.Dept; |
| | | import org.sxkj.system.entity.Role; |
| | | import org.sxkj.system.entity.User; |
| | | import org.sxkj.system.entity.UserInfo; |
| | | import org.sxkj.system.enums.DictEnum; |
| | | import org.sxkj.system.mapper.UserMapper; |
| | | import org.sxkj.system.param.DeptAddParam; |
| | | import org.sxkj.system.service.IDeptService; |
| | | import org.sxkj.system.service.IRoleService; |
| | | import org.sxkj.system.service.IUserService; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; |
| | | import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE; |
| | | |
| | | @NonDS |
| | | @RestController |
| | |
| | | @Api(value = "对外接口", tags = "对外接口") |
| | | public class ExternalController { |
| | | |
| | | private final IRoleService roleService; |
| | | |
| | | private final IDeptService deptService; |
| | | |
| | | private final IUserService userService; |
| | | |
| | | private final BladeLogger bladeLogger; |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | */ |
| | | @PostMapping("/submitDeptExternal") |
| | | @ApiOperationSupport(order = 6) |
| | | @ApiOperation(value = "机构新增或修改", notes = "传入dept") |
| | | @ApiLog("组织机构信息新增或修改") |
| | | public R submit(@Valid @RequestBody DeptAddParam dept) { |
| | | Dept deptEntity = Objects.requireNonNull(BeanUtil.copy(dept, Dept.class)); |
| | | String times = OrderNumUtils.initOrderNum2(WordOrderConstant.ORG_CODE); |
| | | String deptCode = WordOrderConstant.ORG_PREFIX + times; |
| | | deptEntity.setDeptCode(deptCode); |
| | | deptEntity.setCreateTime(new Date()); |
| | | deptEntity.setUpdateTime(new Date()); |
| | | if (deptService.submit(deptEntity)) { |
| | | CacheUtil.clear(SYS_CACHE); |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getDeptId, dept.getId())); |
| | | if (!userList.isEmpty()) { |
| | | List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList()); |
| | | userService.updateUserAreaCode(dept.getAreaCode(), userIds); |
| | | } |
| | | // 返回懒加载树更新节点所需字段 |
| | | Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId()) |
| | | .set("deptCategoryName", DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory())); |
| | | return R.data(kv); |
| | | } |
| | | |
| | | return R.fail("操作失败"); |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | */ |
| | | @PostMapping("/submitRoleExternal") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "角色新增或修改", notes = "传入role") |
| | | @ApiLog("角色信息新增或修改") |
| | | public R submit(@Valid @RequestBody Role role) { |
| | | CacheUtil.clear(SYS_CACHE); |
| | | CacheUtil.clear(SYS_CACHE, Boolean.FALSE); |
| | | return R.status(roleService.submit(role)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 用户信息新增或者修改-对外 |
| | | */ |
| | | @PostMapping("/submitUserExternal") |
| | | @ApiOperationSupport(order = 5) |
| | | @ApiOperation(value = "新增或修改用户", notes = "传入User,新增或修改用户") |
| | | @ApiLog("用户信息新增或者修改-对外") |
| | | public R submitExternal(@Valid @RequestBody User user) { |
| | | CacheUtil.clear(USER_CACHE); |
| | | |
| | | boolean isRet = false; |
| | | |
| | | UserInfo userInfo = userService.userInfo("000000", user.getAccount()); |
| | | if (userInfo != null && userInfo.getUser() != null) { |
| | | bladeLogger.info("用户信息修改", user.toString()); |
| | | user.setId(userInfo.getUser().getId()); |
| | | user.setDeptId(userInfo.getUser().getDeptId()); |
| | | user.setRoleId(userInfo.getUser().getRoleId()); |
| | | isRet = userService.updateUser(user); |
| | | } else { |
| | | Dept dept = deptService.getById(1123598813738675201L); |
| | | user.setAreaCode(HeaderUtils.processAreaCode(dept.getAreaCode())); |
| | | user.setPassword("jadk@2026"); |
| | | user.setDeptId(user.getDeptId() == null ? String.valueOf(dept.getId()) : user.getDeptId()); |
| | | user.setRoleId(user.getRoleId() == null ? "2011678430358691842" : user.getRoleId()); |
| | | isRet = userService.submit(user); |
| | | bladeLogger.info("用户信息新增", user.toString()); |
| | | } |
| | | |
| | | return R.status(isRet); |
| | | } |
| | | |
| | | } |