New file |
| | |
| | | package com.kidgrow.oprationcenter.controller; |
| | | |
| | | import com.kidgrow.common.annotation.LoginUser; |
| | | 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.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 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 java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 产品/明显的充值记录 |
| | | * @Project: 运营中心 |
| | | * @CreateDate: Created in 2020-04-02 18:25:34 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | | * @version: 1.0 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping("/productorderrecord") |
| | | @Api(tags = "产品/明显的充值记录") |
| | | public class ProductOrderRecordController extends BaseController { |
| | | @Autowired |
| | | private IProductOrderRecordService productOrderRecordService; |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private IBusinessRecordsService businessRecordsService; |
| | | @Autowired |
| | | private IProductOrderService productOrderService; |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping |
| | | public PageResult list(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return productOrderRecordService.findList(params); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @ApiOperation(value = "查询列表") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping("/all") |
| | | public PageResult findAllList(@RequestParam Map<String, Object> params,@LoginUser SysUser sysUser) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | String departmentId=MapUtils.getString(params, "departmentId"); |
| | | if (StringUtils.isNotBlank(departmentId)) { |
| | | params.put("enable", 1); |
| | | params.put("isDel", 0); |
| | | } |
| | | return productOrderRecordService.findAllList(params,sysUser); |
| | | } |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @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 productOrderRecordService.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 productOrderRecordService.groupList(params); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户的套餐剩余量 |
| | | */ |
| | | @ApiOperation(value = "查询") |
| | | @GetMapping("/biUserNowProduct") |
| | | public ResultBody biUserNowProduct(@RequestParam long hospitalId, Long departmentId) { |
| | | return productOrderDetailService.biUserNowProduct(hospitalId,departmentId); |
| | | } |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @ApiOperation(value = "查询") |
| | | @GetMapping("/{id}") |
| | | public ResultBody findById(@PathVariable Long id) { |
| | | ProductOrderRecord model = productOrderRecordService.getById(id); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 根据ProductOrderRecord当做查询条件进行查询 |
| | | */ |
| | | @ApiOperation(value = "根据ProductOrderRecord当做查询条件进行查询") |
| | | @PostMapping("/query") |
| | | public ResultBody findByObject(@RequestBody ProductOrderRecord productOrderRecord) { |
| | | ProductOrderRecord model = productOrderRecordService.findByObject(productOrderRecord); |
| | | return ResultBody.ok().data(model).msg("查询成功"); |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody ProductOrderRecord productOrderRecord, BindingResult bindingResult,@LoginUser SysUser sysUser) { |
| | | List<String> errMsg = new ArrayList<>(); |
| | | if (bindingResult.hasErrors()) { |
| | | for (ObjectError error : bindingResult.getAllErrors()) { |
| | | errMsg.add(error.getDefaultMessage()); |
| | | } |
| | | return ResultBody.failed().msg(errMsg.toString()); |
| | | } else { |
| | | List<SysOrganization> organizations = sysUser.getOrganizations(); |
| | | if(organizations.size()>0){ |
| | | productOrderRecord.setCreateUserOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | } |
| | | boolean v = productOrderRecordService.saveOrUpdate(productOrderRecord); |
| | | if (v) { |
| | | return ResultBody.ok().data(productOrderRecord).msg("保存成功"); |
| | | } else { |
| | | return ResultBody.failed().msg("保存失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 新增or更新 |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping("/saveall") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public ResultBody batchInsert(@Valid @RequestBody List<ProductOrderRecord> 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 = productOrderRecordService.saveBatch(list); |
| | | if (v) { |
| | | 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 = "删除") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable Long id) { |
| | | ProductOrderRecord productOrderRecord=productOrderRecordService.getById(id); |
| | | if (productOrderRecord != null) { |
| | | Map<String,Object> detailSelect=new HashMap<String,Object>(); |
| | | detailSelect.put("pro_id",productOrderRecord.getProId()); |
| | | detailSelect.put("order_id",productOrderRecord.getOrderId()); |
| | | List<ProductOrderDetail> productOrderDetailList=productOrderDetailService.listByMap(detailSelect); |
| | | if (productOrderDetailList != null&&productOrderDetailList.size()>0) { |
| | | ProductOrderDetail productOrderDetail=productOrderDetailList.get(0); |
| | | if (productOrderDetail.getAilightCount() == productOrderRecord.getAilightCount()&& |
| | | productOrderDetail.getRecordCount()==productOrderRecord.getRecordCount()) { |
| | | //读片量和报告量都没有改变 可以删除 |
| | | //删记录 |
| | | boolean isdel= productOrderRecordService.removeById(id); |
| | | //删套餐 |
| | | boolean isdelDetail=productOrderDetailService.removeById(productOrderDetail.getId()); |
| | | //写记录 |
| | | boolean record=businessRecordsService.recordBusinessData("删除订单明细:" + id, id.toString()); |
| | | log.info(String.format("删除订单明细id为:{1}",id)); |
| | | if (isdelDetail&&isdel) { |
| | | return ResultBody.ok().msg("套餐删除成功!"); |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed().msg("当前套餐删除失败!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed().msg("当前套餐已经使用,无法删除!"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return ResultBody.failed().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 = productOrderRecordService.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 productOrderRecordService.getTypeByUser(sysUser); |
| | | } |
| | | } |