package com.goafanti.expenseAccount.service.impl; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.dao.*; import com.goafanti.common.error.BusinessException; import com.goafanti.common.model.Admin; import com.goafanti.common.model.ExpenseAccount; import com.goafanti.common.model.ExpenseAccountLog; import com.goafanti.common.model.PublicRelease; import com.goafanti.common.utils.DateUtils; import com.goafanti.core.mybatis.BaseMybatisDao; import com.goafanti.core.mybatis.page.Pagination; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.expenseAccount.bo.*; import com.goafanti.expenseAccount.service.ExpenseAccountService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class ExpenseAccountServiceImpl extends BaseMybatisDao implements ExpenseAccountService { @Autowired private AdminMapper adminMapper; @Autowired private ExpenseAccountMapper expenseAccountMapper; @Autowired private PublicReleaseMapper publicReleaseMapper; @Autowired private ExpenseAccountLogMapper expenseAccountLogMapper; @Autowired private ExpenseAccountDetailsMapper expenseAccountDetailsMapper; @Override public OutExpenseAccount add(InputExpenseAccount in) { if (in.getAid()!=null){ Admin admin = adminMapper.selectByPrimaryKey(in.getAid()); in.setAname(admin.getName()); in.setApplyDep(admin.getDepartmentId()); in.setPayDep(admin.getDepartmentId()); } if (in.getPrid()!=null){ PublicRelease pr = publicReleaseMapper.selectByPrimaryKey(in.getPrid()); in.setReleaseStart(pr.getReleaseStart()); in.setReleaseEnd(pr.getReleaseEnd()); in.setDistrictName(pr.getDistrictName()); in.setUserNames(pr.getUserNames()); } expenseAccountMapper.insertSelective(in); addExpenseAccountLog(in.getId(),0,"创建报销"); OutExpenseAccount outExpenseAccount = expenseAccountMapper.selectByid(in.getId()); return outExpenseAccount; } /** * * @param eaid 报销编号 * @param status 状态 0创建 1发起 2通过 3驳回 4修改 * @param str 备注 */ private void addExpenseAccountLog(Integer eaid, Integer status, String str) { ExpenseAccountLog eaLog=new ExpenseAccountLog(); eaLog.setEaid(eaid); eaLog.setStatus(status); eaLog.setRemarks(str); eaLog.setAuditor(TokenManager.getAdminId()); expenseAccountLogMapper.insertSelective(eaLog); } @Override public int update(InputExpenseAccount in) { OutExpenseAccount useEA = expenseAccountMapper.selectByid(in.getId()); if (useEA.getStatus()!=0&&useEA.getStatus()!=3){ throw new BusinessException("不能操作审核中与完成的订单"); } if (in.getStartTimeStr()!=null&&in.getEndTimeStr()!=null){ in.setReleaseStart(DateUtils.StringToDate(in.getStartTimeStr(), AFTConstants.YYYYMMDDHHMMSS)); in.setReleaseEnd(DateUtils.StringToDate(in.getEndTimeStr(), AFTConstants.YYYYMMDDHHMMSS)); } in.setStatus(1); //计算总金额 in.setTotalAmount(expenseAccountDetailsMapper.selectAmountCountByEAid(in.getId())); if (useEA.getStatus()==0){ addExpenseAccountLog(useEA.getId(),1,"发起报销审核"); }else if (useEA.getStatus()==3){ addExpenseAccountLog(useEA.getId(),4,"修改重新发起审核"); } return expenseAccountMapper.updateByPrimaryKeySelective(in); } @Override public int addDetails(InputExpenseAccountDetails in) { return expenseAccountDetailsMapper.insertSelective(in); } @Override public int deleteDetails(Integer id) { return expenseAccountDetailsMapper.deleteByPrimaryKey(id); } @Override public List detailsList(Integer eaid) { return expenseAccountDetailsMapper.selectByEAid(eaid); } @Override public Object logList(Integer eaid) { return expenseAccountLogMapper.selectByEaid(eaid); } @Override public ExpenseAccountExamineLog examineLog(Integer eaid) { return expenseAccountLogMapper.selectExamineLog(eaid); } @Override public int updateExamine(InputExpenseAccount in) { ExpenseAccount useEa = expenseAccountMapper.selectByPrimaryKey(in.getId()); if (useEa.getStatus()!=1)throw new BusinessException("审核状态错误"); if (useEa.getProcessStatus()!=in.getProcessStatus())throw new BusinessException("审核流程错误"); //审核通知 return 0; } @Override public Object pageList(InputPageListBo in) { Map param=new HashMap<>(); addParam(in, param); return findPage("selectExpenseAccountList", "selectExpenseAccountCount", param, in.getPageNo(), in.getPageSize()); } @Override public Object selectByPrid(InputExpenseAccount in) { in.setAid(TokenManager.getAdminId()); OutExpenseAccount useEa = expenseAccountMapper.selectByaidAndPrid(in); return useEa; } private void addParam(InputPageListBo in, Map param) { param.put("aid",TokenManager.getAdminId()); if (in.getStartTime()!=null&&in.getEndTime()!=null){ param.put("startTime",in.getStartTime()); param.put("endTime",in.getEndTime()+" 23:59:59"); } if (in.getStatus()!=null)param.put("status",in.getStatus()); if (in.getProcessStatus()!=null){ param.put("processStatus", in.getProcessStatus()); }else { param.put("processStatus",0); } } }