init
This commit is contained in:
@@ -0,0 +1,393 @@
|
||||
package io.v.nutz.zhgh.thirtyteach.controller;
|
||||
|
||||
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.enmus.ExcelType;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.v.nutz.base.annontation.ViReturn;
|
||||
import io.v.nutz.base.result.Result;
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.base.utils.Vi;
|
||||
import io.v.nutz.base.dao.CndPlus;
|
||||
import io.v.nutz.base.query.PageForm;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.base.utils.ViTool;
|
||||
import io.v.nutz.sys.models.Sys_user;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
import io.v.nutz.zhgh.thirtyteach.template.ThirtyTeachTemp;
|
||||
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.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.cri.SqlExpressionGroup;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.AdaptBy;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.mvc.upload.TempFile;
|
||||
import org.nutz.mvc.upload.UploadAdaptor;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@At("/platform/thirtyTeach/manage")
|
||||
@Ok("json:full")
|
||||
@IocBean
|
||||
public class ThirtyTeachController {
|
||||
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
|
||||
@Inject
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/thirtyteach/manage.html")
|
||||
@RequiresPermissions("thirtyTeach.manage")
|
||||
public void index() {
|
||||
}
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("thirtyTeach.manage")
|
||||
public Object pageData(PageForm pageForm,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "threeUnitId", required = false) String threeUnitId,
|
||||
@Param(value = "unionGroupId", required = false) String unionGroupId,
|
||||
@Param(value = "personType", required = false) String personType,
|
||||
@Param(value = "userState", required = false) String userState,
|
||||
@Param(value = "teachNum", required = false) String teachNum,
|
||||
@Param(value = "thirtyCertificateProcessingTime",required = false)String thirtyCertificateProcessingTime) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
id,
|
||||
loginname,
|
||||
username,
|
||||
sex,
|
||||
member,
|
||||
welfareMember,
|
||||
personType,
|
||||
userState,
|
||||
unioncode,
|
||||
unionname,
|
||||
unionid,
|
||||
unitname,
|
||||
unitcode,
|
||||
unitid,
|
||||
threeUnitName,
|
||||
threeUnitCode,
|
||||
unionGroupName,
|
||||
mobile,
|
||||
campusName,
|
||||
TIMESTAMPDIFF(YEAR, schoolTime, CURDATE()) AS teachNum,
|
||||
birthday,
|
||||
thirtyCertificateProcessingTime
|
||||
from
|
||||
`user`
|
||||
$condition
|
||||
""");
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("isThirtyTeach", "=", 1);
|
||||
if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("username", pageForm.getSearchKeyword());
|
||||
seg.orLike("loginname", pageForm.getSearchKeyword());
|
||||
cnd.and(seg);
|
||||
}
|
||||
if (!ShiroUtil.hasAnyRoles("sysadmin,A06,SchoolUnionMemberAdmin")) {
|
||||
if (ShiroUtil.hasRole("H04")) {
|
||||
cnd.and("unionid", "=", Vi.getUnionId());
|
||||
} else {
|
||||
cnd.and("unionGroupId", "in", io.v.nutz.web.commons.utils.ShiroUtil.getUnionGroupIds());
|
||||
}
|
||||
}
|
||||
cnd.andEX("TIMESTAMPDIFF(YEAR, schoolTime, CURDATE())", "=", teachNum);
|
||||
cnd.andEX("unionid", "=", unionId);
|
||||
cnd.andEX("unitid", "=", unitId);
|
||||
cnd.andEX("threeUnitId", "=", threeUnitId);
|
||||
cnd.andEX("unionGroupId", "=", unionGroupId);
|
||||
cnd.andEX("personType", "=", personType);
|
||||
cnd.andEX("userState", "=", userState);
|
||||
cnd.and(Cnd.likeEX("thirtyCertificateProcessingTime",thirtyCertificateProcessingTime));
|
||||
sql.setCondition(cnd);
|
||||
return baseService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 一键设置三十年教工
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@ViReturn
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@RequiresPermissions("thirtyTeach.manage")
|
||||
public Object setThirtyTeach(Integer setNum, boolean isFlag) {
|
||||
if (isFlag) {
|
||||
sysUserService.update(Chain.make("isThirtyTeach", 0), Cnd.NEW());
|
||||
}
|
||||
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("schoolTime", "is not", null);
|
||||
cnd.and("schoolTime", "!=", "");
|
||||
cnd.and("TIMESTAMPDIFF(YEAR, schoolTime, CURDATE())", ">", setNum);
|
||||
sysUserService.update(Chain.make("isThirtyTeach", 1), cnd);
|
||||
|
||||
|
||||
// Sql sql = Sqls.create("select id,loginname from `user` $condition");
|
||||
//
|
||||
// if (!ShiroUtil.hasAnyRoles("sysadmin,A06,SchoolUnionMemberAdmin")) {
|
||||
// if (ShiroUtil.hasRole("H04")) {
|
||||
// cnd.and("unionid", "=", Vi.getUnionId());
|
||||
// } else {
|
||||
// cnd.and("unionGroupId", "in", io.v.nutz.web.commons.utils.ShiroUtil.getUnionGroupIds());
|
||||
// }
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
public Object doImport(TempFile file, boolean isFlag) {
|
||||
try {
|
||||
List<ThirtyTeachTemp> thirtyTeachImportList = ExcelImportUtil.importExcel(file.getFile(), ThirtyTeachTemp.class, new ImportParams());
|
||||
|
||||
List<Sys_user> users = sysUserService.query();
|
||||
|
||||
// Map<String, String> userIdMap = users.stream().collect(Collectors.toMap(v -> v.getUsername() + '|' + v.getBirthday(), Sys_user::getId));
|
||||
|
||||
List<ThirtyTeachTemp> errorInfos = new ArrayList<>();
|
||||
List<Sys_user> insertUserList = new ArrayList<>();
|
||||
thirtyTeachImportList.forEach(v -> {
|
||||
if (StrUtil.isBlank(v.getUserName())) {
|
||||
v.setRemark("获取不到该用户的姓名!");
|
||||
errorInfos.add(v);
|
||||
return;
|
||||
} else if (StrUtil.isBlank(v.getBirthday())) {
|
||||
v.setRemark("获取不到该用户的出生日期!");
|
||||
errorInfos.add(v);
|
||||
return;
|
||||
}else if (StrUtil.isBlank(v.getThirtyCertificateProcessingTime())) {
|
||||
v.setRemark("获取不到该用户的荣誉证办理时间!");
|
||||
errorInfos.add(v);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Sys_user> matchUsers = users.stream().filter(u -> (u.getUsername() + "|" + (StrUtil.isNotBlank(u.getBirthday()) ? u.getBirthday().substring(0, 3) : "")).equals(v.getUserName() + "|" + v.getBirthday().substring(0, 3))).map(u -> {
|
||||
Sys_user user = new Sys_user();
|
||||
user.setId(u.getId());
|
||||
user.setLoginname(v.getLoginName());
|
||||
user.setThirtyTeach(true);
|
||||
user.setThirtyCertificateProcessingTime(v.getThirtyCertificateProcessingTime());
|
||||
return user;
|
||||
}).collect(Collectors.toList());
|
||||
insertUserList.addAll(matchUsers);
|
||||
|
||||
boolean b = users.stream().noneMatch(u -> (u.getUsername() + "|" + (StrUtil.isNotBlank(u.getBirthday()) ? u.getBirthday().substring(0, 3) : "")).equals(v.getUserName() + "|" + v.getBirthday().substring(0, 3)));
|
||||
if (b) {
|
||||
v.setRemark("获取不到该用户的信息,请检查工号和出生日期是否正确!");
|
||||
errorInfos.add(v);
|
||||
}
|
||||
|
||||
|
||||
// List<ThirtyTeachTemp> noneMatchUsers = users.stream().filter(u -> !(u.getUsername() + "|" + u.getBirthday()).equals(v.getUserName() + "|" + v.getBirthday())).map(u -> {
|
||||
// v.setRemark("获取不到该用户的信息,请检查工号和出生日期是否正确!");
|
||||
// return v;
|
||||
// }).collect(Collectors.toList());
|
||||
// errorInfos.addAll(noneMatchUsers);
|
||||
|
||||
// if (userIdMap.containsKey(v.getUserName() + "|" + v.getBirthday())) {
|
||||
// Sys_user user = new Sys_user();
|
||||
// user.setId(userIdMap.get(v.getLoginName().trim()));
|
||||
// user.setLoginname(v.getLoginName());
|
||||
// user.setThirtyTeach(true);
|
||||
// insertUserList.add(user);
|
||||
// } else {
|
||||
// v.setRemark("获取不到该用户的信息,请检查工号和出生日期是否正确!");
|
||||
// errorInfos.add(v);
|
||||
// }
|
||||
|
||||
|
||||
// if (userIdMap.containsKey(v.getLoginName())) {
|
||||
// Sys_user user = new Sys_user();
|
||||
// if (v.getSchoolTime() != null) {
|
||||
// user.setSchoolTime(DateUtil.formatDate(v.getSchoolTime()));
|
||||
// } else {
|
||||
// v.setRemark("请填写该教职工的入校时间!");
|
||||
// errorInfos.add(v);
|
||||
// return;
|
||||
// }
|
||||
// user.setId(userIdMap.get(v.getLoginName().trim()));
|
||||
// user.setLoginname(v.getLoginName());
|
||||
// user.setThirtyTeach(true);
|
||||
// insertUserList.add(user);
|
||||
// } else {
|
||||
// v.setRemark("获取不到该用户的工号,请检查工号是否正确!");
|
||||
// errorInfos.add(v);
|
||||
// }
|
||||
});
|
||||
|
||||
int i = 0;
|
||||
if (Lang.isNotEmpty(insertUserList)) {
|
||||
if (isFlag) {
|
||||
sysUserService.update(Chain.make("isThirtyTeach", 0), Cnd.NEW());
|
||||
}
|
||||
i = sysUserService.updateIgnoreNull(insertUserList);
|
||||
}
|
||||
|
||||
if (Lang.isNotEmpty(errorInfos)) {
|
||||
NutMap nutMap = NutMap.NEW();
|
||||
nutMap.setv("totalCount", thirtyTeachImportList.size());
|
||||
nutMap.setv("successCount", i);
|
||||
nutMap.setv("errorCount", errorInfos.size());
|
||||
nutMap.setv("errorList", errorInfos.stream().map(v -> {
|
||||
return NutMap.NEW().addv("工号", v.getLoginName()).addv("姓名", v.getUserName()).addv("错误原因", v.getRemark());
|
||||
}).collect(Collectors.toList()));
|
||||
return Result.success(nutMap);
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@RequiresPermissions("thirtyTeach.manage")
|
||||
public void downloadImport(HttpServletResponse response) {
|
||||
try {
|
||||
ExportParams exportParams = new ExportParams();
|
||||
exportParams.setType(ExcelType.XSSF);
|
||||
List<ThirtyTeachTemp> list = new ArrayList<>();
|
||||
ThirtyTeachTemp temp = new ThirtyTeachTemp();
|
||||
temp.setUserName("超级管理员");
|
||||
list.add(temp);
|
||||
ViTool.excelResponse(response, "导入模版.xlsx");
|
||||
Workbook sheets = ExcelExportUtil.exportExcel(exportParams, ThirtyTeachTemp.class, list);
|
||||
ServletOutputStream outputStream = response.getOutputStream();
|
||||
sheets.write(outputStream);
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
public void doExport(@Param(value = "searchKeyword", required = false) String searchKeyword,
|
||||
@Param(value = "unionId", required = false) String unionId,
|
||||
@Param(value = "unitId", required = false) String unitId,
|
||||
@Param(value = "threeUnitId", required = false) String threeUnitId,
|
||||
@Param(value = "unionGroupId", required = false) String unionGroupId,
|
||||
@Param(value = "personType", required = false) String personType,
|
||||
@Param(value = "userState", required = false) String userState,
|
||||
HttpServletResponse response) {
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
id,
|
||||
loginname,
|
||||
username,
|
||||
sex,
|
||||
member,
|
||||
welfareMember,
|
||||
personType,
|
||||
userState,
|
||||
unioncode,
|
||||
unionname,
|
||||
unionid,
|
||||
unitname,
|
||||
unitcode,
|
||||
unitid,
|
||||
threeUnitName,
|
||||
threeUnitCode,
|
||||
unionGroupName,
|
||||
mobile,
|
||||
campusName,
|
||||
TIMESTAMPDIFF(YEAR, schoolTime, CURDATE()) AS teachNum,
|
||||
birthday,
|
||||
thirtyCertificateProcessingTime
|
||||
from
|
||||
`user`
|
||||
$condition
|
||||
""");
|
||||
CndPlus cnd = CndPlus.create();
|
||||
cnd.and("isThirtyTeach", "=", 1);
|
||||
if (StrUtil.isNotBlank(searchKeyword)) {
|
||||
SqlExpressionGroup seg = new SqlExpressionGroup();
|
||||
seg.orLike("username", searchKeyword);
|
||||
seg.orLike("loginname", searchKeyword);
|
||||
cnd.and(seg);
|
||||
}
|
||||
if (!ShiroUtil.hasAnyRoles("sysadmin,A06,SchoolUnionMemberAdmin")) {
|
||||
if (ShiroUtil.hasRole("H04")) {
|
||||
cnd.and("unionid", "=", Vi.getUnionId());
|
||||
} else {
|
||||
cnd.and("unionGroupId", "in", io.v.nutz.web.commons.utils.ShiroUtil.getUnionGroupIds());
|
||||
}
|
||||
}
|
||||
cnd.andEX("unionid", "=", unionId);
|
||||
cnd.andEX("unitid", "=", unitId);
|
||||
cnd.andEX("threeUnitId", "=", threeUnitId);
|
||||
cnd.andEX("unionGroupId", "=", unionGroupId);
|
||||
cnd.andEX("personType", "=", personType);
|
||||
cnd.andEX("userState", "=", userState);
|
||||
sql.setCondition(cnd);
|
||||
List<NutMap> thirtyTeachList = baseService.listMap(sql);
|
||||
|
||||
List<ExcelExportEntity> entityList = new ArrayList<>();
|
||||
ExcelExportEntity no = new ExcelExportEntity("序号", "no", 10);
|
||||
no.setFormat("isAddIndex");
|
||||
entityList.add(no);
|
||||
entityList.add(new ExcelExportEntity("工号", "loginname", 20));
|
||||
entityList.add(new ExcelExportEntity("姓名", "username", 20));
|
||||
entityList.add(new ExcelExportEntity("性别", "sex", 20));
|
||||
entityList.add(new ExcelExportEntity("教龄(年)", "teachNum", 20));
|
||||
entityList.add(new ExcelExportEntity("电话", "mobile", 20));
|
||||
entityList.add(new ExcelExportEntity("工会", "unionname", 20));
|
||||
entityList.add(new ExcelExportEntity("单位", "unitname", 20));
|
||||
entityList.add(new ExcelExportEntity("在职状态", "userState", 20));
|
||||
entityList.add(new ExcelExportEntity("人员类型", "personType", 20));
|
||||
entityList.add(new ExcelExportEntity("荣誉证办理年月", "thirtyCertificateProcessingTime", 20));
|
||||
|
||||
try {
|
||||
ViTool.excelResponse(response, "30教龄教职工名单.xlsx");
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), entityList, thirtyTeachList);
|
||||
workbook.write(response.getOutputStream());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@ViReturn
|
||||
@RequiresPermissions("thirtyTeach.manage")
|
||||
public Object doBatchDelete(@Param("userIds") String[] userIds) {
|
||||
List<String> userIdList = Arrays.asList(userIds);
|
||||
if (Lang.isNotEmpty(userIdList)) {
|
||||
sysUserService.update(Chain.make("isThirtyTeach", 0), Cnd.where("id", "in", userIdList));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.v.nutz.zhgh.thirtyteach.template;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ThirtyTeachTemp {
|
||||
// @Excel(name = "工号")
|
||||
private String loginName;
|
||||
|
||||
@Excel(name = "姓名", width = 20d)
|
||||
private String userName;
|
||||
|
||||
@Excel(name = "身份证号码", width = 40d)
|
||||
private String idCard;
|
||||
|
||||
@Excel(name = "出生日期", importFormat = "yyyy-MM-dd", width = 40d)
|
||||
private String birthday;
|
||||
|
||||
@Excel(name = "《30年教龄荣誉证》办理年月", importFormat = "yyyy-MM", width = 40d)
|
||||
private String thirtyCertificateProcessingTime;
|
||||
|
||||
|
||||
// @Excel(name = "性别")
|
||||
// private String sex;
|
||||
//
|
||||
// @Excel(name = "联系电话")
|
||||
// private String mobile;
|
||||
//
|
||||
// @Excel(name = "入校时间")
|
||||
private Date schoolTime;
|
||||
|
||||
|
||||
private String remark;
|
||||
}
|
||||
Reference in New Issue
Block a user