package com.zhongzheng.service.impl; import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.HttpStatus; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zhongzheng.bo.SysCertificateBo; import com.zhongzheng.common.filter.CustomException; import com.zhongzheng.common.model.TableDataInfo; import com.zhongzheng.common.util.DateUtils; import com.zhongzheng.domian.SysCertificate; import com.zhongzheng.domian.SysCompany; import com.zhongzheng.domian.SysPerson; import com.zhongzheng.mapper.SysCertificateMapper; import com.zhongzheng.mapper.SysPersonMapper; import com.zhongzheng.service.ISysCertificateService; import com.zhongzheng.service.ISysCompanyService; import com.zhongzheng.service.ISysPersonService; import com.zhongzheng.vo.MajorVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.stream.Collectors; /** * 菜单 业务层处理 * * @author zhongzheng */ @Service public class SysCertificateServiceImpl extends ServiceImpl implements ISysCertificateService { public static final String PREMISSION_STRING = "perms[\"{0}\"]"; @Autowired private SysPersonMapper personMapper; @Autowired private ISysCertificateService sysCertSeaService; @Autowired private ISysCompanyService sysCompanyService; @Autowired private ISysPersonService sysPersonService; @Autowired private SysCertificateMapper certMapper; public void checklegal(long personId,long userid) { SysPerson person = personMapper.selectById(personId); if (person == null) { throw new CustomException("员工不存在"); } SysCompany company = sysCompanyService.getById(person.getCompanyId()); if (company != null && company.getUserId() != userid) { throw new CustomException("非法操作"); } } @Override public TableDataInfo selectCertificateList(SysCertificateBo entity) { if (ObjectUtil.isEmpty(entity.getPageSize()) || entity.getPageSize() < 1) { entity.setPageSize(-1); entity.setPageNum(1); } TableDataInfo info = new TableDataInfo<>(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SysCertificate::getStatus, 1); if(StringUtils.isNotBlank(entity.getCompanyName())){ SysCompany company = sysCompanyService.selectCompanyByName(entity.getCompanyName(),entity.getUserId()); if(ObjectUtil.isEmpty(company)){ return new TableDataInfo<>(); } queryWrapper.eq(SysCertificate::getCompanyId, company.getCompanyId()); } if(StringUtils.isNotBlank(entity.getPersonName())){ List c_list=sysCompanyService.selectCompanyByUserid(entity.getUserId()); if(c_list.isEmpty()){ return new TableDataInfo<>(); } List companyIdList= c_list.stream().map(SysCompany::getCompanyId).collect(Collectors.toList()); List p_list= sysPersonService.selectPersonByName(entity.getPersonName(),companyIdList); if(p_list!=null&&p_list.size()==0){ return new TableDataInfo<>(); } List uids=p_list.stream().map(SysPerson::getPersonId).collect(Collectors.toList()); queryWrapper.in(SysCertificate::getPersonId, uids); } if(entity.getBeginTime()!=null&&entity.getBeginTime()>0&&entity.getEndTime()!=null&&entity.getEndTime()<0){ queryWrapper.between(SysCertificate::getExpiryDate,entity.getBeginTime(),entity.getEndTime()); } Page page = page(new Page<>(entity.getPageNum(), entity.getPageSize()),queryWrapper ); info.setRows(page.getRecords()); info.setTotal(page.getTotal()); info.setCode(HttpStatus.HTTP_OK); info.setMsg("查询成功"); return info; } @Override public SysCertificate selectCertificateById(Integer id) { return null; } @Override public long insertCertificate(SysCertificateBo entity) { if(entity.getPersonId()==0&&entity.getPersonName().isEmpty()){ throw new CustomException("参数未有企业员工信息"); } if(entity.getCompanyId()==0&&entity.getCompanyName().isEmpty()){ throw new CustomException("参数未有客户信息"); } if(entity.getPersonId()==0&& !StringUtils.isNotBlank(entity.getPersonName())){ SysPerson person=new SysPerson(); person.setPersonName(entity.getPersonName()); person.setCompanyId(entity.getCompanyId()); person.setCreator(entity.getUserId()); sysPersonService.getPersonByNameAndNoInert(person); entity.setPersonId(person.getPersonId()); } int count = 0; int i_count=0; SysCertificate info = getOne(new LambdaUpdateWrapper().eq(SysCertificate::getPersonId,entity.getPersonId()) .eq(SysCertificate::getStatus,1) .eq(SysCertificate::getCertificateTypeId,entity.getCertificateTypeId())); boolean ishascert=false; if(info!=null&&info.getCertificateId()>0){ ishascert=true; } for (MajorVo element:entity.getMajorVoList()) { i_count++; SysCertificate model = new SysCertificate(); model.setCreator(entity.getUserId()); model.setCompanyId(entity.getCompanyId()); model.setPersonId(entity.getPersonId()); model.setExpiryDate(entity.getExpiryDate()); model.setCertificateNumber(entity.getCertificateNumber()); model.setCertificateName(entity.getCertificateName()); model.setTenantId(entity.getTenantId()); model.setCreateTime(DateUtils.getNowTime()); model.setStatus(1); model.setCertificateType(entity.getCertificateType()); model.setCertificateTypeId(entity.getCertificateTypeId()); model.setCertificateTypeId2(entity.getCertificateTypeId2()); String majorName = element.getMajorName(); Long majorId = element.getExpiryDate(); if(i_count==1) { if(ishascert) { model.setIsPrimary(0); }else { model.setIsPrimary(1); } }else { model.setIsPrimary(0); } count=count+ certMapper.insert (model); } return count; } @Override public int updateCertificate(SysCertificateBo entity, long userid) { if(entity.getPersonId()==0&&entity.getPersonName().isEmpty()){ throw new CustomException("参数未有企业员工信息"); } if(entity.getCompanyId()==0&&entity.getCompanyName().isEmpty()){ throw new CustomException("参数未有客户信息"); } if(entity.getPersonId()==0&& !StringUtils.isNotBlank(entity.getPersonName())){ SysPerson person=new SysPerson(); person.setPersonName(entity.getPersonName()); person.setCompanyId(entity.getCompanyId()); person.setCreator(entity.getUserId()); sysPersonService.getPersonByNameAndNoInert(person); entity.setPersonId(person.getPersonId()); } int count = 0; int i_count=0; for (MajorVo element:entity.getMajorVoList()) { i_count++; SysCertificate model = new SysCertificate(); // model.setCertificateId(element.getCertificateId()); model.setCreator(entity.getUserId()); model.setCompanyId(entity.getCompanyId()); model.setPersonId(entity.getPersonId()); model.setExpiryDate(entity.getExpiryDate()); model.setCertificateNumber(entity.getCertificateNumber()); model.setCertificateName(entity.getCertificateName()); model.setTenantId(entity.getTenantId()); model.setCreateTime(DateUtils.getNowTime()); model.setStatus(1); model.setCertificateType(entity.getCertificateType()); model.setCertificateTypeId(entity.getCertificateTypeId()); model.setCertificateTypeId2(entity.getCertificateTypeId2()); String majorName = element.getMajorName(); Long majorId = element.getExpiryDate(); if(model.getCertificateId()>0) { count = count + certMapper.updateById(model); }else { model.setIsPrimary(0); count = count + certMapper.insert(model); } } return count; } @Override public boolean deleteCertificateById(Long id, long userid) { SysCertificate model = new SysCertificate(); model.setCertificateId(id); model.setStatus(-1); model.setModifier(userid); model.setUpdateTime(DateUtils.getNowTime()); return certMapper.updateById(model)>0; } }