获取用户deptId
This commit is contained in:
parent
3bf0bb85bf
commit
121c207b74
|
|
@ -7,14 +7,17 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import com.bonus.common.biz.annotation.StoreLog;
|
||||
import com.bonus.common.biz.config.ListPagingUtil;
|
||||
import com.bonus.common.core.utils.ServletUtils;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.material.common.annotation.PreventRepeatSubmit;
|
||||
import com.bonus.material.ma.domain.MaTypeHistory;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeVo;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeSelectVo;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
|
@ -310,4 +313,17 @@ public class TypeController extends BaseController {
|
|||
List<MaTypeVo> list = typeService.getUserList(type);
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户部门id
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "获取用户部门id")
|
||||
@GetMapping("/getUserDeptId")
|
||||
public AjaxResult getUserDeptId(SysUser user) {
|
||||
Long deptId = typeService.getUserDeptId(user);
|
||||
return AjaxResult.success(deptId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import com.bonus.material.ma.domain.Type;
|
|||
import com.bonus.material.ma.domain.vo.MaTypeConfigVo;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeVo;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeSelectVo;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
|
@ -271,4 +273,8 @@ public interface TypeMapper {
|
|||
* @return
|
||||
*/
|
||||
Type selectUserIdsByPatentId(Long parentId);
|
||||
|
||||
SysUser getUserDeptId(Long userId);
|
||||
|
||||
SysDept getDeptIdByUserId(Long deptId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.bonus.material.ma.domain.Type;
|
|||
import com.bonus.material.ma.domain.vo.MaTypeConfigVo;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeVo;
|
||||
import com.bonus.material.ma.domain.vo.MaTypeSelectVo;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
|
||||
/**
|
||||
* 物资类型Service接口
|
||||
|
|
@ -162,4 +163,6 @@ public interface ITypeService {
|
|||
* @return
|
||||
*/
|
||||
List<MaTypeVo> getListByParentIds(List<Integer> parentIds, MaTypeVo maTypeVo);
|
||||
|
||||
Long getUserDeptId(SysUser user);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import com.bonus.material.settlement.domain.SltAgreementInfo;
|
|||
import com.bonus.material.settlement.mapper.SltAgreementInfoMapper;
|
||||
import com.bonus.material.warehouse.domain.WhHouseSet;
|
||||
import com.bonus.material.warehouse.service.IWhHouseSetService;
|
||||
import com.bonus.system.api.domain.SysDept;
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.bonus.material.ma.mapper.TypeMapper;
|
||||
|
|
@ -993,4 +995,32 @@ public class TypeServiceImpl implements ITypeService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户部门id
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Long getUserDeptId(SysUser user) {
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
SysUser sysUser = typeMapper.getUserDeptId(userId);
|
||||
if (sysUser != null) {
|
||||
//获取祖籍部门id
|
||||
SysDept sysDept = typeMapper.getDeptIdByUserId(sysUser.getDeptId());
|
||||
if (sysDept != null && sysDept.getAncestors() != null) {
|
||||
String ancestors = sysDept.getAncestors();
|
||||
String[] ancestorArray = ancestors.split(",");
|
||||
|
||||
// 计算逗号数量(数组长度-1)
|
||||
int commaCount = ancestorArray.length - 1;
|
||||
|
||||
// 根据逗号数量决定取哪个值
|
||||
if (commaCount == 2) { // 两个逗号,如 "0,100,101"
|
||||
// 取最后一个数据
|
||||
sysUser.setDeptId(Long.valueOf(ancestorArray[ancestorArray.length - 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
return sysUser.getDeptId();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1334,4 +1334,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
t.del_flag = 0 AND t.parent_id = #{parentId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
<select id="getUserDeptId" resultType="com.bonus.system.api.domain.SysUser">
|
||||
SELECT
|
||||
su.dept_id AS deptId
|
||||
FROM
|
||||
sys_user su
|
||||
WHERE
|
||||
su.user_id = #{userId}
|
||||
</select>
|
||||
<select id="getDeptIdByUserId" resultType="com.bonus.system.api.domain.SysDept">
|
||||
SELECT
|
||||
sd.dept_id AS deptId,
|
||||
sd.parent_id AS parentId,
|
||||
sd.ancestors AS ancestors
|
||||
FROM
|
||||
sys_dept sd
|
||||
WHERE
|
||||
sd.dept_id = #{deptId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue