From 7a26095d7498faa395fce7eb2f8499871ea9f2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=A3=E4=BA=9B=E8=8A=B1=E5=84=BF?= <1156921458@qq.com> Date: Thu, 27 Mar 2025 15:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=97=85=E4=BA=92=E5=8A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SickHelpImportController.java | 30 ++ .../SickHelpMedicalInsController.java | 335 ++++++++++++++++++ .../sickHelp/model/SickHelpMedicalIns.java | 99 ++++++ .../resources/views/layouts/platform.html | 1 + .../views/platform/sickHelp/import/excel.html | 32 +- .../platform/sickHelp/medicalIns/ecImport.js | 181 ++++++++++ .../platform/sickHelp/medicalIns/index.html | 324 +++++++++++++++++ .../platform/sickHelp/medicalIns/insForm.js | 162 +++++++++ .../platform/sickHelp/medicalIns/insImport.js | 206 +++++++++++ 9 files changed, 1367 insertions(+), 3 deletions(-) create mode 100644 src/main/java/io/v/nutz/sickHelp/controller/SickHelpMedicalInsController.java create mode 100644 src/main/java/io/v/nutz/sickHelp/model/SickHelpMedicalIns.java create mode 100644 src/main/resources/views/platform/sickHelp/medicalIns/ecImport.js create mode 100644 src/main/resources/views/platform/sickHelp/medicalIns/index.html create mode 100644 src/main/resources/views/platform/sickHelp/medicalIns/insForm.js create mode 100644 src/main/resources/views/platform/sickHelp/medicalIns/insImport.js diff --git a/src/main/java/io/v/nutz/sickHelp/controller/SickHelpImportController.java b/src/main/java/io/v/nutz/sickHelp/controller/SickHelpImportController.java index edee048..48b4a31 100644 --- a/src/main/java/io/v/nutz/sickHelp/controller/SickHelpImportController.java +++ b/src/main/java/io/v/nutz/sickHelp/controller/SickHelpImportController.java @@ -6,15 +6,19 @@ 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 cn.wizzer.framework.base.Result; import io.v.nutz.annontation.ViReturn; import io.v.nutz.sickHelp.model.SickHelp; +import io.v.nutz.sickHelp.model.SickHelpMedicalIns; import io.v.nutz.sickHelp.service.SickHelpImportService; import io.v.nutz.util.ViTool; import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.usermodel.Workbook; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.nutz.dao.Cnd; +import org.nutz.dao.Dao; import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.lang.Lang; @@ -28,6 +32,7 @@ import org.nutz.mvc.upload.UploadAdaptor; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; @IocBean @At("/platform/sickHelp/import") @@ -51,6 +56,8 @@ public class SickHelpImportController { // excelTemplateEntityList.add(new ExcelExportEntity("补助比例", "", 20)); } + @Inject + private Dao dao; @Inject private SickHelpImportService sickHelpImportService; @@ -186,4 +193,27 @@ public class SickHelpImportController { return sickHelpImportService.dao().fetch(SickHelp.class, id); } + + @At("/convertIns") + @Ok("json:full") + @RequiresPermissions("sickHelp.import.excel") + public Result convertIns(){ + List insList = dao.query(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1)); + + List collect = insList.stream().map(v -> { + SickHelp sickHelp = new SickHelp(); + sickHelp.setYear(v.getYear()); + sickHelp.setLoginName(v.getLoginName()); + sickHelp.setUserName(v.getUserName()); + sickHelp.setMedicalFourTotalMoney(v.getSxzf()); + sickHelp.setSelfPayTotalMoney(v.getLxzf()); + sickHelp.setSchoolSecondSubsidyMoney(v.getEcbx()); + sickHelp.setSelfPayMoney(v.getCalc()); + return sickHelp; + }).collect(Collectors.toList()); + + List sickHelps = sickHelpImportService.checkData(collect); + return Result.success(sickHelps); + } + } diff --git a/src/main/java/io/v/nutz/sickHelp/controller/SickHelpMedicalInsController.java b/src/main/java/io/v/nutz/sickHelp/controller/SickHelpMedicalInsController.java new file mode 100644 index 0000000..595d349 --- /dev/null +++ b/src/main/java/io/v/nutz/sickHelp/controller/SickHelpMedicalInsController.java @@ -0,0 +1,335 @@ +package io.v.nutz.sickHelp.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.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.wizzer.framework.base.Result; +import io.v.nutz.base.page.Pagination; +import io.v.nutz.modules.models.PageForm; +import io.v.nutz.sickHelp.model.SickHelpMedicalIns; +import io.v.nutz.sys.services.SysUserService; +import io.v.nutz.util.ViTool; +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.ioc.aop.Aop; +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.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.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@IocBean +@At("/platform/sickHelp/medicalIns") +@Ok("json:full") +public class SickHelpMedicalInsController { + + @Inject + private Dao dao; + @Inject + private SysUserService sysUserService; + + @At("") + @RequiresPermissions("sickHelp.medicalIns") + @Ok("beetl:/platform/sickHelp/medicalIns/index.html") + public void index() { + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"}) + @Aop(TransAop.READ_COMMITTED) + public Result importIns(@Param("file") TempFile tempFile) { + if (ObjectUtil.isEmpty(tempFile)) { + return Result.error("excel为空"); + } + if (!tempFile.getFile().getName().endsWith(".xlsx")) { + return Result.error("请上传xlsx格式的excel文件"); + } + + List list = ExcelImportUtil.importExcel(tempFile.getFile(), SickHelpMedicalIns.class, new ImportParams()); + + // 按身份证分组并聚合数据 过滤出四项之和大于10000的 + List aggregatedData = list.stream() + .collect(Collectors.groupingBy(SickHelpMedicalIns::getIdCard)) + .entrySet().stream() + .map(entry -> { + List group = entry.getValue(); + SickHelpMedicalIns aggregated = new SickHelpMedicalIns(); + aggregated.setUserName(group.get(0).getUserName()); + aggregated.setIdCard(entry.getKey()); + + aggregated.setZhzl(group.stream().map(SickHelpMedicalIns::getZhzl).reduce(BigDecimal.ZERO, BigDecimal::add)); + aggregated.setZhzf(group.stream().map(SickHelpMedicalIns::getZhzf).reduce(BigDecimal.ZERO, BigDecimal::add)); + aggregated.setXjzl(group.stream().map(SickHelpMedicalIns::getXjzl).reduce(BigDecimal.ZERO, BigDecimal::add)); + aggregated.setXjzf(group.stream().map(SickHelpMedicalIns::getXjzf).reduce(BigDecimal.ZERO, BigDecimal::add)); + aggregated.setSxzf(aggregated.getZhzl() + .add(aggregated.getZhzf()) + .add(aggregated.getXjzl()) + .add(aggregated.getXjzf())); + aggregated.setLxzf(aggregated.getZhzf().add(aggregated.getXjzf())); + + return aggregated; + }) + .filter(data -> data.getSxzf().compareTo(BigDecimal.valueOf(10000)) > 0) + .collect(Collectors.toList()); + + Sql sql = Sqls.create(""" + SELECT + t1.loginName, + t1.userName, + t2.idcard AS idCard + FROM + sick_fund_member t1 + LEFT JOIN sys_user t2 ON t2.loginname = t1.loginName + """); + sql.setCallback(Sqls.callback.maps()); + dao.execute(sql); + List userList = sql.getList(NutMap.class); + for (SickHelpMedicalIns ins : aggregatedData) { + String idCard = ins.getIdCard(); + String userName = ins.getUserName(); + ins.setYear(DateUtil.thisYear() - 1); + // 先通过身份证匹配用户 + Optional idCardOptional = userList.stream().filter(v -> v.getString("idCard", "").equals(idCard)).findFirst(); + if (idCardOptional.isPresent()) { + ins.setUserId(idCardOptional.get().getString("id")); + ins.setLoginName(idCardOptional.get().getString("loginName")); + ins.setUserName(idCardOptional.get().getString("userName")); + ins.setUserId(idCardOptional.get().getString("id")); + } + + // 如果没有匹配到用户,则通过姓名匹配用户 + if (idCardOptional.isEmpty()) { + if (StrUtil.isNotBlank(userName) && userName.equals("徐为民")) { + System.out.println(1); + } + Optional userNameOptional = userList.stream().filter(v -> v.getString("userName", "").equals(userName)).findFirst(); + if (userNameOptional.isPresent()) { + ins.setUserId(userNameOptional.get().getString("id")); + ins.setLoginName(userNameOptional.get().getString("loginName")); + ins.setUserName(userNameOptional.get().getString("userName")); + } + } + } + + // 再次过滤 + List successData = aggregatedData.stream().filter(v -> StrUtil.isNotBlank(v.getLoginName())).collect(Collectors.toList()); + List failData = aggregatedData.stream().filter(v -> StrUtil.isBlank(v.getLoginName())).collect(Collectors.toList()); + + dao.clear(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1)); + dao.insert(successData); + + HashMap hashMap = new HashMap<>(); + hashMap.put("total", aggregatedData.size()); + hashMap.put("success", successData.size()); + hashMap.put("fail", failData.size()); + hashMap.put("totalData", aggregatedData); + hashMap.put("failData", failData); + return Result.success(hashMap); + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + @AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"}) + @Aop(TransAop.READ_COMMITTED) + public Result importEc(@Param("file") TempFile tempFile) { + if (ObjectUtil.isEmpty(tempFile)) { + return Result.error("excel为空"); + } + if (!tempFile.getFile().getName().endsWith(".xlsx")) { + return Result.error("请上传xlsx格式的excel文件"); + } + + List excelList = ExcelImportUtil.importExcel(tempFile.getFile(), SickHelpMedicalIns.class, new ImportParams()); + List list = dao.query(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1)); + + int success = 0; + + List failData = new ArrayList<>(); + + for (SickHelpMedicalIns ins : list) { + if (StrUtil.isNotBlank(ins.getLoginName())) { + Optional optional = excelList.stream().filter(x -> x.getLoginName().equals(ins.getLoginName())).findFirst(); + if (optional.isPresent()) { + ins.setEcbx(optional.get().getEcbx()); + BigDecimal subtract = ins.getSxzf().subtract(optional.get().getEcbx()); + ins.setCalc(subtract); + success += 1; + } else { + failData.add(ins); + } + } + } + + System.out.println(); + + dao.update(list, "ecbx|calc"); + HashMap hashMap = new HashMap<>(); + hashMap.put("success", success); + hashMap.put("fail", failData.size()); + hashMap.put("totalData", excelList); + hashMap.put("failData", failData); + + return Result.success(hashMap); + } + + + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result pageData(PageForm pageForm, Integer year, String dataCheck) { + Sql sql = Sqls.create("select * from sick_help_medical_ins $condition"); + Cnd cnd = Cnd.NEW(); + cnd.asc("ecbx"); + cnd.asc("loginName"); + cnd.andEX("year", "=", year); + + if (StrUtil.isNotBlank(dataCheck)) { + if (dataCheck.equals("1")) { + SqlExpressionGroup seg = new SqlExpressionGroup(); + seg.or("loginName", "is", null); + seg.or("loginName", "=", ""); + cnd.and(seg); + } + if (dataCheck.equals("2")) { + SqlExpressionGroup seg = new SqlExpressionGroup(); + seg.or("ecbx", "is", null); + seg.or("ecbx", "=", ""); + cnd.and(seg); + } + } + + if (StrUtil.isNotBlank(pageForm.getSearchKeyword())) { + SqlExpressionGroup seg = new SqlExpressionGroup(); + seg.orLike("loginName", pageForm.getSearchKeyword()); + seg.orLike("userName", pageForm.getSearchKeyword()); + seg.orLike("idCard", pageForm.getSearchKeyword()); + cnd.and(seg); + } + sql.setCondition(cnd); + Pagination pagination = sysUserService.listPageMap(pageForm.getPageNumber(), pageForm.getPageSize(), sql); + return Result.success(pagination); + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result delete(String id) { + dao.delete(SickHelpMedicalIns.class, id); + return Result.success(); + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result update(SickHelpMedicalIns ins) { + dao.updateIgnoreNull(ins); + return Result.success(); + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result queryUser(String query) { + Sql sql = Sqls.create("select id,loginname,username from `user` $condition limit 0,10"); + Cnd cnd = Cnd.NEW(); + SqlExpressionGroup seg = new SqlExpressionGroup(); + seg.orLike("loginname", query); + seg.orLike("username", query); + cnd.and(seg); + sql.setCondition(cnd); + List list = sysUserService.listMap(sql); + return Result.success(list); + } + + + /** + * 检查是否还有错误的医保数据 + */ + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result checkIns() { + int count = dao.count(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1) + .and("loginName", "is", null)); + if (count > 0) { + return Result.error("医保数据还有" + count + "条未核对正确,请先核对!"); + } + + int fullCount = dao.count(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1)); + if (fullCount == 0) { + return Result.success("医保数据未导入!"); + } + return Result.success(); + } + + @At + @RequiresPermissions("sickHelp.medicalIns") + public Result checkEc() { + int count = dao.count(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1) + .and("ecbx", "is", null)); + if (count > 0) { + return Result.error("二次报销数据还有" + count + "条未核对正确,请先核对!"); + } + int fullCount = dao.count(SickHelpMedicalIns.class, Cnd.where("year", "=", DateUtil.thisYear() - 1)); + if (fullCount == 0) { + return Result.success("二次报销数据未导入!"); + } + return Result.success(); + } + + + @At + @RequiresPermissions("sickHelp.medicalIns") + @Ok("void") + public Result exportXlsx(int year, HttpServletResponse response) { + List list = dao.query(SickHelpMedicalIns.class, Cnd.where("year", "=", year)); + + List entities = new ArrayList<>(); + entities.add(new ExcelExportEntity("工号", "loginName", 20)); + entities.add(new ExcelExportEntity("姓名", "userName", 20)); + entities.add(new ExcelExportEntity("身份证号码", "idCard", 30)); + entities.add(new ExcelExportEntity("账户自理", "zhzl", 20)); + entities.add(new ExcelExportEntity("账户自付", "zhzf", 20)); + entities.add(new ExcelExportEntity("现金自理", "xjzl", 20)); + entities.add(new ExcelExportEntity("现金自付", "xjzf", 20)); + entities.add(new ExcelExportEntity("四项之和", "sxzf", 20)); + entities.add(new ExcelExportEntity("两项之和", "lxzf", 20)); + entities.add(new ExcelExportEntity("学校二次报销", "ecbx", 20)); + entities.add(new ExcelExportEntity("补助计算额度", "calc", 20)); + + try (ServletOutputStream outputStream = response.getOutputStream()) { + ViTool.excelResponse(response, year + "医保数据.xlsx"); + ExportParams exportParams = new ExportParams(); + exportParams.setType(ExcelType.XSSF); + Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entities, list); + workbook.write(outputStream); + } catch (Exception e) { + e.printStackTrace(); + } + + return Result.success(); + } + + +} diff --git a/src/main/java/io/v/nutz/sickHelp/model/SickHelpMedicalIns.java b/src/main/java/io/v/nutz/sickHelp/model/SickHelpMedicalIns.java new file mode 100644 index 0000000..f2fd08a --- /dev/null +++ b/src/main/java/io/v/nutz/sickHelp/model/SickHelpMedicalIns.java @@ -0,0 +1,99 @@ +package io.v.nutz.sickHelp.model; + +import cn.afterturn.easypoi.excel.annotation.Excel; +import cn.wizzer.framework.base.model.BaseModel; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.nutz.dao.entity.annotation.*; +import org.nutz.dao.interceptor.annotation.PrevInsert; + +import java.math.BigDecimal; + +@EqualsAndHashCode(callSuper = true) +@Table +@Comment("大病互助医保数据") +@Data +public class SickHelpMedicalIns extends BaseModel { + + @Name + @Comment("id") + @PrevInsert(uu32 = true) + private String id; + + @Column + @ColDefine(type = ColType.VARCHAR) + @Comment("用户id") + private String userId; + + @Column + @ColDefine(type = ColType.VARCHAR) + @Comment("工号") + @Excel(name = "工号") + private String loginName; + + @Column + @ColDefine(type = ColType.VARCHAR) + @Comment("人员姓名") + @Excel(name = "人员姓名") + private String userName; + + @Column + @ColDefine(type = ColType.VARCHAR) + @Comment("身份证号") + @Excel(name = "身份证号") + private String idCard; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("账户自理") + @Excel(name = "账户自理") + private BigDecimal zhzl; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("账户自付") + @Excel(name = "账户自付") + private BigDecimal zhzf; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("现金自理") + @Excel(name = "现金自理") + private BigDecimal xjzl; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("现金自付") + @Excel(name = "现金自付") + private BigDecimal xjzf; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("四项之和金额") + @Excel(name = "两项自付之和金额") + private BigDecimal sxzf; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("两项自付之和金额") + @Excel(name = "两项自付之和金额") + private BigDecimal lxzf; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("学校二次报销金额") + @Excel(name = "学校二次报销金额") + private BigDecimal ecbx; + + @Column + @ColDefine(type = ColType.FLOAT, width = 10, precision = 2) + @Comment("补助计算额度") + @Excel(name = "补助计算额度") + private BigDecimal calc; + + @Column + @ColDefine(type = ColType.INT) + @Comment("年份") + private Integer year; + +} diff --git a/src/main/resources/views/layouts/platform.html b/src/main/resources/views/layouts/platform.html index 57a9aae..f24c67d 100644 --- a/src/main/resources/views/layouts/platform.html +++ b/src/main/resources/views/layouts/platform.html @@ -23,6 +23,7 @@ + diff --git a/src/main/resources/views/platform/sickHelp/medicalIns/ecImport.js b/src/main/resources/views/platform/sickHelp/medicalIns/ecImport.js new file mode 100644 index 0000000..d69268c --- /dev/null +++ b/src/main/resources/views/platform/sickHelp/medicalIns/ecImport.js @@ -0,0 +1,181 @@ +const ecImport = { + template: /*language=HTML*/ ` + +
+ +
+ + 下载导入模板 + + 请按照模板格式填写数据后上传 +
+ +
+ + +
将文件拖到此处,或点击上传
+
+
+ +
+ +
+ 导入结果 +
+
+
+ 匹配成功数据数: + + {{ importResult.success || 0 }} + +
+
+ 匹配失败数据数: + + {{ importResult.fail || 0 }} + + + + +
+
+
+
+
+
+ `, + data() { + return { + files: [], + fileList: [], + uploadUrl: loc() + '/importEc', + importVisible: false, + importData: {}, + importLoading: false, + importResult: { + totalData: [], + successData: [], + failData: [], + total: 0, + success: 0, + fail: 0 + }, + excelKeyMap: { + "userName": '姓名', + "loginName": '工号', + "ecbx": '学校二次报销金额' + } + } + }, + methods: { + onOpen() { + this.importVisible = true + }, + + handleSuccess(resp) { + this.importLoading = false + if (resp.code === 0) { + this.$message.success('导入成功') + this.importResult = resp.data + this.$emit('refresh', null) + } else { + this.$message.error('导入失败') + } + }, + handleProgress() { + this.importLoading = true + }, + beforeUpload(file, files) { + const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1); + const whiteList = ['xlsx'] + if (!whiteList.includes(fileSuffix)) { + this.files = [] + this.$message.warning('上传文件只能是' + whiteList.join(',') + '格式') + return false + } + this.files = files + }, + + transformData(dataArray, excelKeyMap) { + if (!Array.isArray(dataArray) || dataArray.length === 0) { + return []; + } + return dataArray.map(v => { + let row = {}; + const keys = Object.keys(excelKeyMap); // 缓存 keys 避免重复计算 + keys.forEach(k1 => { + row[excelKeyMap[k1]] = v[k1]; + }); + return row; + }); + }, + + exportExcel(type) { + let data = []; + + if (type === 'total') { + if (!Array.isArray(this.importResult.totalData) || this.importResult.totalData.length === 0) { + this.$message.warning('没有数据可导出'); + return; + } + data = this.transformData(this.importResult.totalData, this.excelKeyMap); + } else if (type === 'fail') { + if (!Array.isArray(this.importResult.failData) || this.importResult.failData.length === 0) { + this.$message.warning('没有数据可导出'); + return; + } + data = this.transformData(this.importResult.failData, this.excelKeyMap); + } + + const workName = type === 'total' ? '匹配成功数据' : '匹配失败数据'; + const worksheetName = "Sheet1"; + const fileName = workName + ".xlsx"; + + if (data.length === 0) { + this.$message.warning('没有数据可以生成工作表'); + return; + } + const worksheet = XLSX.utils.json_to_sheet(data); + const workbook = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(workbook, worksheet, worksheetName); + XLSX.writeFile(workbook, fileName); + }, + + downloadTemplate() { + // 创建一个空工作簿 + const workbook = XLSX.utils.book_new(); + // 创建示例数据 + const templateData = [ + { + "工号": "000001", + "姓名": "张三", + "学校二次报销金额": "10000.00" + } + ]; + // 创建工作表 + const worksheet = XLSX.utils.json_to_sheet(templateData); + // 添加到工作簿 + XLSX.utils.book_append_sheet(workbook, worksheet, "医保数据"); + // 导出文件 + XLSX.writeFile(workbook, "医保数据导入模板.xlsx"); + } + + } +}; \ No newline at end of file diff --git a/src/main/resources/views/platform/sickHelp/medicalIns/index.html b/src/main/resources/views/platform/sickHelp/medicalIns/index.html new file mode 100644 index 0000000..caaa646 --- /dev/null +++ b/src/main/resources/views/platform/sickHelp/medicalIns/index.html @@ -0,0 +1,324 @@ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + diff --git a/src/main/resources/views/platform/sickHelp/medicalIns/insForm.js b/src/main/resources/views/platform/sickHelp/medicalIns/insForm.js new file mode 100644 index 0000000..be03d55 --- /dev/null +++ b/src/main/resources/views/platform/sickHelp/medicalIns/insForm.js @@ -0,0 +1,162 @@ +const insForm = { + template: /*language=HTML*/ ` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + `, + data() { + return { + title: '新增', + visible: false, + form: {}, + rules: { + loginName: [ + {required: true, message: '请输入工号', trigger: 'blur'} + ], + userName: [ + {required: true, message: '请输入姓名', trigger: 'blur'} + ], + idCard: [ + {required: true, message: '请输入身份证号', trigger: 'blur'} + ], + zhzl: [ + {required: true, message: '请输入账户自理', trigger: 'blur'} + ], + zhzf: [ + {required: true, message: '请输入账户自付', trigger: 'blur'} + ], + xjzl: [ + {required: true, message: '请输入现金自理', trigger: 'blur'} + ], + xjzf: [ + {required: true, message: '请输入现金自付', trigger: 'blur'} + ], + lxzf: [ + {required: true, message: '请输入两项自付之和', trigger: 'blur'} + ], + sxzf: [ + {required: true, message: '请输入四项之和金额', trigger: 'blur'} + ] + }, + userOptions: {} + } + }, + methods: { + onOpen(row = {}) { + this.visible = true + this.form = {...row} + }, + remoteMethod(query) { + if (query) { + $.post('/platform/sickHelp/medicalIns/queryUser', {query}).then(res => { + if (res.code === 0) { + this.userOptions = res.data + } + }) + } + }, + loginNameChange(val) { + console.log(val) + const user = this.userOptions.find(v => v.loginname === val) + if (user) { + this.form.userName = user.username + } + }, + onSave() { + this.$refs.form.validate(valid => { + if (valid) { + $.post('/platform/sickHelp/medicalIns/update', this.form).then(res => { + if (res.code === 0) { + this.visible = false + this.$message.success("保存成功") + this.$emit('refresh') + } else { + this.$message.error(res.msg) + } + }) + } + }) + } + } +}; \ No newline at end of file diff --git a/src/main/resources/views/platform/sickHelp/medicalIns/insImport.js b/src/main/resources/views/platform/sickHelp/medicalIns/insImport.js new file mode 100644 index 0000000..653a460 --- /dev/null +++ b/src/main/resources/views/platform/sickHelp/medicalIns/insImport.js @@ -0,0 +1,206 @@ +const insImport = { + template: /*language=HTML*/ ` + + +
+ +
+ + 下载导入模板 + + 请按照模板格式填写数据后上传,填写不完整将会导致数据解析错误 +
+ +
+ +
    +
  • 导入之前请确认大病互助会员库数据是最新且准确的
  • +
  • 导入会先过滤掉四项之和小于10000的(达不到补助标准)
  • +
  • 导入会过滤掉非会员数据
  • +
  • 导入会覆盖上一次同年份的数据
  • +
+
+
+ +
+ + +
将文件拖到此处,或点击上传
+
+
+ +
+ +
+ 导入结果 +
+
+
+ 人员总数据数: + + {{ importResult.total || 0 }} + + + + +
+
+ 匹配成功数据数: + + {{ importResult.success || 0 }} + +
+
+ 匹配失败数据数: + + {{ importResult.fail || 0 }} + + + + +
+
+
+
+ + `, + data() { + return { + files: [], + fileList: [], + uploadUrl: loc() + '/importIns', + importVisible: false, + importData: {}, + importLoading: false, + importResult: { + totalData: [], + successData: [], + failData: [], + total: 0, + success: 0, + fail: 0 + }, + excelKeyMap: { + "idCard": '身份证号', + "userName": '姓名', + "zhzl": '账户自理', + "zhzf": '账户自付', + "xjzl": '现金自理', + "xjzf": '现金自付' + } + } + }, + methods: { + onOpen() { + this.importVisible = true + }, + + handleSuccess(resp) { + this.importLoading = false + if (resp.code === 0) { + this.$message.success('导入成功') + this.importResult = resp.data + this.$emit('refresh', null) + } else { + this.$message.error('导入失败') + } + }, + handleProgress() { + this.importLoading = true + }, + beforeUpload(file, files) { + const fileSuffix = file.name.substring(file.name.lastIndexOf(".") + 1); + const whiteList = ['xlsx'] + if (!whiteList.includes(fileSuffix)) { + this.files = [] + this.$message.warning('上传文件只能是' + whiteList.join(',') + '格式') + return false + } + this.files = files + }, + + transformData(dataArray, excelKeyMap) { + if (!Array.isArray(dataArray) || dataArray.length === 0) { + return []; + } + return dataArray.map(v => { + let row = {}; + const keys = Object.keys(excelKeyMap); // 缓存 keys 避免重复计算 + keys.forEach(k1 => { + row[excelKeyMap[k1]] = v[k1]; + }); + return row; + }); + }, + + exportExcel(type) { + let data = []; + + if (type === 'total') { + if (!Array.isArray(this.importResult.totalData) || this.importResult.totalData.length === 0) { + this.$message.warning('没有数据可导出'); + return; + } + data = this.transformData(this.importResult.totalData, this.excelKeyMap); + } else if (type === 'fail') { + if (!Array.isArray(this.importResult.failData) || this.importResult.failData.length === 0) { + this.$message.warning('没有数据可导出'); + return; + } + data = this.transformData(this.importResult.failData, this.excelKeyMap); + } + + const workName = type === 'total' ? '总数据' : '匹配失败数据'; + const worksheetName = "Sheet1"; + const fileName = workName + ".xlsx"; + + if (data.length === 0) { + this.$message.warning('没有数据可以生成工作表'); + return; + } + const worksheet = XLSX.utils.json_to_sheet(data); + const workbook = XLSX.utils.book_new(); + XLSX.utils.book_append_sheet(workbook, worksheet, worksheetName); + XLSX.writeFile(workbook, fileName); + }, + + downloadTemplate() { + // 创建一个空工作簿 + const workbook = XLSX.utils.book_new(); + // 创建示例数据 + const templateData = [ + { + "人员姓名": "张三", + "身份证号": "1234567890", + "账户自理": "10000.00", + "账户自付": "10000.00", + "现金自理": "10000.00", + "现金自付": "10000.00" + } + ]; + // 创建工作表 + const worksheet = XLSX.utils.json_to_sheet(templateData); + // 添加到工作簿 + XLSX.utils.book_append_sheet(workbook, worksheet, "医保数据"); + // 导出文件 + XLSX.writeFile(workbook, "医保数据导入模板.xlsx"); + } + + } +}; \ No newline at end of file