package doumeemes.api.ext; 
 | 
  
 | 
import doumeemes.api.BaseController; 
 | 
import doumeemes.core.annotation.excel.ExcelExporter; 
 | 
import doumeemes.core.annotation.pr.PreventRepeat; 
 | 
import doumeemes.core.model.ApiResponse; 
 | 
import doumeemes.core.model.PageData; 
 | 
import doumeemes.core.model.PageWrap; 
 | 
import doumeemes.core.utils.Constants; 
 | 
import doumeemes.dao.business.model.Category; 
 | 
import doumeemes.dao.business.model.CategoryUnion; 
 | 
import doumeemes.dao.ext.dto.QueryCategoryExtDTO; 
 | 
import doumeemes.dao.ext.vo.CategoryExtListVO; 
 | 
import doumeemes.service.business.CategoryService; 
 | 
import doumeemes.service.business.CategoryUnionService; 
 | 
import doumeemes.service.ext.CategoryExtService; 
 | 
import io.swagger.annotations.Api; 
 | 
import io.swagger.annotations.ApiImplicitParam; 
 | 
import io.swagger.annotations.ApiImplicitParams; 
 | 
import io.swagger.annotations.ApiOperation; 
 | 
import org.apache.commons.lang3.StringUtils; 
 | 
import org.apache.shiro.authz.annotation.RequiresPermissions; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.web.bind.annotation.*; 
 | 
import org.springframework.web.multipart.MultipartFile; 
 | 
  
 | 
import javax.servlet.http.HttpServletRequest; 
 | 
import javax.servlet.http.HttpServletResponse; 
 | 
import java.util.ArrayList; 
 | 
import java.util.Date; 
 | 
import java.util.List; 
 | 
  
 | 
/** 
 | 
 * 设置类分类信息表接口 
 | 
 * 
 | 
 * @author 江蹄蹄 
 | 
 * @date 2022/04/27 16:15 
 | 
 */ 
 | 
@RestController 
 | 
@RequestMapping("/ext/categoryExt") 
 | 
@Api(tags = "设置类分类信息表接口") 
 | 
public class CategoryExtController extends BaseController { 
 | 
  
 | 
    @Autowired 
 | 
    private CategoryExtService categoryExtService; 
 | 
  
 | 
    @Autowired 
 | 
    private CategoryService categoryService; 
 | 
  
 | 
    @Autowired 
 | 
    private CategoryUnionService categoryUnionService; 
 | 
  
 | 
  
