package com.zcloud.modules.custormerInfo.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zcloud.common.utils.PageUtils;
 import com.zcloud.modules.custormerInfo.dao.SysDeveloperLogDao;
 import com.zcloud.modules.custormerInfo.entity.SysDeveloperLogEntity;
 import com.zcloud.modules.custormerInfo.service.SysDeveloperLogService;
 import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

 import java.util.List;
 import java.util.Map;

/**
 * @Author lizenan
 * @Desc 系统日志(SysDeveloperLog)表服务实现类
 * @Date 2024-04-11 11:53:29
 */
@Service("sysDeveloperLogService")
public class SysDeveloperLogServiceImpl extends ServiceImpl<SysDeveloperLogDao, SysDeveloperLogEntity> implements SysDeveloperLogService {
 
    @Override
	public SysDeveloperLogEntity queryByFlexibleParams(String paramName, Object paramValue) {
		QueryWrapper<SysDeveloperLogEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

		return baseMapper.selectOne(queryWrapper);
	}

	@Override
	public List<SysDeveloperLogEntity> queryListByFlexibleParams(String paramName, Object paramValue) {
		QueryWrapper<SysDeveloperLogEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq(paramName, paramValue); // 根据传入的参数名和参数值动态构建查询条件

		return baseMapper.selectList(queryWrapper);
	}
	
    @Override
    public List<String> listYear() {
        return baseMapper.listYear();
    }

    @Override
    public PageUtils listPage(Map<String, Object> params) {
        Page<Map<String,Object>> page = new Page<>(Integer.parseInt(params.get("curPage").toString()),Integer.parseInt(params.get("limit").toString()));
        params.put("isDelete",0);
        //申请时间
        if(params.get("createDates")!=null){
            List<String> createDates = (List<String>) params.get("createDates");
            params.put("createDateStart",createDates.get(0));
            params.put("createDateEnd",createDates.get(1));
        }
        //动态拼接年
        params.put("tableName","sys_developer_log_"+params.get("year"));
        IPage<SysDeveloperLogEntity> ipage = baseMapper.listPage(page,params);
        return new PageUtils(ipage);
    }

 
   @Override
	public void delete(String id,String userId){
		UpdateWrapper<SysDeveloperLogEntity> updateWrapper = new UpdateWrapper<>();
		updateWrapper.eq("id",id);

		SysDeveloperLogEntity sysDeveloperLog = new SysDeveloperLogEntity();
//		sysDeveloperLog.setOperator(userId);
//		sysDeveloperLog.setIsDelete(1);

		this.update(sysDeveloperLog, updateWrapper);
	}

}
