-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from WeBankFinTech/dev
v1.3.1 dev => master
- Loading branch information
Showing
85 changed files
with
3,359 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/main/java/com/webank/webase/node/mgr/abi/AbiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* Copyright 2014-2020 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.webank.webase.node.mgr.abi; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.webank.webase.node.mgr.abi.entity.AbiInfo; | ||
import com.webank.webase.node.mgr.abi.entity.ReqAbiListParam; | ||
import com.webank.webase.node.mgr.abi.entity.ReqImportAbi; | ||
import com.webank.webase.node.mgr.base.code.ConstantCode; | ||
import com.webank.webase.node.mgr.base.controller.BaseController; | ||
import com.webank.webase.node.mgr.base.entity.BasePageResponse; | ||
import com.webank.webase.node.mgr.base.entity.BaseResponse; | ||
import com.webank.webase.node.mgr.base.enums.SqlSortType; | ||
import com.webank.webase.node.mgr.base.properties.ConstantProperties; | ||
import lombok.extern.log4j.Log4j2; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Log4j2 | ||
@RestController | ||
@RequestMapping("abi") | ||
public class AbiController extends BaseController { | ||
@Autowired | ||
AbiService abiService; | ||
|
||
@GetMapping("/list/{groupId}/{pageNumber}/{pageSize}") | ||
public Object listAbi( | ||
@PathVariable("groupId") Integer groupId, | ||
@PathVariable("pageNumber") Integer pageNumber, | ||
@PathVariable("pageSize") Integer pageSize) { | ||
Instant startTime = Instant.now(); | ||
if (pageNumber < 1 || pageSize <= 0) { | ||
return new BaseResponse(ConstantCode.PARAM_EXCEPTION); | ||
} | ||
log.info("start listAbi. startTime:{},groupId:{},pageNumber:{},pageSize:{}", | ||
startTime.toEpochMilli(), groupId, pageNumber, pageSize); | ||
|
||
Integer start = Optional.ofNullable(pageNumber).map(page -> (page - 1) * pageSize) | ||
.orElse(0); | ||
ReqAbiListParam param = new ReqAbiListParam(start, pageSize, | ||
SqlSortType.DESC.getValue()); | ||
param.setGroupId(groupId); | ||
List<AbiInfo> resList = abiService.getListByGroupId(param); | ||
// total count | ||
int count = abiService.countOfAbi(); | ||
|
||
log.info("end listAbi. useTime:{}, resList:{}", | ||
Duration.between(startTime, Instant.now()).toMillis(), resList); | ||
return new BasePageResponse(ConstantCode.SUCCESS, resList, count); | ||
} | ||
|
||
@GetMapping("/{abiId}") | ||
public Object getAbiById(@PathVariable("abiId") Integer abiId) { | ||
Instant startTime = Instant.now(); | ||
log.info("start getAbiById. startTime:{} abiId:{}", | ||
startTime.toEpochMilli(), abiId); | ||
AbiInfo res = abiService.getAbiById(abiId); | ||
log.info("end getAbiById. useTime:{}, res:{}", | ||
Duration.between(startTime, Instant.now()).toMillis(), res); | ||
return new BaseResponse(ConstantCode.SUCCESS, res); | ||
} | ||
|
||
@PostMapping("") | ||
@PreAuthorize(ConstantProperties.HAS_ROLE_ADMIN) | ||
public Object saveAbi(@Valid @RequestBody ReqImportAbi param, BindingResult result) { | ||
checkBindResult(result); | ||
Instant startTime = Instant.now(); | ||
log.info("start saveAbi. startTime:{} ReqImportAbi:{}", | ||
startTime.toEpochMilli(), JSON.toJSONString(param)); | ||
abiService.saveAbi(param); | ||
log.info("end saveAbi. useTime:{}", | ||
Duration.between(startTime, Instant.now()).toMillis()); | ||
return new BaseResponse(ConstantCode.SUCCESS); | ||
} | ||
|
||
/** | ||
* @param param abiId is not empty to update | ||
* @return | ||
*/ | ||
@PutMapping("") | ||
@PreAuthorize(ConstantProperties.HAS_ROLE_ADMIN) | ||
public Object updateAbi(@RequestBody ReqImportAbi param, BindingResult result) { | ||
checkBindResult(result); | ||
Instant startTime = Instant.now(); | ||
log.info("start updateAbi. startTime:{} ReqImportAbi:{}", | ||
startTime.toEpochMilli(), JSON.toJSONString(param)); | ||
if(param.getAbiId() == null) { | ||
return new BaseResponse(ConstantCode.PARAM_FAIL_ABI_ID_EMPTY); | ||
} | ||
abiService.saveAbi(param); | ||
AbiInfo res = abiService.getAbiById(param.getAbiId()); | ||
log.info("end updateAbi. useTime:{}, res:{}", | ||
Duration.between(startTime, Instant.now()).toMillis(), res); | ||
return new BaseResponse(ConstantCode.SUCCESS, res); | ||
} | ||
|
||
@DeleteMapping("/{abiId}") | ||
@PreAuthorize(ConstantProperties.HAS_ROLE_ADMIN) | ||
public BaseResponse deleteAbi(@PathVariable("abiId") Integer abiId) { | ||
log.debug("start deleteAbi. abiId:{}", abiId); | ||
abiService.delete(abiId); | ||
log.debug("end deleteAbi"); | ||
return new BaseResponse(ConstantCode.SUCCESS); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/webank/webase/node/mgr/abi/AbiMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright 2014-2020 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.webank.webase.node.mgr.abi; | ||
|
||
import com.webank.webase.node.mgr.abi.entity.AbiInfo; | ||
import com.webank.webase.node.mgr.abi.entity.ReqAbiListParam; | ||
import org.apache.ibatis.annotations.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface AbiMapper { | ||
|
||
List<AbiInfo> listOfAbi(@Param("param") ReqAbiListParam param); | ||
|
||
Integer countOfAbi(); | ||
|
||
AbiInfo queryByAbiId(@Param("abiId") int abiId); | ||
|
||
AbiInfo queryByGroupIdAndAddress(@Param("groupId") int groupId, | ||
@Param("contractAddress") String contractAddress); | ||
|
||
AbiInfo queryByGroupIdAndContractName(@Param("groupId") int groupId, | ||
@Param("contractName") String contractName); | ||
void add(AbiInfo abiInfo); | ||
|
||
void update(AbiInfo abiInfo); | ||
|
||
void deleteByAbiId(@Param("abiId") int abiId); | ||
} |
Oops, something went wrong.