/*
 *      Copyright (c) 2018-2028, Chill Zhuang 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 dreamlu.net 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: Chill 庄骞 (smallchill@163.com)
 */
package org.security.trans.securityCommandCenter.service.impl;

import lombok.AllArgsConstructor;
import org.security.common.Constant;
import org.security.trans.common.service.IFileService;
import org.security.trans.securityCommandCenter.dto.SccCheckLinesDTO;
import org.security.trans.securityCommandCenter.entity.SccCheckLines;
import org.security.trans.securityCommandCenter.vo.SccCheckLinesVO;
import org.security.trans.securityCommandCenter.mapper.SccCheckLinesMapper;
import org.security.trans.securityCommandCenter.service.ISccCheckLinesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 安保指挥中心-营业网点检查和自助银行检查记录明细 服务实现类
 *
 * @author BladeX
 * @since 2022-07-06
 */
@Service
@AllArgsConstructor
public class SccCheckLinesServiceImpl extends ServiceImpl<SccCheckLinesMapper, SccCheckLines> implements ISccCheckLinesService {

	private final IFileService fileService;

	@Override
	public SccCheckLinesVO getData(String id) {
		//获取明细详情
		SccCheckLines checkLines = this.getById(id);
		SccCheckLinesVO sccCheckLinesVO = Func.copy(checkLines, SccCheckLinesVO.class);
		//获取相关附件信息
		assert sccCheckLinesVO != null;
		sccCheckLinesVO.setRelevantAttachments(fileService.getAttachments(id,null));
		return sccCheckLinesVO;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean updateData(SccCheckLinesDTO sccCheckLinesDTO) {
		//保存提报记录信息
		SccCheckLines sccCheckLines = Func.copy(sccCheckLinesDTO, SccCheckLines.class);
		//根据用户操作设置明细状态：若用户以暂存提交则状态不变，若用户以提报形式提交数据则状态要变为已整改
		assert sccCheckLines != null;
		sccCheckLines.setCheckStatus(Constant.SUBMIT_TYPE_ZERO.equals(sccCheckLinesDTO.getSubmitType())?Constant.CHECK_STATUS_ZERO:Constant.CHECK_STATUS_TWO);
		this.saveOrUpdate(sccCheckLines);
		//保存提报记录的相关附件信息
		fileService.saveAttachments(sccCheckLinesDTO.getRelevantAttachments(),sccCheckLines.getId());
		return true;
	}

	@Override
	public List<SccCheckLinesVO> selectDetailPage(IPage<SccCheckLinesVO> page, SccCheckLinesDTO sccCheckLinesDTO) {
		return baseMapper.selectDetailPage(page,sccCheckLinesDTO);
	}
}
