| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.service.impl.SuperServiceImpl; |
| | | import com.kidgrow.common.utils.DateUtil; |
| | | import com.kidgrow.common.utils.RandomValueUtils; |
| | | import com.kidgrow.oprationcenter.feign.RoleOrganizationService; |
| | | import com.kidgrow.oprationcenter.mapper.ProductOrderDetailMapper; |
| | | import com.kidgrow.oprationcenter.mapper.ProductOrderMapper; |
| | | import com.kidgrow.oprationcenter.mapper.ProductOrderRecordMapper; |
| | | import com.kidgrow.oprationcenter.model.ProductOrder; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderRecord; |
| | | import com.kidgrow.oprationcenter.model.SysProduct; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderService; |
| | | import com.kidgrow.oprationcenter.service.ISysProductService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | public class ProductOrderServiceImpl extends SuperServiceImpl<ProductOrderMapper, ProductOrder> implements IProductOrderService { |
| | | @Autowired |
| | | private RoleOrganizationService roleOrganizationService; |
| | | @Autowired |
| | | private ISysProductService sysProductService; |
| | | @Autowired |
| | | private ProductOrderDetailMapper productOrderDetailMapper; |
| | | @Autowired |
| | | private ProductOrderRecordMapper productOrderRecordMapper; |
| | | /** |
| | | * 列表 |
| | | * @param params |
| | |
| | | public int delProductDetail(Long orderId) { |
| | | return baseMapper.delProductDetail(orderId); |
| | | } |
| | | |
| | | /** |
| | | * 用户充值(创建订单,增加充值记录,冲套餐) |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean saveProductDetail(Map<String,Object> params) |
| | | { |
| | | //指定套餐数据 |
| | | SysProduct sysProduct=sysProductService.getById(CommonConstant.REG_USER_PRODUCT_ID); |
| | | if (sysProduct != null) { |
| | | //订单合同数据 |
| | | ProductOrder productOrder=new ProductOrder(); |
| | | productOrder.setIsDel(false); |
| | | productOrder.setEnabled(true); |
| | | productOrder.setContractBeginTime(new Date()); |
| | | productOrder.setContractEndTime(DateUtil.addDays(new Date(), CommonConstant.REG_USER_CONTRACT_DAY)); |
| | | productOrder.setContractTime(new Date()); |
| | | productOrder.setContractNo(RandomValueUtils.getRandom(10)); |
| | | productOrder.setContractTitle(CommonConstant.REG_USER_CONTRACT_NAME); |
| | | productOrder.setHospitalId(Long.valueOf(params.get("departmentId").toString())); |
| | | productOrder.setHospitalName(params.get("hospitalName").toString()); |
| | | productOrder.setDepartmentId(Long.valueOf(params.get("hospitalId").toString())); |
| | | productOrder.setDepartmentName(params.get("departmentName").toString()); |
| | | productOrder.setCreateUserId(CommonConstant.CREATE_USER_ID); |
| | | productOrder.setCreateUserName(CommonConstant.CREATE_USER_NAME); |
| | | if (baseMapper.insert(productOrder)==1) { |
| | | //套餐数据 |
| | | ProductOrderDetail productOrderDetail=new ProductOrderDetail(); |
| | | productOrderDetail.setEnabled(true); |
| | | productOrderDetail.setIsDel(false); |
| | | productOrderDetail.setAilightCount(sysProduct.getAilightCount()); |
| | | productOrderDetail.setRecordCount(sysProduct.getRecordCount()); |
| | | productOrderDetail.setProBegintime(new Date()); |
| | | //0 天 1 月 2 年 |
| | | switch(sysProduct.getProTimeUnit()) |
| | | { |
| | | case 0: |
| | | default: |
| | | productOrderDetail.setProEndtime(DateUtil.addDays(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | case 1: |
| | | productOrderDetail.setProEndtime(DateUtil.addMonths(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | case 2: |
| | | productOrderDetail.setProEndtime(DateUtil.addYears(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | } |
| | | productOrderDetail.setProId(sysProduct.getId()); |
| | | productOrderDetail.setProName(sysProduct.getProName()); |
| | | productOrderDetail.setOrderId(productOrder.getId()); |
| | | productOrderDetail.setProType(sysProduct.getProType()); |
| | | if(productOrderDetailMapper.insert(productOrderDetail)==1) |
| | | { |
| | | //充值记录 |
| | | ProductOrderRecord productOrderRecord=new ProductOrderRecord(); |
| | | productOrderRecord.setEnabled(true); |
| | | productOrderRecord.setIsDel(false); |
| | | productOrderRecord.setAilightCount(sysProduct.getAilightCount()); |
| | | productOrderRecord.setRecordCount(sysProduct.getRecordCount()); |
| | | productOrderRecord.setProBegintime(new Date()); |
| | | //0 天 1 月 2 年 |
| | | switch(sysProduct.getProTimeUnit()) |
| | | { |
| | | case 0: |
| | | default: |
| | | productOrderRecord.setProEndtime(DateUtil.addDays(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | case 1: |
| | | productOrderRecord.setProEndtime(DateUtil.addMonths(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | case 2: |
| | | productOrderRecord.setProEndtime(DateUtil.addYears(new Date(),sysProduct.getProTime())); |
| | | break; |
| | | } |
| | | productOrderRecord.setProId(sysProduct.getId()); |
| | | productOrderRecord.setProName(sysProduct.getProName()); |
| | | productOrderRecord.setOrderId(productOrder.getId()); |
| | | productOrderRecord.setProType(sysProduct.getProType()); |
| | | if(productOrderRecordMapper.insert(productOrderRecord)<1) |
| | | { |
| | | baseMapper.deleteById(productOrder.getId()); |
| | | productOrderDetailMapper.deleteById(productOrderDetail.getId()); |
| | | } |
| | | else |
| | | { |
| | | return true; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | baseMapper.deleteById(productOrder.getId()); |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | } |