parent
98cd7fc8fc
commit
a224984866
9 changed files with 689 additions and 0 deletions
@ -0,0 +1,115 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.pojo.entity; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.Getter; |
||||||
|
import org.springblade.core.mp.base.BaseEntity; |
||||||
|
import org.springblade.core.tool.utils.ObjectUtil; |
||||||
|
import org.springblade.core.tool.utils.StringPool; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 实体类 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("BS_URGENT_PART") |
||||||
|
@Schema(description = "UrgentPart Entity对象") |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class UrgentPart extends BaseEntity { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
public static final String COL_PLAN_NO = "PLAN_NO"; |
||||||
|
public static final String COL_PART_CODE = "PART_CODE"; |
||||||
|
public static final String COL_BATCH_NO = "BATCH_NO"; |
||||||
|
public static final String COL_REQUIRE_DATE = "REQUIRE_DATE"; |
||||||
|
public static final String COL_EXPIRE_DATE = "EXPIRE_DATE"; |
||||||
|
public static final String COL_STATUS = "STATUS"; |
||||||
|
public static final String COL_MAINTAIN_MAN = "MAINTAIN_MAN"; |
||||||
|
public static final String COL_MAINTAIN_TIME = "MAINTAIN_TIME"; |
||||||
|
|
||||||
|
@Schema(description = "计划单号") |
||||||
|
private String planNo; |
||||||
|
|
||||||
|
@Schema(description = "零件号") |
||||||
|
private String partCode; |
||||||
|
|
||||||
|
@Schema(description = "批次号") |
||||||
|
private String batchNo; |
||||||
|
|
||||||
|
@Schema(description = "需求交期") |
||||||
|
private Date requireDate; |
||||||
|
|
||||||
|
@Schema(description = "到期日期") |
||||||
|
private Date expireDate; |
||||||
|
|
||||||
|
@Schema(description = "状态:0-生效,1-作废") |
||||||
|
private Integer status; |
||||||
|
|
||||||
|
@Schema(description = "维护人") |
||||||
|
private Long maintainMan; |
||||||
|
|
||||||
|
@Schema(description = "维护时间") |
||||||
|
private Date maintainTime; |
||||||
|
|
||||||
|
|
||||||
|
@Getter |
||||||
|
@AllArgsConstructor |
||||||
|
public enum UrgentPartStatusEnum { |
||||||
|
EMPTY(StringPool.EMPTY, -1), |
||||||
|
|
||||||
|
/** |
||||||
|
* 状态:0-生效,1-作废 |
||||||
|
*/ |
||||||
|
EFFECTIVE("生效", 0), |
||||||
|
VOID("作废", 1), |
||||||
|
; |
||||||
|
|
||||||
|
final String name; |
||||||
|
final int code; |
||||||
|
|
||||||
|
/** |
||||||
|
* 匹配枚举值 |
||||||
|
* |
||||||
|
* @param name 名称 |
||||||
|
* @return UrgentPartStatusEnum |
||||||
|
*/ |
||||||
|
public static UrgentPartStatusEnum of(String name) { |
||||||
|
return Arrays.stream(UrgentPartStatusEnum.values()) |
||||||
|
.filter(enumItem -> enumItem.getName().equalsIgnoreCase(name != null ? name : "web")) |
||||||
|
.findFirst() |
||||||
|
// 在没有找到匹配项时返回默认值
|
||||||
|
.orElse(UrgentPartStatusEnum.EMPTY); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据值获取名称 |
||||||
|
* |
||||||
|
* @param code 状态码 |
||||||
|
* @return 状态名称 |
||||||
|
*/ |
||||||
|
public static String getName(int code) { |
||||||
|
UrgentPartStatusEnum item = Arrays.stream(UrgentPartStatusEnum.values()) |
||||||
|
.filter(enumItem -> enumItem.getCode() == code) |
||||||
|
.findFirst() |
||||||
|
.orElse(null); |
||||||
|
return ObjectUtil.isEmpty(item) ? StringPool.EMPTY : item.getName(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,36 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.pojo.vo; |
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import org.springblade.desk.basic.pojo.entity.UrgentPart; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 视图实体类 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class UrgentPartVO extends UrgentPart { |
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@Schema(description = "维护人名称") |
||||||
|
private String maintainManName; |
||||||
|
|
||||||
|
@Schema(description = "创建人名称") |
||||||
|
private String createUserName; |
||||||
|
|
||||||
|
@Schema(description = "修改人名称") |
||||||
|
private String updateUserName; |
||||||
|
|
||||||
|
@Schema(description = "状态名称") |
||||||
|
private String statusName; |
||||||
|
} |
||||||
@ -0,0 +1,114 @@ |
|||||||
|
package org.springblade.desk.basic.controller; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
||||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
import org.springframework.core.io.Resource; |
||||||
|
import jakarta.servlet.http.HttpServletResponse; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.boot.ctrl.BladeController; |
||||||
|
import org.springblade.core.excel.util.ExcelUtil; |
||||||
|
import org.springblade.core.log.annotation.ApiLog; |
||||||
|
import org.springblade.core.mp.support.Condition; |
||||||
|
import org.springblade.core.mp.support.Query; |
||||||
|
import org.springblade.core.secure.BladeUser; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.desk.basic.constant.BAModuleConst; |
||||||
|
import org.springblade.desk.basic.excel.UrgentPartExcel; |
||||||
|
import org.springblade.desk.basic.pojo.entity.UrgentPart; |
||||||
|
import org.springblade.desk.basic.pojo.vo.UrgentPartVO; |
||||||
|
import org.springblade.desk.basic.service.IUrgentPartService; |
||||||
|
import org.springblade.desk.basic.util.ExcelExtUtil; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 控制器 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
@RestController |
||||||
|
@RequestMapping(BAModuleConst.CONTROLLER_PREFIX + "/UrgentPart") |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@Slf4j |
||||||
|
@Tag(name = "[BA][急件维护]", description = "[急件维护]接口") |
||||||
|
public class UrgentPartController extends BladeController { |
||||||
|
|
||||||
|
private final IUrgentPartService service; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 分页查询 |
||||||
|
*/ |
||||||
|
@GetMapping("/page") |
||||||
|
@ApiOperationSupport(order = 20) |
||||||
|
@Operation(summary = "分页查询", description = "传入UrgentPartVO Obj") |
||||||
|
public R<IPage<UrgentPartVO>> page(UrgentPartVO urgentPart, Query query) { |
||||||
|
IPage<UrgentPart> page = Condition.getPage(query); |
||||||
|
IPage<UrgentPartVO> pagesVO = service.selectUrgentPartPage( |
||||||
|
page, urgentPart |
||||||
|
); |
||||||
|
return R.data(pagesVO); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 导入Excel |
||||||
|
*/ |
||||||
|
@PostMapping("/importExcel") |
||||||
|
@ApiOperationSupport(order = 70) |
||||||
|
@ApiLog("急件维护导入") |
||||||
|
@Operation(summary = "导入Excel", description = "MultipartFile") |
||||||
|
public R importExcel(@RequestParam("file") MultipartFile file) { |
||||||
|
return service.importExcel(file); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 作废 |
||||||
|
*/ |
||||||
|
@PostMapping("/voidRecords") |
||||||
|
@ApiOperationSupport(order = 71) |
||||||
|
@ApiLog("急件维护作废") |
||||||
|
@Operation(summary = "作废", description = "传入ids") |
||||||
|
public R voidRecords(@Parameter(description = "主键集合", required = true) @RequestBody List<Long> ids) { |
||||||
|
return service.voidRecords(ids); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 导出Excel |
||||||
|
*/ |
||||||
|
@GetMapping("/exportExcel") |
||||||
|
@ApiOperationSupport(order = 72) |
||||||
|
@Operation(summary = "导出Excel", description = "传入UrgentPart") |
||||||
|
public void exportExcel(@Parameter(hidden = true) @RequestParam Map<String, Object> urgentPart, |
||||||
|
HttpServletResponse response) { |
||||||
|
List<UrgentPartExcel> list = service.exportUrgentPart(Condition.getQueryWrapper(urgentPart, UrgentPart.class)); |
||||||
|
ExcelUtil.export(response, "[急件维护]数据" + DateUtil.time(), |
||||||
|
"[急件维护]数据表", list, UrgentPartExcel.class); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 下载Excel模板 |
||||||
|
*/ |
||||||
|
@GetMapping("/downloadExcelTemplate") |
||||||
|
@ApiOperationSupport(order = 73) |
||||||
|
@Operation(summary = "下载Excel模板", description = "") |
||||||
|
public ResponseEntity<Resource> downloadExcelTemplate() { |
||||||
|
return ExcelExtUtil.downloadXlsTemplate( |
||||||
|
"Excel/BA/急件维护导入模板.xls", |
||||||
|
"导入模版-急件维护.xls"); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,74 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.excel; |
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||||
|
import com.alibaba.excel.annotation.write.style.ContentRowHeight; |
||||||
|
import com.alibaba.excel.annotation.write.style.HeadRowHeight; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import java.io.Serial; |
||||||
|
import java.io.Serializable; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] Excel实体类 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@ColumnWidth(25) |
||||||
|
@HeadRowHeight(20) |
||||||
|
@ContentRowHeight(18) |
||||||
|
public class UrgentPartExcel implements Serializable { |
||||||
|
|
||||||
|
@Serial |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
/** |
||||||
|
* 计划单号 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("计划单号") |
||||||
|
private String planNo; |
||||||
|
|
||||||
|
/** |
||||||
|
* 零件号 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("零件号") |
||||||
|
private String partCode; |
||||||
|
|
||||||
|
/** |
||||||
|
* 批次号 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("批次号") |
||||||
|
private String batchNo; |
||||||
|
|
||||||
|
/** |
||||||
|
* 需求交期 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("需求交期") |
||||||
|
private Date requireDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 到期日期 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("到期日期") |
||||||
|
private Date expireDate; |
||||||
|
|
||||||
|
/** |
||||||
|
* 状态 |
||||||
|
*/ |
||||||
|
@ColumnWidth(20) |
||||||
|
@ExcelProperty("状态") |
||||||
|
private String status; |
||||||
|
} |
||||||
@ -0,0 +1,32 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.mapper; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.springblade.desk.basic.excel.UrgentPartExcel; |
||||||
|
import org.springblade.desk.basic.pojo.entity.UrgentPart; |
||||||
|
import org.springblade.desk.basic.pojo.vo.UrgentPartVO; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] Mapper 接口 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
public interface UrgentPartMapper extends BaseMapper<UrgentPart> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取导出数据 |
||||||
|
* |
||||||
|
* @param queryWrapper 查询条件 |
||||||
|
* @return List<UrgentPartExcel> |
||||||
|
*/ |
||||||
|
List<UrgentPartExcel> exportUrgentPart(@Param("ew") Wrapper<UrgentPart> queryWrapper); |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,19 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||||
|
<mapper namespace="org.springblade.desk.basic.mapper.UrgentPartMapper"> |
||||||
|
|
||||||
|
<!-- 导出数据 --> |
||||||
|
<select id="exportUrgentPart" resultType="org.springblade.desk.basic.excel.UrgentPartExcel"> |
||||||
|
SELECT |
||||||
|
PLAN_NO as planNo, |
||||||
|
PART_CODE as partCode, |
||||||
|
BATCH_NO as batchNo, |
||||||
|
REQUIRE_DATE as requireDate, |
||||||
|
EXPIRE_DATE as expireDate, |
||||||
|
STATUS as status |
||||||
|
FROM BS_URGENT_PART |
||||||
|
${ew.customSqlSegment} |
||||||
|
</select> |
||||||
|
|
||||||
|
|
||||||
|
</mapper> |
||||||
@ -0,0 +1,64 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.service; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import org.springblade.core.mp.base.BaseService; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import org.springblade.desk.basic.excel.UrgentPartExcel; |
||||||
|
import org.springblade.desk.basic.pojo.entity.UrgentPart; |
||||||
|
import org.springblade.desk.basic.pojo.vo.UrgentPartVO; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 服务类 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
public interface IUrgentPartService extends BaseService<UrgentPart> { |
||||||
|
|
||||||
|
/** |
||||||
|
* 自定义分页 |
||||||
|
* |
||||||
|
* @param page 分页参数 |
||||||
|
* @param urgentPart 查询参数 |
||||||
|
* @return IPage<UrgentPartVO> |
||||||
|
*/ |
||||||
|
IPage<UrgentPartVO> selectUrgentPartPage(IPage<UrgentPart> page, UrgentPartVO urgentPart); |
||||||
|
|
||||||
|
/** |
||||||
|
* 导出数据 |
||||||
|
* |
||||||
|
* @param queryWrapper 查询条件 |
||||||
|
* @return List<UrgentPartExcel> |
||||||
|
*/ |
||||||
|
List<UrgentPartExcel> exportUrgentPart(Wrapper<UrgentPart> queryWrapper); |
||||||
|
|
||||||
|
/** |
||||||
|
* 检查并更新过期数据 |
||||||
|
* |
||||||
|
* @return 更新的记录数 |
||||||
|
*/ |
||||||
|
void checkAndUpdateExpiredRecords(); |
||||||
|
|
||||||
|
/** |
||||||
|
* 导入Excel |
||||||
|
* |
||||||
|
* @param file Excel文件 |
||||||
|
* @return R |
||||||
|
*/ |
||||||
|
R importExcel(MultipartFile file); |
||||||
|
|
||||||
|
/** |
||||||
|
* 作废 |
||||||
|
* |
||||||
|
* @param ids 主键ID集合 |
||||||
|
* @return R |
||||||
|
*/ |
||||||
|
R voidRecords(List<Long> ids); |
||||||
|
} |
||||||
@ -0,0 +1,235 @@ |
|||||||
|
/** |
||||||
|
* Author: AI Assistant |
||||||
|
*/ |
||||||
|
package org.springblade.desk.basic.service.impl; |
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil; |
||||||
|
import cn.hutool.core.util.StrUtil; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.Wrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import jakarta.annotation.Resource; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springblade.core.excel.util.ExcelUtil; |
||||||
|
import org.springblade.core.mp.base.BaseServiceImpl; |
||||||
|
import org.springblade.core.secure.utils.AuthUtil; |
||||||
|
import org.springblade.core.tool.api.R; |
||||||
|
import cn.hutool.core.bean.BeanUtil; |
||||||
|
import org.springblade.core.tool.utils.DateUtil; |
||||||
|
import org.springblade.core.tool.utils.Func; |
||||||
|
import org.springblade.desk.basic.excel.UrgentPartExcel; |
||||||
|
import org.springblade.desk.basic.mapper.UrgentPartMapper; |
||||||
|
import org.springblade.desk.basic.pojo.entity.UrgentPart; |
||||||
|
import org.springblade.desk.basic.pojo.vo.UrgentPartVO; |
||||||
|
import org.springblade.desk.basic.service.IUrgentPartService; |
||||||
|
import org.springblade.system.cache.UserCache; |
||||||
|
import org.springblade.system.feign.IUserClient; |
||||||
|
import org.springblade.system.pojo.entity.User; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.*; |
||||||
|
import java.util.stream.Collectors; |
||||||
|
|
||||||
|
/** |
||||||
|
* [急件维护] 服务实现类 |
||||||
|
* |
||||||
|
* @author AI Assistant |
||||||
|
* @since 2026-05-22 |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
@Slf4j |
||||||
|
public class UrgentPartServiceImpl extends BaseServiceImpl<UrgentPartMapper, UrgentPart> implements IUrgentPartService { |
||||||
|
@Resource |
||||||
|
IUserClient userClient; |
||||||
|
|
||||||
|
@Override |
||||||
|
public IPage<UrgentPartVO> selectUrgentPartPage(IPage<UrgentPart> page, UrgentPartVO urgentPart) { |
||||||
|
// 查询前先检查并更新过期数据
|
||||||
|
checkAndUpdateExpiredRecords(); |
||||||
|
// 使用IService的page方法查询
|
||||||
|
LambdaQueryWrapper<UrgentPart> queryWrapper = new LambdaQueryWrapper<>(); |
||||||
|
queryWrapper |
||||||
|
.eq(UrgentPart::getIsDeleted, 0) |
||||||
|
.like(StrUtil.isNotEmpty(urgentPart.getPlanNo()), UrgentPart::getPlanNo, urgentPart.getPlanNo()) |
||||||
|
.like(StrUtil.isNotEmpty(urgentPart.getPartCode()), UrgentPart::getPartCode, urgentPart.getPartCode()) |
||||||
|
.like(StrUtil.isNotEmpty(urgentPart.getBatchNo()), UrgentPart::getBatchNo, urgentPart.getBatchNo()) |
||||||
|
.eq(Objects.nonNull(urgentPart.getStatus()), UrgentPart::getStatus, urgentPart.getStatus()) |
||||||
|
.eq(Objects.isNull(urgentPart.getStatus()),UrgentPart::getStatus, 0) |
||||||
|
.orderByDesc(UrgentPart::getUpdateTime); |
||||||
|
IPage<UrgentPart> iPage = page(page, queryWrapper); |
||||||
|
String userIdSet = iPage.getRecords().stream().map(s -> { |
||||||
|
ArrayList<String> userIds = new ArrayList<>(); |
||||||
|
if (Objects.nonNull(s.getCreateUser())) { |
||||||
|
userIds.add(s.getCreateUser().toString()); |
||||||
|
} |
||||||
|
if (Objects.nonNull(s.getUpdateUser())) { |
||||||
|
userIds.add(s.getUpdateUser().toString()); |
||||||
|
} |
||||||
|
if (Objects.nonNull(s.getMaintainMan())) { |
||||||
|
userIds.add(s.getMaintainMan().toString()); |
||||||
|
} |
||||||
|
return userIds; |
||||||
|
}).flatMap(Collection::stream).collect(Collectors.joining( ",")); |
||||||
|
List<User> users = userClient.userListByIds(userIdSet); |
||||||
|
Map<Long,String> userMap = users.stream().collect(Collectors.toMap(User::getId, User::getName)); |
||||||
|
|
||||||
|
List<UrgentPartVO> collect = iPage.getRecords().stream().map(s -> { |
||||||
|
UrgentPartVO urgentPartVO = BeanUtil.copyProperties(s, UrgentPartVO.class); |
||||||
|
// 设置状态名称
|
||||||
|
if (s.getStatus() != null) { |
||||||
|
urgentPartVO.setStatusName(UrgentPart.UrgentPartStatusEnum.getName(s.getStatus())); |
||||||
|
} |
||||||
|
// 设置用户名称
|
||||||
|
if (CollUtil.isNotEmpty(userMap)) { |
||||||
|
urgentPartVO.setMaintainManName(userMap.getOrDefault(s.getMaintainMan(), null)); |
||||||
|
urgentPartVO.setCreateUserName(userMap.getOrDefault(s.getCreateUser(), null)); |
||||||
|
urgentPartVO.setUpdateUserName(userMap.getOrDefault(s.getUpdateUser(), null)); |
||||||
|
} |
||||||
|
return urgentPartVO; |
||||||
|
}).collect(Collectors.toList()); |
||||||
|
|
||||||
|
IPage<UrgentPartVO> voPage = new Page<>(); |
||||||
|
|
||||||
|
BeanUtil.copyProperties(iPage, voPage, "records"); |
||||||
|
|
||||||
|
voPage.setRecords(collect); |
||||||
|
|
||||||
|
return voPage; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<UrgentPartExcel> exportUrgentPart(Wrapper<UrgentPart> queryWrapper) { |
||||||
|
List<UrgentPartExcel> urgentPartList = baseMapper.exportUrgentPart(queryWrapper); |
||||||
|
return urgentPartList; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void checkAndUpdateExpiredRecords() { |
||||||
|
update(Wrappers.lambdaUpdate(UrgentPart.class) |
||||||
|
.lt(UrgentPart::getExpireDate, new Date()) |
||||||
|
.set(UrgentPart::getStatus, 1) |
||||||
|
.set(UrgentPart::getMaintainTime,new Date())); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置VO的用户名称 |
||||||
|
* |
||||||
|
* @param vo 视图对象 |
||||||
|
*/ |
||||||
|
private void setVOValue(UrgentPartVO vo) { |
||||||
|
// 设置维护人名称
|
||||||
|
if (vo.getMaintainMan() != null) { |
||||||
|
User maintainMan = UserCache.getUser(vo.getMaintainMan()); |
||||||
|
if (maintainMan != null) { |
||||||
|
vo.setMaintainManName(maintainMan.getRealName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 设置创建人名称
|
||||||
|
if (vo.getCreateUser() != null) { |
||||||
|
User createUser = UserCache.getUser(vo.getCreateUser()); |
||||||
|
if (createUser != null) { |
||||||
|
vo.setCreateUserName(createUser.getRealName()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// 设置修改人名称
|
||||||
|
if (vo.getUpdateUser() != null) { |
||||||
|
User updateUser = UserCache.getUser(vo.getUpdateUser()); |
||||||
|
if (updateUser != null) { |
||||||
|
vo.setUpdateUserName(updateUser.getRealName()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor = Exception.class) |
||||||
|
public R importExcel(MultipartFile file) { |
||||||
|
try { |
||||||
|
List<UrgentPartExcel> excelList = ExcelUtil.read(file, UrgentPartExcel.class); |
||||||
|
if (excelList == null || excelList.isEmpty()) { |
||||||
|
return R.fail("导入数据不能为空"); |
||||||
|
} |
||||||
|
|
||||||
|
Long userId = AuthUtil.getUserId(); |
||||||
|
Date now = new Date(); |
||||||
|
List<UrgentPart> urgentPartList = excelList.stream().map(excel -> { |
||||||
|
// 校验必填字段
|
||||||
|
if (StrUtil.isEmpty(excel.getPlanNo()) || StrUtil.isEmpty(excel.getPartCode())) { |
||||||
|
throw new RuntimeException("计划单号和零件号为必填项"); |
||||||
|
} |
||||||
|
UrgentPart urgentPart = BeanUtil.copyProperties(excel, UrgentPart.class); |
||||||
|
if (BeanUtil.isEmpty(urgentPart)){ |
||||||
|
return null; |
||||||
|
} |
||||||
|
// 如果到期日期为空,默认为当前时间+60天
|
||||||
|
if (Objects.isNull(urgentPart.getExpireDate())) { |
||||||
|
urgentPart.setExpireDate(DateUtil.plusDays(now, 60)); |
||||||
|
} |
||||||
|
// 根据是否超过有效日期判断状态:未过期为生效(0),已过期为作废(1)
|
||||||
|
if (StrUtil.isNotEmpty(excel.getStatus())) { |
||||||
|
urgentPart.setStatus(UrgentPart.UrgentPartStatusEnum.of(excel.getStatus()).getCode()); |
||||||
|
} |
||||||
|
|
||||||
|
if (urgentPart.getStatus() == null) { |
||||||
|
urgentPart.setStatus(urgentPart.getExpireDate().after(now) ? 0 : 1); |
||||||
|
} |
||||||
|
urgentPart.setMaintainTime(now); |
||||||
|
urgentPart.setCreateUser(userId); |
||||||
|
urgentPart.setCreateTime(now); |
||||||
|
urgentPart.setUpdateUser(userId); |
||||||
|
urgentPart.setUpdateTime(now); |
||||||
|
return urgentPart; |
||||||
|
}).filter(BeanUtil::isNotEmpty) |
||||||
|
.collect(Collectors.toList()); |
||||||
|
|
||||||
|
boolean result = saveBatch(urgentPartList); |
||||||
|
|
||||||
|
if (result) { |
||||||
|
return R.success("导入成功,共导入 " + urgentPartList.size() + " 条数据"); |
||||||
|
} else { |
||||||
|
return R.fail("导入失败"); |
||||||
|
} |
||||||
|
|
||||||
|
} catch (Exception e) { |
||||||
|
log.error("导入Excel失败", e); |
||||||
|
return R.fail("导入失败:" + e.getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
@Transactional(rollbackFor = Exception.class) |
||||||
|
public R voidRecords(List<Long> ids) { |
||||||
|
if (CollUtil.isEmpty(ids)) { |
||||||
|
return R.fail("请选择要作废的记录"); |
||||||
|
} |
||||||
|
|
||||||
|
Long userId = AuthUtil.getUserId(); |
||||||
|
Date now = new Date(); |
||||||
|
|
||||||
|
// 批量更新状态为作废
|
||||||
|
LambdaUpdateWrapper<UrgentPart> queryWrapper = Wrappers.lambdaUpdate(UrgentPart.class) |
||||||
|
.in(UrgentPart::getId, ids) |
||||||
|
.set(UrgentPart::getStatus,1) |
||||||
|
.set(UrgentPart::getMaintainMan,userId) |
||||||
|
.set(UrgentPart::getMaintainTime,now); |
||||||
|
boolean result = update(queryWrapper); |
||||||
|
if (result) { |
||||||
|
log.info("作废急件记录成功,IDs: {}", ids); |
||||||
|
return R.success("作废成功"); |
||||||
|
} else { |
||||||
|
return R.fail("作废失败"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Binary file not shown.
Loading…
Reference in new issue