package com.unioncast.db.api.rest.adx;
import java.net.URI;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponentsBuilder;
import com.unioncast.common.adx.model.AdxSspFinanceManagement;
import com.unioncast.common.page.Pagination;
import com.unioncast.common.restClient.RestResponse;
import com.unioncast.db.api.rest.GeneralController;
import com.unioncast.db.rdbms.core.exception.DaoException;
import com.unioncast.db.rdbms.core.service.adxDBService.AdxSspFinanceManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(value = "API - AdxSspFinanceManagementController")
@RestController
@RequestMapping("/rest/adxSspFinanceManagement")
public class AdxSspFinanceManagementController extends GeneralController {
private static final Logger LOG = LoggerFactory.getLogger(AdxSspFinanceManagementController.class);
@Autowired
private AdxSspFinanceManagementService adxSspFinanceManagementService;
/**
* 查找所有
*
* @date 2016年10月19日 下午1:30:29
*
* @return
* @throws DaoException
*/
@ApiOperation(value = "查找所有", httpMethod = "POST", response = RestResponse.class)
@RequestMapping(value = "/findAll", method = RequestMethod.POST)
public RestResponse findAll() throws DaoException {
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
AdxSspFinanceManagement[] adxSspFinanceManagements = adxSspFinanceManagementService.findAll();
LOG.info("adxSspFinanceManagements:{}", (Object) adxSspFinanceManagements);
restResponse.setResult(adxSspFinanceManagementService.findAll());
return restResponse;
}
/**
* 分页条件查找
*
* @date 2016年9月29日 下午6:59:46
*
* @return
* @throws DaoException
*/
@ApiOperation(value = "分页条件查找", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "currentPage", required = true, dataType = "Integer", paramType = "path"),
@ApiImplicitParam(name = "pageSize", required = true, dataType = "Integer", paramType = "path"),
@ApiImplicitParam(name = "adxSspFinanceManagement", required = true, dataType = "AdxSspFinanceManagement", paramType = "body") })
@RequestMapping(value = "/page/{currentPage}/{pageSize}", method = RequestMethod.POST)
public RestResponse page(@RequestBody AdxSspFinanceManagement adxSspFinanceManagement,
@PathVariable Integer currentPage, @PathVariable Integer pageSize) throws DaoException {
LOG.info("adxSspFinanceManagementCondition:{}", adxSspFinanceManagement);
LOG.info("currentPage:{}", currentPage);
LOG.info("pageSize:{}", pageSize);
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
Pagination<AdxSspFinanceManagement> pagination = adxSspFinanceManagementService.page(adxSspFinanceManagement,
currentPage, pageSize);
LOG.info("pagination:{}", pagination);
restResponse.setResult(adxSspFinanceManagementService.page(adxSspFinanceManagement, currentPage, pageSize));
return restResponse;
}
/**
* 根据id查找
*
* @date 2016年9月29日 下午7:09:03
*
* @param id
* @return
* @throws DaoException
*/
@ApiOperation(value = "根据id查找", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "id", required = true, dataType = "Integer", paramType = "path") })
@RequestMapping(value = "/findById/{id}", method = RequestMethod.POST)
public RestResponse findById(@PathVariable Long id) throws DaoException {
LOG.info("id:{}", id);
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
AdxSspFinanceManagement adxSspFinanceManagement = adxSspFinanceManagementService.findById(id);
LOG.info("adxSspFinanceManagement:{}", adxSspFinanceManagement);
restResponse.setResult(adxSspFinanceManagementService.findById(id));
return restResponse;
}
/**
* 增加
*
* @date 2016年10月21日 下午5:02:59
*
* @param adxSspFinanceManagement
* @param uriComponentsBuilder
* @return
* @throws DaoException
*/
@ApiOperation(value = "增加", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "adxSspFinanceManagement", required = true, dataType = "AdxSspFinanceManagement", paramType = "body") })
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResponseEntity<RestResponse> add(@RequestBody AdxSspFinanceManagement adxSspFinanceManagement,
UriComponentsBuilder uriComponentsBuilder) throws DaoException {
LOG.info("adxSspFinanceManagement:{}", adxSspFinanceManagement);
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
Long id = adxSspFinanceManagementService.save(adxSspFinanceManagement);
LOG.info("id:{}", id);
restResponse.setResult(id);
HttpHeaders httpHeaders = new HttpHeaders();
URI uri = uriComponentsBuilder.path("/rest/adxSspFinanceManagement/findById/").path(String.valueOf(id)).build()
.toUri();
httpHeaders.setLocation(uri);
return new ResponseEntity<RestResponse>(restResponse, httpHeaders, HttpStatus.CREATED);
}
/**
* 批量增加
*
* @date 2016年10月21日 下午5:02:47
*
* @param adxSspFinanceManagements
* @return
* @throws DaoException
*/
@ApiOperation(value = "批量增加", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "adxSspFinanceManagements", required = true, dataType = "List", paramType = "body") })
@RequestMapping(value = "/batchAdd", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public RestResponse batchAdd(@RequestBody List<AdxSspFinanceManagement> adxSspFinanceManagements)
throws DaoException {
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
List<Long> ids = adxSspFinanceManagementService.batchAdd(adxSspFinanceManagements);
LOG.info("ids:{}", ids);
restResponse.setResult(ids);
return restResponse;
}
/**
* 修改
*
* @date 2016年10月21日 下午5:03:38
*
* @param adxSspFinanceManagement
* @throws DaoException
*/
@ApiOperation(value = "修改", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "adxSspFinanceManagement", required = true, dataType = "AdxSspFinanceManagement", paramType = "body") })
@RequestMapping(value = "/update", method = RequestMethod.POST)
public void update(@RequestBody AdxSspFinanceManagement adxSspFinanceManagement) throws DaoException {
LOG.info("adxSspFinanceManagement:{}", adxSspFinanceManagement);
adxSspFinanceManagementService.updateNotNullField(adxSspFinanceManagement);
}
/**
* 删除
*
* @date 2016年9月29日 下午7:27:57
*
* @param id
* @return 删除了多少条
* @throws DaoException
*/
@ApiOperation(value = "删除", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "path") })
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public RestResponse delete(@PathVariable Long id) throws DaoException {
RestResponse restResponse = new RestResponse();
restResponse.setStatus(RestResponse.OK);
int i = adxSspFinanceManagementService.deleteById(id);
LOG.info("the number of delete:{}", i);
restResponse.setResult(i);
return restResponse;
}
/**
* 批量删除
*
* @date 2016年9月29日 下午7:29:22
*
* @param id
* @return 删除了多少条
* @throws DaoException
*/
@ApiOperation(value = "删除", httpMethod = "POST", response = RestResponse.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "id", required = true, dataType = "Long", paramType = "path") })
@RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
public RestResponse batchDelete(@RequestBody List<Long> ids) throws DaoException {
RestResponse restResponse = new RestResponse();
int i = adxSspFinanceManagementService.batchDelete(ids);
restResponse.setStatus(RestResponse.OK);
restResponse.setResult(i);
LOG.info("the number of delete:{}", i);
return restResponse;
}
}