|
@@ -1,7 +1,100 @@
|
|
|
package cn.com.ty.lift.system.template.controller;
|
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import cn.com.ty.lift.system.template.dao.entity.Template;
|
|
|
+import cn.com.ty.lift.system.template.dao.entity.model.TemplateReq;
|
|
|
+import cn.com.ty.lift.system.template.service.impl.TemplateServiceImpl;
|
|
|
+import cn.com.xwy.boot.web.dto.RestResponse;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wang-hai-cheng
|
|
|
+ * @date 2019/12/6
|
|
|
+ * @description 模板
|
|
|
+ */
|
|
|
@RestController
|
|
|
+@RequestMapping("/template")
|
|
|
+@AllArgsConstructor
|
|
|
public class TemplateController {
|
|
|
-}
|
|
|
+ private final TemplateServiceImpl templateService;
|
|
|
+
|
|
|
+ @RequestMapping("/list")
|
|
|
+ /**
|
|
|
+ * @description 分页获取全部模板
|
|
|
+ * @date 2019/12/6 11:20
|
|
|
+ * @param [TemplateReq]
|
|
|
+ * @return java.util.List<cn.com.ty.lift.system.template.dao.entity.Template>
|
|
|
+ */
|
|
|
+ public RestResponse list(@RequestBody TemplateReq templateReq) {
|
|
|
+ IPage<Template> templateIPage = templateService.page(
|
|
|
+ new Page<>(templateReq.getPageNum(), templateReq.getPageSize()),
|
|
|
+ new QueryWrapper<Template>()
|
|
|
+ .eq(templateReq.getMtCompanyId() != null, "mt_company_id", templateReq.getMtCompanyId()));
|
|
|
+ if (templateIPage.getRecords().isEmpty()) {
|
|
|
+ return RestResponse.ok(null, "9", "无数据");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(templateIPage, "1", "查询成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/add")
|
|
|
+ /**
|
|
|
+ * @description 新增模板
|
|
|
+ * @date 2019/12/6 11:26
|
|
|
+ * @param [Template]
|
|
|
+ * @return org.springframework.http.ResponseEntity
|
|
|
+ */
|
|
|
+ public RestResponse<Object> add(@RequestBody Template template) {
|
|
|
+ if (template.getMtCompanyId() == 0) {
|
|
|
+ template.setEdit(0);
|
|
|
+ }
|
|
|
+ if (templateService.save(template)) {
|
|
|
+ return RestResponse.ok(null, "1", "新增成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, "0", "新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/update")
|
|
|
+ /**
|
|
|
+ * @description 根据id修改模板信息
|
|
|
+ * @date 2019/12/6 11:26
|
|
|
+ * @param [Template]
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RestResponse update(@RequestBody Template template) {
|
|
|
+ if (templateService.updateById(template)) {
|
|
|
+ return RestResponse.ok(null, "1", "修改模板成功");
|
|
|
+ }
|
|
|
+ return RestResponse.ok(null, "0", "修改模板失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ /**
|
|
|
+ * @description 根据id删除模板及未被其它模板依赖的模板项
|
|
|
+ * @date 2019/12/6 11:27
|
|
|
+ * @param [id]
|
|
|
+ * @return org.springframework.http.ResponseEntity
|
|
|
+ */
|
|
|
+ public RestResponse delete(@RequestBody Template template) {
|
|
|
+ Template byId = templateService.getById(template.getId());
|
|
|
+ if (byId.getEdit() == 1) {
|
|
|
+ return RestResponse.ok(null, "0", "此模板无法删除");
|
|
|
+ }
|
|
|
+ //删除模板及相关模板项
|
|
|
+ return templateService.removeItemOfTemplate(template.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/items")
|
|
|
+ /**
|
|
|
+ * @description 分页获取模板下模板项
|
|
|
+ * @date 2019/12/6 11:27
|
|
|
+ * @param [templateId]
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public RestResponse items(@RequestBody TemplateReq templateReq) {
|
|
|
+ return templateService.getItems(templateReq);
|
|
|
+ }
|
|
|
+}
|