commit
This commit is contained in:
+158
-43
@@ -1,13 +1,17 @@
|
||||
package io.v.nutz.activity.controller.basic;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.activity.models.ActivityUserCnd;
|
||||
import io.v.nutz.activity.models.ActivityUserScope;
|
||||
import io.v.nutz.activity.services.ActivityBasicScopeService;
|
||||
import io.v.nutz.activity.template.UserTemp;
|
||||
import io.v.nutz.annontation.ViReturn;
|
||||
import io.v.nutz.base.service.SimpleService;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
@@ -19,27 +23,31 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.dao.util.cri.Static;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.POST;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.annotation.*;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,6 +63,8 @@ public class ActivityBasicScopeController {
|
||||
|
||||
@Inject
|
||||
private SimpleService simpleService;
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
@Inject
|
||||
private ActivityBasicScopeService activityBasicScopeService;
|
||||
@@ -97,6 +107,7 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "personTypes", required = false) String[] personTypes,
|
||||
@Param(value = "userStates", required = false) String[] userStates,
|
||||
@Param(value = "memberTypes", required = false) String[] memberTypes,
|
||||
@Param(value = "maritalTypes", required = false) String[] maritalTypes,
|
||||
@Param(value = "sexTypes", required = false) String[] sexTypes,
|
||||
@Param(value = "age", required = false) String[] age,
|
||||
@Param(value = "teacherMeetingId", required = false) String teacherMeetingId,
|
||||
@@ -105,7 +116,8 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "clubId", required = false) String clubId,
|
||||
@Param(value = "reverseSelection") boolean reverseSelection,
|
||||
@Param(value = "activityGroupId", required = false) Integer activityGroupId,
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr) {
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr,
|
||||
@Param(value = "existsLoginNameRedisKey", required = false) String existsLoginNameRedisKey) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
DISTINCT(u.id) as id,
|
||||
@@ -118,16 +130,22 @@ public class ActivityBasicScopeController {
|
||||
u.userState,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName,
|
||||
TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) AS age
|
||||
TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) AS age,
|
||||
TIMESTAMPDIFF(YEAR, u.schoolTime, CURDATE()) AS teachNum,
|
||||
su.maritalStatus
|
||||
FROM
|
||||
`user` u
|
||||
LEFT JOIN sys_user_role sur on sur.userid = u.id
|
||||
LEFT JOIN sys_club_user clubuser ON clubuser.userid=u.id
|
||||
LEFT JOIN single_user su on su.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
try {
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, maritalTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
if (StrUtil.isNotBlank(existsLoginNameRedisKey)) {
|
||||
List<String> loginNames = redisService.lrange(existsLoginNameRedisKey, 0, -1);
|
||||
cnd.andEX("u.loginname", "in", loginNames);
|
||||
}
|
||||
|
||||
sql.setCondition(cnd);
|
||||
return simpleService.list(pageForm, sql);
|
||||
@@ -151,6 +169,7 @@ public class ActivityBasicScopeController {
|
||||
@At
|
||||
@ViReturn
|
||||
@POST
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@RequiresPermissions("activity.basic.scope")
|
||||
public Object doSetActivityUser(PageForm pageForm,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@@ -158,6 +177,7 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "personTypes", required = false) String[] personTypes,
|
||||
@Param(value = "userStates", required = false) String[] userStates,
|
||||
@Param(value = "memberTypes", required = false) String[] memberTypes,
|
||||
@Param(value = "maritalTypes", required = false) String[] maritalTypes,
|
||||
@Param(value = "sexTypes", required = false) String[] sexTypes,
|
||||
@Param(value = "age", required = false) String[] age,
|
||||
@Param(value = "activityGroupId", required = false) Integer activityGroupId,
|
||||
@@ -169,7 +189,8 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "userId", required = false) String[] userId,
|
||||
@Param(value = "clubId", required = false) String clubId,
|
||||
@Param(value = "reverseSelection") boolean reverseSelection,
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr) {
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr,
|
||||
@Param(value = "existsLoginNameRedisKey", required = false) String existsLoginNameRedisKey) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT DISTINCT
|
||||
( u.id ) AS userId
|
||||
@@ -177,10 +198,14 @@ public class ActivityBasicScopeController {
|
||||
`user` u
|
||||
LEFT JOIN sys_user_role sur ON sur.userid = u.id
|
||||
LEFT JOIN sys_club_user clubuser ON clubuser.userid=u.id
|
||||
LEFT JOIN single_user su on su.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, maritalTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
if (StrUtil.isNotBlank(existsLoginNameRedisKey)) {
|
||||
List<String> loginNames = redisService.lrange(existsLoginNameRedisKey, 0, -1);
|
||||
cnd.andEX("u.loginname", "in", loginNames);
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
sql.setCallback(Sqls.callback.entities());
|
||||
sql.setEntity(dao.getEntity(ActivityUserScope.class));
|
||||
@@ -235,11 +260,11 @@ public class ActivityBasicScopeController {
|
||||
$condition
|
||||
""");
|
||||
Cnd cnd = Cnd.NEW();
|
||||
// if (!ShiroUtil.hasAnyRoles("sysadmin,H06,H10")) {
|
||||
// if (ShiroUtil.hasAnyRoles(new String[]{"H04", "club01"})) {
|
||||
// cnd.and("creator", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
// }
|
||||
// }
|
||||
if (!ShiroUtil.hasAnyRoles("sysadmin,H06,H10")) {
|
||||
if (ShiroUtil.hasAnyRoles(new String[]{"H04", "club01"})) {
|
||||
cnd.and("creator", "=", ShiroUtil.getPrincipalProperty("id"));
|
||||
}
|
||||
}
|
||||
cnd.and("groupId", "IS NOT", null);
|
||||
cnd.and("groupName", "IS NOT", null);
|
||||
cnd.groupBy("groupId");
|
||||
@@ -257,8 +282,8 @@ public class ActivityBasicScopeController {
|
||||
@ViReturn
|
||||
// @RequiresPermissions("activity.basic.scope")
|
||||
public Object getScopeUser(String activityGroupId, @Param(value = "userId", required = false) String userId) {
|
||||
String userid = StrUtil.isNotBlank(userId) ? userId : ShiroUtil.getUserId();
|
||||
return simpleService.dao().count(ActivityUserScope.class, Cnd.where("groupId", "=", activityGroupId).and("userId", "=", userid));
|
||||
String userid = StrUtil.isNotBlank(userId) ? userId : io.v.nutz.util.ShiroUtil.getUserId();
|
||||
return simpleService.dao().count(ActivityUserScope.class, Cnd.where("groupId", "=", activityGroupId).and("userId", "=", io.v.nutz.util.ShiroUtil.getUserId()));
|
||||
}
|
||||
|
||||
@At
|
||||
@@ -283,7 +308,7 @@ public class ActivityBasicScopeController {
|
||||
addv("is_A06", ShiroUtil.hasRole("A06"));
|
||||
addv("is_H04", ShiroUtil.hasRole("H04"));
|
||||
addv("is_H02", ShiroUtil.hasRole("club01"));
|
||||
addv("is_H03", ShiroUtil.hasRole("SchoolUnionMemberAdmin"));
|
||||
addv("is_H03", ShiroUtil.hasRole("H03"));
|
||||
addv("is_sysadmin", ShiroUtil.hasRole("sysadmin"));
|
||||
addv("unionid", Vi.getUnionId());
|
||||
}};
|
||||
@@ -308,11 +333,10 @@ public class ActivityBasicScopeController {
|
||||
COLUMN_COMMENT
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME = 'sys_user'
|
||||
AND TABLE_SCHEMA = 'zhgh_hmc'
|
||||
AND TABLE_SCHEMA = 'zhgh_ctbu'
|
||||
""");
|
||||
List<NutMap> sqlDataList = activityBasicScopeService.listMap(sql);
|
||||
// sqlDataList.forEach(v -> v.put("DATA_TYPE", new String((byte[]) v.get("DATA_TYPE"))));
|
||||
sqlDataList.forEach(v -> v.put("DATA_TYPE", v.getString("DATA_TYPE")));
|
||||
sqlDataList.forEach(v -> v.put("DATA_TYPE", new String((byte[]) v.get("DATA_TYPE"))));
|
||||
return sqlDataList;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -323,6 +347,7 @@ public class ActivityBasicScopeController {
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
|
||||
@RequiresPermissions("activity.basic.scope")
|
||||
public void doExportUser(PageForm pageForm,
|
||||
@Param(value = "props", required = false) String props,
|
||||
@@ -331,6 +356,7 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "personTypes", required = false) String[] personTypes,
|
||||
@Param(value = "userStates", required = false) String[] userStates,
|
||||
@Param(value = "memberTypes", required = false) String[] memberTypes,
|
||||
@Param(value = "maritalTypes", required = false) String[] maritalTypes,
|
||||
@Param(value = "sexTypes", required = false) String[] sexTypes,
|
||||
@Param(value = "age", required = false) String[] age,
|
||||
@Param(value = "teacherMeetingId", required = false) String teacherMeetingId,
|
||||
@@ -339,31 +365,39 @@ public class ActivityBasicScopeController {
|
||||
@Param(value = "clubId", required = false) String clubId,
|
||||
@Param(value = "reverseSelection") boolean reverseSelection,
|
||||
@Param(value = "activityGroupId", required = false) Integer activityGroupId,
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr, HttpServletResponse response) {
|
||||
@Param(value = "activityUserCnd", required = false) String activityUserCndStr,
|
||||
@Param(value = "existsLoginNameRedisKey", required = false) String existsLoginNameRedisKey,
|
||||
HttpServletResponse response) {
|
||||
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
DISTINCT(u.id) as id,
|
||||
u.loginname AS loginName,
|
||||
u.username AS userName,
|
||||
u.sex,
|
||||
u.birthday,
|
||||
u.mobile,
|
||||
u.personType,
|
||||
u.userState,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName,
|
||||
TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) AS age
|
||||
FROM
|
||||
`user` u
|
||||
LEFT JOIN sys_user_role sur on sur.userid = u.id
|
||||
LEFT JOIN sys_club_user clubuser ON clubuser.userid=u.id
|
||||
$condition
|
||||
""");
|
||||
SELECT
|
||||
DISTINCT(u.id) as id,
|
||||
u.loginname AS loginName,
|
||||
u.username AS userName,
|
||||
u.sex,
|
||||
u.birthday,
|
||||
u.mobile,
|
||||
u.personType,
|
||||
u.userState,
|
||||
u.unitname AS unitName,
|
||||
u.unionname AS unionName,
|
||||
TIMESTAMPDIFF(YEAR, u.birthday, CURDATE()) AS age,
|
||||
TIMESTAMPDIFF(YEAR, u.schoolTime, CURDATE()) AS teachNum,
|
||||
su.maritalStatus
|
||||
FROM
|
||||
`user` u
|
||||
LEFT JOIN sys_user_role sur on sur.userid = u.id
|
||||
LEFT JOIN sys_club_user clubuser ON clubuser.userid=u.id
|
||||
LEFT JOIN single_user su on su.userId = u.id
|
||||
$condition
|
||||
""");
|
||||
|
||||
try {
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
|
||||
Cnd cnd = getCnd(pageForm, unionId, unitId, personTypes, userStates, memberTypes, maritalTypes, sexTypes, age, teacherMeetingId, roleIds, userId, clubId, reverseSelection, activityGroupId, activityUserCndStr);
|
||||
if (StrUtil.isNotBlank(existsLoginNameRedisKey)) {
|
||||
List<String> loginNames = redisService.lrange(existsLoginNameRedisKey, 0, -1);
|
||||
cnd.andEX("u.loginname", "in", loginNames);
|
||||
}
|
||||
sql.setCondition(cnd);
|
||||
|
||||
List<NutMap> map = simpleService.listMap(sql);
|
||||
@@ -392,6 +426,7 @@ public class ActivityBasicScopeController {
|
||||
String[] personTypes,
|
||||
String[] userStates,
|
||||
String[] memberTypes,
|
||||
String[] maritalTypes,
|
||||
String[] sexTypes,
|
||||
String[] age,
|
||||
String teacherMeetingId,
|
||||
@@ -426,6 +461,16 @@ public class ActivityBasicScopeController {
|
||||
if (ArrayUtils.contains(memberTypes, "基金会员")) {
|
||||
cnd.and(new Static(" u.loginname " + IN_OR_NIN_OP + " (select loginname from sick_fund_member)"));
|
||||
}
|
||||
if (ArrayUtils.contains(memberTypes, "单身教工")) {
|
||||
cnd.and(new Static("u.id " + IN_OR_NIN_OP + " (select userId from single_user)"));
|
||||
}
|
||||
if (ArrayUtils.contains(memberTypes, "30教龄教工")) {
|
||||
cnd.and("u.isThirtyTeach", EQ_OR_NEQ_OP, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (Lang.isNotEmpty(maritalTypes)) {
|
||||
cnd.and("su.maritalStatus", IN_OR_NIN_OP, Arrays.asList(maritalTypes));
|
||||
}
|
||||
|
||||
if (!Lang.isEmptyArray(age)) {
|
||||
@@ -462,4 +507,74 @@ public class ActivityBasicScopeController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清空查询条件
|
||||
*
|
||||
* @param existsLoginNameRedisKey
|
||||
* @return java.lang.Object
|
||||
* @author zhf
|
||||
* @description
|
||||
*/
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@RequiresPermissions("activity.basic.scope")
|
||||
public Object clearSearchCnd(String existsLoginNameRedisKey) {
|
||||
if (StrUtil.isNotBlank(existsLoginNameRedisKey)) {
|
||||
redisService.del(existsLoginNameRedisKey);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
@RequiresPermissions("activity.basic.scope")
|
||||
public Object doImport(String groupId, TempFile file) {
|
||||
String matchUserLoginNamesKey = "ActivityBasicScopeController.doImport.time=" + System.currentTimeMillis();
|
||||
|
||||
List<UserTemp> userImportList = ExcelImportUtil.importExcel(file.getFile(), UserTemp.class, new ImportParams());
|
||||
|
||||
//判断人员哪些存在哪些不存在
|
||||
Sql sql = Sqls.queryString("""
|
||||
SELECT
|
||||
u.loginname
|
||||
FROM
|
||||
sys_user u
|
||||
""");
|
||||
dao.execute(sql);
|
||||
String[] sysLoginNames = (String[]) sql.getResult();
|
||||
|
||||
//存在的工号
|
||||
List<String> existsLoginNames = new ArrayList<>();
|
||||
|
||||
for (UserTemp excelUser : userImportList) {
|
||||
if (ArrayUtil.contains(sysLoginNames, excelUser.getLoginname())) {
|
||||
existsLoginNames.add(excelUser.getLoginname());
|
||||
} else {
|
||||
excelUser.setRemarks("系统查不到此人");
|
||||
}
|
||||
}
|
||||
|
||||
//匹配不到的用户
|
||||
List<UserTemp> errorExcelTempUsers = userImportList.stream().filter(v -> StrUtil.isNotBlank(v.getRemarks())).collect(Collectors.toList());
|
||||
|
||||
NutMap nutMap = NutMap.NEW();
|
||||
nutMap.setv("totalCount", userImportList.size());
|
||||
nutMap.setv("successCount", existsLoginNames.size());
|
||||
nutMap.setv("errorCount", errorExcelTempUsers.size());
|
||||
nutMap.setv("errorList", errorExcelTempUsers.stream().map(v -> {
|
||||
return new NutMap().addv("工号", v.getLoginname()).addv("姓名", v.getUsername()).addv("错误信息", v.getRemarks());
|
||||
}));
|
||||
nutMap.setv("existsLoginNameRedisKey", matchUserLoginNamesKey);
|
||||
|
||||
//保存存在的工号
|
||||
if (Lang.isNotEmpty(existsLoginNames)) {
|
||||
redisService.lpush(matchUserLoginNamesKey, existsLoginNames.toArray(new String[0]));
|
||||
redisService.expire(matchUserLoginNamesKey, 60 * 3);
|
||||
}
|
||||
|
||||
return io.v.nutz.base.result.Result.success(nutMap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user