 | 
    @PreventRepeat 
 | 
    @ApiOperation("新建") 
 | 
    @PostMapping("/create") 
 | 
    @RequiresPermissions("ext:categoryext:create") 
 | 
    public ApiResponse create(@RequestBody Category category) { 
 | 
  
 | 
        if(StringUtils.isBlank(category.getCode())){ 
 | 
            category.setCode(categoryService.getNextCode(getLoginUser().getCompany().getId())); 
 | 
        } 
 | 
  
 | 
        Category query = new Category(); 
 | 
        query.setDeleted(Constants.ZERO); 
 | 
        query.setCateType(category.getCateType()); 
 | 
        query.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        query.setCode(category.getCode()); 
 | 
        List<Category> list = categoryService.findList(query); 
 | 
  
 | 
        Category query1 = new Category(); 
 | 
        query1.setDeleted(Constants.ZERO); 
 | 
        query1.setCateType(category.getCateType()); 
 | 
        query1.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        query1.setName(category.getName()); 
 | 
        List<Category> list1 = categoryService.findList(query1); 
 | 
        if (list.size() > 0 || list1.size() > 0) { 
 | 
            return ApiResponse.failed("分类编码/分类名称已存在,不允许添加"); 
 | 
        } 
 | 
        category.setDeleted(Constants.ZERO); 
 | 
        category.setCreateTime(new Date()); 
 | 
        category.setCreateUser(getLoginUser().getId()); 
 | 
        category.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        int r =  categoryService.create(category); 
 | 
        CategoryUnion categoryUnion = new CategoryUnion(); 
 | 
        categoryUnion.setDeleted(Constants.ZERO); 
 | 
        categoryUnion.setCreateUser(getLoginUser().getId()); 
 | 
        categoryUnion.setCreateTime(new Date()); 
 | 
        categoryUnion.setUpdateUser(getLoginUser().getId()); 
 | 
        categoryUnion.setUpdateTime(new Date()); 
 | 
        categoryUnion.setRemark(""); 
 | 
        categoryUnion.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        categoryUnion.setCateBigId(category.getId()); 
 | 
        categoryUnionService.create(categoryUnion); 
 | 
        categoryExtService.loadCom(getLoginUser().getCompany()); 
 | 
        return ApiResponse.success(r ); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("根据ID删除") 
 | 
    @ApiImplicitParam(value = "主键id", name = "id", paramType = "query", dataType = "Integer") 
 | 
    @GetMapping("/delete/{id}") 
 | 
    @RequiresPermissions("ext:categoryext:delete") 
 | 
    public ApiResponse deleteById(@PathVariable Integer id) { 
 | 
  
 | 
        categoryService.deleteCategory(id); 
 | 
        return ApiResponse.success(null); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("批量删除") 
 | 
    @ApiImplicitParam(value = "主键ids", name = "ids", paramType = "query", dataType = "Integer") 
 | 
    @GetMapping("/delete/batch") 
 | 
    @RequiresPermissions("ext:categoryext:delete") 
 | 
    public ApiResponse deleteByIds(@RequestParam String ids) { 
 | 
        String[] idArray = ids.split(","); 
 | 
        List<Category> idList = new ArrayList<>(); 
 | 
        for (String id : idArray) { 
 | 
            Category category = categoryService.findById(Integer.valueOf(id)); 
 | 
            category.setDeleted(Constants.ONE); 
 | 
            idList.add(category); 
 | 
        } 
 | 
        categoryService.updateByIdInBatch(idList); 
 | 
        return ApiResponse.success(null); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("根据ID修改") 
 | 
    @PostMapping("/updateById") 
 | 
    @RequiresPermissions("ext:categoryext:update") 
 | 
    public ApiResponse updateById(@RequestBody Category category) { 
 | 
  
 | 
        Category query = new Category(); 
 | 
        query.setDeleted(Constants.ZERO); 
 | 
        query.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        query.setCode(category.getCode()); 
 | 
        List<Category> list = categoryService.findList(query); 
 | 
        if (list.size() > 0) { 
 | 
            if (!Constants.equalsInteger(list.get(0).getId(),category.getId()) ) { 
 | 
                return ApiResponse.failed("分类编码/分类名称已存在,不允许编辑"); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        Category query1 = new Category(); 
 | 
        query1.setDeleted(Constants.ZERO); 
 | 
        query1.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        query1.setName(category.getName()); 
 | 
        List<Category> list1 = categoryService.findList(query1); 
 | 
        if (list1.size() > 0) { 
 | 
            if (!Constants.equalsInteger(list1.get(0).getId(),category.getId())) { 
 | 
                return ApiResponse.failed("分类编码/分类名称已存在,不允许编辑"); 
 | 
            } 
 | 
        } 
 | 
  
 | 
        Category find= categoryService.findById(category.getId()); 
 | 
        find.setUpdateTime(new Date()); 
 | 
        find.setCateType(category.getCateType()); 
 | 
        find.setCode(category.getCode()); 
 | 
        find.setName(category.getName()); 
 | 
        find.setType(category.getType()); 
 | 
        find.setParentId(category.getParentId()); 
 | 
        category.setUpdateUser(getLoginUser().getId()); 
 | 
        categoryService.updateById(find); 
 | 
        return ApiResponse.success(null); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("分页查询") 
 | 
    @PostMapping("/page") 
 | 
    @RequiresPermissions("ext:categoryext:query") 
 | 
    public ApiResponse<PageData<CategoryExtListVO>> findPage(@RequestBody PageWrap<QueryCategoryExtDTO> pageWrap) { 
 | 
        pageWrap.getModel().setDeleted(Constants.ZERO); 
 | 
        pageWrap.getModel().setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        return ApiResponse.success(categoryExtService.findPage(pageWrap)); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("列表查询") 
 | 
    @PostMapping("/list") 
 | 
    @RequiresPermissions("ext:categoryext:query") 
 | 
    public ApiResponse<List<CategoryExtListVO>> list(@RequestBody QueryCategoryExtDTO queryCategoryExtDTO) { 
 | 
        queryCategoryExtDTO.setDeleted(Constants.ZERO); 
 | 
        queryCategoryExtDTO.setRootDepartId(getLoginUser().getRootDepartment().getId()); 
 | 
        return ApiResponse.success(categoryExtService.findList(queryCategoryExtDTO)); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("导出Excel") 
 | 
    @PostMapping("/exportExcel") 
 | 
    @RequiresPermissions("ext:categoryext:exportExcel") 
 | 
    public void exportExcel(@RequestBody PageWrap<QueryCategoryExtDTO> pageWrap, HttpServletResponse response) { 
 | 
        ExcelExporter.build(CategoryExtListVO.class).export(categoryExtService.findPage(pageWrap).getRecords(), "设置类分类信息表", response); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("根据ID查询") 
 | 
    @ApiImplicitParam(value = "主键id", name = "id", paramType = "query", dataType = "Integer") 
 | 
    @GetMapping("/{id}") 
 | 
    @RequiresPermissions("ext:categoryext:query") 
 | 
    public ApiResponse<Category> findById(@PathVariable Integer id) { 
 | 
        return ApiResponse.success(categoryService.findById(id)); 
 | 
    } 
 | 
  
 | 
    @ApiOperation("查询当前用户主组织下所有从属属性名称") 
 | 
    @ApiImplicitParams({ 
 | 
            @ApiImplicitParam(value = "分类属性0大类 1中类 2小类", name = "type", paramType = "query", required = true, dataType = "String"), 
 | 
            @ApiImplicitParam(value = "型 0物料 1客户 2工装器具 3不良品", name = "cateType", paramType = "query", required = true, dataType = "String"), 
 | 
            @ApiImplicitParam(value = "主类型id", name = "id", paramType = "query", required = false, dataType = "String") 
 | 
    }) 
 | 
    @GetMapping("/getListByType") 
 | 
    public ApiResponse<List<CategoryExtListVO>> getListByType(@RequestParam String type, @RequestParam String cateType,String id) { 
 | 
        if (StringUtils.isEmpty(type)) { 
 | 
            return ApiResponse.failed("参数不正确"); 
 | 
        } 
 | 
        return ApiResponse.success(categoryExtService.getListByType(type, getLoginUser().getRootDepartment().getId(), cateType,id)); 
 | 
    } 
 | 
  
 | 
  
 | 
    @ApiOperation("分类导入Excel") 
 | 
    @PostMapping("/importExcel") 
 | 
    @RequiresPermissions("ext:categoryext:importExcel") 
 | 
    public ApiResponse importExcel(@RequestParam(name = "file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws Exception { 
 | 
        categoryService.importcategory(file); 
 | 
        return ApiResponse.success(null); 
 | 
    } 
 | 
  
 | 
  
 | 
    @ApiOperation("分类树形列表查询") 
 | 
    @PostMapping("/treeCategoryList") 
 | 
    public ApiResponse<List<CategoryExtListVO>> treeCategoryList (@RequestBody QueryCategoryExtDTO pageWrap) { 
 | 
        return ApiResponse.success(categoryExtService.treeCategoryList(pageWrap)); 
 | 
    } 
 | 
} 
 |