commit
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.budwk.app.zhgh.integral.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -266,16 +269,71 @@ public class IntegralManageController {
|
||||
|
||||
@At
|
||||
@Ok("void")
|
||||
@ApiOperation("下载福利名单导入模板")
|
||||
@ApiOperation("下载积分增加导入模板")
|
||||
@SaCheckPermission("benefit.user")
|
||||
public void downloadImport(HttpServletResponse response) {
|
||||
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();) {
|
||||
EasyExcel.write(byteArrayOutputStream, BenefitUserTemp.class)
|
||||
.sheet("福利名单导入模版")
|
||||
.doWrite(ArrayList::new);
|
||||
CommonDownloadUtil.download("福利名单导入模版.xlsx", byteArrayOutputStream.toByteArray(), response);
|
||||
List<ExcelExportEntity> entities = new ArrayList<>();
|
||||
entities.add(new ExcelExportEntity("工号", "loginName", 20));
|
||||
entities.add(new ExcelExportEntity("姓名", "userName", 20));
|
||||
entities.add(new ExcelExportEntity("增加积分", "integral", 20));
|
||||
ExportParams exportParams = new ExportParams();
|
||||
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entities, Collections.emptyList());
|
||||
CommonDownloadUtil.download("积分增加导入模板.xlsx", workbook, response);
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
@SaCheckPermission("integral.manage")
|
||||
@ApiOperation("导入扣减积分名单")
|
||||
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
|
||||
public Result doImportAdd(TempFile file){
|
||||
try {
|
||||
List<T> ts = EasyExcelUtil.syncReadModel(file.getFile(), IntegralAddTemp.class, 0, 1);
|
||||
List<IntegralAddTemp> integralTempList = JSONUtil.parseArray(JSONUtil.toJsonStr(ts)).toList(IntegralAddTemp.class);
|
||||
|
||||
List<String> loginNames = integralTempList.stream().map(IntegralAddTemp::getLoginName).toList();
|
||||
List<View_user> userList = integralManageService.dao().query(View_user.class, Cnd.NEW().andEX(View_user::getLoginname, "in", loginNames));
|
||||
Map<String, String> userMap = userList.stream().collect(Collectors.toMap(View_user::getLoginname, View_user::getId));
|
||||
|
||||
List<IntegralAddTemp> errorInfos = new ArrayList<>();
|
||||
List<IntegralDetail> insertInfos = new ArrayList<>();
|
||||
integralTempList.forEach(v -> {
|
||||
if (userMap.containsKey(v.getLoginName().trim())) {
|
||||
View_user viewUser = userList.stream().filter(user -> user.getLoginname().equals(v.getLoginName())).findFirst().orElse(null);
|
||||
IntegralDetail detail = new IntegralDetail();
|
||||
detail.setYear(String.valueOf(DateUtil.thisYear()));
|
||||
detail.setIntegral(v.getIntegral());
|
||||
detail.setIntegralTime(new Date());
|
||||
detail.setIntegralNotes("增加积分导入");
|
||||
detail.setUserId(viewUser.getId());
|
||||
detail.setUnionId(viewUser.getUnionId());
|
||||
detail.setUnitId(viewUser.getUnitId());
|
||||
detail.setUnionName(viewUser.getUnionName());
|
||||
detail.setUnitName(viewUser.getUnitName());
|
||||
insertInfos.add(detail);
|
||||
} else {
|
||||
v.setResult("获取不到该用户信息,请检查工号是否正确!");
|
||||
errorInfos.add(v);
|
||||
}
|
||||
});
|
||||
|
||||
int successCount = Lang.isNotEmpty(insertInfos) ? integralManageService.insert(insertInfos).size() : 0;
|
||||
|
||||
if (Lang.isNotEmpty(errorInfos)) {
|
||||
NutMap nutMap = new NutMap();
|
||||
nutMap.setv("totalCount", integralTempList.size());
|
||||
nutMap.setv("successCount", successCount);
|
||||
nutMap.setv("errorCount", errorInfos.size());
|
||||
nutMap.setv("errorList", errorInfos.stream().map(v -> {
|
||||
return NutMap.NEW().addv("工号", v.getLoginName()).addv("姓名", v.getUserName()).addv("错误原因", v.getResult());
|
||||
}).collect(Collectors.toList()));
|
||||
return Result.success(nutMap);
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
log.error("下载福利名单导入模版失败", e);
|
||||
e.printStackTrace();
|
||||
return Result.error();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,6 +416,22 @@ public class IntegralManageController {
|
||||
@ExcelProperty("扣减时间")
|
||||
private Date integralTime;
|
||||
|
||||
@ExcelIgnore
|
||||
private String result;
|
||||
}
|
||||
@Data
|
||||
@EqualsAndHashCode
|
||||
public static class IntegralAddTemp {
|
||||
|
||||
@ExcelProperty("工号")
|
||||
private String loginName;
|
||||
|
||||
@ExcelProperty("姓名")
|
||||
private String userName;
|
||||
|
||||
@ExcelProperty("积分")
|
||||
private String integral;
|
||||
|
||||
@ExcelIgnore
|
||||
private String result;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ public class IntegralDetail extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Name
|
||||
@Comment("id")
|
||||
@Prev(els = {@EL("uuid()")})
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
private String id;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user