package com.goafanti.techproject.service.impl; import com.goafanti.common.dao.*; import com.goafanti.common.model.*; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.techproject.bo.TaskDetailsBo; import com.goafanti.techproject.service.TaskDetailsService; import org.apache.commons.beanutils.BeanUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 项目申报详情(TaskDetails)表服务实现类 * * @author makejava * @since 2024-12-26 17:11:50 */ @Service("taskDetailsService") public class TaskDetailsServiceImpl extends BaseMybatisDao implements TaskDetailsService { @Resource private TaskDetailsMapper taskDetailsMapper; @Resource private TaskDetailsExtendMapper taskDetailsExtendMapper; @Resource private TaskDetailsSupplementMapper taskDetailsSupplementMapper; @Resource private TOrderNewMapper tOrderNewMapper; @Resource private TaskAnnualReportMapper taskAnnualReportMapper; @Override public Pagination list(TaskDetails taskDetails, Integer pageNo, Integer pageSize) { Map params = new HashMap<>(); params.put("in", taskDetails); return (Pagination) findPage("findTaskDetailsList", "findTaskDetailsCount", params, pageNo, pageSize); } /** * 通过ID查询单条数据 * * @param id 主键 * @return 实例对象 */ @Override public TaskDetailsBo queryById(Integer id) { TaskDetailsBo taskDetailsBo = new TaskDetailsBo(); TaskDetails taskDetails = this.taskDetailsMapper.selectById(id); TaskDetailsExtend taskDetailsExtend = taskDetailsExtendMapper.selectById(id); TaskDetailsSupplement taskDetailsSupplement = taskDetailsSupplementMapper.selectById(id); if (taskDetails != null){ try { BeanUtils.copyProperties(taskDetailsBo,taskDetails ); BeanUtils.copyProperties( taskDetailsBo,taskDetailsExtend); BeanUtils.copyProperties( taskDetailsBo,taskDetailsSupplement); } catch (Exception e) { e.printStackTrace(); } } return taskDetailsBo; } /** * 新增数据 * * @param taskDetails 实例对象 * @return 实例对象 */ @Override public TaskDetailsBo insert(TaskDetails taskDetails, TaskDetailsExtend taskDetailsExtend, TaskDetailsSupplement taskDetailsSupp) { TOrderNew tOrderNew =tOrderNewMapper.selectByTid(taskDetails.getTid()); taskDetails.setAid(TokenManager.getAdminId()); taskDetails.setUid(tOrderNew.getBuyerId()); Date date = new Date(); taskDetails.setCreateTime(date); taskDetails.setUpdateTime(date); //数据计算 countTaskDetails(taskDetails); this.taskDetailsMapper.insert(taskDetails); if (taskDetails.getId() != null) { taskDetailsExtend.setId(taskDetails.getId()); taskDetailsSupp.setId(taskDetails.getId()); taskDetailsExtendMapper.insert(taskDetailsExtend); taskDetailsSupplementMapper.insert(taskDetailsSupp); } TaskDetailsBo taskDetailsBo = new TaskDetailsBo(); try { BeanUtils.copyProperties(taskDetailsBo,taskDetails ); BeanUtils.copyProperties( taskDetailsBo,taskDetailsExtend); BeanUtils.copyProperties( taskDetailsBo,taskDetailsSupp); } catch (Exception e) { e.printStackTrace(); } return taskDetailsBo; } private void countTaskDetails(TaskDetails taskDetails) { //计算人员占比 if (taskDetails.getWorkersNumber()!=null|| taskDetails.getTechnologyNumber()!=null){ BigDecimal wn = BigDecimal.valueOf(taskDetails.getWorkersNumber()); BigDecimal tn = BigDecimal.valueOf(taskDetails.getTechnologyNumber()); BigDecimal res = tn.divide(wn,4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); taskDetails.setWorkersRate(res.doubleValue()); } //计算年度研发占比 //计算三年度的研发占比 if(taskDetails.getRdBudget() !=null || taskDetails.getRdSalesAmount() !=null){ BigDecimal rdBudget = taskDetails.getRdBudget(); BigDecimal rdSalesAmount = taskDetails.getRdSalesAmount(); BigDecimal res = rdBudget.divide(rdSalesAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); taskDetails.setRdBudgetRate(res.doubleValue()); //计算三年度的研发占比 LocalDate now = LocalDate.now(); int year = now.getYear(); List taskAnnualReports = taskAnnualReportMapper.selectThreeYear(taskDetails.getTid(), year); if (taskAnnualReports.size()==2){ BigDecimal threeYearsRdSalesAmount = rdSalesAmount; BigDecimal threeYearsRdBudget = rdBudget; for (TaskAnnualReport e : taskAnnualReports) { threeYearsRdBudget.add(e.getResearchAmount()); threeYearsRdSalesAmount.add(e.getSalesAmount()); } BigDecimal res2 = threeYearsRdBudget.divide(threeYearsRdSalesAmount, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); taskDetails.setThreeYearsRdBudgetRate(res2.doubleValue()); } } } /** * 修改数据 * * @param taskDetails 实例对象 * @return 实例对象 */ @Override public TaskDetailsBo update(TaskDetails taskDetails, TaskDetailsExtend taskDetailsExtend, TaskDetailsSupplement taskDetailsSupp) { if (taskDetails.getId()!=null){ taskDetailsExtend.setId(taskDetails.getId()); taskDetailsSupp.setId(taskDetails.getId()); this.taskDetailsMapper.update(taskDetails); taskDetailsExtendMapper.update(taskDetailsExtend); taskDetailsSupplementMapper.update(taskDetailsSupp); } return this.queryById(taskDetails.getId()); } /** * 通过主键删除数据 * * @param id 主键 * @return 是否成功 */ @Override public boolean deleteById(Integer id) { this.taskDetailsMapper.deleteById(id); taskDetailsExtendMapper.deleteById(id); taskDetailsSupplementMapper.deleteById(id); return true; } }