|
|
@@ -1,11 +1,12 @@
|
|
|
package com.jpsoft.employment.modules.job.controller;
|
|
|
|
|
|
import com.github.pagehelper.Page;
|
|
|
-import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
-import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
import com.jpsoft.employment.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.employment.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.employment.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.employment.modules.job.entity.WorkCategory;
|
|
|
import com.jpsoft.employment.modules.job.service.WorkCategoryService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
@@ -19,20 +20,37 @@ import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/job/workCategory")
|
|
|
+@Api(description = "workCategory")
|
|
|
public class WorkCategoryController {
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
private WorkCategoryService workCategoryService;
|
|
|
|
|
|
- @ApiOperation(value="添加信息")
|
|
|
+ @ApiOperation(value="创建空记录")
|
|
|
+ @GetMapping("create")
|
|
|
+ public MessageResult<WorkCategory> create(){
|
|
|
+ MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ WorkCategory workCategory = new WorkCategory();
|
|
|
+
|
|
|
+ msgResult.setData(workCategory);
|
|
|
+ msgResult.setResult(true);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="添加一级分类")
|
|
|
@PostMapping("add")
|
|
|
- public MessageResult<WorkCategory> add(@ModelAttribute WorkCategory workCategory){
|
|
|
+ public MessageResult<WorkCategory> add(@RequestBody WorkCategory workCategory,@RequestAttribute String subject){
|
|
|
MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
workCategory.setId(UUID.randomUUID().toString());
|
|
|
-
|
|
|
+ workCategory.setDelFlag(false);
|
|
|
+ workCategory.setCreateBy(subject);
|
|
|
+ workCategory.setCreateTime(new Date());
|
|
|
+
|
|
|
int affectCount = workCategoryService.insert(workCategory);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
|
@@ -54,8 +72,8 @@ public class WorkCategoryController {
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="获取信息")
|
|
|
- @GetMapping("detail/{id}")
|
|
|
- public MessageResult<WorkCategory> detail(@PathVariable("id") String id){
|
|
|
+ @GetMapping("edit/{id}")
|
|
|
+ public MessageResult<WorkCategory> edit(@PathVariable("id") String id){
|
|
|
MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
@@ -81,10 +99,13 @@ public class WorkCategoryController {
|
|
|
|
|
|
@ApiOperation(value="更新用户")
|
|
|
@PostMapping("update")
|
|
|
- public MessageResult<WorkCategory> update(@ModelAttribute WorkCategory workCategory){
|
|
|
+ public MessageResult<WorkCategory> update(@RequestBody WorkCategory workCategory,@RequestAttribute String subject){
|
|
|
MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
+ workCategory.setUpdateBy(subject);
|
|
|
+ workCategory.setUpdateTime(new Date());
|
|
|
+
|
|
|
int affectCount = workCategoryService.update(workCategory);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
|
@@ -105,19 +126,25 @@ public class WorkCategoryController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="删除用户")
|
|
|
+ @ApiOperation(value="删除")
|
|
|
@PostMapping("delete/{id}")
|
|
|
- public MessageResult<WorkCategory> delete(@PathVariable("id") String id){
|
|
|
- MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
+ public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
|
|
try {
|
|
|
- int affectCount = workCategoryService.delete(id);
|
|
|
+ WorkCategory workCategory = workCategoryService.get(id);
|
|
|
+ workCategory.setDelFlag(true);
|
|
|
+ workCategory.setUpdateBy(subject);
|
|
|
+ workCategory.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ int affectCount = workCategoryService.update(workCategory);
|
|
|
|
|
|
if (affectCount > 0) {
|
|
|
msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
} else {
|
|
|
msgResult.setResult(false);
|
|
|
- msgResult.setMessage("数据库删除失败");
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
}
|
|
|
}
|
|
|
catch(Exception ex){
|
|
|
@@ -132,45 +159,67 @@ public class WorkCategoryController {
|
|
|
|
|
|
|
|
|
@ApiOperation(value="批量删除")
|
|
|
- @PostMapping("batchDelete/{id}")
|
|
|
- public MessageResult<WorkCategory> batchDelete(@PathVariable("id") String id){
|
|
|
- MessageResult<WorkCategory> msgResult = new MessageResult<>();
|
|
|
+ @PostMapping("batchDelete")
|
|
|
+ public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
|
|
|
+ MessageResult<Integer> msgResult = new MessageResult<>();
|
|
|
|
|
|
- msgResult.setResult(false);
|
|
|
- msgResult.setMessage("未实现");
|
|
|
+ try {
|
|
|
+ int affectCount = 0;
|
|
|
+
|
|
|
+ for (String id : idList) {
|
|
|
+ WorkCategory workCategory = workCategoryService.get(id);
|
|
|
+ workCategory.setDelFlag(true);
|
|
|
+ workCategory.setUpdateBy(subject);
|
|
|
+ workCategory.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ affectCount += workCategoryService.update(workCategory);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (affectCount > 0) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ } else {
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("删除失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value="列表")
|
|
|
@RequestMapping(value = "list",method = RequestMethod.POST)
|
|
|
- public MessageResult<Map> list(
|
|
|
- String id,
|
|
|
- @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
|
|
|
- @RequestParam(value="pageSize",defaultValue="20") int pageSize,
|
|
|
- HttpServletRequest request){
|
|
|
- String subject = (String)request.getAttribute("subject");
|
|
|
+ public MessageResult<List> list(@RequestAttribute String subject){
|
|
|
|
|
|
//当前用户ID
|
|
|
System.out.println(subject);
|
|
|
|
|
|
- MessageResult<Map> msgResult = new MessageResult<>();
|
|
|
+ MessageResult<List> msgResult = new MessageResult<>();
|
|
|
|
|
|
Map<String,Object> searchParams = new HashMap<>();
|
|
|
+ searchParams.put("level",1);
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("id_","asc"));
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(id)) {
|
|
|
- searchParams.put("id","%" + id + "%");
|
|
|
+ sortList.add(new Sort("sort_no","asc"));
|
|
|
+
|
|
|
+ Page<WorkCategory> page = workCategoryService.pageSearch(searchParams,1,1000,false,sortList);
|
|
|
+ for (WorkCategory workCategory : page.getResult()){
|
|
|
+ List<WorkCategory> children2 = workCategoryService.findListByParentId(workCategory.getId());
|
|
|
+ for (WorkCategory workCategory2 : children2){
|
|
|
+ List<WorkCategory> children3 = workCategoryService.findListByParentId(workCategory2.getId());
|
|
|
+ workCategory2.setChildren(children3);
|
|
|
+ }
|
|
|
+ workCategory.setChildren(children2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- Page<WorkCategory> page = workCategoryService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
|
|
|
-
|
|
|
-
|
|
|
msgResult.setResult(true);
|
|
|
- msgResult.setData(PojoUtils.pageWrapper(page));
|
|
|
+ msgResult.setData(page.getResult());
|
|
|
|
|
|
return msgResult;
|
|
|
}
|