package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.dao.AttProjectInsuranceRecordDao; import cn.com.goldenwater.dcproj.exception.ServiceException; import cn.com.goldenwater.dcproj.model.AttProjectInsuranceRecord; import cn.com.goldenwater.dcproj.param.AttProjectInsuranceRecordParam; import cn.com.goldenwater.dcproj.service.AttProjectInsuranceRecordService; import cn.com.goldenwater.dcproj.utils.DateUtils; import cn.com.goldenwater.id.util.UuidUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; /** * @author lql * @date 2026-4-21 */ @Service @Transactional public class AttProjectInsuranceRecordServiceImpl extends AbstractCrudService implements AttProjectInsuranceRecordService { @Autowired private AttProjectInsuranceRecordDao attProjectInsuranceRecordDao; public AttProjectInsuranceRecordServiceImpl(AttProjectInsuranceRecordDao attProjectInsuranceRecordDao) { super(attProjectInsuranceRecordDao); this.attProjectInsuranceRecordDao = attProjectInsuranceRecordDao; } @Override public int insert(AttProjectInsuranceRecord attProjectInsuranceRecord) { if (attProjectInsuranceRecord.getProjectId() == null) { throw new ServiceException("请选择项目编号"); } if (attProjectInsuranceRecord.getInsuranceDate() == null) { throw new ServiceException("请选择保险时间"); } String year = DateUtils.Date2Str(attProjectInsuranceRecord.getInsuranceDate(), "yyyy"); AttProjectInsuranceRecord record = getByYear(attProjectInsuranceRecord.getProjectId(), year); if (record != null) { attProjectInsuranceRecord.setId(record.getId()); return update(attProjectInsuranceRecord); } String uuid = UuidUtil.uuid(); attProjectInsuranceRecord.setId(uuid); attProjectInsuranceRecord.setDataStat("0"); attProjectInsuranceRecord.setState("0"); attProjectInsuranceRecord.setYear(year); attProjectInsuranceRecord.setIntm(new Date()); attProjectInsuranceRecord.setUptm(new Date()); return this.attProjectInsuranceRecordDao.insert(attProjectInsuranceRecord); } @Override public int update(AttProjectInsuranceRecord attProjectInsuranceRecord) { if (attProjectInsuranceRecord.getInsuranceDate() != null){ String year = DateUtils.Date2Str(attProjectInsuranceRecord.getInsuranceDate(), "yyyy"); attProjectInsuranceRecord.setYear(year); } attProjectInsuranceRecord.setUptm(new Date()); return this.attProjectInsuranceRecordDao.update(attProjectInsuranceRecord); } @Override public int delete(String id) { // 删除 return this.attProjectInsuranceRecordDao.delete(id); } @Override public AttProjectInsuranceRecord getByYear(String projectId, String year) { AttProjectInsuranceRecordParam param = new AttProjectInsuranceRecordParam(); param.setProjectId(projectId); param.setYear(year); return this.attProjectInsuranceRecordDao.getBy(param); } }