diff --git a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/LeaseOutDetails.java b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/LeaseOutDetails.java index cb6e51e3..0f1de29c 100644 --- a/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/LeaseOutDetails.java +++ b/sgzb-api/sgzb-api-system/src/main/java/com/bonus/sgzb/base/api/domain/LeaseOutDetails.java @@ -1,6 +1,7 @@ package com.bonus.sgzb.base.api.domain; import com.alibaba.fastjson2.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -135,9 +136,13 @@ public class LeaseOutDetails implements Serializable { * 创建时间 */ @ApiModelProperty(value = "创建时间") - @JSONField(format = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") private Date createTime; + @ApiModelProperty(value = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private String outTime; + /** * 更新者 */ diff --git a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysLoginService.java b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysLoginService.java index 7341ecfc..5ba295ad 100644 --- a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysLoginService.java +++ b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysLoginService.java @@ -92,6 +92,11 @@ public class SysLoginService { recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); throw new ServiceException("对不起,您的账号:" + username + " 已停用"); } + // 判断密码是否为原始密码,原始密码需要修改密码方可登录 + if (passwordService.checkFirstLogin(user, password)) { + recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录密码为系统默认密码,请修改密码后重新登录"); + throw new ServiceException("登录密码为系统默认密码,请修改密码后重新登录"); + } passwordService.validate(user, password); recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); return userInfo; diff --git a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java index 97e111b8..719fa9f1 100644 --- a/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java +++ b/sgzb-auth/src/main/java/com/bonus/sgzb/auth/service/SysPasswordService.java @@ -1,6 +1,8 @@ package com.bonus.sgzb.auth.service; import java.util.concurrent.TimeUnit; + +import com.bonus.sgzb.common.core.domain.SystemConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.bonus.sgzb.common.core.constant.CacheConstants; @@ -10,6 +12,8 @@ import com.bonus.sgzb.common.redis.service.RedisService; import com.bonus.sgzb.common.security.utils.SecurityUtils; import com.bonus.sgzb.system.api.domain.SysUser; +import javax.annotation.Resource; + /** * 登录密码方法 * @@ -24,6 +28,9 @@ public class SysPasswordService { private Long lockTime = CacheConstants.PASSWORD_LOCK_TIME; + @Resource + private SystemConfig systemConfig; + @Autowired private SysRecordLogService recordLogService; @@ -71,4 +78,14 @@ public class SysPasswordService { redisService.deleteObject(getCacheKey(loginName)); } } + + public boolean checkFirstLogin(SysUser user, String password) { + if (!systemConfig.getPasswordConfig().isForcePasswordChangeOnFirstLogin()) { + return false; + } + if (matches(user, password)) { + return true; + } + return false; + } } diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/SystemConfig.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/SystemConfig.java new file mode 100644 index 00000000..8d4f4ac6 --- /dev/null +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/domain/SystemConfig.java @@ -0,0 +1,178 @@ +package com.bonus.sgzb.common.core.domain; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @Author ma_sh + * @create 2025/4/17 14:11 + */ +@RefreshScope +@Component +@ConfigurationProperties(prefix = "system-config") +@Data +public class SystemConfig { + + /** + * 登录配置 + */ + private LoginConfig loginConfig; + /** + * 增加配置以支持增加根节点公司的添加和删除功能 + */ + private boolean addRootCompany; + + /** + * 公司是否添加地址信息 + */ + private boolean addAddress; + /** + * token过期时间 + */ + private Long tokenTime; + /** + * 是否是管理员登录,如果启用超级管理员,则除了登录时需要系统验证码还需要短信验证码 + */ + private boolean admin; + /** + * 注册配置 + */ + private RegistersConfig registersConfig; + /** + * 网络请求 + */ + private RequestConfig requestConfig; + /** + * 密码配置校验 + */ + private PasswordConfig passwordConfig; + + /** + * websocketUrl + */ + private String websocketurl; + + @Data + @RefreshScope + public static class LoginConfig { + /** + * 手机密码登录 + */ + private boolean phonePassword; + /** + * 邮箱密码登录 + */ + private boolean emailPassword; + /** + * 手机验证码 + */ + private boolean phoneCode; + /** + * 邮箱验证码 + */ + private boolean emailCode; + } + + @Data + @RefreshScope + public static class RegistersConfig { + /** + * 手机注册 + */ + private boolean phoneRegisters; + /** + * 邮箱注册 + */ + private boolean emailRegisters; + /** + * 是否开启手机验证码 + */ + private boolean verificationCode; + /** + * 注册是否审核 + */ + private boolean approvalStatus; + } + + @Data + @RefreshScope + public static class RequestConfig { + /** + * 请求加密 + */ + private boolean encryptRequest; + /** + * 数据完整性校验 + */ + private boolean checkIntegrity; + /** + * 返回数据加密 + */ + private boolean encryptResponse; + } + + @Data + @RefreshScope + public static class PasswordConfig { + /** + * 密码的最小长度 + */ + private int minLength; + /** + * 密码的最大长度 + */ + private int maxLength; + /** + * 是否需要包含大写字母 + */ + private boolean requireUpperCase; + /** + * 是否需要包含小写字母 + */ + private boolean requireLowerCase; + /** + * 是否需要包含数字 + */ + private boolean requireDigit; + /** + * 是否需要包含特殊字符 + */ + private boolean requireSpecialChar; + /** + * 常见的弱密码列表,禁止使用这些密码 + */ + private List weakPasswords; + /** + * 密码历史记录限制 + */ + private int passwordHistoryLimit; + /** + * 是否限制连续相同字符 + */ + private boolean restrictConsecutiveChars; + /** + * 最大允许的连续字符数 + */ + private int maxConsecutiveChars; + /** + * 密码中是否不能包含用户名 + */ + private boolean excludeUsernameInPassword; + /** + * 是否在首次登录时强制修改密码 + */ + private boolean forcePasswordChangeOnFirstLogin; + /** + * 是否开启定期修改密码 + */ + private boolean enableRegularlyChangePassword; + /** + * 定期修改密码天数 + */ + private Integer regularlyChangePassword; + } +} diff --git a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/poi/PoiOutPage.java b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/poi/PoiOutPage.java index f4d97f08..846f21bf 100644 --- a/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/poi/PoiOutPage.java +++ b/sgzb-common/sgzb-common-core/src/main/java/com/bonus/sgzb/common/core/utils/poi/PoiOutPage.java @@ -385,4 +385,218 @@ public class PoiOutPage { return style; } + + public static HSSFWorkbook excelForCheckOut(List> result, List list, String fileName, String projectName, String unit, String code, String leasePerson) { + // 创建工作簿和工作表 + HSSFWorkbook workbook = new HSSFWorkbook(); + HSSFSheet sheet = workbook.createSheet(); + sheet.setDefaultColumnWidth(15); // 设置列宽 + + // 创建样式 + HSSFCellStyle titleStyle = createTitleStyle(workbook); + HSSFCellStyle headerStyle = createHeaderStyle(workbook); + HSSFCellStyle contentStyle = createCellStyleCost(workbook); + + // 设置工作簿名称 + workbook.setSheetName(0, fileName); + + // 填充标题行 + int rowNum = 0; + rowNum = createTitleRowStyle(sheet, rowNum, fileName, titleStyle, list.size()); + rowNum = createProjectInfoRowOut(sheet, rowNum, projectName, unit, titleStyle, list.size(), code); + + // 填充表头 + rowNum = createHeaderRow(sheet, rowNum, list, headerStyle); + + // 填充数据行 + if (result != null && !result.isEmpty()) { + rowNum = createDataRows(sheet, rowNum, result, contentStyle, list.size()); + } else { + // 如果没有数据,则仅显示表头 +// rowNum++; +// rowNum = createDataRows(sheet, rowNum, result, contentStyle, list.size()); + HSSFRow row = sheet.createRow(rowNum++); + HSSFCell cell = row.createCell(0); + cell.setCellStyle(headerStyle); + cell.setCellValue("暂无数据"); + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (list.size() - 1))); + CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (list.size() - 1)); + // 设置边框样式 + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); + } + rowNum = createTotalRow(sheet, rowNum, list, leasePerson, headerStyle); + return workbook; + } + + private static int createTotalRow(HSSFSheet sheet, int rowNum, List list, String leasePerson, HSSFCellStyle headerStyle) { + + /*HSSFRow row = sheet.createRow(rowNum++); + HSSFCell cell = row.createCell(0); + cell.setCellStyle(headerStyle); + cell.setCellValue(leasePerson + " " + "批注人:" + " " + "审批人:"); + + sheet.addMergedRegion(new CellRangeAddress(rowNum-1, rowNum-1, 1, (short) (list.size() - 1))); + CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 1, (short) (list.size() - 1)); + // 设置边框样式 + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); + + + return rowNum;*/ + HSSFRow row = sheet.createRow(rowNum++); + row.setHeightInPoints(30); + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (list.size() - 1))); + HSSFCell cell = row.createCell(0); + cell.setCellStyle(headerStyle); + cell.setCellValue("领料申请人:" + leasePerson + " 批注人: " + " 审批人: "); + + // 添加边框 + CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, (short) (list.size() - 1)); + // 设置边框样式 + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); + + return rowNum; + } + + + /** + * 创建标题行以及样式 + */ + private static int createTitleRowStyle(HSSFSheet sheet, int rowNum, String filename, HSSFCellStyle titleStyle, int nColumn) { + HSSFRow row = sheet.createRow(rowNum++); + row.setHeightInPoints(30); + sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, (short) (nColumn - 1))); + HSSFCell cell = row.createCell(0); + cell.setCellStyle(titleStyle); + cell.setCellValue(filename); + // 添加边框 + CellRangeAddress cellRange = new CellRangeAddress(rowNum - 1, rowNum - 1, rowNum - 1, (short) (nColumn - 1)); + // 设置边框样式 + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange, sheet); + + return rowNum; + } + + /** + * 创建内容样式 + * @param workbook + * @return + */ + public static HSSFCellStyle createCellStyleCost(HSSFWorkbook workbook) { + + HSSFCellStyle style = workbook.createCellStyle(); + style.setAlignment(HorizontalAlignment.CENTER); + style.setVerticalAlignment(VerticalAlignment.CENTER); + HSSFFont font = workbook.createFont(); + font.setFontHeightInPoints((short) 10); + style.setFont(font); + + // 设置边框 + style.setBorderTop(BorderStyle.THIN); + style.setBorderBottom(BorderStyle.THIN); + style.setBorderLeft(BorderStyle.THIN); + style.setBorderRight(BorderStyle.THIN); + + // 设置边框颜色为黑色 + style.setTopBorderColor(IndexedColors.BLACK.getIndex()); + style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); + style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); + style.setRightBorderColor(IndexedColors.BLACK.getIndex()); + + + // 设置数字格式为保留两位小数 + DataFormat dataFormat = workbook.createDataFormat(); + style.setDataFormat(dataFormat.getFormat("0.00")); // 设置格式为"0.00" + + return style; + } + + private static int createProjectInfoRowOut(HSSFSheet sheet, int rowNum, String projectName, String unit, HSSFCellStyle titleStyle, int nColumn, String code) { + // 第一行:领料单位 + HSSFRow row1 = sheet.createRow(rowNum++); + row1.setHeightInPoints(30); + // bug修复:修改合并单元格区域,确保包含两个或以上单元格 + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1)); + HSSFCell cell1 = row1.createCell(0); + cell1.setCellStyle(titleStyle); + cell1.setCellValue("领料单位:"); + + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 1))); + HSSFCell cell2 = row1.createCell(2); + cell2.setCellStyle(titleStyle); + cell2.setCellValue(unit); + + // 第二行:领料工程 + HSSFRow row2 = sheet.createRow(rowNum++); + row2.setHeightInPoints(30); + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1)); + HSSFCell cell3 = row2.createCell(0); + cell3.setCellStyle(titleStyle); + cell3.setCellValue("领料工程:"); + + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 1))); // projectName 占剩余的22 + HSSFCell cell4 = row2.createCell(2); + cell4.setCellStyle(titleStyle); + cell4.setCellValue(projectName); + + // 第二行:领料单号 + HSSFRow row3 = sheet.createRow(rowNum++); + row2.setHeightInPoints(30); + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1)); + HSSFCell cell5 = row3.createCell(0); + cell5.setCellStyle(titleStyle); + cell5.setCellValue("领料单号:"); + + sheet.addMergedRegion(new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 1))); // projectName 占剩余的22 + HSSFCell cell6 = row3.createCell(2); + cell6.setCellStyle(titleStyle); + cell6.setCellValue(code); + + // 添加边框 + CellRangeAddress cellRange1 = new CellRangeAddress(rowNum - 3, rowNum - 3, 0, 1); + CellRangeAddress cellRange2 = new CellRangeAddress(rowNum - 3, rowNum - 3, 2, (short) (nColumn - 1)); + CellRangeAddress cellRange3 = new CellRangeAddress(rowNum - 2, rowNum - 2, 0, 1); + CellRangeAddress cellRange4 = new CellRangeAddress(rowNum - 2, rowNum - 2, 2, (short) (nColumn - 1)); + CellRangeAddress cellRange5 = new CellRangeAddress(rowNum - 1, rowNum - 1, 0, 1); + CellRangeAddress cellRange6 = new CellRangeAddress(rowNum - 1, rowNum - 1, 2, (short) (nColumn - 1)); + // 设置边框样式 + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange1, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange1, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange1, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange1, sheet); + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange2, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange2, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange2, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange2, sheet); + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange3, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange3, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange3, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange3, sheet); + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange4, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange4, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange4, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange4, sheet); + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange5, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange5, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange5, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange5, sheet); + RegionUtil.setBorderTop(BorderStyle.THIN, cellRange6, sheet); + RegionUtil.setBorderBottom(BorderStyle.THIN, cellRange6, sheet); + RegionUtil.setBorderLeft(BorderStyle.THIN, cellRange6, sheet); + RegionUtil.setBorderRight(BorderStyle.THIN, cellRange6, sheet); + + + return rowNum; + } } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/controller/LeaseOutDetailsController.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/controller/LeaseOutDetailsController.java index 073b1f4f..c4da4272 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/controller/LeaseOutDetailsController.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/controller/LeaseOutDetailsController.java @@ -16,6 +16,7 @@ import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -138,16 +139,34 @@ public class LeaseOutDetailsController extends BaseController { /** * 领料出库,出库单查询 * - * @param parentId + * @param bean */ @Log(title = "出库单查询", businessType = BusinessType.QUERY) @GetMapping("/getOutboundOrder") - public AjaxResult getOutboundOrder(String parentId) { + public AjaxResult getOutboundOrder(LeaseOutDetails bean) { startPage(); - List outboundOrder = leaseOutDetailsService.getOutboundOrder(parentId); + List outboundOrder = leaseOutDetailsService.getOutboundOrder(bean); return AjaxResult.success(getDataTable(outboundOrder)); } + @Log(title = "出库单车牌号查询", businessType = BusinessType.QUERY) + @GetMapping("/getCarCodeList") + public AjaxResult getCarCodeList(LeaseOutDetails bean) { + List outboundOrder = leaseOutDetailsService.getCarCodeList(bean); + return AjaxResult.success(outboundOrder); + } + + /** + * 出库单导出 + * @param bean + * @param response + */ + @Log(title = "出库单导出", businessType = BusinessType.EXPORT) + @PostMapping("/exportOutboundOrder") + public void exportInfo(LeaseOutDetails bean, HttpServletResponse response) { + leaseOutDetailsService.exportInfo(bean, response); + } + /** * @param recordList * @return diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/LeaseOutDetailsMapper.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/LeaseOutDetailsMapper.java index 445898c3..82175cdb 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/LeaseOutDetailsMapper.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/mapper/LeaseOutDetailsMapper.java @@ -108,7 +108,7 @@ public interface LeaseOutDetailsMapper { int updateLeaseApplyDetails(@Param("record") LeaseOutDetails record); - List getOutboundOrder(String parentId); + List getOutboundOrder(LeaseOutDetails bean); int getCountOfCodeMachine(@Param("record") LeaseOutDetails record); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/LeaseOutDetailsService.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/LeaseOutDetailsService.java index c44c8e1a..458c3fe7 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/LeaseOutDetailsService.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/LeaseOutDetailsService.java @@ -6,6 +6,7 @@ import com.bonus.sgzb.base.api.domain.LeaseOutDetails; import com.bonus.sgzb.base.api.domain.MaMachine; import com.bonus.sgzb.common.core.web.domain.AjaxResult; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -40,7 +41,7 @@ public interface LeaseOutDetailsService { * @return 结果 */ AjaxResult submitOut(LeaseOutDetails record); - List getOutboundOrder(String parentId); + List getOutboundOrder(LeaseOutDetails bean); /** * 根据code编码查询设备信息 * @param maCode 机具编码 @@ -78,4 +79,18 @@ public interface LeaseOutDetailsService { AjaxResult submitOutRfid(List recordList); List getDetailsByApplyId(TmTask id); + + /** + * 根据carCode查询设备信息 + * @param bean + * @return + */ + List getCarCodeList(LeaseOutDetails bean); + + /** + * 出库单导出 + * @param bean + * @param response + */ + void exportInfo(LeaseOutDetails bean, HttpServletResponse response); } diff --git a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/LeaseOutDetailsServiceImpl.java b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/LeaseOutDetailsServiceImpl.java index 5eff49eb..15367789 100644 --- a/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/LeaseOutDetailsServiceImpl.java +++ b/sgzb-modules/sgzb-base/src/main/java/com/bonus/sgzb/app/service/impl/LeaseOutDetailsServiceImpl.java @@ -2,6 +2,7 @@ package com.bonus.sgzb.app.service.impl; import cn.hutool.core.collection.CollUtil; import com.bonus.sgzb.app.domain.LeaseApplyDetails; +import com.bonus.sgzb.app.mapper.TmTaskMapper; import com.bonus.sgzb.base.api.domain.MachinePart; import com.bonus.sgzb.app.domain.TmTask; import com.bonus.sgzb.app.mapper.LeaseApplyDetailsMapper; @@ -11,18 +12,23 @@ import com.bonus.sgzb.base.api.domain.*; import com.bonus.sgzb.base.mapper.MaLabelBindMapper; import com.bonus.sgzb.base.mapper.MaMachineMapper; import com.bonus.sgzb.base.vo.MaLabelBindVO; +import com.bonus.sgzb.common.core.utils.DateUtils; import com.bonus.sgzb.common.core.utils.StringUtils; +import com.bonus.sgzb.common.core.utils.poi.PoiOutPage; import com.bonus.sgzb.common.core.web.domain.AjaxResult; import com.bonus.sgzb.common.security.utils.SecurityUtils; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; import java.math.BigDecimal; -import java.util.Date; -import java.util.List; -import java.util.Objects; +import java.net.URLEncoder; +import java.util.*; +import java.util.stream.Collectors; /** * Description: 领料出库详情接口实现类 @@ -45,6 +51,9 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService { @Resource private MaLabelBindMapper maLabelBindMapper; + @Resource + private TmTaskMapper tmTaskMapper; + /** * 根据任务id查询出库数据 * @@ -141,6 +150,144 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService { return leaseApplyDetailsMapper.getDetailsByApplyId(typeId); } + @Override + public List getCarCodeList(LeaseOutDetails bean) { + List list = new ArrayList<>(); + List outboundOrder = leaseOutDetailsMapper.getOutboundOrder(bean); + if (CollUtil.isNotEmpty(outboundOrder)) { + // 过滤出outboundOrder集合中carCode不为空的数据 + List carCodeList = outboundOrder.stream().filter(item -> StringUtils.isNotBlank(item.getCarCode())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(carCodeList)) { + for (LeaseOutDetails leaseOutDetails : carCodeList) { + // list中不能包含相同的车牌号 + if (!list.contains(leaseOutDetails.getCarCode())) { + list.add(leaseOutDetails.getCarCode()); + } + } + } + } + return list; + } + + /** + * 出库单导出 + * @param bean + * @param response + */ + @Override + public void exportInfo(LeaseOutDetails bean, HttpServletResponse response) { + if (bean == null || bean.getParentId() == null) { + throw new RuntimeException("参数不能为空"); + } + TmTask tmTask = new TmTask(); + tmTask.setId(String.valueOf(bean.getParentId())); + List taskList = tmTaskMapper.getLeaseOutListByAdmin(tmTask); + List list = leaseOutDetailsMapper.getOutboundOrder(bean); + //将list集合中的createTime转换为字符串 + list.forEach(item -> { + item.setOutTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", item.getCreateTime())); + }); + try { + String fileName = "领料出库单"; + String projectName = ""; + String unitName = ""; + String code = ""; + String leasePerson = ""; + if (CollUtil.isNotEmpty(taskList)) { + unitName = taskList.get(0).getUnitName(); + code = taskList.get(0).getCode(); + projectName = taskList.get(0).getProName(); + leasePerson = taskList.get(0).getApplyFor(); + } + expOutExcel(response, list, fileName, projectName, unitName, code, leasePerson); + } catch (Exception e) { + log.error(e.toString(), e); + } + } + + /** + * 出库单导出 + * @param response + * @param list + * @param fileName + * @param projectName + * @param unitName + * @param code + */ + private void expOutExcel(HttpServletResponse response, List list, String fileName, String projectName, String unitName, String code, String leasePerson) + throws Exception { + if (list != null) { + List> results = new ArrayList>(); + int size = list.size(); + for (int i = 0; i < size; i++) { + LeaseOutDetails bean = list.get(i); + Map maps = outReceiveDetailsBeanToMap(bean); + results.add(maps); + } + List headers = receiveDetailsHeader(); + HSSFWorkbook workbook = PoiOutPage.excelForCheckOut(results, headers, fileName,projectName,unitName, code, leasePerson); + OutputStream out = null; + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.addHeader("Content-Disposition", + "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xls"); + response.setHeader("Pragma", "No-cache"); + out = response.getOutputStream(); + workbook.write(out); + out.flush(); + out.close(); + }else{ + List> results = new ArrayList>(); + List headers = receiveDetailsHeader(); + HSSFWorkbook workbook = PoiOutPage.excel(results, headers, fileName); + OutputStream out = null; + response.setContentType("application/vnd.ms-excel;charset=UTF-8"); + response.addHeader("Content-Disposition", + "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xls"); + response.setHeader("Pragma", "No-cache"); + out = response.getOutputStream(); + workbook.write(out); + out.flush(); + out.close(); + } + } + + /** + * 出库单导出 + * @param bean + * @return + */ + private Map outReceiveDetailsBeanToMap(LeaseOutDetails bean) { + Map maps = new LinkedHashMap(); + maps.put("typeName", bean.getTypeName()); + maps.put("typeModelName", bean.getTypeModelName()); + maps.put("maCode", bean.getMaCode()); + maps.put("preNum", bean.getPreNum()); + maps.put("outNum", bean.getOutNum()); + maps.put("leasePerson", bean.getLeasePerson()); + maps.put("outPerson", bean.getOutPerson()); + maps.put("createTime", bean.getOutTime()); + maps.put("carCode", bean.getCarCode()); + return maps; + } + + /** + * 出库单导出头 + * @return + */ + private List receiveDetailsHeader() { + List list = new ArrayList(); + list.add("设备类型"); + list.add("规格型号"); + list.add("设备编码"); + list.add("申请数量"); + list.add("出库数量"); + list.add("领料人"); + list.add("出库人"); + list.add("出库日期"); + list.add("车牌号"); + return list; + } + /** * 领料出库处理 * @@ -201,8 +348,8 @@ public class LeaseOutDetailsServiceImpl implements LeaseOutDetailsService { } @Override - public List getOutboundOrder(String parentId) { - return leaseOutDetailsMapper.getOutboundOrder(parentId); + public List getOutboundOrder(LeaseOutDetails bean) { + return leaseOutDetailsMapper.getOutboundOrder(bean); } private int insertRecords(LeaseOutDetails record) { diff --git a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml index 7be081ab..da5855bb 100644 --- a/sgzb-modules/sgzb-base/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml +++ b/sgzb-modules/sgzb-base/src/main/resources/mapper/app/LeaseOutDetailsMapper.xml @@ -475,6 +475,9 @@ LEFT JOIN ma_type mt2 ON mt.parent_id = mt2.type_id WHERE lod.parent_id = #{parentId} + + and lod.car_code like concat('%', #{carCode}, '%') +