| | |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.utils.ArithUtils; |
| | | import com.kidgrow.oprationcenter.model.PayManager; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.service.IPayManagerService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.usercenter.feign.SysDepartmentService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.BindingResult; |
| | |
| | | private IPayManagerService payManagerService; |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private SysDepartmentService sysDepartmentService; |
| | | |
| | | /** |
| | | * 列表 |
| | |
| | | return ResultBody.ok().data(true).msg("已开通单次支付功能"); |
| | | } |
| | | } |
| | | /** |
| | | * 查询一个科室是否有支付功能 |
| | | */ |
| | | @ApiOperation(value = "查询一个科室是否有支付功能") |
| | | @PostMapping("/departmentIsPayFegin") |
| | | public ResultBody departmentIsPayFegin(@RequestBody Map<String,Long> map) { |
| | | Long hospitalId = MapUtils.getLong(map, "hospitalId"); |
| | | if(hospitalId==null){ |
| | | return ResultBody.failed("请输入医院id"); |
| | | } |
| | | Long departmentId = MapUtils.getLong(map, "departmentId"); |
| | | if(departmentId==null){ |
| | | return ResultBody.failed("请输入部门id"); |
| | | } |
| | | PayManager payManager=payManagerService.findByObject(hospitalId,departmentId); |
| | | if (payManager.getId() == null) { |
| | | return ResultBody.ok().data(false).msg("未开通单次支付功能"); |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.ok().data(true).msg("已开通单次支付功能"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | if (payManager.getId()!=null) { |
| | | //修改支付功能 |
| | | ProductOrderDetail modelDetail=payManagerService.getProductDetail(payManager.getHospitalId(),payManager.getDepartmentId()); |
| | | if(!payManager.getEnabled()&&modelDetail!=null) |
| | | { |
| | | //支付禁用 禁用套餐 |
| | | modelDetail.setEnabled(false); |
| | | modelDetail.setIsDel(true); |
| | | if(!productOrderDetailService.saveOrUpdate(modelDetail)) |
| | | int userdCount=-1; |
| | | if (payManager.getEnabled()) { |
| | | userdCount=productOrderDetailService.getUserdProduct(payManager.getHospitalId(),payManager.getDepartmentId()); |
| | | } |
| | | if (userdCount>0) { |
| | | return ResultBody.failed().msg("该医院已有可用的套餐,不能开通单次支付!"); |
| | | } |
| | | else |
| | | { |
| | | payManager.setPayPrice(ArithUtils.round(payManager.getPayPrice()*100,2)); |
| | | payManager.setPayKidgrow(ArithUtils.round(payManager.getPayKidgrow()*100,2)); |
| | | payManager.setPayCustom(ArithUtils.round(payManager.getPayCustom()*100,2)); |
| | | if (payManager.getId()!=null) { |
| | | //修改支付功能 |
| | | ProductOrderDetail modelDetail=payManagerService.getProductDetail(payManager.getHospitalId(),payManager.getDepartmentId()); |
| | | if(!payManager.getEnabled()&&modelDetail!=null) |
| | | { |
| | | return ResultBody.failed().msg("套餐修改失败!支付开通修改失败!"); |
| | | //支付禁用 禁用套餐 |
| | | modelDetail.setEnabled(false); |
| | | modelDetail.setIsDel(true); |
| | | if(!productOrderDetailService.saveOrUpdate(modelDetail)) |
| | | { |
| | | return ResultBody.failed().msg("套餐修改失败!支付开通修改失败!"); |
| | | } |
| | | } |
| | | } |
| | | else if(modelDetail==null) |
| | | { |
| | | else if(modelDetail==null) |
| | | { |
| | | if(payManager.getEnabled()){ |
| | | Boolean isResult=payManagerService.saveproductOrder(payManager,sysUser); |
| | | if (!isResult) { |
| | | return ResultBody.failed().msg("套餐充入失败,支付开通失败!"); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | Boolean isResult=payManagerService.saveproductOrder(payManager,sysUser); |
| | | if (!isResult) { |
| | | return ResultBody.failed().msg("套餐充入失败,支付开通失败!"); |
| | | return ResultBody.failed().msg("套餐充入失败!支付开通失败!"); |
| | | } |
| | | } |
| | | } else { |
| | | Boolean isResult=payManagerService.saveproductOrder(payManager,sysUser); |
| | | if (!isResult) { |
| | | return ResultBody.failed().msg("套餐充入失败!支付开通失败!"); |
| | | boolean v = payManagerService.saveOrUpdate(payManager); |
| | | //修改科室的支付功能状态 |
| | | sysDepartmentService.updatePay(payManager.getDepartmentId(),payManager.getEnabled()); |
| | | if (v) { |
| | | return ResultBody.ok().data(payManager).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | | boolean v = payManagerService.saveOrUpdate(payManager); |
| | | |
| | | if (v) { |
| | | return ResultBody.ok().data(payManager).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | | } |
| | | } |