/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yifu4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
package com.yifu.cloud.plus.v1.yifu.archives.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.archives.entity.TEmpProfessionalQualification;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TAttaInfoMapper;
import com.yifu.cloud.plus.v1.yifu.archives.mapper.TEmpProfessionalQualificationMapper;
import com.yifu.cloud.plus.v1.yifu.archives.service.TEmpProfessionalQualificationService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 员工职业资格信息表
 *
 * @author fxj
 * @date 2022-06-18 09:39:46
 */
@RequiredArgsConstructor
@Service
public class TEmpProfessionalQualificationServiceImpl extends ServiceImpl<TEmpProfessionalQualificationMapper, TEmpProfessionalQualification> implements TEmpProfessionalQualificationService {

	private final TAttaInfoMapper attaInfoMapper;

	@Override
	public R<Boolean> saveDiy(TEmpProfessionalQualification qualification) {
		int res  = baseMapper.insert(qualification);
		if (res <= CommonConstants.ZERO_INT){
			return R.failed();
		}
		//更新附件信息
		List<String> ids;
		if (Common.isNotNull(qualification.getAttaIds())){
			ids = Common.initStrToList(qualification.getAttaIds(), CommonConstants.COMMA_STRING);
			attaInfoMapper.updateDomainId(qualification.getId(),ids);
		}
		return R.ok();
	}
}
