Browse Source

refactor: 使用mybatis-plus重构接口回传设置

master
李永德 3 months ago
parent
commit
0af6c82df2
  1. 59
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/controller/InterfaceBackController.java
  2. 4
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/package-info.java
  3. 57
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/IInterfaceBackService.java
  4. 57
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/InterfaceBack.java
  5. 11
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/mapper/InterfaceBackMapper.java
  6. 5
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/mapper/InterfaceBackMapper.xml
  7. 87
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/impl/InterfaceBackServiceImpl.java
  8. 2
      lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/rest/InterfacebackController.java
  9. 17
      lms/nladmin-ui/src/views/wms/basedata/master/interfaceback/index.vue

59
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/controller/InterfaceBackController.java

@ -0,0 +1,59 @@
package org.nl.wms.basedata.master.interfaceback.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.modules.logging.annotation.Log;
import org.nl.wms.basedata.master.interfaceback.service.IInterfaceBackService;
import org.nl.wms.basedata.master.interfaceback.service.dao.InterfaceBack;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @Author: lyd
* @Date: 2024/10/15
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/interfaceback")
@Slf4j
public class InterfaceBackController {
@Autowired
private IInterfaceBackService interfaceBackService;
@GetMapping
@Log("查询接口回传设置")
//@SaCheckPermission("@el.check('interfaceback:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, PageQuery page) {
return new ResponseEntity<>(TableDataInfo.build(interfaceBackService.queryAll(whereJson, page)), HttpStatus.OK);
}
@PostMapping
@Log("新增接口回传设置")
//@SaCheckPermission("@el.check('interfaceback:add')")
public ResponseEntity<Object> create(@Validated @RequestBody InterfaceBack dto) {
interfaceBackService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改接口回传设置")
//@SaCheckPermission("@el.check('interfaceback:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody InterfaceBack dto) {
interfaceBackService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除接口回传设置")
//@SaCheckPermission("@el.check('interfaceback:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody String[] ids) {
interfaceBackService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

4
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/package-info.java

@ -0,0 +1,4 @@
/**
* 接口回传
*/
package org.nl.wms.basedata.master.interfaceback;

57
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/IInterfaceBackService.java

@ -0,0 +1,57 @@
package org.nl.wms.basedata.master.interfaceback.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.basedata.master.interfaceback.service.dao.InterfaceBack;
import org.nl.wms.basedata.master.service.dto.InterfacebackDto;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* 接口回传
* @Author: lyd
* @Date: 2024/10/15
*/
public interface IInterfaceBackService extends IService<InterfaceBack> {
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
IPage<InterfaceBack> queryAll(Map whereJson, PageQuery page);
/**
* 根据编码查询
*
* @param code code
* @return Interfaceback
*/
InterfaceBack findByCode(String code);
/**
* 创建
*
* @param dto /
*/
void create(InterfaceBack dto);
/**
* 编辑
*
* @param dto /
*/
void update(InterfaceBack dto);
/**
* 多选删除
*
* @param ids /
*/
void deleteAll(String[] ids);
}

57
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/InterfaceBack.java

@ -0,0 +1,57 @@
package org.nl.wms.basedata.master.interfaceback.service.dao;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
/**
* @Author: lyd
* @Date: 2024/10/15
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("md_pb_interfaceback")
public class InterfaceBack {
/** 标识 */
/**
* 防止精度丢失
*/
@TableId
private String interface_id;
/**
* 类型
*/
private String interface_type;
/**
* 接口名称
*/
private String interface_name;
/**
* 接口描述
*/
private String remark;
/**
* 是否回传
*/
private String is_back;
/**
* 业务说明
*/
private String business_comment;
/**
* 业务说明
*/
private String product_area;
@TableField(exist = false)
private String[] product_areas;
}

11
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/mapper/InterfaceBackMapper.java

@ -0,0 +1,11 @@
package org.nl.wms.basedata.master.interfaceback.service.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.nl.wms.basedata.master.interfaceback.service.dao.InterfaceBack;
/**
* @Author: lyd
* @Date: 2024/10/15
*/
public interface InterfaceBackMapper extends BaseMapper<InterfaceBack> {
}

5
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/dao/mapper/InterfaceBackMapper.xml

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.nl.wms.basedata.master.interfaceback.service.dao.mapper.InterfaceBackMapper">
</mapper>

87
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/interfaceback/service/impl/InterfaceBackServiceImpl.java

