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.domain.PledgeContract;
|
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 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 CoreDeptMapper coreDeptMapper;
|
@Resource
|
private InoutConfService inoutConfService;
|
|
/**
|
* 根据用户类型获取对应库区列表信息
|
*
|
* @param parentId
|
* @return
|
*/
|
public List<Dept> getDeptByUserType(String parentId) {
|
|
if(StringUtils.isNotBlank(parentId)){
|
//查公司下所有库区
|
return this.listDept(null,null, parentId);
|
}
|
//获取当前登录人
|
SysUser user = ContextUtil.getLoginUser();
|
|
if (Constant.USER_TYPE_10.equals(user.getUserType())) {
|
//监管用户,直接查询组织下所有库区
|
return this.listDept(null,user.getCompanyId(),null);
|
}
|
if (Constant.USER_TYPE_20.equals(user.getUserType())) {
|
//银行用户,根据合同查询银行下所有库区
|
return this.getDeptByContract(user.getUserData());
|
}
|
if (Constant.USER_TYPE_30.equals(user.getUserType())) {
|
//库区用户
|
String deptId = user.getDeptId() + "";
|
if(deptId.length() > 7){
|
//查询用户所属库区
|
return this.listDept(deptId,null,null);
|
}else {
|
//查询用户所属公司下所有库区
|
return this.listDept(null,null, deptId);
|
}
|
}
|
return this.listDept(null,user.getCompanyId(),null);
|
}
|
|
/**
|
* 根据银行id,关联合同表查询库区列表
|
* @param bankId
|
* @return
|
*/
|
public List<Dept> getDeptByContract(String bankId) {
|
|
if (StringUtils.isBlank(bankId)){
|
return null;
|
}
|
|
QueryWrapper<PledgeContract> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("c.pledge_bank", bankId);
|
|
return coreDeptMapper.selectDeptByBankId(queryWrapper);
|
}
|
|
/**
|
* 根据条件查询库区信息
|
* @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);
|
}
|
queryWrapper.orderByAsc("id");
|
return coreDeptMapper.selectList(queryWrapper);
|
}
|
|
/**
|
* 查询信息
|
* @return
|
*/
|
public List<Dept> getDeptData() {
|
SysUser user = ContextUtil.getLoginUser();
|
if (Constant.USER_TYPE_30.equals(user.getUserType())) {
|
return this.listDept(ContextUtil.subDeptId(user),null,null);
|
}else {
|
return this.listDept(null,null,user.getDeptId()+"");
|
}
|
}
|
|
/**
|
* 根据ID查询库区信息
|
* @param id
|
* @return
|
*/
|
public Dept getDeptById(String id) {
|
|
return coreDeptMapper.selectById(id);
|
}
|
|
/**
|
* 新增或更新库区信息
|
* @param sysDept
|
* @param isAdd
|
* @return
|
*/
|
public void saveOrUpdate(SysDept sysDept, Boolean isAdd) {
|
if (null == sysDept) {
|
return;
|
}
|
Dept dept = new Dept();
|
String deptId = sysDept.getDeptId() + "";
|
dept.setId(deptId);
|
dept.setParentId(deptId.substring(0, deptId.length() - 3));
|
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);
|
}
|
}
|