| | |
| | | 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.validation.ObjectError; |
| | | 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.service.IBusinessRecordsService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderDetailService; |
| | | import com.kidgrow.oprationcenter.service.IProductOrderService; |
| | | 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; |
| | | |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 产品/明显的充值记录 |
| | | * @Project: 运营中心 |
| | | * @CreateDate: Created in 2020-04-02 18:25:34 <br> |
| | |
| | | @RestController |
| | | @RequestMapping("/productorderdetail") |
| | | @Api(tags = "产品/明显的充值记录") |
| | | public class ProductOrderDetailController extends BaseController{ |
| | | public class ProductOrderDetailController extends BaseController { |
| | | @Autowired |
| | | private IProductOrderDetailService productOrderDetailService; |
| | | @Autowired |
| | | private IBusinessRecordsService businessRecordsService; |
| | | @Autowired |
| | | private IProductOrderService productOrderService; |
| | | |
| | | /** |
| | | * 列表 |
| | |
| | | @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer") |
| | | }) |
| | | @GetMapping |
| | | public ResultBody<PageResult> list(@RequestParam Map<String, Object> params) { |
| | | if(params.size()==0){ |
| | | params.put("page",1); |
| | | params.put("limit",10); |
| | | public PageResult list(@RequestParam Map<String, Object> params) { |
| | | if (params.size() == 0) { |
| | | params.put("page", 1); |
| | | params.put("limit", 10); |
| | | } |
| | | return ResultBody.ok().data(productOrderDetailService.findList(params)); |
| | | return productOrderDetailService.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); |
| | | } |
| | | return productOrderDetailService.findAllList(params,sysUser); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiOperation(value = "保存") |
| | | @PostMapping |
| | | public ResultBody save(@Valid @RequestBody ProductOrderDetail productOrderDetail, BindingResult bindingResult) { |
| | | List<String> errMsg= new ArrayList<>(); |
| | | public ResultBody save(@Valid @RequestBody ProductOrderDetail productOrderDetail, 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 { |
| | | boolean v= productOrderDetailService.saveOrUpdate(productOrderDetail); |
| | | if(v) { |
| | | return ResultBody.ok().data(productOrderDetail).msg("保存成功"); |
| | | } else { |
| | | List<SysOrganization> organizations = sysUser.getOrganizations(); |
| | | if(organizations.size()>0){ |
| | | productOrderDetail.setCreateUserOrgCode(organizations.get(organizations.size()-1).getOrgCode()); |
| | | } |
| | | else { |
| | | 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); |
| | | 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 = "删除") |
| | | @DeleteMapping("/{id}") |
| | | public ResultBody delete(@PathVariable Long id) { |
| | | boolean v= productOrderDetailService.removeById(id); |
| | | if(v) { |
| | | 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 { |
| | | } 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; |
| | | } |
| | | } |