|
@@ -0,0 +1,127 @@
|
|
|
+package com.txz.operating.controller;
|
|
|
+
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.txz.operating.core.ResultCode;
|
|
|
+import com.txz.operating.model.Config;
|
|
|
+import com.txz.operating.result.Result;
|
|
|
+import com.txz.operating.service.ConfigService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Api(tags = "配置接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping(value = "/config")
|
|
|
+public class ConfigController {
|
|
|
+
|
|
|
+ private static Logger log = LoggerFactory.getLogger(ConfigController.class);
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ConfigService configService;
|
|
|
+
|
|
|
+ @ApiOperation("根据code拿值")
|
|
|
+ @GetMapping(value = "/getConfigByCode")
|
|
|
+ public Result getConfigByCode(@RequestParam String code) {
|
|
|
+ return configService.getConfigByCode(code);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ @ApiOperation(value = "config新增")
|
|
|
+ public Result add(@RequestBody Config config) {
|
|
|
+ if (config == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+// config.setCreateTime(new Date());
|
|
|
+// config.setCreateUserId(userId);
|
|
|
+ configService.save(config);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("新增对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ @ApiOperation(value = "config删除")
|
|
|
+ public Result delete(@RequestParam Integer id) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Config config = new Config();
|
|
|
+ config.setId(id);
|
|
|
+// config.setIsDelete(1);
|
|
|
+ configService.update(config);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("删除对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ @ApiOperation(value = "config更新")
|
|
|
+ public Result update(@RequestBody Config config) {
|
|
|
+ if (config == null) {
|
|
|
+ return Result.fail(ResultCode.OBJECT_IS_NULL);
|
|
|
+ }
|
|
|
+ if (config.getId() == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+// config.setUpdateTime(new Date());
|
|
|
+// config.setUpdateUserId(userId);
|
|
|
+ configService.update(config);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("更新对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/detail")
|
|
|
+ @ApiOperation(value = "config获取详情")
|
|
|
+ public Result<Config> detail(@RequestParam Long id) {
|
|
|
+ if (id == null) {
|
|
|
+ return Result.fail(ResultCode.ID_IS_NULL);
|
|
|
+ }
|
|
|
+ Config config = null;
|
|
|
+ try {
|
|
|
+ config = configService.findById(id);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ @ApiOperation(value = "config获取列表")
|
|
|
+ public Result<List<Config>> list(@RequestBody Config config, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ PageHelper.startPage(page, size);
|
|
|
+
|
|
|
+ Condition condition = new Condition(config.getClass());
|
|
|
+ Example.Criteria criteria = condition.createCriteria();
|
|
|
+ criteria.andEqualTo("isDelete", 0);
|
|
|
+ condition.setOrderByClause("create_time DESC");
|
|
|
+ PageInfo pageInfo = null;
|
|
|
+ try {
|
|
|
+ List<Config> list = configService.findByCondition(condition);
|
|
|
+ pageInfo = new PageInfo(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询对象操作异常e:{}", e);
|
|
|
+ return Result.fail(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ return Result.success(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|