1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package com.pj.project.tb_entity;
- import java.util.Date;
- import java.util.List;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.pj.utils.so.SoMap;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.pj.utils.sg.*;
- import org.springframework.transaction.annotation.Transactional;
- /**
- * Service: tb_entity -- 开票主体表
- * @author lzm
- */
- @Service
- @Transactional
- public class TbEntityService extends ServiceImpl<TbEntityMapper, TbEntity> implements IService<TbEntity> {
- /** 底层 Mapper 对象 */
- @Autowired
- TbEntityMapper tbEntityMapper;
- /** 增 */
- int add(TbEntity t){
- if (!validateName(t)) {
- throw new RuntimeException("该主体名称已存在");
- }
- t.setCreateTime(new Date());
- return tbEntityMapper.add(t);
- }
- private boolean validateName(TbEntity t){
- String name = t.getName();
- TbEntity db = this.findByName(name);
- if(db == null){
- return true;
- }
- return StrUtil.equals(db.getId(), t.getId());
- }
- public TbEntity findByName(String name){
- QueryWrapper<TbEntity> qw = new QueryWrapper<>();
- qw.eq("name", name);
- return this.getOne(qw);
- }
- /** 删 */
- int delete(Long id){
- return tbEntityMapper.delete(id);
- }
- /** 改 */
- int update(TbEntity t){
- if (!validateName(t)) {
- throw new RuntimeException("该主体名称已存在");
- }
- t.setUpdateTime(new Date());
- return tbEntityMapper.update(t);
- }
- /** 查 */
- TbEntity getById(Long id){
- return tbEntityMapper.getById(id);
- }
- /** 查集合 - 根据条件(参数为空时代表忽略指定条件) */
- List<TbEntity> getList(SoMap so) {
- return tbEntityMapper.getList(so);
- }
-
- }
|