地质所 沉降监测网建设项目
zmk
2024-10-23 3f47c88e7cb4e53b3637620794420181f47b5a5e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.javaweb.cms.service.impl;
 
import java.util.List;
import java.util.ArrayList;
import com.javaweb.common.core.domain.Ztree;
import com.javaweb.common.utils.DateUtils;
import com.javaweb.framework.util.ShiroUtils;
import com.javaweb.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.javaweb.cms.mapper.CategoryMapper;
import com.javaweb.cms.domain.Category;
import com.javaweb.cms.service.ICategoryService;
import com.javaweb.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;
 
/**
 * 栏目分类Service业务层处理
 * 
 * @author wujiyue
 * @date 2019-10-28
 */
@Service
public class CategoryServiceImpl implements ICategoryService 
{
    @Autowired
    private CategoryMapper categoryMapper;
 
    /**
     * 查询栏目分类
     * 
     * @param categoryId 栏目分类ID
     * @return 栏目分类
     */
    @Override
    public Category selectCategoryById(Long categoryId)
    {
        return categoryMapper.selectCategoryById(categoryId);
    }
 
    /**
     * 查询栏目分类列表
     * 
     * @param category 栏目分类
     * @return 栏目分类
     */
    @Override
    public List<Category> selectCategoryList(Category category)
    {
        return categoryMapper.selectCategoryList(category);
    }
 
    /**
     * 新增栏目分类
     * 
     * @param category 栏目分类
     * @return 结果
     */
    @Override
    @Transactional
    public int insertCategory(Category category)
    {
        category.setCreateTime(DateUtils.getNowDate());
        SysUser user=ShiroUtils.getSysUser();
        category.setCreateBy(user.getUserId().toString());
        int n=categoryMapper.insertCategory(category);
        //更新parentids
        Long pid=category.getParentId();
        Category p=categoryMapper.selectCategoryById(pid);
        String ancestors="";
        if(p!=null){
            ancestors = p.getAncestors();
            ancestors += category.getCategoryId()+",";
        }else{
            ancestors=category.getCategoryId()+",";
        }
        category.setAncestors(ancestors);
        n=categoryMapper.updateCategory(category);
        return n;
    }
 
    /**
     * 修改栏目分类
     * 
     * @param category 栏目分类
     * @return 结果
     */
    @Override
    public int updateCategory(Category category)
    {
        category.setUpdateTime(DateUtils.getNowDate());
        SysUser user=ShiroUtils.getSysUser();
        category.setUpdateBy(user.getUserId().toString());
        return categoryMapper.updateCategory(category);
    }
 
    /**
     * 删除栏目分类对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCategoryByIds(String ids)
    {
        return categoryMapper.deleteCategoryByIds(Convert.toStrArray(ids));
    }
 
    /**
     * 删除栏目分类信息
     * 
     * @param categoryId 栏目分类ID
     * @return 结果
     */
    @Override
    public int deleteCategoryById(String categoryId)
    {
        return categoryMapper.deleteCategoryById(categoryId);
    }
 
    /**
     * 查询栏目分类树列表
     * 
     * @return 所有栏目分类信息
     */
    @Override
    public List<Ztree> selectCategoryTree()
    {
        List<Category> categoryList = categoryMapper.selectCategoryList(new Category());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (Category category : categoryList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(category.getCategoryId());
            ztree.setpId(category.getParentId());
            ztree.setName(category.getCategoryName());
            ztree.setTitle(category.getCategoryName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
 
    @Override
    public List<Category> selectNavCategories(Category category) {
        return categoryMapper.selectNavCategories(category);
    }
}