..
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package com.budwk.app;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_user_source;
|
||||
import com.budwk.app.zhgh.welfare.model.WelfareList;
|
||||
import com.budwk.app.zhgh.welfare.model.WelfareProjectSubjectOption;
|
||||
import com.budwk.app.zhgh.welfare.model.WelfareUserSelection;
|
||||
import com.budwk.app.zhgh.welfare.service.WelfareProjectService;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.nutz.boot.test.junit4.NbJUnit4Runner;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean
|
||||
@RunWith(NbJUnit4Runner.class)
|
||||
public class WelfareTest {
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
@Inject
|
||||
private WelfareProjectService welfareService;
|
||||
|
||||
@Test
|
||||
public void importSelectUser() {
|
||||
List<SelectUser> list = ExcelImportUtil.importExcel(new File("C:\\Users\\jug\\Desktop\\新建文件夹 (2)\\蛋糕汇总表.xlsx"), SelectUser.class, new ImportParams());
|
||||
// 福利id
|
||||
String welfareId = "6b6b438811044d7180b76facaebbe2f3";
|
||||
|
||||
// 福利名单
|
||||
Sql sql = Sqls.create("""
|
||||
SELECT
|
||||
u.id,
|
||||
u.username AS userName,
|
||||
u.loginname AS loginName,
|
||||
u.mobile
|
||||
FROM
|
||||
`welfare_list` t1
|
||||
LEFT JOIN sys_user u ON u.id = t1.userId
|
||||
WHERE
|
||||
t1.projectId = @projectId
|
||||
group by u.loginname
|
||||
""");
|
||||
sql.setParam("projectId", welfareId);
|
||||
List<NutMap> welfareLists = welfareService.listMap(sql);
|
||||
List<String> loginNames = welfareLists.stream().map(v -> v.getString("loginName")).toList();
|
||||
Map<String, NutMap> loginNameMap = welfareLists.stream().collect(Collectors.toMap(v -> v.getString("loginName"), v -> v));
|
||||
|
||||
// 筛选出本次导入的
|
||||
List<SelectUser> thisList = list.stream().filter(v -> StrUtil.isNotBlank(v.getLoginName()) && loginNames.contains(v.getLoginName()))
|
||||
.peek(v -> v.setLoginName(v.getLoginName().trim()))
|
||||
.toList();
|
||||
System.out.println(thisList.size());
|
||||
|
||||
// 福利选项
|
||||
List<WelfareProjectSubjectOption> options = dao.query(WelfareProjectSubjectOption.class, Cnd.where(WelfareProjectSubjectOption::getWelfareId, "=", welfareId));
|
||||
|
||||
List<WelfareUserSelection> selections = thisList.stream().map(v -> {
|
||||
WelfareUserSelection welfareUserSelection = new WelfareUserSelection();
|
||||
welfareUserSelection.setSelectTime(new Date());
|
||||
welfareUserSelection.setSelectUserId(loginNameMap.get(v.getLoginName()).getString("id"));
|
||||
welfareUserSelection.setSelectNum(1);
|
||||
if (StrUtil.isNotBlank(v.getMobile())) {
|
||||
welfareUserSelection.setMobile(v.getMobile());
|
||||
} else {
|
||||
welfareUserSelection.setMobile(loginNameMap.get(v.getLoginName()).getString("mobile"));
|
||||
}
|
||||
welfareUserSelection.setWelfareId(welfareId);
|
||||
|
||||
String optionId = options.stream().filter(option -> option.getOptionName().equals(v.getOptionName())).findFirst().map(option -> option.getId()).orElse(null);
|
||||
welfareUserSelection.setSelectOptionId(optionId);
|
||||
return welfareUserSelection;
|
||||
}).toList();
|
||||
|
||||
dao.insert(selections);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void deleteUser() {
|
||||
List<SelectUser> list = ExcelImportUtil.importExcel(new File("C:\\Users\\jug\\Desktop\\新建文件夹 (2)\\蛋糕汇总表.xlsx"), SelectUser.class, new ImportParams());
|
||||
List<String> loginNames = list.stream().map(v -> v.getLoginName()).toList();
|
||||
|
||||
Sql sql = Sqls.create("select id from sys_user where loginname in (@loginname)");
|
||||
sql.setParam("loginname", loginNames);
|
||||
sql.setCallback(Sqls.callback.strList());
|
||||
dao.execute(sql);
|
||||
List<String> ids = sql.getList(String.class);
|
||||
|
||||
List<WelfareList> welfareLists = dao.query(WelfareList.class, Cnd.NEW());
|
||||
List<String> welfareUserIds = welfareLists.stream().map(v -> v.getUserId()).toList();
|
||||
|
||||
List<String> list1 = welfareUserIds.stream().filter(v -> !ids.contains(v)).toList();
|
||||
System.out.println(list1.size());
|
||||
|
||||
//dao.clear(WelfareList.class, Cnd.where("userId", "not in", ids.stream().map(v -> v.getString("id")).toList()));
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class SelectUser {
|
||||
@Excel(name = "工号")
|
||||
private String loginName;
|
||||
|
||||
@Excel(name = "姓名")
|
||||
private String userName;
|
||||
|
||||
@Excel(name = "手机号码")
|
||||
private String mobile;
|
||||
|
||||
@Excel(name = "选择物品")
|
||||
private String optionName;
|
||||
|
||||
@Excel(name = "出生日期", importFormat = "yyyy-MM-dd", exportFormat = "yyyy-MM-dd")
|
||||
private Date birthday;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fixData() throws IOException {
|
||||
List<Sys_user_source> users = dao.query(Sys_user_source.class, Cnd.NEW().groupBy(Sys_user::getLoginname));
|
||||
Map<String, Date> userMap = users.stream().filter(v -> v.getBirthday() != null).collect(Collectors.toMap(v -> v.getLoginname(), v -> v.getBirthday()));
|
||||
|
||||
List<SelectUser> allList = ExcelImportUtil.importExcel(new File("C:\\Users\\jug\\Desktop\\南京师范蛋糕卡\\蛋糕汇总表2.xlsx"), SelectUser.class, new ImportParams());
|
||||
for (SelectUser selectUser : allList) {
|
||||
if (userMap.containsKey(selectUser.getLoginName())) {
|
||||
selectUser.setBirthday(userMap.get(selectUser.getLoginName()));
|
||||
}
|
||||
}
|
||||
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(
|
||||
new ExportParams("修改后数据", "Sheet1"),
|
||||
SelectUser.class,
|
||||
allList
|
||||
);
|
||||
|
||||
FileOutputStream fos = new FileOutputStream("C:\\Users\\jug\\Desktop\\南京师范蛋糕卡\\匹配上生日.xlsx");
|
||||
workbook.write(fos);
|
||||
fos.close();
|
||||
workbook.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void importUser() {
|
||||
List<SelectUser> allList = ExcelImportUtil.importExcel(new File("C:\\Users\\jug\\Desktop\\南京师范蛋糕卡\\匹配上生日.xlsx"), SelectUser.class, new ImportParams());
|
||||
List<SelectUser> list = allList.stream().filter(v -> StrUtil.isNotBlank(v.getLoginName())).toList();
|
||||
|
||||
// 福利id
|
||||
String welfareId = "a93b1694e41f49f3b9e6364e36bf48cd";
|
||||
// 找出月份等于1、2、3的
|
||||
// list.stream().filter(v -> v.getBirthday().getMonth() + 1 <= 3).map(v -> {
|
||||
// WelfareList welfareList = new WelfareList();
|
||||
// welfareList.setProjectId(welfareId);
|
||||
//
|
||||
//
|
||||
//
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user