Ver Código Fonte

工单类型

1550076451 2 anos atrás
pai
commit
02035f8e34

+ 2 - 0
zxkf-api/src/main/java/api/controller/system/MenuController.java

@@ -1,6 +1,7 @@
1 1
 package api.controller.system;
2 2
 
3 3
 import api.entity.view.system.UserView;
4
+import api.util.annotation.Anonymous;
4 5
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
5 6
 import com.baomidou.mybatisplus.core.metadata.IPage;
6 7
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -107,6 +108,7 @@ public class MenuController extends BaseController {
107 108
     /**
108 109
      * 获取菜单下拉树列表
109 110
      */
111
+
110 112
     @GetMapping("/treeselect")
111 113
     public AjaxResult treeselect(Menu menu) {
112 114
         List<Menu> menus = menuService.selectMenuList(menu, CurrentUser().getUserId());

+ 153 - 0
zxkf-api/src/main/java/api/controller/system/WorkroderTypeController.java

@@ -0,0 +1,153 @@
1
+package api.controller.system;
2
+
3
+import api.entity.database.system.Menu;
4
+import api.entity.database.system.WorkroderType;
5
+import api.service.system.IWorkroderTypeService;
6
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
7
+import com.baomidou.mybatisplus.core.metadata.IPage;
8
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
9
+import api.controller.BaseController;
10
+
11
+import api.entity.input.PageInput;
12
+import api.model.AjaxResult;
13
+
14
+import api.util.annotation.Log;
15
+import api.util.enums.BusinessType;
16
+import api.util.helper.StringHelper;
17
+import io.swagger.annotations.Api;
18
+import io.swagger.annotations.ApiOperation;
19
+import lombok.var;
20
+import org.springframework.beans.factory.annotation.Autowired;
21
+import org.springframework.web.bind.annotation.*;
22
+import java.util.Arrays;
23
+import java.util.Date;
24
+import java.util.List;
25
+
26
+@Api(value = "工单类型表",tags = "工单类型表")
27
+@RestController
28
+@RequestMapping("/worker/type")
29
+public class WorkroderTypeController extends BaseController {
30
+    @Autowired
31
+    private IWorkroderTypeService workrodertypeService;
32
+
33
+    @ApiOperation("列表")
34
+    @Log(title = "查询工单类型表列表",businessType = BusinessType.QUERY)
35
+    @GetMapping
36
+    public AjaxResult getList(WorkroderType input, PageInput pageInput) {
37
+        LambdaQueryWrapper<WorkroderType> qw = new LambdaQueryWrapper<>();
38
+        qw.eq(input.getParentId() != null && input.getParentId() > 0, WorkroderType::getParentId, input.getParentId());
39
+        qw.like(!StringHelper.isEmpty(input.getTypeCode()), WorkroderType::getTypeCode, input.getTypeCode());
40
+        qw.like(!StringHelper.isEmpty(input.getAncestors()), WorkroderType::getAncestors, input.getAncestors());
41
+        qw.like(!StringHelper.isEmpty(input.getTypeName()), WorkroderType::getTypeName, input.getTypeName());
42
+        qw.eq(input.getTypeOrder() != null && input.getTypeOrder() > 0, WorkroderType::getTypeOrder, input.getTypeOrder());
43
+        qw.eq(input.getCrateTime() != null , WorkroderType::getCrateTime, input.getCrateTime());
44
+        qw.eq(WorkroderType::getIsDelete, 0);
45
+        qw.like(!StringHelper.isEmpty(input.getCreateBy()), WorkroderType::getCreateBy, input.getCreateBy());
46
+        if (pageInput.getPageNum() == null) {
47
+            pageInput.setPageNum(1);
48
+        }
49
+        if (pageInput.getPageSize() == null) {
50
+            pageInput.setPageNum(10);
51
+        }
52
+        Page<WorkroderType> page = GetPage(pageInput);
53
+        if (page != null) {
54
+            IPage<WorkroderType> iPage = workrodertypeService.getListPage(page, qw);
55
+            return Success("成功", iPage.getRecords(), iPage.getTotal());
56
+        } else {
57
+            return Success("成功", workrodertypeService.getList(qw));
58
+        }
59
+    }
60
+
61
+    @ApiOperation("详情")
62
+    @Log(title = "查询工单类型详情",businessType = BusinessType.QUERY)
63
+    @GetMapping("/{id}")
64
+    public AjaxResult getInfo(@PathVariable long id) {
65
+        return Success("成功", workrodertypeService.getEntity(id));
66
+    }
67
+
68
+    @ApiOperation("新增")
69
+    @Log(title = "新增工单类型",businessType = BusinessType.INSERT)
70
+    @PostMapping
71
+    public AjaxResult add(@RequestBody WorkroderType input) {
72
+        Date currentDate = new Date(System.currentTimeMillis());
73
+        if (input.getParentId()>0)
74
+        {
75
+            var model=workrodertypeService.getEntity(input.getParentId());
76
+            if (model!=null)
77
+            {
78
+                input.setAncestors(model.getAncestors()+","+model.getId());
79
+            }
80
+            else
81
+            {
82
+                return Error("该父级分类不存在");
83
+            }
84
+        }
85
+        else
86
+        {
87
+            input.setAncestors("0");
88
+        }
89
+
90
+        input.setIsDelete(0L);
91
+        input.setCrateTime(currentDate);
92
+        input.setCreateBy(CurrentUser().getUserId().toString());
93
+        boolean result = workrodertypeService.insert(input);
94
+        if (result) {
95
+            return Success("成功");
96
+        } else {
97
+            return Error("新增失败");
98
+        }
99
+    }
100
+
101
+    @ApiOperation("编辑")
102
+    @Log(title = "编辑工单类型",businessType = BusinessType.UPDATE)
103
+    @PutMapping
104
+    public AjaxResult edit(@RequestBody WorkroderType input)  {
105
+        boolean result = workrodertypeService.update(input);
106
+        if (result) {
107
+            return Success("成功");
108
+        } else {
109
+            return Error("修改失败");
110
+        }
111
+    }
112
+
113
+    @ApiOperation("删除")
114
+    @Log(title = "删除工单类型",businessType = BusinessType.DELETE)
115
+    @DeleteMapping("/{ids}")
116
+    public AjaxResult delete(@PathVariable Long[] ids)  {
117
+        StringBuilder error= new StringBuilder();
118
+        for (int i=0;i<ids .length;i++)
119
+        {
120
+            var Type=workrodertypeService.getEntity(ids[i] );
121
+            if (Type!=null)
122
+            {
123
+                Type.setIsDelete(1L);
124
+                boolean result = workrodertypeService.update(Type);
125
+                if (!result)
126
+                {
127
+                    error.append(Type.getTypeName()).append("删除失败;");
128
+                }
129
+            }
130
+            else
131
+            {
132
+                error.append("第").append(i).append("行删除失败;");
133
+            }
134
+        }
135
+        if (error.toString().equals("")) {
136
+            return Success("成功");
137
+        } else {
138
+            return Error(error.toString());
139
+        }
140
+    }
141
+    @GetMapping("/treeselect")
142
+    public AjaxResult treeselect(Menu menu) {
143
+        LambdaQueryWrapper<WorkroderType> qw = new LambdaQueryWrapper<>();
144
+        qw.eq(WorkroderType::getIsDelete, 0);
145
+        List<WorkroderType> menus = workrodertypeService.getList(qw);
146
+        return Success("获取菜单下拉树列表成功", workrodertypeService.buildMenuTreeSelect(menus));
147
+    }
148
+
149
+
150
+
151
+
152
+}
153
+

+ 52 - 0
zxkf-entity/src/main/java/api/entity/database/system/WorkroderType.java

@@ -0,0 +1,52 @@
1
+package api.entity.database.system;
2
+
3
+
4
+
5
+import com.baomidou.mybatisplus.annotation.IdType;
6
+import com.baomidou.mybatisplus.annotation.TableField;
7
+import com.baomidou.mybatisplus.annotation.TableId;
8
+import com.baomidou.mybatisplus.annotation.TableName;
9
+import io.swagger.annotations.ApiModel;
10
+import io.swagger.annotations.ApiModelProperty;
11
+import lombok.Data;
12
+
13
+import java.util.ArrayList;
14
+import java.util.Date;
15
+import java.util.List;
16
+
17
+/** workroder_type */
18
+@ApiModel(value = "WorkroderType", description = "workroder_type实体")
19
+@Data
20
+@TableName("workroder_type")
21
+public class WorkroderType {
22
+    /** id */
23
+    @ApiModelProperty("id")
24
+    private Long id;
25
+    /** parent_id */
26
+    @ApiModelProperty("parent_id")
27
+    private Long parentId;
28
+    /** type_code */
29
+    @ApiModelProperty("type_code")
30
+    private String typeCode;
31
+    /** ancestors */
32
+    @ApiModelProperty("ancestors")
33
+    private String ancestors;
34
+    /** type_name */
35
+    @ApiModelProperty("type_name")
36
+    private String typeName;
37
+    /** type_order */
38
+    @ApiModelProperty("type_order")
39
+    private Long typeOrder;
40
+    /** crate_time */
41
+    @ApiModelProperty("crate_time")
42
+    private Date crateTime;
43
+    /** is_delete */
44
+    @ApiModelProperty("is_delete")
45
+    private Long isDelete;
46
+    /** create_by */
47
+    @ApiModelProperty("create_by")
48
+    private String createBy;
49
+
50
+    @TableField(exist = false)
51
+    private List<WorkroderType> children = new ArrayList<WorkroderType>();
52
+}

+ 8 - 0
zxkf-entity/src/main/java/api/entity/view/TreeSelect.java

@@ -2,6 +2,7 @@ package api.entity.view;
2 2
 
3 3
 import api.entity.database.system.Dept;
4 4
 import api.entity.database.system.Menu;
5
+import api.entity.database.system.WorkroderType;
5 6
 import com.fasterxml.jackson.annotation.JsonInclude;
6 7
 import lombok.Data;
7 8
 
@@ -46,4 +47,11 @@ public class TreeSelect implements Serializable
46 47
         this.children=menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
47 48
 
48 49
     }
50
+    public TreeSelect(WorkroderType Type) {
51
+        this.id=Type.getId();
52
+        this.label=Type.getTypeName();
53
+        this.children=Type.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
54
+
55
+    }
56
+
49 57
 }

