package com.gkhy.exam.system.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gkhy.exam.common.api.CommonPage; import com.gkhy.exam.common.api.CommonResult; import com.gkhy.exam.common.exception.ApiException; import com.gkhy.exam.common.utils.PageUtils; import com.gkhy.exam.common.utils.SecurityUtils; import com.gkhy.exam.system.domain.CustomerRecord; import com.gkhy.exam.system.domain.CustomerRecordNeed; import com.gkhy.exam.system.mapper.CustomerRecordMapper; import com.gkhy.exam.system.mapper.CustomerRecordNeedMapper; import com.gkhy.exam.system.service.CustomerRecordService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.List; @Service public class CustomerRecordServiceImpl extends ServiceImpl implements CustomerRecordService { @Autowired private CustomerRecordMapper customerRecordMapper; @Autowired private CustomerRecordNeedMapper customerRecordNeedMapper; @Override public CommonPage selectCustomerRecordList(CustomerRecord customerRecord) { if (!SecurityUtils.adminUser()){ if (customerRecord.getCompanyId()==null){ throw new ApiException("非管理员操作,查询条件不可为空"); } } PageUtils.startPage(); List customerRecords = customerRecordMapper.selectRecordList(customerRecord); for (CustomerRecord record : customerRecords) { List customerRecordNeeds = customerRecordNeedMapper.selectByRecordId(record.getId()); record.setCustomerRecordNeeds(customerRecordNeeds); } return CommonPage.restPage(customerRecords); } @Override @Transactional public CommonResult insertCustomerRecord(CustomerRecord customerRecord) { customerRecord.setCreateBy(SecurityUtils.getUsername()); customerRecord.setCreateTime(LocalDateTime.now()); int insert = customerRecordMapper.insert(customerRecord); if (insert>0){ List customerRecordNeeds = customerRecord.getCustomerRecordNeeds(); for (CustomerRecordNeed customerRecordNeed : customerRecordNeeds) { customerRecordNeed.setRecordId(customerRecord.getId()); } Integer i = customerRecordNeedMapper.insertNeeds(customerRecordNeeds); if (i>0){ return CommonResult.success(); }else { return CommonResult.failed(); } } return CommonResult.failed(); } @Override @Transactional public CommonResult updateCustomerRecord(CustomerRecord customerRecord) { customerRecord.setUpdateBy(SecurityUtils.getUsername()); customerRecord.setUpdateTime(LocalDateTime.now()); int insert = customerRecordMapper.updateById(customerRecord); if (insert>0){ customerRecordNeedMapper.deleteByRecordId(customerRecord.getId()); Integer i = customerRecordNeedMapper.insertNeeds(customerRecord.getCustomerRecordNeeds()); if (i>0){ return CommonResult.success(); }else { return CommonResult.failed(); } } return CommonResult.failed(); } @Override public CommonResult deletedCustomerRecord(Integer recordId) { CustomerRecord customerRecord = new CustomerRecord(); customerRecord.setId(recordId); customerRecord.setUpdateBy(SecurityUtils.getUsername()); customerRecord.setUpdateTime(LocalDateTime.now()); customerRecord.setDelFlag(2); int i = customerRecordMapper.updateById(customerRecord); if (i>0){ return CommonResult.success(); }else { return CommonResult.failed(); } } }