# EngineeringRequestIssueServiceImpl.java

    package cloud.wconnect.frontoffice.service.engineeringrequest.impl;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.frontoffice.entity.engineeringrequest.EngineeringRequestIssue;
    import cloud.wconnect.frontoffice.mapper.engineeringrequest.EngineeringRequestIssueMapper;
    import cloud.wconnect.frontoffice.pojo.dto.engineeringrequest.IssueDTO;
    import cloud.wconnect.frontoffice.pojo.dto.engineeringrequest.SelectOptionQuery;
    import cloud.wconnect.frontoffice.service.engineeringrequest.IEngineeringRequestIssueService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import jakarta.annotation.Nullable;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.stereotype.Service;

    import java.util.List;
    import java.util.Objects;

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-05-10
     */
    @Service
    @DS("logbook")
    public class EngineeringRequestIssueServiceImpl extends ServiceImpl<EngineeringRequestIssueMapper, EngineeringRequestIssue> implements IEngineeringRequestIssueService {

        /**
         * 校验存在
         *
         * @param id issue id
         * @return issue
         * @author yyt
         * @date 2023/5/11
         */
        @Override
        public EngineeringRequestIssue checkExist(Integer id) {
            EngineeringRequestIssue issue = getById(id);
            if (Objects.isNull(issue)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the issue is not found;id:" + id);
            }
            return issue;
        }

        /**
         * 获取 issue 列表
         *
         * @param propertyId 资产
         * @return issue 列表
         * @author yyt
         * @date 2023/5/12
         */
        @Override
        public List<EngineeringRequestIssue> listByPropertyId(Integer propertyId) {
            return list(new QueryWrapper<EngineeringRequestIssue>().lambda().eq(EngineeringRequestIssue::getPropertyId, propertyId));
        }

        /**
         * 校验存在
         *
         * @param propertyId 资产
         * @param name       名称
         * @param id         排除自身
         * @author yyt
         * @date 2023/5/12
         */
        @Override
        public void checkExist(Integer propertyId, String name, @Nullable Integer id) {
            EngineeringRequestIssue issue = getOne(new QueryWrapper<EngineeringRequestIssue>().lambda()
                    .eq(EngineeringRequestIssue::getPropertyId, propertyId)
                    .eq(EngineeringRequestIssue::getName, name)
                    .ne(Objects.nonNull(id), EngineeringRequestIssue::getId, id)
                    .select(EngineeringRequestIssue::getId));
            if (Objects.nonNull(issue)) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_EXISTED,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "the issue already exist;propertyId:" + propertyId + ",name:" + name);
            }
        }

        /**
         * 删除
         *
         * @param issue issue
         * @author yyt
         * @date 2023/5/12
         */
        @Override
        public void delete(EngineeringRequestIssue issue) {
            removeById(issue.getId());
        }

        /**
         * 查询 issue
         *
         * @param query 查询条件
         * @return issue
         * @author yyt
         * @date 2024/2/8
         **/
        @Override
        public Page<EngineeringRequestIssue> page(SelectOptionQuery query) {
            return baseMapper.selectPage(new Page<>(query.getPage(), query.getSize()), query);
        }

        /**
         * 查询 issue
         *
         * @param propertyId 资产 id
         * @param query      查询条件
         * @return issue
         * @author yyt
         * @date 2026/1/19
         **/
        @Override
        public List<EngineeringRequestIssue> listByCondition(Integer propertyId, SelectOptionQuery query) {
            return list(new QueryWrapper<EngineeringRequestIssue>().lambda()
                    .eq(EngineeringRequestIssue::getPropertyId, propertyId)
                    .eq(StringUtils.isNotEmpty(query.getName()), EngineeringRequestIssue::getName, query.getName()));
        }

        /**
         * 保存 issue
         *
         * @param propertyId 资产 id
         * @param issueDTO   issue
         * @param userId     操作人
         * @author yyt
         * @date 2026/1/19
         */
        @Override
        public void save(Integer propertyId, IssueDTO issueDTO, int userId) {
            save(new EngineeringRequestIssue().setPropertyId(propertyId)
                    .setName(issueDTO.getName())
                    .setUpdateBy(userId)
                    .setUpdateTime(DateTimeUtils.nowTimestamp()));
        }

        /**
         * 修改 issue
         *
         * @param id       issue id
         * @param issueDTO issue
         * @param userId   操作人
         * @author yyt
         * @date 2026/1/19
         */
        @Override
        public void update(int id, IssueDTO issueDTO, int userId) {
            updateById(new EngineeringRequestIssue().setId(id)
                    .setName(issueDTO.getName())
                    .setUpdateBy(userId)
                    .setUpdateTime(DateTimeUtils.nowTimestamp()));
        }

    }