package com.vci.web.dao.impl; import com.vci.constant.VciFileBtmTypeConstant; import com.vci.model.VciFileDocClassifyDO; import com.vci.starter.web.constant.QueryOptionConstant; import com.vci.starter.web.util.VciBaseUtil; import com.vci.starter.web.wrapper.VciQueryWrapperForDO; import com.vci.web.dao.VciFileDocClassifyDaoI; import com.vci.web.service.WebBoServiceI; import com.vci.web.util.WebUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import org.springframework.util.CollectionUtils; import java.util.*; /** * 文档的类型 * @author weidy * @date 2021/3/11 */ @Repository public class VciFileDocClassifyDaoImpl implements VciFileDocClassifyDaoI { /** * 业务数据对象的服务 */ @Autowired private WebBoServiceI boService; /** * 使用主键删除 * * @param oid 数据主键 * @return 执行结果 */ @Override public int deleteByPrimaryKey(String oid) { VciBaseUtil.alertNotNull(oid,"文档类型的主键"); boService.deleteByCondition(VciFileBtmTypeConstant.FILE_DOC_CLASSIFY, WebUtil.getOidQuery(oid)); return StringUtils.countMatches(oid,",") + 1; } /** * 添加数据 * * @param record 文档的类型数据对象 * @return 执行结果 */ @Override public int insert(VciFileDocClassifyDO record) { VciBaseUtil.alertNotNull(record,"要添加的内容"); if(StringUtils.isBlank(record.getOid())){ record.setOid(VciBaseUtil.getPk()); } boService.addSave(record); return 1; } /** * 根据主键查询 * * @param oid 数据主键 * @return 数据对象 */ @Override public VciFileDocClassifyDO selectByPrimaryKey(String oid) { return boService.selectByOid(oid, VciFileDocClassifyDO.class); } /** * 根据主键批量获取对象 * * @param oids 主键,包含单引号,但是不能超过1000 * @return 数据对象列表 */ @Override public List selectByPrimaryKeys(String oids) { return boService.selectByOidCollection(VciBaseUtil.str2List(oids),VciFileDocClassifyDO.class); } /** * 根据主键批量查询对象 * * @param oids 对象主键,使用逗号分隔,但是不能超过1000 * @return 业务对象 */ @Override public List selectByPrimaryKeyCollection(Collection oids) { return boService.selectByOidCollection(oids,VciFileDocClassifyDO.class); } /** * 查询所有分类 * * @return 查询结果 */ @Override public List selectAll() { return boService.queryObject(VciFileDocClassifyDO.class,null); } /** * 更新物料、工具基本分类 * * @param record 物料、工具基本分类数据对象 * @return 执行结果 */ @Override public int updateByPrimaryKey(VciFileDocClassifyDO record) { VciBaseUtil.alertNotNull(record,"要修改的内容",record.getOid(),"主键"); boService.editSave(record); return 1; } /** * 根据查询条件查询数据 * * @param wrapper 查询条件,包括分页,排序 * @return 数据对象列表 */ @Override public List selectByWrapper(VciQueryWrapperForDO wrapper) { return boService.selectByQueryWrapper(wrapper,VciFileDocClassifyDO.class); } /** * 根据查询条件来查询总数 * * @param wrapper 查询条件 * @return 总数 */ @Override public Long countByWrapper(VciQueryWrapperForDO wrapper) { return Long.valueOf(boService.countByQueryWrapper(wrapper,VciFileDocClassifyDO.class)); } /** * 根据主键获取名称 * * @param oid 主键 * @return 中文名称 */ @Override public String selectNameByOid(String oid) { VciFileDocClassifyDO fileObjectDO = selectByPrimaryKey(oid); return fileObjectDO!=null?fileObjectDO.getName():""; } /** * 批量删除对象 * * @param oids 对象的主键集合 * @return 受印象的行数 */ @Override public long batchDeleteByOids(Collection oids) { VciBaseUtil.switchCollectionForOracleIn(oids).forEach(oidList->{ Map conditionMap = new HashMap<>(); conditionMap.put("oid", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(oidList.toArray(new String[0])) + ")"); boService.deleteByCondition(VciFileBtmTypeConstant.FILE_DOC_CLASSIFY,conditionMap); }); return oids.size(); } /** * 使用编号查询 * * @param ids 编号 * @return 查询结果 */ @Override public List selectByIdCollection(Collection ids) { VciBaseUtil.alertNotNull(ids,"文档类型的编号"); List doList = new ArrayList<>(); VciBaseUtil.switchCollectionForOracleIn(ids).stream().forEach(idList-> { Map conditionMap = new HashMap<>(); conditionMap.put("id", QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(idList.toArray(new String[0])) + ")"); List tempDOs = boService.queryObject(VciFileDocClassifyDO.class, conditionMap); if(!CollectionUtils.isEmpty(tempDOs)){ doList.addAll(tempDOs); } }); return doList; } /** * 使用编号查询对象 * * @param id 编号 * @return 数据对象 */ @Override public VciFileDocClassifyDO selectById(String id) { VciBaseUtil.alertNotNull(id,"编号"); Map conditionMap = new HashMap<>(); conditionMap.put("id", id); List classifyDOS = boService.queryObject(VciFileDocClassifyDO.class, conditionMap); if(!CollectionUtils.isEmpty(classifyDOS)){ return classifyDOS.get(0); } return null; } }