|
@@ -0,0 +1,124 @@
|
|
|
+package com.zhongzheng.modules.top.system.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
+import com.zhongzheng.common.utils.DateUtils;
|
|
|
+import com.zhongzheng.modules.base.domain.Certificate;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopInstitutionAddBo;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopInstitutionEditBo;
|
|
|
+import com.zhongzheng.modules.top.system.bo.TopInstitutionQueryBo;
|
|
|
+import com.zhongzheng.modules.top.system.domain.TopInstitution;
|
|
|
+import com.zhongzheng.modules.top.system.mapper.TopInstitutionMapper;
|
|
|
+import com.zhongzheng.modules.top.system.service.ITopInstitutionService;
|
|
|
+import com.zhongzheng.modules.top.system.vo.TopInstitutionVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 职能机构Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2023-07-17
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TopInstitutionServiceImpl extends ServiceImpl<TopInstitutionMapper, TopInstitution> implements ITopInstitutionService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TopInstitutionVo queryById(Long instId){
|
|
|
+ TopInstitution db = this.baseMapper.selectById(instId);
|
|
|
+ return BeanUtil.toBean(db, TopInstitutionVo.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TopInstitutionVo> queryList(TopInstitutionQueryBo bo) {
|
|
|
+ LambdaQueryWrapper<TopInstitution> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getInstName()), TopInstitution::getInstName, bo.getInstName());
|
|
|
+ lqw.like(StrUtil.isNotBlank(bo.getBankName()), TopInstitution::getBankName, bo.getBankName());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getBank()), TopInstitution::getBank, bo.getBank());
|
|
|
+ lqw.eq(StrUtil.isNotBlank(bo.getBankAccount()), TopInstitution::getBankAccount, bo.getBankAccount());
|
|
|
+ lqw.eq(bo.getStatus() != null, TopInstitution::getStatus, bo.getStatus());
|
|
|
+ return entity2Vo(this.list(lqw));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实体类转化成视图对象
|
|
|
+ *
|
|
|
+ * @param collection 实体类集合
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<TopInstitutionVo> entity2Vo(Collection<TopInstitution> collection) {
|
|
|
+ List<TopInstitutionVo> voList = collection.stream()
|
|
|
+ .map(any -> BeanUtil.toBean(any, TopInstitutionVo.class))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collection instanceof Page) {
|
|
|
+ Page<TopInstitution> page = (Page<TopInstitution>)collection;
|
|
|
+ Page<TopInstitutionVo> pageVo = new Page<>();
|
|
|
+ BeanUtil.copyProperties(page,pageVo);
|
|
|
+ pageVo.addAll(voList);
|
|
|
+ voList = pageVo;
|
|
|
+ }
|
|
|
+ return voList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean insertByAddBo(TopInstitutionAddBo bo) {
|
|
|
+ TopInstitution add = BeanUtil.toBean(bo, TopInstitution.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.save(add);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean updateByEditBo(TopInstitutionEditBo bo) {
|
|
|
+ TopInstitution update = BeanUtil.toBean(bo, TopInstitution.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ update.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ return this.updateById(update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ *
|
|
|
+ * @param entity 实体类数据
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(TopInstitution entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ if(checkNameUnique(entity)){
|
|
|
+ throw new CustomException("名称重复");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkNameUnique(TopInstitution entity) {
|
|
|
+ TopInstitution info = getOne(new LambdaQueryWrapper<TopInstitution>()
|
|
|
+ .eq(TopInstitution::getInstName,entity.getInstName()).ne(TopInstitution::getStatus,-1)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (Validator.isNotNull(info)) {
|
|
|
+ if(Validator.isNotEmpty(entity.getInstId())){
|
|
|
+ if(entity.getInstId().longValue() != info.getInstId().longValue()){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|