MouldServiceImpl.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.hssx.cloudmodel.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.hssx.cloudmodel.entity.Mould;
  4. import com.hssx.cloudmodel.entity.User;
  5. import com.hssx.cloudmodel.mapper.MouldMapper;
  6. import com.hssx.cloudmodel.service.MouldService;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.hssx.cloudmodel.util.HttpRespMsg;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import javax.annotation.Resource;
  12. import java.util.List;
  13. /**
  14. * <p>
  15. * 服务实现类
  16. * </p>
  17. *
  18. * @author 吴涛涛
  19. * @since 2019-07-30
  20. */
  21. @Service
  22. public class MouldServiceImpl extends ServiceImpl<MouldMapper, Mould> implements MouldService {
  23. @Resource
  24. MouldMapper mouldMapper;
  25. @Override
  26. public HttpRespMsg addAndUpdateMould(Mould mould, User user) {
  27. HttpRespMsg msg = new HttpRespMsg();
  28. if(mould.getId() != null){
  29. //修改
  30. Mould m = mouldMapper.selectOne(new QueryWrapper<Mould>().eq("model_no", mould.getModelNo()));
  31. if((m != null && m.getId()==mould.getId()) || m == null){
  32. mouldMapper.updateById(mould);
  33. }else{
  34. msg.setError("当前模具编号已存在,请重新输入其他模具编号");
  35. }
  36. }else{
  37. //查询当前模具编号的模具是否存在
  38. Integer count = mouldMapper.selectCount(new QueryWrapper<Mould>().eq("model_no", mould.getModelNo()));
  39. if(count>0){
  40. msg.setError("当前模具编号已存在,请重新输入其他模具编号");
  41. }else{
  42. mould.setCreatorId(user.getId());
  43. mouldMapper.insert(mould);
  44. }
  45. }
  46. return msg;
  47. }
  48. }