|
|
@@ -4,13 +4,16 @@ import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
import com.usoftchina.saas.commons.api.MessageLogService;
|
|
|
import com.usoftchina.saas.commons.dto.ComboDTO;
|
|
|
import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
|
|
|
import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.document.entities.Productbrand;
|
|
|
import com.usoftchina.saas.document.mapper.ProductbrandMapper;
|
|
|
import com.usoftchina.saas.document.service.ProductbrandService;
|
|
|
+import com.usoftchina.saas.exception.BizException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@@ -27,11 +30,21 @@ public class ProductbrandServiceImpl extends CommonBaseServiceImpl<ProductbrandM
|
|
|
public boolean save(Productbrand productbrand){
|
|
|
productbrand.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
if(productbrand.getId() == 0){
|
|
|
+ productbrand.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ productbrand.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ productbrand.setCreateTime(new Date());
|
|
|
+ //验证名称是否重复
|
|
|
+ validName(productbrand.getPb_name());
|
|
|
+
|
|
|
productbrandMapper.insertSelective(productbrand);
|
|
|
//记录日志
|
|
|
DocBaseDTO docBaseDTO = new DocBaseDTO(productbrand.getId(), null, LOG_NAME);
|
|
|
messageLogService.save(docBaseDTO);
|
|
|
}else{
|
|
|
+ productbrand.setUpdaterId(BaseContextHolder.getUserId());
|
|
|
+ productbrand.setUpdateTime(new Date());
|
|
|
+ //验证名称是否重复
|
|
|
+ validName(productbrand.getPb_name());
|
|
|
productbrandMapper.updateByPrimaryKeySelective(productbrand);
|
|
|
//记录日志
|
|
|
DocBaseDTO docBaseDTO = new DocBaseDTO(productbrand.getId(), null, LOG_NAME);
|
|
|
@@ -53,4 +66,17 @@ public class ProductbrandServiceImpl extends CommonBaseServiceImpl<ProductbrandM
|
|
|
public List<ComboDTO> getCombo() {
|
|
|
return getMapper().getCombo(BaseContextHolder.getCompanyId());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验
|
|
|
+ * @param name
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean validName(String name){
|
|
|
+ int count = getMapper().selectCountByName(name, BaseContextHolder.getCompanyId());
|
|
|
+ if (count > 0){
|
|
|
+ throw new BizException(BizExceptionCode.REPEAT_NAME);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|