| | |
| | | package com.kidgrow.oprationcenter.controller; |
| | | |
| | | import java.util.Map; |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | import com.kidgrow.common.controller.BaseController; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | 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.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.model.ProductOrderRecord; |
| | | import com.kidgrow.oprationcenter.service.IBusinessRecordsService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderRecordService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderService; |
| | | import com.kidgrow.oprationcenter.vo.ProductOrderJoinDetail; |
| | | 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 com.kidgrow.oprationcenter.model.ProductOrderDetail; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.common.model.*; |
| | | |
| | | import org.apache.commons.collections.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.*; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.Valid; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 产品/明显的充值记录 |
| | | * @Project: 用户中心 |
| | | * @CreateDate: Created in 2020-04-01 09:37:05 <br> |
| | | * @Project: 运营中心 |
| | | * @CreateDate: Created in 2020-04-02 18:25:34 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | * @version: 1.0 |
| | | */ |
| | |
| | | @RestController |
| | | @RequestMapping("/productorderdetail") |
| | | @Api(tags = "产品/明显的充值记录") |
| | | public class ProductOrderDetailController extends BaseController{ |
| | | public class ProductOrderDetailController extends BaseController { |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private IProductOrderRecordService productOrderRecordService; |
| | | @Autowired |
| | | private IBusinessRecordsService businessRecordsService; |
| | | @Autowired |
| | | private IProductOrderService productOrderService; |
| | | |
| | | /** |
| | | * 列表 |
| | |
| | | }) |
| | | @GetMapping |
| | | public PageResult list(@RequestParam Map<String, Object> params) { |
| | | if(params.size()==0){ |
| | | params.put("page",1); |
| | | params.put("limit",10); |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return productOrderDetailService.findList(params); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @PostMapping("/alldata") |
| | | public PageResult findAllDataList(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | if(params.get("diagnosticHospitalId")==null) |
| | | return PageResult.<ProductOrderJoinDetail>builder().data(null).code(0).count(0L).build(); |
| | | return productOrderDetailService.findAllDataList(params); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping("/group") |
| | | public PageResult groupList(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return productOrderDetailService.groupList(params); |
| | | } |
| | | |
| | | /** |
| | | * 获取医院套餐是否到期和到期时间 |
| | | * data内 isend为true说明套餐到期 |
| | | * endtime上套餐的到期时间 |
| | | * @param hospitalId |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | |
| | | @ApiOperation(value = "获取医院套餐是否到期和到期时间") |
| | | @GetMapping("/UserProductDetailData") |
| | | public ResultBody UserProductDetailData(@RequestParam Long hospitalId,Long departmentId) { |
| | | return productOrderDetailService.UserProductDetailData(hospitalId,departmentId); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody ProductOrderDetail productOrderDetail, BindingResult bindingResult) { |
| | | public ResultBody save(@Valid @RequestBody ProductOrderDetail productOrderDetail, BindingResult bindingResult,@LoginUser SysUser sysUser) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | return ResultBody.failed().msg(bindingResult.getFieldError().getDefaultMessage()); |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | | errMsg.add(error.getDefaultMessage()); |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | productOrderDetailService.saveOrUpdate(productOrderDetail); |
| | | return ResultBody.ok().data(productOrderDetail).msg("保存成功"); |
| | | List<SysOrganization> organizations = sysUser.getOrganizations(); |
| | | if(organizations.size()>0){ |
| | | productOrderDetail.setCreateUserOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | } |
| | | boolean v = productOrderDetailService.saveOrUpdate(productOrderDetail); |
| | | if (v) { |
| | | return ResultBody.ok().data(productOrderDetail).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping("/saveall") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResultBody batchInsert(@Valid @RequestBody List<ProductOrderDetail> list, BindingResult bindingResult) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | | errMsg.add(error.getDefaultMessage()); |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | //写充值套餐给用户 |
| | | Boolean v = productOrderDetailService.saveBatch(list); |
| | | //写充值记录 |
| | | //对象转换 |
| | | List<ProductOrderRecord> productOrderRecordList= new ArrayList<ProductOrderRecord>();; |
| | | list.forEach(item->{ |
| | | ProductOrderRecord productOrderRecord=new ProductOrderRecord(); |
| | | productOrderRecord.setAilightCount(item.getAilightCount()); |
| | | productOrderRecord.setOrderId(item.getOrderId()); |
| | | productOrderRecord.setProId(item.getProId()); |
| | | productOrderRecord.setProName(item.getProName()); |
| | | productOrderRecord.setProType(item.getProType()); |
| | | productOrderRecord.setIsShare(item.getIsShare()); |
| | | productOrderRecord.setIsDel(item.getIsDel()); |
| | | productOrderRecord.setRecordCount(item.getRecordCount()); |
| | | productOrderRecord.setProBegintime(item.getProBegintime()); |
| | | productOrderRecord.setProEndtime(item.getProEndtime()); |
| | | productOrderRecord.setEnabled(item.getEnabled()); |
| | | productOrderRecordList.add(productOrderRecord); |
| | | }); |
| | | Boolean r = productOrderRecordService.saveBatch(productOrderRecordList); |
| | | if (v&&r) { |
| | | return ResultBody.ok().data(list.size()).msg("产品充值成功"); |
| | | } else { |
| | | //写入订单明细失败,则删除订单记录数据 |
| | | Boolean e = productOrderService.removeById(list.get(0).getOrderId()); |
| | | if (e) |
| | | return ResultBody.failed().msg("充值数据保存失败,订单已撤回!"); |
| | | else |
| | | return ResultBody.failed().msg("充值数据保存失败,订单撤回失败!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "删除") |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable Long id) { |
| | | productOrderDetailService.removeById(id); |
| | | return ResultBody.ok().msg("删除成功"); |
| | | boolean v = productOrderDetailService.removeById(id); |
| | | if (v) { |
| | | if (!businessRecordsService.recordBusinessData("删除订单明细:" + id, id.toString())) { |
| | | //log.error(String.format("删除订单明细id为:{1}",id)); |
| | | } |
| | | return ResultBody.ok().msg("删除成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("删除失败"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改状态 |
| | | * |
| | | * @param params |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "修改数据状态") |
| | | @GetMapping("/updateEnabled") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "enabled", value = "是否启用", required = true, dataType = "Boolean") |
| | | }) |
| | | public ResultBody updateEnabled(@RequestParam Map<String, Object> params, HttpServletRequest request) { |
| | | if (params.size() == 0) { |
| | | return ResultBody.failed().msg("参数异常!"); |
| | | } |
| | | ResultBody resultBody = productOrderDetailService.updateEnabled(params); |
| | | //记录业务日志 |
| | | 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"))); |
| | | } |
| | | } |
| | | return resultBody; |
| | | } |
| | | |
| | | /** |
| | | * 获取 用户的状态 为试用状态还是 启用状态 |
| | | * |
| | | * @return |
| | | */ |
| | | @ApiOperation(value = "获取 用户的状态") |
| | | @GetMapping("/getTypeByUser") |
| | | public ResultBody getTypeByUser(@LoginUser SysUser sysUser) { |
| | | return productOrderDetailService.getTypeByUser(sysUser); |
| | | } |
| | | } |