lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamMaintenanceStandardController.java
@@ -168,8 +168,10 @@ @ApiOperation(value = "保养标准-查询标准列表-前端展示该用户拥有的标准", notes = "保养标准-查询标准列表-前端展示该用户拥有的标准") @GetMapping(value = "/listByUser") public Result<?> listByUser(@RequestParam(name = "keyword", required = false) String keyword, @RequestParam(name = "equipmentId", required = false) String equipmentId, @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize, @RequestParam(name = "maintenanceCategory", required = false) String maintenanceCategory) { List<EamMaintenanceStandard> list = eamMaintenanceStandardService.queryListBykeywordAndCategory(keyword, maintenanceCategory); List<EamMaintenanceStandard> list = eamMaintenanceStandardService.queryListByKeywordAndCategory(keyword, equipmentId, pageSize, maintenanceCategory); return Result.OK(list); } lxzn-module-eam/src/main/java/org/jeecg/modules/eam/entity/EamMaintenanceStandard.java
@@ -1,6 +1,7 @@ package org.jeecg.modules.eam.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; @@ -14,81 +15,125 @@ import java.io.Serializable; import java.util.Date; /** * @Description: 保养标准 * @Author: jeecg-boot * @Date: 2025-03-26 * @Date: 2025-03-26 * @Version: V1.0 */ @Data @TableName("eam_maintenance_standard") @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) @ApiModel(value="eam_maintenance_standard对象", description="保养标准") @ApiModel(value = "eam_maintenance_standard对象", description = "保养标准") public class EamMaintenanceStandard implements Serializable { /**主键*/ @TableId(type = IdType.ASSIGN_ID) /** * 主键 */ @TableId(type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键") private String id; /**创建人*/ private String id; /** * 创建人 */ @ApiModelProperty(value = "创建人") private String createBy; /**创建时间*/ private String createBy; /** * 创建时间 */ @ApiModelProperty(value = "创建时间") private Date createTime; /**更新人*/ private Date createTime; /** * 更新人 */ @ApiModelProperty(value = "更新人") private String updateBy; /**更新时间*/ private String updateBy; /** * 更新时间 */ @ApiModelProperty(value = "更新时间") private Date updateTime; /**删除标记*/ private Date updateTime; /** * 删除标记 */ @ApiModelProperty(value = "删除标记") private Integer delFlag; /**标准编码*/ private Integer delFlag; /** * 标准编码 */ @ApiModelProperty(value = "标准编码") private String standardCode; /**标准名称*/ private String standardCode; /** * 标准名称 */ @ApiModelProperty(value = "标准名称") private String standardName; /**保养周期;单位:天*/ private String standardName; /** * 保养周期;单位:天 */ @ApiModelProperty(value = "保养周期;单位:天") private Integer maintenancePeriod; /**初始日期 从哪一天开始计算下次保养日期*/ @ApiModelProperty(value = "初始日期") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date initialDate; /**保养分类*/ private Integer maintenancePeriod; /** * 初始日期 从哪一天开始计算下次保养日期 */ @ApiModelProperty(value = "初始日期") @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date initialDate; /** * 保养分类 */ @ApiModelProperty(value = "保养分类") @Dict(dicCode = "maintenance_category") private String maintenanceCategory; /**设备编号*/ @Dict(dicCode = "maintenance_category") private String maintenanceCategory; /** * 设备编号 */ @ApiModelProperty(value = "设备编号") @Dict(dicCode = "eam_equipment, equipment_code, id") private String equipmentId; /**标准状态*/ @Dict(dicCode = "eam_equipment, equipment_code, id") private String equipmentId; /** * 标准状态 */ @ApiModelProperty(value = "标准状态") @Dict(dicCode = "maintenance_standard_status") private String standardStatus; /**标准版本*/ @Dict(dicCode = "maintenance_standard_status") private String standardStatus; /** * 标准版本 */ @ApiModelProperty(value = "标准版本") private Integer standardVersion; /**文件编号*/ @ApiModelProperty(value = "文件编号") private String fileCode; /**参考文件*/ @ApiModelProperty(value = "参考文件") private String referenceFile; /** * 最新生成工单时间 * 下一次生成时间为此时间 + 保养周期 */ @ApiModelProperty(value = "最新生成工单时间") private Date lastGenerateTime; private Integer standardVersion; /** * 文件编号 */ @ApiModelProperty(value = "文件编号") private String fileCode; /** * 参考文件 */ @ApiModelProperty(value = "参考文件") private String referenceFile; /** * 最新生成工单时间 * 下一次生成时间为此时间 + 保养周期 */ @ApiModelProperty(value = "最新生成工单时间") private Date lastGenerateTime; /**设备编号*/ private transient String equipmentText; //列表展示 @TableField(exist = false) private String equipmentCode; @TableField(exist = false) private String equipmentName; /** * 设备编号拼接 */ @TableField(exist = false) private String equipmentText; public String getEquipmentText() { return equipmentCode + "[" + equipmentName + "]"; } } lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/EamMaintenanceStandardMapper.java
@@ -1,6 +1,9 @@ package org.jeecg.modules.eam.mapper; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Constants; import org.apache.ibatis.annotations.Param; import org.jeecg.modules.eam.entity.EamMaintenanceStandard; @@ -9,18 +12,16 @@ /** * @Description: 保养标准 * @Author: jeecg-boot * @Date: 2025-03-26 * @Date: 2025-03-26 * @Version: V1.0 */ public interface EamMaintenanceStandardMapper extends BaseMapper<EamMaintenanceStandard> { /** * 查询标准列表-前端展示该用户拥有的标准 * @param userId 用户 * @param keyword 设备编号 * @param maintenanceCategory 保养类型 * 分页查询 * @param page * @param queryWrapper * @return */ List<EamMaintenanceStandard> queryListBykeywordAndCategory(@Param("userId")String userId ,@Param("keyword") String keyword, @Param("maintenanceCategory") String maintenanceCategory); IPage<EamMaintenanceStandard> queryPageList(IPage<EamMaintenanceStandard> page, @Param(Constants.WRAPPER) Wrapper<EamMaintenanceStandard> queryWrapper); } lxzn-module-eam/src/main/java/org/jeecg/modules/eam/mapper/xml/EamMaintenanceStandardMapper.xml
@@ -1,34 +1,11 @@ <?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.jeecg.modules.eam.mapper.EamMaintenanceStandardMapper"> <select id="queryListBykeywordAndCategory" resultType="org.jeecg.modules.eam.entity.EamMaintenanceStandard"> SELECT e.equipment_code+ '[' + e.equipment_name+ ']' AS 'equipmentText', m.id, m.standard_code, m.standard_name, m.maintenance_period, m.equipment_id FROM eam_maintenance_standard m -- 先过滤设备表,减少 JOIN 量 INNER JOIN ( SELECT id, eam_equipment.equipment_code as equipment_code, eam_equipment.equipment_name as equipment_name, org_id FROM eam_equipment WHERE del_flag = 0 AND ( equipment_code LIKE CONCAT ( #{ keyword }, '%' ) -- 右模糊利用索引 OR equipment_name LIKE CONCAT ( #{ keyword }, '%' ) ) ) e ON m.equipment_id = e.id WHERE m.del_flag = 0 AND m.standard_status= 'NORMAL' AND m.maintenance_category = #{maintenanceCategory} AND EXISTS ( SELECT 1 FROM mdc_user_production t WHERE t.user_id = #{ userId } AND t.pro_id = e.org_id ); <select id="queryPageList" resultType="org.jeecg.modules.eam.entity.EamMaintenanceStandard"> select ems.*, e.equipment_code, e.equipment_name from eam_maintenance_standard ems inner join eam_equipment e on ems.equipment_id = e.id ${ew.customSqlSegment} </select> </mapper> lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamMaintenanceStandardService.java
@@ -52,9 +52,9 @@ /** * 查询标准列表-前端展示该用户拥有的标准 * @param keyword 设备编号 * @param keyword 关键词 * @param maintenanceCategory 保养类型 * @return */ List<EamMaintenanceStandard> queryListBykeywordAndCategory( String keyword, String maintenanceCategory); List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory); } lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
@@ -2,6 +2,7 @@ import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -47,8 +48,8 @@ @Override public IPage<EamMaintenanceStandard> queryPageList(Page<EamMaintenanceStandard> page, EamMaintenanceStandard eamMaintenanceStandard) { LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0); QueryWrapper<EamMaintenanceStandard> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("ems.del_flag", CommonConstant.DEL_FLAG_0); //用户数据权限 LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); if (sysUser == null) { @@ -57,41 +58,42 @@ if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { //选择了设备,根据设备id过滤设备 List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); StringBuilder sqlSb = new StringBuilder("select 1 from eam_equipment t where t.id = equipment_id and t.equipment_code in ("); equipArr.forEach(equipmentCode -> { sqlSb.append("'").append(equipmentCode).append("',"); }); sqlSb.append(")"); String sql = sqlSb.toString().replaceAll(",\\)", ")"); queryWrapper.exists(sql); queryWrapper.in("e.equipment_code", equipArr); } else { //没有选择设备,根据车间过滤设备 queryWrapper.exists("select 1 from eam_equipment e where exists (select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id) and e.id = equipment_id", sysUser.getId()); } queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId()); } if(eamMaintenanceStandard != null) { //编码 模糊查询 if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) { queryWrapper.like(EamMaintenanceStandard::getStandardCode, eamMaintenanceStandard.getStandardCode()); queryWrapper.like("ems.standard_code", eamMaintenanceStandard.getStandardCode()); } //名称 模糊查询 if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) { queryWrapper.like(EamMaintenanceStandard::getStandardName, eamMaintenanceStandard.getStandardName()); queryWrapper.like("ems.standard_name", eamMaintenanceStandard.getStandardCode()); } //设备 if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) { queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, eamMaintenanceStandard.getEquipmentId()); queryWrapper.eq("ems.equipment_id", eamMaintenanceStandard.getEquipmentId()); } //保养分类 if(StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) { queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, eamMaintenanceStandard.getMaintenanceCategory()); queryWrapper.eq("ems.maintenance_category", eamMaintenanceStandard.getMaintenanceCategory()); } //保养分类 if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) { queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, eamMaintenanceStandard.getStandardStatus()); queryWrapper.eq("ems.standard_status", eamMaintenanceStandard.getStandardStatus()); } //设备编码 if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentCode())) { queryWrapper.like("e.equipment_code", eamMaintenanceStandard.getEquipmentCode()); } //设备名称 if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentName())) { queryWrapper.like("e.equipment_name", eamMaintenanceStandard.getEquipmentName()); } } queryWrapper.orderByDesc(EamMaintenanceStandard::getCreateTime); return eamMaintenanceStandardMapper.selectPage(page, queryWrapper); queryWrapper.orderByDesc("ems.create_time"); return eamMaintenanceStandardMapper.queryPageList(page, queryWrapper); } @Override @@ -269,8 +271,13 @@ * @return */ @Override public List<EamMaintenanceStandard> queryListBykeywordAndCategory(String keyword, String maintenanceCategory){ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); return eamMaintenanceStandardMapper.queryListBykeywordAndCategory(loginUser.getId(),keyword, maintenanceCategory); public List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory){ Page<EamMaintenanceStandard> page = new Page<EamMaintenanceStandard>(1, pageSize); EamMaintenanceStandard query = new EamMaintenanceStandard(); query.setEquipmentId(equipmentId); query.setEquipmentCode(keyword); query.setEquipmentName(keyword); IPage<EamMaintenanceStandard> pageData = this.queryPageList(page, query); return pageData.getRecords(); } }