package com.mosty.yjzl.service.Impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.base.model.dto.yjzl.TbZdxlFgmrpzUpdateDTO;
import com.mosty.base.model.entity.yjzl.zddw.TbZdxlFgmrpz;
import com.mosty.yjzl.mapper.TbZdxlFgmrpzMapper;
import com.mosty.yjzl.service.TbZdxlFgmrpzService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
 * @author zhangzhao
 * @description 指导巡逻方格默认配置表Service实现类
 * @modifier zhangzhao
 * @modifiedTime 2025/09/05 19:02
 * @since 2025/09/05 19:02
 */
@Service
@AllArgsConstructor
public class TbZdxlFgmrpzServiceImpl extends ServiceImpl<TbZdxlFgmrpzMapper, TbZdxlFgmrpz> implements TbZdxlFgmrpzService {

    @Override
    public TbZdxlFgmrpz selectDefault() {
        return this.baseMapper.selectOne(new QueryWrapper<>());
    }

    @Override
    public String updateEntity(TbZdxlFgmrpzUpdateDTO dto) {
        //复制参数至实体
        TbZdxlFgmrpz entity = BeanUtil.copyProperties(dto, TbZdxlFgmrpz.class);

        //如果参数为空，则设置默认值为0
        if(ObjectUtils.isEmpty(entity.getPcCl())){
            entity.setPcCl(0);
        }
        if(ObjectUtils.isEmpty(entity.getPcRy())){
            entity.setPcRy(0);
        }
        if(ObjectUtils.isEmpty(entity.getXlSc())){
            entity.setXlSc(0.0);
        }
        if(ObjectUtils.isEmpty(entity.getXlLc())){
            entity.setXlLc(0.0);
        }

        //修改实体
        int resultInt = this.baseMapper.updateById(entity);
        if(resultInt > 0){
            //返回主键
            return entity.getId();
        }
        return null;
    }

}
