|
@@ -0,0 +1,235 @@
|
|
|
+package edp.davinci.controller;
|
|
|
+
|
|
|
+import edp.core.annotation.AuthIgnore;
|
|
|
+import edp.core.annotation.CurrentUser;
|
|
|
+import edp.davinci.common.controller.BaseController;
|
|
|
+import edp.davinci.core.common.Constants;
|
|
|
+import edp.davinci.core.common.ResultMap;
|
|
|
+import edp.davinci.model.*;
|
|
|
+import edp.davinci.service.DictService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.ApiResponse;
|
|
|
+import io.swagger.annotations.ApiResponses;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import springfox.documentation.annotations.ApiIgnore;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Api(value = "/dict", tags = "dict", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
+@ApiResponses(@ApiResponse(code = 404, message = "dict not found"))
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = Constants.BASE_API_PATH + "/dict", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
+public class DictController extends BaseController
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private DictService dictService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字典类型列表
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "get dict type")
|
|
|
+ @GetMapping(value = "/dictTypes")
|
|
|
+ public ResponseEntity dictTypes(
|
|
|
+ HttpServletRequest request)
|
|
|
+ {
|
|
|
+ List<DictType> dictTypes = dictService.getDictType();
|
|
|
+ return ResponseEntity.ok(dictTypes);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字典数据
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "get dict data")
|
|
|
+ @GetMapping(value = "/dictDatas")
|
|
|
+ public ResponseEntity dictDatas(@RequestParam String dictType,
|
|
|
+ HttpServletRequest request)
|
|
|
+ {
|
|
|
+ List<DictData> dictDataList = dictService.getDictData(dictType);
|
|
|
+ return ResponseEntity.ok(dictDataList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建字典类型
|
|
|
+ *
|
|
|
+ * @param dictType
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "create dict type", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/createDictType",consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public ResponseEntity createDictType(@RequestBody DictType dictType,
|
|
|
+ HttpServletRequest request)
|
|
|
+ {
|
|
|
+
|
|
|
+ DictType record = dictService.createDictType(dictType);
|
|
|
+
|
|
|
+ return ResponseEntity.ok(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建字典数据
|
|
|
+ *
|
|
|
+ * @param dictData
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "create dict data", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/createDictData",consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public ResponseEntity createDictData(@RequestBody DictData dictData,
|
|
|
+ HttpServletRequest request)
|
|
|
+ {
|
|
|
+
|
|
|
+ DictData record = dictService.createDictData(dictData);
|
|
|
+ return ResponseEntity.ok(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取dict type 信息
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param user
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "get dict type detail")
|
|
|
+ @GetMapping("/getDictTypeDetail/{id}")
|
|
|
+ public ResponseEntity getDictTypeDetail(@PathVariable Long id,
|
|
|
+ @ApiIgnore @CurrentUser User user,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ if (invalidId(id)) {
|
|
|
+ ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid project id");
|
|
|
+ return ResponseEntity.status(resultMap.getCode()).body(resultMap);
|
|
|
+ }
|
|
|
+ DictType sourceDetail = dictService.getDictTypeDetail(id);
|
|
|
+ return ResponseEntity.ok(sourceDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取dict data 信息
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param user
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "get dict data detail")
|
|
|
+ @GetMapping("/getDictDataDetail/{id}")
|
|
|
+ public ResponseEntity getDictDataDetail(@PathVariable Long id,
|
|
|
+ HttpServletRequest request) {
|
|
|
+ DictData sourceDetail = dictService.getDictDataDetail(id);
|
|
|
+ return ResponseEntity.ok(sourceDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新dictType
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param source
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "update a dictType", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PutMapping(value = "/updateDictType/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public ResponseEntity updateDictType(@PathVariable Long id,
|
|
|
+ @RequestBody DictType dictType,
|
|
|
+ HttpServletRequest request) {
|
|
|
+
|
|
|
+ if (invalidId(id) || !id.equals(dictType.getDictId())) {
|
|
|
+ ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid dictType id");
|
|
|
+ return ResponseEntity.status(resultMap.getCode()).body(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ dictService.updateDictType(dictType);
|
|
|
+ return ResponseEntity.ok("update success");
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 更新dictData
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param source
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "update a dictData", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PutMapping(value = "/updateDictData/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public ResponseEntity updateDictData(@PathVariable Long id,
|
|
|
+ @RequestBody DictData dictData,
|
|
|
+ HttpServletRequest request) {
|
|
|
+
|
|
|
+ if (invalidId(id) || !id.equals(dictData.getDictCode())) {
|
|
|
+ ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid dictData id");
|
|
|
+ return ResponseEntity.status(resultMap.getCode()).body(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ dictService.updateDictData(dictData);
|
|
|
+ return ResponseEntity.ok("update success");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除dicttype
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param user
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "delete a dicttype")
|
|
|
+ @DeleteMapping("/deleteDictType/{id}")
|
|
|
+ public ResponseEntity deleteDictType(@PathVariable Long id,
|
|
|
+ HttpServletRequest request) {
|
|
|
+
|
|
|
+ if (invalidId(id)) {
|
|
|
+ ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid dicttype id");
|
|
|
+ return ResponseEntity.status(resultMap.getCode()).body(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ dictService.deleteDictType(id);
|
|
|
+ return ResponseEntity.ok("delete success");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除dictdata
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @param user
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @AuthIgnore
|
|
|
+ @ApiOperation(value = "delete a dictdata")
|
|
|
+ @DeleteMapping("/deleteDictData/{id}")
|
|
|
+ public ResponseEntity deleteDictData(@PathVariable Long id,
|
|
|
+ HttpServletRequest request) {
|
|
|
+
|
|
|
+ if (invalidId(id)) {
|
|
|
+ ResultMap resultMap = new ResultMap(tokenUtils).failAndRefreshToken(request).message("Invalid dictdata id");
|
|
|
+ return ResponseEntity.status(resultMap.getCode()).body(resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ dictService.deleteDictData(id);
|
|
|
+ return ResponseEntity.ok("delete success");
|
|
|
+ }
|
|
|
+}
|