@ -0,0 +1,87 @@
package org.nl.wms.basedata.master.interfaceback.service.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.nl.common.domain.query.PageQuery;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.wms.basedata.master.interfaceback.service.IInterfaceBackService;
import org.nl.wms.basedata.master.interfaceback.service.dao.InterfaceBack;
import org.nl.wms.basedata.master.interfaceback.service.dao.mapper.InterfaceBackMapper;
import org.nl.wms.basedata.master.service.dto.InterfacebackDto;
import org.nl.wms.basedata.master.standard.service.dao.ClassStandard;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Author: lyd
* @Date: 2024/10/15
*/
@Service
public class InterfaceBackServiceImpl extends ServiceImpl<InterfaceBackMapper, InterfaceBack> implements IInterfaceBackService {
@Autowired
private InterfaceBackMapper interfaceBackMapper;
@Override
public IPage<InterfaceBack> queryAll(Map whereJson, PageQuery page) {
String interface_name = MapUtil.getStr(whereJson, "interface_name");
LambdaQueryWrapper<InterfaceBack> lam = new QueryWrapper<InterfaceBack>().lambda();
lam.like(ObjectUtil.isNotEmpty(interface_name), InterfaceBack::getInterface_name, interface_name);
IPage<InterfaceBack> pages = new Page<>(page.getPage() + 1, page.getSize());
interfaceBackMapper.selectPage(pages, lam);
pages.getRecords().forEach(ib -> {
if (ObjectUtil.isEmpty(ib.getProduct_area())) {
return;
}
String product_area = (ib.getProduct_area().replace("[", "").replace("]", "")).replaceAll("\\\"", "");
ib.setProduct_areas(product_area.split(","));
});
return pages;
}
@Override
public InterfaceBack findByCode(String code) {
LambdaQueryWrapper<InterfaceBack> lam = new LambdaQueryWrapper<>();
lam.eq(InterfaceBack::getInterface_name, code);
InterfaceBack one = getOne(lam);
if (ObjectUtil.isNotEmpty(one.getProduct_area())) {
String product_area = (one.getProduct_area().replace("[", "").replace("]", "")).replaceAll("\\\"", "");
one.setProduct_areas(product_area.split(","));
}
return one;
}
@Override
public void create(InterfaceBack dto) {
dto.setInterface_id(IdUtil.getSnowflake(1, 1).nextIdStr());
String result = Arrays.toString(dto.getProduct_areas());
result = result.replaceAll(" ", "");
dto.setProduct_area(result);
interfaceBackMapper.insert(dto);
}
@Override
public void update(InterfaceBack dto) {
InterfaceBack entity = this.getById(dto.getInterface_id());
if (entity == null) {
throw new BadRequestException("被删除或无权限,操作失败!");
}
String result = Arrays.toString(dto.getProduct_areas());
result = result.replaceAll(" ", "");
dto.setProduct_area(result);
interfaceBackMapper.updateById(dto);
}
@Override
public void deleteAll(String[] ids) {
removeByIds(Arrays.asList(ids));
}
}

2
lms/nladmin-system/src/main/java/org/nl/wms/basedata/master/rest/InterfacebackController.java

@ -21,7 +21,7 @@ import java.util.Map;
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/interfaceback")
@RequestMapping("/api/interfaceback2")
@Slf4j
public class InterfacebackController {

17
lms/nladmin-ui/src/views/wms/basedata/master/interfaceback/index.vue

@ -71,7 +71,7 @@
<el-col :span="24">
<el-form-item label="回传区域">
<el-select
v-model="form.product_area"
v-model="form.product_areas"
clearable
multiple
size="mini"
@ -91,7 +91,7 @@
<el-row>
<el-col :span="24">
<el-form-item label="业务说明">
<el-input type="textarea" :rows="2" v-model="form.business_comment" style="width: 550px;" />
<el-input v-model="form.business_comment" type="textarea" :rows="2" style="width: 550px;" />
</el-form-item>
</el-col>
</el-row>
@ -105,10 +105,10 @@
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
<el-table-column type="selection" width="55" />
<el-table-column prop="interface_type" label="回传类型" :formatter="formatType" :min-width="flexWidth('interface_type',crud.data,'回传类型')" />
<el-table-column prop="interface_name" label="接口名称" :min-width="flexWidth('interface_name',crud.data,'接口名称')"/>
<el-table-column prop="is_back" label="是否回传" :formatter="formatBack" :min-width="flexWidth('is_back',crud.data,'是否回传')"/>
<el-table-column prop="remark" label="接口描述" :min-width="flexWidth('remark',crud.data,'接口描述')"/>
<el-table-column prop="business_comment" label="业务说明" :min-width="flexWidth('business_comment',crud.data,'业务说明')"/>
<el-table-column prop="interface_name" label="接口名称" :min-width="flexWidth('interface_name',crud.data,'接口名称')" />
<el-table-column prop="is_back" label="是否回传" :formatter="formatBack" :min-width="flexWidth('is_back',crud.data,'是否回传')" />
<el-table-column prop="remark" label="接口描述" :min-width="flexWidth('remark',crud.data,'接口描述')" />
<el-table-column prop="business_comment" label="业务说明" :min-width="flexWidth('business_comment',crud.data,'业务说明')" />
<el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
<template slot-scope="scope">
<udOperation
@ -139,7 +139,8 @@ const defaultForm = {
remark: null,
is_back: null,
business_comment: null,
product_area: null
product_area: null,
product_areas: null
}
export default {
name: 'Interfaceback',
@ -176,7 +177,7 @@ export default {
is_back: [
{ required: true, message: '是否回传不能为空', trigger: 'blur' }
]
} }
}}
},
methods: {
// false

Loading…
Cancel
Save