+ 10 - 0
zxkf-mapper/src/main/java/api/mapper/system/WorkroderTypeMapper.java

@@ -0,0 +1,10 @@
1
+package api.mapper.system;
2
+
3
+import api.entity.database.system.WorkroderType;
4
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
+
6
+import org.apache.ibatis.annotations.Mapper;
7
+
8
+@Mapper
9
+public interface WorkroderTypeMapper extends BaseMapper<WorkroderType> {
10
+}

+ 27 - 0
zxkf-service/src/main/java/api/service/system/IWorkroderTypeService.java

@@ -0,0 +1,27 @@
1
+package api.service.system;
2
+
3
+import api.entity.database.system.Menu;
4
+import api.entity.database.system.WorkroderType;
5
+import api.entity.view.TreeSelect;
6
+import api.service.IBaseService;
7
+
8
+import java.util.List;
9
+
10
+public interface IWorkroderTypeService extends IBaseService<WorkroderType> {
11
+
12
+
13
+    /**
14
+     * 构建前端所需要下拉树结构
15
+     *
16
+     * @param menus 菜单列表
17
+     * @return 下拉树结构列表
18
+     */
19
+    public List<TreeSelect> buildMenuTreeSelect(List<WorkroderType> menus);
20
+
21
+
22
+
23
+
24
+    public List<WorkroderType> buildMenuTree(List<WorkroderType> menus);
25
+
26
+}
27
+

