新增APP的字典接口

This commit is contained in:
wenc000 2020-04-02 09:46:33 +08:00
parent 75d06e7ed6
commit a04ebf7829
3 changed files with 232 additions and 10 deletions

View File

@ -0,0 +1,148 @@
package com.cm.common.plugin.controller.app.datadictionary;
import com.cm.common.annotation.CheckRequestBodyAnnotation;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.SearchException;
import com.cm.common.plugin.pojo.dtos.datadictionary.DataDictionaryDTO;
import com.cm.common.plugin.pojo.vos.datadictionary.DataDictionaryVO;
import com.cm.common.plugin.service.datadictionary.IDataDictionaryService;
import com.cm.common.pojo.ListPage;
import com.cm.common.pojo.dtos.ZTreeDTO;
import com.cm.common.result.ErrorResult;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;
import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* When you feel like quitting. Think about why you started
* 当你想要放弃的时候想想当初你为何开始
*
* @ClassName: DictionaryController
* @Description: 字典
* @Author: WangGeng
* @Date: 2019/11/18 14:00
* @Version: 1.0
**/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "字典管理接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/datadictionary")
public class DataDictionaryAppController extends AbstractController {
@Autowired
private IDataDictionaryService dataDictionaryService;
@ApiOperation(value = "字典新增", notes = "字典新增接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("savedictionary")
@CheckRequestBodyAnnotation
public SuccessResult saveDictionary(@RequestHeader("token") String token, @RequestBody DataDictionaryVO dictionaryVO) throws Exception {
return dataDictionaryService.saveDictionary(token, dictionaryVO);
}
@ApiOperation(value = "字典删除", notes = "通过id列表批量删除字典接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "ids", value = "字典ID列表用下划线分隔", paramType = "path", example = "1_2_3")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@DeleteMapping("removedictionary/{ids}")
public SuccessResult removeDictionary(@RequestHeader("token") String token, @PathVariable("ids") String ids) {
return dataDictionaryService.removeDictionary(token, ids);
}
@ApiOperation(value = "字典修改", notes = "字典修改接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "dictionaryId", value = "字典ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PutMapping("updatedictionary/{dictionaryId}")
@CheckRequestBodyAnnotation
public SuccessResult updateDictionary(@RequestHeader("token") String token, @PathVariable("dictionaryId") String dictionaryId, @RequestBody DataDictionaryVO dictionaryVO) throws Exception {
return dataDictionaryService.updateDictionary(token, dictionaryId, dictionaryVO);
}
@ApiOperation(value = "字典详情ID查询", notes = "字典详情ID查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "dictionaryId", value = "字典ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("getdictionarybyid/{dictionaryId}")
public DataDictionaryDTO getDictionaryById(@RequestHeader("token") String token, @PathVariable("dictionaryId") String dictionaryId) {
return dataDictionaryService.getDictionaryById(dictionaryId);
}
@ApiOperation(value = "字典列表上级ID查询", notes = "字典列表上级ID查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "dictionaryParentId", value = "字典上级ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdictionarybyparentid/{dictionaryParentId}")
public List<DataDictionaryDTO> listDictionaryByParentId(@RequestHeader("token") String token, @PathVariable("dictionaryParentId") String dictionaryParentId) {
return dataDictionaryService.listDictionaryByParentId(dictionaryParentId);
}
@ApiOperation(value = "字典全部列表上级ID查询", notes = "字典全部列表上级ID查询接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "dictionaryParentId", value = "字典上级ID", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listdictionaryallbyparentid/{dictionaryParentId}")
public List<DataDictionaryDTO> listDictionary(@RequestHeader("token") String token, @PathVariable("dictionaryParentId") String dictionaryParentId) throws SearchException {
return dataDictionaryService.listDictionaryAllByParentId(dictionaryParentId);
}
@ApiOperation(value = "分页字典列表", notes = "分页字典列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "parentId", value = "上级ID", paramType = "form", dataType = "String"),
@ApiImplicitParam(name = "page", value = "当前页码", paramType = "form", dataType = "Integer", defaultValue = "1"),
@ApiImplicitParam(name = "rows", value = "显示数量", paramType = "form", dataType = "Integer", defaultValue = "20"),
@ApiImplicitParam(name = "keywords", value = "关键字", paramType = "form", dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "form", dataType = "String"),
@ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "form", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listpagedictionary")
public SuccessResultList<List<DataDictionaryDTO>> listPageDictionary(@RequestHeader("token") String token, ListPage page) {
Map<String, Object> params = requestParams();
String dictionaryParentId = "0";
if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_PARENT_ID) == null ? null : params.get(ISystemConstant.PARAMS_PARENT_ID).toString())) {
dictionaryParentId = params.get(ISystemConstant.PARAMS_PARENT_ID).toString();
}
params.put("dictionaryParentId", dictionaryParentId);
page.setParams(params);
return dataDictionaryService.listPageDictionary(page);
}
@ApiOperation(value = "zTree列表", notes = "zTree列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "token", paramType = "header"),
@ApiImplicitParam(name = "id", value = "父ID", paramType = "form", dataType = "String")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("listztreedictionary")
public List<ZTreeDTO> listZTreeDictionary(@RequestHeader("token") String token) throws SearchException {
Map<String, Object> params = requestParams();
String dictionaryParentId = "0";
if (!StringUtils.isBlank(params.get(ISystemConstant.PARAMS_ID) == null ? null : params.get(ISystemConstant.PARAMS_ID).toString())) {
dictionaryParentId = params.get(ISystemConstant.PARAMS_ID).toString();
}
params.put("dictionaryParentId", dictionaryParentId);
return dataDictionaryService.listZTreeDictionary(params);
}
}

View File

@ -30,10 +30,20 @@ public interface IDataDictionaryService {
*
* @param dictionaryVO
* @return
* @throws SaveException
* @throws Exception
*/
SuccessResult saveDictionary(DataDictionaryVO dictionaryVO) throws Exception;
/**
* 字典新增
*
* @param token
* @param dictionaryVO
* @return
* @throws Exception
*/
SuccessResult saveDictionary(String token, DataDictionaryVO dictionaryVO) throws Exception;
/**
* 字典删除
*
@ -43,16 +53,37 @@ public interface IDataDictionaryService {
*/
SuccessResult removeDictionary(String ids) throws RemoveException;
/**
* 字典删除
*
* @param token
* @param ids
* @return
* @throws RemoveException
*/
SuccessResult removeDictionary(String token, String ids) throws RemoveException;
/**
* 字典修改
*
* @param dictionaryId
* @param dictionaryVO
* @return
* @throws UpdateException
* @throws Exception
*/
SuccessResult updateDictionary(String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception;
/**
* 字典修改
*
* @param token
* @param dictionaryId
* @param dictionaryVO
* @return
* @throws Exception
*/
SuccessResult updateDictionary(String token, String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception;
/**
* 通过ID获取字典
*
@ -98,4 +129,5 @@ public interface IDataDictionaryService {
*/
List<ZTreeDTO> listZTreeDictionary(Map<String, Object> params) throws SearchException;
}

View File

@ -42,6 +42,17 @@ public class DataDictionaryServiceImpl extends AbstractService implements IDataD
@Override
public SuccessResult saveDictionary(DataDictionaryVO dictionaryVO) throws Exception {
saveDictionaryInfo(null, dictionaryVO);
return new SuccessResult();
}
@Override
public SuccessResult saveDictionary(String token, DataDictionaryVO dictionaryVO) throws Exception {
saveDictionaryInfo(token, dictionaryVO);
return new SuccessResult();
}
private void saveDictionaryInfo(String token, DataDictionaryVO dictionaryVO) throws Exception {
String parentCode = null;
String dictionaryParentId = dictionaryVO.getDictionaryParentId();
if (!StringUtils.equals(dictionaryParentId, ISystemConstant.TREE_BASE_ROOT_ID_VALUE)) {
@ -52,27 +63,58 @@ public class DataDictionaryServiceImpl extends AbstractService implements IDataD
Map<String, Object> params = HashMapUtil.beanToMap(dictionaryVO);
params.put("dictionaryCode", dictionaryCode);
params.put("dictionaryId", UUIDUtil.getUUID());
setSaveInfo(params);
if (StringUtils.isBlank(token)) {
setSaveInfo(params);
} else {
setSaveInfo(token, params);
}
dictionaryDao.saveDictionary(params);
return new SuccessResult();
}
@Override
public SuccessResult removeDictionary(String ids) throws RemoveException {
Map<String, Object> params = getHashMap(3);
params.put("dictionaryIds", Arrays.asList(ids.split("_")));
setUpdateInfo(params);
dictionaryDao.removeDictionary(params);
removeDictionaryInfo(null, ids);
return new SuccessResult();
}
@Override
public SuccessResult removeDictionary(String token, String ids) throws RemoveException {
removeDictionaryInfo(token, ids);
return new SuccessResult();
}
private void removeDictionaryInfo(String token, String ids) {
Map<String, Object> params = getHashMap(3);
params.put("dictionaryIds", Arrays.asList(ids.split("_")));
if (StringUtils.isBlank(token)) {
setUpdateInfo(params);
} else {
setUpdateInfo(token, params);
}
dictionaryDao.removeDictionary(params);
}
@Override
public SuccessResult updateDictionary(String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception {
updateDictionaryInfo(null, dictionaryId, dictionaryVO);
return new SuccessResult();
}
@Override
public SuccessResult updateDictionary(String token, String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception {
updateDictionaryInfo(token, dictionaryId, dictionaryVO);
return new SuccessResult();
}
private void updateDictionaryInfo(String token, String dictionaryId, DataDictionaryVO dictionaryVO) throws Exception {
Map<String, Object> params = HashMapUtil.beanToMap(dictionaryVO);
params.put("dictionaryId", dictionaryId);
setUpdateInfo(params);
if (StringUtils.isBlank(token)) {
setUpdateInfo(params);
} else {
setUpdateInfo(token, params);
}
dictionaryDao.updateDictionary(params);
return new SuccessResult();
}
@Override