package com.kidgrow.oprationcenter.controller;
import com.kidgrow.common.controller.BaseController;
import com.kidgrow.common.model.PageResult;
import com.kidgrow.common.model.ResultBody;
import com.kidgrow.oprationcenter.model.BusinessRecords;
import com.kidgrow.oprationcenter.service.IBusinessRecordsService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020
*
* @Description: 业务操作记录
* @Project: 运营中心
* @CreateDate: Created in 2020-04-02 18:25:34
* @Author: liuke
* @version: 1.0
*/
@Slf4j
@RestController
@RequestMapping("/businessrecords")
@Api(tags = "业务操作记录")
public class BusinessRecordsController extends BaseController {
@Autowired
private IBusinessRecordsService businessRecordsService;
/**
* 列表
*/
@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 params) {
if (params.size() == 0) {
params.put("page", 1);
params.put("limit", 10);
}
return businessRecordsService.findList(params);
}
/**
* 查询
*/
@ApiOperation(value = "查询")
@GetMapping("/{id}")
public ResultBody findById(@PathVariable Long id) {
BusinessRecords model = businessRecordsService.getById(id);
return ResultBody.ok().data(model).msg("查询成功");
}
/**
* 根据BusinessRecords当做查询条件进行查询
*/
@ApiOperation(value = "根据BusinessRecords当做查询条件进行查询")
@PostMapping("/query")
public ResultBody findByObject(@RequestBody BusinessRecords businessRecords) {
BusinessRecords model = businessRecordsService.findByObject(businessRecords);
return ResultBody.ok().data(model).msg("查询成功");
}
// /**
// * 新增or更新
// */
// @ApiOperation(value = "保存")
// @PostMapping
// public ResultBody save(@Valid @RequestBody BusinessRecords businessRecords, BindingResult bindingResult) {
// if (bindingResult.hasErrors()) {
// return ResultBody.failed().msg(bindingResult.getFieldError().getDefaultMessage());
// } else {
// BusinessRecords model = businessRecordsService.getById(businessRecords.getId());
// if (model == null) {
// boolean v = businessRecordsService.saveOrUpdate(businessRecords);
// if (v) {
// return ResultBody.ok().data(businessRecords).msg("保存成功");
// } else {
// return ResultBody.failed().msg("保存失败");
// }
// } else {
// return ResultBody.failed().msg("业务日志不允许更新!");
// }
// }
// }
/**
* 新增
*/
@ApiOperation(value = "保存")
@PostMapping
public ResultBody save(String recordTitle,String recordNote) {
if (recordTitle.isEmpty()||recordNote.isEmpty()) {
return ResultBody.failed().msg("业务日志参数有误!");
} else {
boolean v = businessRecordsService.recordBusinessData(recordTitle,recordNote);
if (v) {
return ResultBody.ok().msg("保存成功");
} else {
return ResultBody.failed().msg("保存失败");
}
}
}
/**
* 删除
*/
@ApiOperation(value = "删除")
@DeleteMapping("/{id}")
public ResultBody delete(@PathVariable Long id) {
boolean v = businessRecordsService.removeById(id);
if (v) {
return ResultBody.ok().msg("删除成功");
} else {
return ResultBody.failed().msg("删除失败");
}
}
}