Browse Source

小程序管理员查得部门及下级部门 report

dev
巴林闲侠 1 year ago
parent
commit
670de58d72
  1. 4
      api/.vscode/launch.json
  2. 21
      api/app/lib/controllers/auth/index.js
  3. 38
      api/app/lib/controllers/report/index.js

4
api/.vscode/launch.json

@ -13,8 +13,8 @@
"NODE_ENV": "development"
},
"args": [
"-p 13401",
"-f http://localhost:13401",
"-p 13400",
"-f http://localhost:13400",
"-g postgres://postgres:123@10.8.30.32:5432/highways4good",
//"-g postgres://FashionAdmin:123456@10.8.30.156:5432/highway4goodn0728",
"--qnak XuDgkao6cL0HidoMAPnA5OB10Mc_Ew08mpIfRJK5",

21
api/app/lib/controllers/auth/index.js

@ -4,7 +4,7 @@ const MD5 = require('crypto-js/md5');
const moment = require('moment');
const uuid = require('uuid');
async function login(ctx, next) {
async function login (ctx, next) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
@ -77,7 +77,7 @@ async function login(ctx, next) {
* 微信小程序登录
* @@requires.body {phone-手机号, password-密码} ctx
*/
async function wxLogin(ctx, next) {
async function wxLogin (ctx, next) {
const transaction = await ctx.fs.dc.orm.transaction();
try {
const models = ctx.fs.dc.models;
@ -106,14 +106,27 @@ async function wxLogin(ctx, next) {
let userRslt = Object.assign({
authorized: true,
loginSource: 'wx',
token: token,
...userRes.dataValues
...userRes.dataValues,
});
if (params.phone == 'SuperAdmin') {
const allResource = await models.Resource.findAll({})
userRslt.userResources = allResource.map(r => {
return {
resourceId: r.dataValues.code
}
})
}
await models.UserToken.create({
token: token,
userInfo: userRslt,
expired: moment().add(30, 'day').format('YYYY-MM-DD HH:mm:ss')
}, { transaction: transaction });
ctx.status = 200;
ctx.body = Object.assign({
...userRslt,
@ -130,7 +143,7 @@ async function wxLogin(ctx, next) {
}
}
async function logout(ctx) {
async function logout (ctx) {
try {
const { token, code } = ctx.request.body;
const models = ctx.fs.dc.models;

38
api/app/lib/controllers/report/index.js

@ -5,6 +5,40 @@ async function reportList (ctx) {
try {
const models = ctx.fs.dc.models;
const { limit, page, startTime, endTime, keyword, userId, reportType, isTop, asc, projectType } = ctx.query
const { userInfo } = ctx.fs.api
const sequelize = ctx.fs.dc.orm;
let findUsers = []
if (
userInfo.loginSource == 'wx'
&& userInfo.isAdmin
&& userInfo.phone != 'SuperAdmin'
) {
// 是管理员但不是超管 查自己部门及下级部门的所有信息
const sqlStr = `
WITH RECURSIVE sub_departments AS (
SELECT id, dependence
FROM department
WHERE id = 1
UNION ALL
SELECT d.id, d.dependence
FROM sub_departments sd
JOIN department d ON sd.id = d.dependence
)
SELECT u.id
FROM "user" AS u
JOIN sub_departments sd ON u.department_id = sd.id
WHERE u.delete = false;
`
const res = await sequelize.query(sqlStr, { type: QueryTypes.SELECT })
let a = 1
findUsers = res.map(item => {
return item.id
})
findUsers.push(-1)
}
let findOption = {
where: {
@ -43,6 +77,9 @@ async function reportList (ctx) {
if (userId) {
findOption.where.userId = userId
}
if (findUsers.length) {
findOption.where.userId = { $in: findUsers }
}
if (reportType) {
findOption.where.reportType = reportType
}
@ -53,7 +90,6 @@ async function reportList (ctx) {
if (isTop) {
const sqlStr = 'select * from (SELECT R.*, "row_number"() OVER(PARTITION BY R.user_id ORDER BY R."time" DESC) AS NEWINDEX FROM report AS R ) AS NR WHERE NEWINDEX = 1'
const sequelize = ctx.fs.dc.orm;
reportRes = await sequelize.query(sqlStr, { type: QueryTypes.SELECT });
} else {
reportRes = await models.Report.findAll(findOption)

Loading…
Cancel
Save