package com.lxzn.nc.controller;
|
|
import com.lxzn.api.nc.ProductInfoControllerApi;
|
import com.lxzn.auth.JwtUtil;
|
import com.lxzn.framework.domain.nc.ProductInfo;
|
import com.lxzn.framework.domain.ucenter.Department;
|
import com.lxzn.framework.domain.ucenter.User;
|
import com.lxzn.framework.domain.ucenter.ext.UserDepartExt;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.model.response.CommonGenericTree;
|
import com.lxzn.framework.model.response.QueryListResponseResult;
|
import com.lxzn.framework.model.response.ResponseResult;
|
import com.lxzn.framework.utils.ValidateUtil;
|
import com.lxzn.nc.service.IProductInfoService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Collections;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/nc/product")
|
public class ProductInfoController implements ProductInfoControllerApi {
|
|
@Autowired
|
private IProductInfoService productInfoService;
|
|
@Override
|
@PostMapping("/add")
|
public ResponseResult addProductInfo(@RequestBody ProductInfo productInfo) {
|
boolean b = productInfoService.addProductInfo(productInfo);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PutMapping("/edit/{id}")
|
public ResponseResult editProductInfo(@PathVariable("id") String id,@RequestBody ProductInfo productInfo) {
|
boolean b = productInfoService.editProductInfo(id, productInfo);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@GetMapping("/load/tree")
|
public QueryListResponseResult<CommonGenericTree> loadProductTree() {
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
|
List<CommonGenericTree> list = productInfoService.loadProductTree(userId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/load/tree/base")
|
public QueryListResponseResult<CommonGenericTree> loadBaseTree() {
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
|
List<CommonGenericTree> list = productInfoService.loadBaseTree(userId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/load/tree/child/{nodeType}/{paramId}")
|
public QueryListResponseResult<CommonGenericTree> loadTree(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
|
List<CommonGenericTree> list = productInfoService.loadTree(userId, nodeType, paramId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@DeleteMapping("/delete")
|
public ResponseResult deleteProductInfo(@RequestParam("id") String id) {
|
boolean b = productInfoService.deleteProductInfo(id);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@GetMapping("/check/{nodeType}/{paramId}")
|
public ResponseResult checkProductPerm(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
|
boolean b = productInfoService.checkProductPerm(nodeType, paramId);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.UNAUTHORISE);
|
}
|
|
@Override
|
@GetMapping("/get/perm/user/{nodeType}/{paramId}")
|
public QueryListResponseResult<UserDepartExt> getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) {
|
List<UserDepartExt> list = productInfoService.getUserPermsList(nodeType, paramId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/get/non/perm/user/{nodeType}/{paramId}")
|
public QueryListResponseResult<User> getUserNonPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
|
List<User> list = productInfoService.getUserNonPermsList(nodeType, paramId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/get/perm/depart/{nodeType}/{paramId}")
|
public QueryListResponseResult<Department> getDepartPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
|
List<Department> list = productInfoService.getDepartPermsList(nodeType, paramId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/get/non/perm/depart/{nodeType}/{paramId}")
|
public QueryListResponseResult<Department> getDepartNonPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) {
|
List<Department> list = productInfoService.getDepartNonPermsList(nodeType, paramId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@PostMapping("/assign/add/user/{nodeType}/{paramId}/{relativeFlag}")
|
public ResponseResult assignAddUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
|
boolean b = productInfoService.assignAddUser(nodeType, paramId, relativeFlag, userIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
|
@Override
|
@PostMapping("/assign/remove/user/{nodeType}/{paramId}/{relativeFlag}")
|
public ResponseResult assignRemoveUser(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) {
|
boolean b = productInfoService.assignRemoveUser(nodeType, paramId, relativeFlag, userIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
|
@Override
|
@PostMapping("/assign/add/department/{nodeType}/{paramId}/{relativeFlag}")
|
public ResponseResult assignAddDepartment(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] departmentIds) {
|
boolean b = productInfoService.assignAddDepartment(nodeType, paramId, relativeFlag, departmentIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PostMapping("/assign/remove/department/{nodeType}/{paramId}/{relativeFlag}")
|
public ResponseResult assignRemoveDepartment(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] departmentIds) {
|
boolean b = productInfoService.assignRemoveDepartment(nodeType, paramId, relativeFlag, departmentIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@GetMapping("/search")
|
public QueryListResponseResult<CommonGenericTree> searchProductTree(String queryParam) {
|
String userId = JwtUtil.getUserId();
|
if(!ValidateUtil.validateString(userId))
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList());
|
List<CommonGenericTree> list = productInfoService.searchProductTree(userId, queryParam);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
}
|