+ 91 - 0
zxkf-service/src/main/java/api/service/system/impl/WorkroderTypeServiceImpl.java

@@ -0,0 +1,91 @@
1
+package api.service.system.impl;
2
+
3
+
4
+import api.entity.database.system.Menu;
5
+import api.entity.database.system.WorkroderType;
6
+import api.entity.view.TreeSelect;
7
+import api.mapper.system.WorkroderTypeMapper;
8
+import api.service.BaseServiceImpl;
9
+import api.service.system.IWorkroderTypeService;
10
+import org.springframework.stereotype.Service;
11
+import org.springframework.transaction.annotation.Transactional;
12
+
13
+import java.util.ArrayList;
14
+import java.util.Iterator;
15
+import java.util.List;
16
+import java.util.stream.Collectors;
17
+
18
+@Transactional
19
+@Service
20
+public class WorkroderTypeServiceImpl extends BaseServiceImpl<WorkroderTypeMapper, WorkroderType> implements IWorkroderTypeService {
21
+    public WorkroderTypeServiceImpl(){ super(false); }
22
+
23
+
24
+    @Override
25
+    public List<TreeSelect> buildMenuTreeSelect(List<WorkroderType> Type) {
26
+        List<WorkroderType> menuTrees = buildMenuTree(Type);
27
+        return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
28
+    }
29
+
30
+    /**
31
+     * 构建前端所需要树结构
32
+     *
33
+     * @param Type 菜单列表
34
+     * @return 树结构列表
35
+     */
36
+    @Override
37
+    public List<WorkroderType> buildMenuTree(List<WorkroderType> Type) {
38
+        List<WorkroderType> returnList = new ArrayList<WorkroderType>();
39
+        List<Long> tempList = Type.stream().map(WorkroderType::getId).collect(Collectors.toList());
40
+        for (Iterator<WorkroderType> iterator = Type.iterator(); iterator.hasNext(); ) {
41
+            WorkroderType menu = (WorkroderType) iterator.next();
42
+            // 如果是顶级节点, 遍历该父节点的所有子节点
43
+            if (!tempList.contains(menu.getParentId())) {
44
+                recursionFn(Type, menu);
45
+                returnList.add(menu);
46
+            }
47
+        }
48
+        if (returnList.isEmpty()) {
49
+            returnList = Type;
50
+        }
51
+        return returnList;
52
+    }
53
+    /**
54
+     * 递归列表
55
+     *
56
+     * @param list 分类表
57
+     * @param t    子节点
58
+     */
59
+    private void recursionFn(List<WorkroderType> list, WorkroderType t) {
60
+        // 得到子节点列表
61
+        List<WorkroderType> childList = getChildList(list, t);
62
+        t.setChildren(childList);
63
+        for (WorkroderType tChild : childList) {
64
+            if (hasChild(list, tChild)) {
65
+                recursionFn(list, tChild);
66
+            }
67
+        }
68
+    }
69
+    /**
70
+     * 判断是否有子节点
71
+     */
72
+    private boolean hasChild(List<WorkroderType> list, WorkroderType t) {
73
+        return getChildList(list, t).size() > 0;
74
+    }
75
+
76
+    /**
77
+     * 得到子节点列表
78
+     */
79
+    private List<WorkroderType> getChildList(List<WorkroderType> list, WorkroderType t) {
80
+        List<WorkroderType> tlist = new ArrayList<WorkroderType>();
81
+        Iterator<WorkroderType> it = list.iterator();
82
+        while (it.hasNext()) {
83
+            WorkroderType n = (WorkroderType) it.next();
84
+            if (n.getParentId().longValue() == t.getId().longValue()) {
85
+                tlist.add(n);
86
+            }
87
+        }
88
+        return tlist;
89
+    }
90
+
91
+}