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 loadProductTree() { String userId = JwtUtil.getUserId(); if(!ValidateUtil.validateString(userId)) return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList()); List list = productInfoService.loadProductTree(userId); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @Override @GetMapping("/load/tree/base") public QueryListResponseResult loadBaseTree() { String userId = JwtUtil.getUserId(); if(!ValidateUtil.validateString(userId)) return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList()); List 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 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 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 getUserPermsList(@PathVariable("nodeType") Integer nodeType, @PathVariable("paramId") String paramId) { List 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 getUserNonPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) { List 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 getDepartPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) { List 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 getDepartNonPermsList(@PathVariable("nodeType") Integer nodeType,@PathVariable("paramId") String paramId) { List 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 searchProductTree(String queryParam) { String userId = JwtUtil.getUserId(); if(!ValidateUtil.validateString(userId)) return new QueryListResponseResult<>(CommonCode.SUCCESS, Collections.emptyList()); List list = productInfoService.searchProductTree(userId, queryParam); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } }