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.PurchaseApply; import com.gkhy.exam.system.domain.PurchaseApplyPlan; import com.gkhy.exam.system.mapper.PurchaseApplyMapper; import com.gkhy.exam.system.mapper.PurchaseApplyPlanMapper; import com.gkhy.exam.system.service.PurchaseApplyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.List; @Service public class PurchaseApplyServiceImpl extends ServiceImpl implements PurchaseApplyService { @Autowired private PurchaseApplyMapper applyMapper; @Autowired private PurchaseApplyPlanMapper applyPlanMapper; @Override public CommonPage selectApplyList(PurchaseApply purchaseApply) { if (!SecurityUtils.adminUser()){ if (purchaseApply.getCompanyId()==null){ throw new ApiException("非管理员操作,企业id不可为空"); } } PageUtils.startPage(); List purchaseApplies = applyMapper.selectApplyList(purchaseApply); for (PurchaseApply apply : purchaseApplies) { List purchaseApplyPlans = applyPlanMapper.selectByApplyId(apply.getId()); apply.setPurchaseApplyPlans(purchaseApplyPlans); } return CommonPage.restPage(purchaseApplies); } @Override public CommonResult insertApply(PurchaseApply purchaseApply) { purchaseApply.setCreateTime(LocalDateTime.now()); purchaseApply.setCreateBy(SecurityUtils.getUsername()); applyMapper.insert(purchaseApply); List purchaseApplyPlans = purchaseApply.getPurchaseApplyPlans(); for (PurchaseApplyPlan purchaseApplyPlan : purchaseApplyPlans) { purchaseApplyPlan.setApplyId(purchaseApply.getId()); } applyPlanMapper.insertPlans(purchaseApplyPlans); return CommonResult.success(); } @Override public CommonResult updateApply(PurchaseApply purchaseApply) { purchaseApply.setUpdateTime(LocalDateTime.now()); purchaseApply.setUpdateBy(SecurityUtils.getUsername()); applyMapper.updateById(purchaseApply); List purchaseApplyPlans = purchaseApply.getPurchaseApplyPlans(); applyPlanMapper.deletedByIds(purchaseApply.getId()); applyPlanMapper.insertPlans(purchaseApplyPlans); return CommonResult.success(); } @Override public CommonResult deletedApply(Integer applyId) { PurchaseApply purchaseApply = new PurchaseApply(); purchaseApply.setId(applyId); purchaseApply.setUpdateBy(SecurityUtils.getUsername()); purchaseApply.setUpdateTime(LocalDateTime.now()); purchaseApply.setDelFlag(2); applyMapper.updateById(purchaseApply); return CommonResult.success(); } }