💗wei_shuo的个人主页
💫wei_shuo的学习社区
🌐Hello World !
增删改查
@RestController
@RequestMapping("system/mappingCode")
@Slf4j
@Api(tags = "系统管理 - 映射码")
public class SystemMappingCodeEndpoint {
@Resource
private SystemMappingCodeService systemMappingCodeService;
@PostMapping("add")
@ApiOperation("新增映射码")
@Logger(menu = "系统管理", action = "映射码")
public Result add(@RequestBody @Validated SystemMappingCodeAddVo request) {
systemMappingCodeService.add(request);
return Result.succ();
}
@PostMapping("getByID")
@ApiOperation("根据ID获取")
@Logger(menu = "系统管理", action = "映射码")
public Result<SystemMappingCodeResp> getByID(@RequestBody CommonRequestId request) {
SystemMappingCodeResp systemMappingCodeResp= systemMappingCodeService.getByID(request.getId());
return Result.succ(systemMappingCodeResp);
}
@PostMapping("update")
@ApiOperation("修改")
@Logger(menu = "系统管理", action = "映射码")
public Result<SystemMappingCodeResp> update(@RequestBody SystemMappingCodeResp request) {
systemMappingCodeService.update(request);
return Result.succ();
}
@PostMapping("bindAdd")
@ApiOperation("映射码配置应答码")
@Logger(menu = "系统管理", action = "映射码")
public Result bindSave(@RequestBody SystemMappingCodeBindListVo request) {
systemMappingCodeService.bindSaveOrUpdate(request);
return Result.succ();
}
@PostMapping("getBindCodeByID")
@ApiOperation("根据ID获取映射码绑定的应答码")
@Logger(menu = "系统管理", action = "映射码")
public Result<SystemMappingCodeBindListVo> getBindCodeByID(@RequestBody CommonRequestId request) {
SystemMappingCodeBindListVo addBindVo= systemMappingCodeService.getBindCodeByID(request.getId());
return Result.succ(addBindVo);
}
@GetMapping("list")
@ApiOperation("查询映射码")
public Result<PageResult<SystemMappingCodeResp>> list (SystemMappingCodeQuery query){
PageResult<SystemMappingCodeResp> list = systemMappingCodeService.list(query);
return Result.succ(list);
}
}
@Service
public class SystemMappingCodeService {
@Resource
private SystemMappingCodeRepo systemMappingCodeRepo;
@Resource
private SystemMappingCodeMapper systemMappingCodeMapper;
@Resource
private SystemMappingCodeBindRepo systemMappingCodeBindRepo;
@Resource
private SystemCompanyRepo systemCompanyRepo;
public void add(SystemMappingCodeAddVo request) {
SystemMappingCode one = systemMappingCodeRepo.getOne(new QueryWrapper<SystemMappingCode>().eq(SystemMappingCodeCol.CODE_RESP, request.getCodeResp()));
if (one != null){
throw new ManageException("该映射码已存在,不可进行重复添加");
}
SystemMappingCode systemMappingCode = new SystemMappingCode();
ConvertBeanUtils.copy(request, systemMappingCode);
systemMappingCode.setCreateAt(new Date());
systemMappingCodeRepo.save(systemMappingCode);
}
public SystemMappingCodeResp getByID(Long id) {
SystemMappingCode mappingCode = systemMappingCodeRepo.getById(id);
if (mappingCode == null){
throw new ManageException("该映射码信息不存在");
}
SystemMappingCodeResp resp = new SystemMappingCodeResp();
resp.setId(mappingCode.getId());
resp.setCodeResp(mappingCode.getCodeResp());
resp.setMerchantResp(mappingCode.getMerchantResp());
resp.setCardholderResp(mappingCode.getCardholderResp());
resp.setRemark(mappingCode.getRemark());
return resp;
}
public void update(SystemMappingCodeResp request){
List<SystemMappingCode> codeListExcludeCurrentId = systemMappingCodeRepo.list(new QueryWrapper<SystemMappingCode>().ne(SystemMappingCodeCol.ID, request.getId()));
List<SystemMappingCode> repeatCode = codeListExcludeCurrentId.stream().filter(bean -> bean.getCodeResp().equals(request.getCodeResp())).collect(Collectors.toList());
if (repeatCode.isEmpty()){
throw new ManageException("该映射码已存在,不可重复");
}
systemMappingCodeRepo.update(
new UpdateWrapper<SystemMappingCode>()
.set(SystemMappingCodeCol.CODE_RESP, request.getCodeResp())
.set(SystemMappingCodeCol.MERCHANT_RESP, request.getMerchantResp())
.set(SystemMappingCodeCol.CARDHOLDER_RESP, request.getCardholderResp())
.set(SystemMappingCodeCol.REMARK, request.getRemark())
.set(SystemMappingCodeCol.UPDATE_AT, new Date())
.eq(SystemMappingCodeCol.ID, request.getId())
);
}
public void bindSaveOrUpdate(SystemMappingCodeBindListVo request) {
//删除当前绑定列表
systemMappingCodeBindRepo.remove(new QueryWrapper<SystemMappingCodeBind>().eq(SystemMappingCodeBindCol.CODE_MAPPING_ID, request.getCodeMappingId()));
HashMap<Long, Date> stringDateHashMap = new HashMap<>();
List<SystemMappingCodeBindVo> requestList = request.getList();
List<SystemMappingCodeBind> addList = new ArrayList<>();
if (requestList.isEmpty()) {
throw new ManageException("应答码列表为空,不可进行操作");
}
checkMappingCodeList(requestList);
List<Long> requestIds = requestList.stream().map(SystemMappingCodeBindVo::getId).collect(Collectors.toList());
List<SystemMappingCodeBind> systemMappingCodeBinds = systemMappingCodeBindRepo.listByIds(requestIds);
for (SystemMappingCodeBind bean : systemMappingCodeBinds){
stringDateHashMap.put(bean.getId(),bean.getCreateAt());
}
for (SystemMappingCodeBindVo bean : requestList) {
SystemMappingCodeBind systemMappingCodeBind = new SystemMappingCodeBind();
ConvertBeanUtils.copy(bean, systemMappingCodeBind);
systemMappingCodeBind.setCodeMappingId(request.getCodeMappingId());
if (request.getIsAdd()) {
systemMappingCodeBind.setCreateAt(new Date());
} else {
systemMappingCodeBind.setCreateAt(stringDateHashMap.get(bean.getId()));
systemMappingCodeBind.setUpdateAt(new Date());
}
addList.add(systemMappingCodeBind);
}
systemMappingCodeBindRepo.saveBatch(addList);
}
private void checkMappingCodeList(List<SystemMappingCodeBindVo> request) {
HashMap<String, String> errorMessageMap = new HashMap<>();
for (SystemMappingCodeBindVo bean : request) {
QueryWrapper<SystemMappingCodeBind> wrapper = new QueryWrapper<SystemMappingCodeBind>()
.eq(SystemMappingCodeBindCol.COMPANY_CODE, bean.getCompanyCode())
.eq(SystemMappingCodeBindCol.RESPONSE_CODE, bean.getResponseCode());
SystemMappingCodeBind one = systemMappingCodeBindRepo.getOne(wrapper);
if (one != null) {
SystemCompany company = systemCompanyRepo.getOne(new QueryWrapper<SystemCompany>().eq(SystemCompanyCol.COMPANY_CODE, bean.getCompanyCode()));
errorMessageMap.put(company.getCompanyName() + "---" + bean.getResponseCode(), "该应答码已存在于其他映射码,不可进行重复添加");
}
}
if (!errorMessageMap.isEmpty()){
throw new ManageException(JsonMapper.objectToJson(errorMessageMap));
}
}
public PageResult<SystemMappingCodeResp> list(SystemMappingCodeQuery query) {
SystemMappingCodeQueryBo convert = SystemMappingCodeQueryBo.convert(query);
List<SystemMappingCodeResp> collect = systemMappingCodeMapper.queryList(convert);
return PageResult.<SystemMappingCodeResp>builder().pageNo(Integer.parseInt(query.getPageNo()))
.pageSize(Integer.parseInt(query.getPageSize()))
.total(systemMappingCodeMapper.getTotal(convert)).items(collect).build();
}
public SystemMappingCodeBindListVo getBindCodeByID(Long id) {
QueryWrapper<SystemMappingCodeBind> wrapper = new QueryWrapper<SystemMappingCodeBind>()
.eq(SystemMappingCodeBindCol.CODE_MAPPING_ID, id);
List<SystemMappingCodeBind> list = systemMappingCodeBindRepo.list(wrapper);
List<SystemMappingCodeBindVo> listResp = list.stream()
.map(codeBind -> {
SystemMappingCodeBindVo codeBindVo = new SystemMappingCodeBindVo();
codeBindVo.setId(codeBind.getId());
codeBindVo.setCompanyCode(codeBind.getCompanyCode());
codeBindVo.setResponseCode(codeBind.getResponseCode());
codeBindVo.setResponseCodeDescription(codeBind.getResponseCodeDescription());
return codeBindVo;
})
.collect(Collectors.toList());
SystemMappingCodeBindListVo resp = new SystemMappingCodeBindListVo();
resp.setCodeMappingId(id);
resp.setList(listResp);
return resp;
}
}
🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——
点赞
👍收藏
⭐️评论
📝