|
@@ -0,0 +1,115 @@
|
|
|
|
|
+package com.zhiqiyun.open.mvc.controller;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.zhiqiyun.open.annotation.Permission;
|
|
|
|
|
+import com.zhiqiyun.open.core.models.base.CategoryBase;
|
|
|
|
|
+import com.zhiqiyun.open.core.models.user.OauthInfo;
|
|
|
|
|
+import com.zhiqiyun.open.core.service.CategoryBaseExtendColumnService;
|
|
|
|
|
+import com.zhiqiyun.open.core.service.CategoryBaseService;
|
|
|
|
|
+import com.zhiqiyun.open.core.service.OauthService;
|
|
|
|
|
+import com.zhiqiyun.open.core.service.SequenceService;
|
|
|
|
|
+import com.zhiqiyun.open.mvc.Result;
|
|
|
|
|
+import com.zhiqiyun.open.mvc.params.base.QueryCategoryBaseParam;
|
|
|
|
|
+import com.zhiqiyun.open.mvc.params.base.SaveCategoryBaseParam;
|
|
|
|
|
+import com.zhiqiyun.open.utils.DateUtil;
|
|
|
|
|
+import com.zhiqiyun.open.utils.ServletContext;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
+
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/category/base")
|
|
|
|
|
+public class CategoryBaseController {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CategoryBaseService categoryBaseService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CategoryBaseExtendColumnService categoryBaseExtendColumnService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SequenceService sequenceService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OauthService oauthService;
|
|
|
|
|
+
|
|
|
|
|
+ @Permission(value = "category.base.find", tags = "查询基础数据分类")
|
|
|
|
|
+ @PostMapping("/findPage")
|
|
|
|
|
+ public Result findPage(@RequestBody QueryCategoryBaseParam param) {
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<CategoryBase> wrapper = new QueryWrapper<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(param.getName())) {
|
|
|
|
|
+ wrapper.like("name", param.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ Page<CategoryBase> page = param.getPage();
|
|
|
|
|
+ page.addOrder(OrderItem.asc("sort_number"));
|
|
|
|
|
+ page.addOrder(OrderItem.desc("id"));
|
|
|
|
|
+
|
|
|
|
|
+ Page<CategoryBase> resultData = this.categoryBaseService.page(page, wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ return Result.instance(Result.Code.SUCCESS).setData(resultData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Permission(value = "category.base.add", tags = "新建基础数据分类")
|
|
|
|
|
+ @PostMapping("/save")
|
|
|
|
|
+ public Result save(@Valid @RequestBody SaveCategoryBaseParam param) throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ CategoryBase entity = new CategoryBase();
|
|
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
|
|
+
|
|
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
|
|
+
|
|
|
|
|
+ if (param.getSortNumber() == null) {
|
|
|
|
|
+ entity.setSortNumber(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ entity.setCreatedTime(DateUtil.current());
|
|
|
|
|
+ entity.setCreatedBy(oauthInfo.getId());
|
|
|
|
|
+
|
|
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
|
|
+ entity.setId(this.sequenceService.nextId());
|
|
|
|
|
+
|
|
|
|
|
+ this.categoryBaseService.save(entity);
|
|
|
|
|
+
|
|
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Permission(value = "category.base.edit", tags = "更新基础数据分类")
|
|
|
|
|
+ @PostMapping("/updateById")
|
|
|
|
|
+ public Result updateById(Long id, @Valid @RequestBody SaveCategoryBaseParam param) {
|
|
|
|
|
+ CategoryBase entity = new CategoryBase();
|
|
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
|
|
+
|
|
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
|
|
+
|
|
|
|
|
+ if (param.getSortNumber() == null) {
|
|
|
|
|
+ entity.setSortNumber(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
|
|
+ entity.setId(id);
|
|
|
|
|
+
|
|
|
|
|
+ this.categoryBaseService.updateById(entity);
|
|
|
|
|
+
|
|
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Permission(value = "category.base.delete", tags = "删除基础数据分类")
|
|
|
|
|
+ @PostMapping("/deleteByIds")
|
|
|
|
|
+ public Result deleteByIds(@RequestBody List<Long> ids) {
|
|
|
|
|
+ this.categoryBaseService.removeByIds(ids);
|
|
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|