|
@@ -14,6 +14,7 @@ import com.persagy.fm.profession.model.Profession;
|
|
import com.persagy.fm.profession.model.dto.AddProfessionDTO;
|
|
import com.persagy.fm.profession.model.dto.AddProfessionDTO;
|
|
import com.persagy.fm.profession.model.dto.UpdateProfessionDTO;
|
|
import com.persagy.fm.profession.model.dto.UpdateProfessionDTO;
|
|
import com.persagy.fm.profession.service.IProfessionService;
|
|
import com.persagy.fm.profession.service.IProfessionService;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.assertj.core.util.Lists;
|
|
import org.assertj.core.util.Lists;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -43,6 +44,7 @@ public class ProfessionServiceImpl extends ServiceImpl<ProfessionMapper, Profess
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public String createProfession(AddProfessionDTO addProfessionDTO) {
|
|
public String createProfession(AddProfessionDTO addProfessionDTO) {
|
|
|
|
+ checkDuplicateName(addProfessionDTO.getName());
|
|
Profession profession = ConvertProfessionTool.INSTANCE.convertAddDto2Entity(addProfessionDTO);
|
|
Profession profession = ConvertProfessionTool.INSTANCE.convertAddDto2Entity(addProfessionDTO);
|
|
// 设置默认值
|
|
// 设置默认值
|
|
setDefaultValue(profession);
|
|
setDefaultValue(profession);
|
|
@@ -51,6 +53,20 @@ public class ProfessionServiceImpl extends ServiceImpl<ProfessionMapper, Profess
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 校验专业名称是否重复
|
|
|
|
+ *
|
|
|
|
+ * @param name 名称
|
|
|
|
+ * @author lixing
|
|
|
|
+ * @version V1.0 2021/4/21 2:26 下午
|
|
|
|
+ */
|
|
|
|
+ private void checkDuplicateName(String name) {
|
|
|
|
+ List<Profession> professions = queryProfessionListByName(name);
|
|
|
|
+ if (!CollectionUtils.isEmpty(professions)) {
|
|
|
|
+ throw new IllegalArgumentException("专业名称已被使用");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 如果某些字段没有赋值,使用默认的值
|
|
* 如果某些字段没有赋值,使用默认的值
|
|
*
|
|
*
|
|
* @param profession 专业实体
|
|
* @param profession 专业实体
|
|
@@ -73,6 +89,11 @@ public class ProfessionServiceImpl extends ServiceImpl<ProfessionMapper, Profess
|
|
@Override
|
|
@Override
|
|
public void updateProfession(UpdateProfessionDTO updateProfessionDTO) {
|
|
public void updateProfession(UpdateProfessionDTO updateProfessionDTO) {
|
|
Profession profession = getById(updateProfessionDTO.getId());
|
|
Profession profession = getById(updateProfessionDTO.getId());
|
|
|
|
+ // 校验名称重复
|
|
|
|
+ if (StringUtils.isNotBlank(updateProfessionDTO.getName()) &&
|
|
|
|
+ !updateProfessionDTO.getName().equals(profession.getName())) {
|
|
|
|
+ checkDuplicateName(updateProfessionDTO.getName());
|
|
|
|
+ }
|
|
profession = ConvertProfessionTool.INSTANCE.convertUpdateDto2Entity(profession, updateProfessionDTO);
|
|
profession = ConvertProfessionTool.INSTANCE.convertUpdateDto2Entity(profession, updateProfessionDTO);
|
|
profession.setModifier(DefaultAppContext.getContext().getAccountId());
|
|
profession.setModifier(DefaultAppContext.getContext().getAccountId());
|
|
updateById(profession);
|
|
updateById(profession);
|
|
@@ -146,4 +167,23 @@ public class ProfessionServiceImpl extends ServiceImpl<ProfessionMapper, Profess
|
|
return simpleObjVO;
|
|
return simpleObjVO;
|
|
}).collect(Collectors.toList());
|
|
}).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据专业名称查询专业
|
|
|
|
+ *
|
|
|
|
+ * @return List<Profession>
|
|
|
|
+ * @author lixing
|
|
|
|
+ * @version V1.0 2021-03-19 16:38:19
|
|
|
|
+ */
|
|
|
|
+ private List<Profession> queryProfessionListByName(String name) {
|
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<Profession> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(Profession.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
|
+ queryWrapper.eq(Profession.PROP_NAME, name);
|
|
|
|
+ // 默认按创建时间倒序排序
|
|
|
|
+ queryWrapper.orderBy(true, false, Profession.PROP_CREATIONTIME);
|
|
|
|
+ return list(queryWrapper);
|
|
|
|
+ }
|
|
}
|
|
}
|