| | |
| | | package com.kidgrow.oprationcenter.controller; |
| | | |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | | import com.kidgrow.common.controller.BaseController; |
| | | import com.kidgrow.common.model.PageResult; |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.common.model.SysOrganization; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.model.ProductOrder; |
| | | import com.kidgrow.oprationcenter.service.IBusinessRecordsService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderService; |
| | |
| | | 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; |
| | | import org.springframework.validation.ObjectError; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping |
| | | public PageResult list(@RequestParam Map<String, Object> params) { |
| | | public PageResult list(@RequestParam Map<String, Object> params, @LoginUser SysUser sysUser) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return productOrderService.findList(params); |
| | | return productOrderService.findList(params,sysUser); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody ProductOrder productOrder, BindingResult bindingResult) { |
| | | public ResultBody save(@Valid @RequestBody ProductOrder productOrder, BindingResult bindingResult,@LoginUser SysUser sysUser) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | List<SysOrganization> organizations = sysUser.getOrganizations(); |
| | | if(organizations.size()>0){ |
| | | productOrder.setCreateUserOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | } |
| | | //默认添加的合同视为无效合同,在充值完成后,会将对应合同启用 |
| | | productOrder.setIsDel(true); |
| | | boolean v = productOrderService.saveOrUpdate(productOrder); |
| | | if (v) { |
| | | return ResultBody.ok().data(productOrder).msg("保存成功"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 冲试用套餐 用于注册医生自动充值 |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "套餐充值") |
| | | @PostMapping("/saveTemp") |
| | | public ResultBody saveProductDetail(@RequestBody Map<String,Object> params,@LoginUser SysUser sysUser) |
| | | { |
| | | if (StringUtils.isNotBlank(params.get("hospitalId").toString()) && |
| | | StringUtils.isNotBlank(params.get("departmentId").toString())&& |
| | | StringUtils.isNotBlank(params.get("hospitalName").toString())&& |
| | | StringUtils.isNotBlank(params.get("departmentName").toString())) { |
| | | params.put("proId", CommonConstant.REG_USER_PRODUCT_ID); |
| | | boolean isResult= productOrderService.saveProductDetail(params,sysUser); |
| | | if (isResult) { |
| | | return ResultBody.ok().data(isResult).msg("试用套餐充值成功"); |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed().data(isResult).msg("试用套餐充值失败"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed().data(false).msg("充值参数有误"); |
| | | } |
| | | } |
| | | /** |
| | | * 删除 |
| | | */ |
| | | @ApiOperation(value = "删除") |
| | | @DeleteMapping("/{id}") |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public ResultBody delete(@PathVariable Long id,HttpServletRequest request) { |
| | | //先删除合同下的充值 |
| | | int delRows= productOrderService.delProductDetail(id); |
| | | if (delRows==0) { |
| | | log.info(String.format("该订单下无套餐数据{0}!",id)); |
| | | } |
| | | //再删除合同 |
| | | boolean v = productOrderService.removeById(id); |
| | | if (v) { |
| | | if (!businessRecordsService.recordBusinessData("删除合同:"+id,id.toString())) { |
| | | //log.error(String.format("删除合同编号为:{0}的数据后,写入业务日志失败!",id)); |
| | | log.error(String.format("删除合同编号为:{0}的数据后,写入业务日志失败!",id)); |
| | | |
| | | } |
| | | return ResultBody.ok().msg("删除成功"); |
| | |
| | | if (resultBody.getCode()==0) { |
| | | String enablad=(MapUtils.getBoolean(params, "enabled"))?"启用":"禁用"; |
| | | if (!businessRecordsService.recordBusinessData("修改合同状态为:"+enablad,enablad)) { |
| | | //log.error(String.format("修改合同状态为:{0},写入业务日志失败!合同管理id为:{1}",enablad,MapUtils.getString(params,"id"))); |
| | | log.error(String.format("修改合同状态为:{0},写入业务日志失败!合同管理id为:{1}",enablad,MapUtils.getString(params,"id"))); |
| | | } |
| | | } |
| | | return resultBody; |
| | | } |
| | | @ApiOperation(value = "获取用户套餐的使用状态") |
| | | @PostMapping("/getStatus") |
| | | public ResultBody getStatus(@RequestBody ProductOrder productOrder) { |
| | | return productOrderService.getStatus(productOrder); |
| | | } |
| | | |
| | | } |