czt
2025-12-01 096296cd7485c5583c8194d88cca700e3c4d84a0
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
package com.fzzy.igds.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzzy.igds.constant.Constant;
import com.fzzy.igds.domain.Dept;
import com.fzzy.igds.mapper.CoreDeptMapper;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @Description service层
 * @Author CZT
 * @Date 2025/11/26 17:48
 */
@Service
public class CoreDeptService {
 
    @Resource
    private ISysDeptService iSysDeptService;
    @Resource
    private CoreDeptMapper coreDeptMapper;
    @Resource
    private InoutConfService inoutConfService;
 
    /**
     * 根据条件查询库区信息
     * @param id
     * @param companyId
     * @param parentId
     * @return
     */
    public List<Dept> listDept(String id, String companyId, String parentId) {
 
        QueryWrapper<Dept> queryWrapper = new QueryWrapper<>();
 
        if(StringUtils.isNotBlank(id)){
            queryWrapper.eq("id", id);
        }
        if(StringUtils.isNotBlank(companyId)){
            queryWrapper.eq("company_id", companyId);
        }
        if(StringUtils.isNotBlank(parentId)){
            queryWrapper.likeRight("id", parentId);
        }
 
        return coreDeptMapper.selectList(queryWrapper);
    }
 
    /**
     * 查询信息
     * @return
     */
    public List<Dept> getDeptData() {
        SysUser user = ContextUtil.getLoginUser();
        SysDept userDept = iSysDeptService.selectDeptById(user.getDeptId());
        if (Constant.DEPT_TYPE_20.equals(userDept.getType())) {
            return this.listDept(ContextUtil.subDeptId(user),null,null);
        }else {
            return this.listDept(null,null,user.getDeptId() + "%");
        }
    }
 
    /**
     * 新增或更新库区信息
     * @param sysDept
     * @param isAdd
     * @return
     */
    public void saveOrUpdate(SysDept sysDept, Boolean isAdd) {
        if (null == sysDept) {
            return;
        }
        Dept dept = new Dept();
        dept.setId(sysDept.getDeptId() + "");
        dept.setKqmc(sysDept.getDeptName());
        dept.setCompanyId(sysDept.getCompanyId());
 
        if (isAdd) {
            this.save(dept);
        }else {
            this.update(dept);
        }
    }
 
    /**
     * 保存库区信息
     * @param data
     */
    public void save(Dept data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
        //创建信息
        data.setCreateBy(ContextUtil.getLoginUserName());
        data.setCreateTime(new Date());
 
        coreDeptMapper.insert(data);
 
        //初始化出入库流程配置信息
        inoutConfService.initSysConfData(data.getCompanyId(), data.getId());
    }
 
    /**
     * 更新库区信息
     * @param data
     */
    public void update(Dept data) {
        if (StringUtils.isEmpty(data.getCompanyId())) {
            data.setCompanyId(ContextUtil.getCompanyId());
        }
 
        //更新信息
        data.setUpdateBy(ContextUtil.getLoginUserName());
        data.setUpdateTime(new Date());
 
        coreDeptMapper.updateById(data);
    }
 
    /**
     * 删除库区信息
     * @param deptId
     * @return
     */
    public void delData(String deptId) {
        //删除库区信息
        coreDeptMapper.deleteById(deptId);
 
        //删除流程配置信息
        inoutConfService.delSysConfData(deptId);
    }
}