|
@@ -1,5 +1,6 @@
|
|
|
package com.anyway.favor.service.impl;
|
|
|
|
|
|
+import com.anyway.exception.BusinessException;
|
|
|
import com.anyway.favor.dao.PersonDao;
|
|
|
import com.anyway.favor.model.Person;
|
|
|
import com.anyway.favor.service.PersonService;
|
|
@@ -11,6 +12,7 @@ import com.google.common.cache.LoadingCache;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Arrays;
|
|
@@ -29,7 +31,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class PersonServiceImpl implements PersonService {
|
|
|
|
|
|
@Autowired
|
|
|
- private PersonDao personMapper;
|
|
|
+ private PersonDao personDao;
|
|
|
/**
|
|
|
* 人员缓存
|
|
|
*/
|
|
@@ -43,32 +45,33 @@ public class PersonServiceImpl implements PersonService {
|
|
|
.build(new CacheLoader<Long, Person>() {
|
|
|
@Override
|
|
|
public Person load(Long id) {
|
|
|
- return personMapper.findById(id);
|
|
|
+ return personDao.findById(id);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Person> findAll() {
|
|
|
- return personMapper.findAll();
|
|
|
+ return personDao.findAll();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Person> findByCondition(Map<String, Object> map) {
|
|
|
- return personMapper.findByCondition(map);
|
|
|
+ return personDao.findByCondition(map);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Person> findPage(PageQuery<Map<String, Object>> pageQuery) {
|
|
|
PageUtils.startPage(pageQuery.getPage());
|
|
|
- List<Person> personList = personMapper.findByCondition(pageQuery.getTerms());
|
|
|
+ List<Person> personList = personDao.findByCondition(pageQuery.getTerms());
|
|
|
PageUtils.setPageTotal(personList, pageQuery.getPage());
|
|
|
return personList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public boolean add(Person person) {
|
|
|
- int c = personMapper.add(person);
|
|
|
+ int c = personDao.add(person);
|
|
|
this.updateMate(person);
|
|
|
return c > 0;
|
|
|
}
|
|
@@ -76,7 +79,7 @@ public class PersonServiceImpl implements PersonService {
|
|
|
@Override
|
|
|
public boolean update(Person person) {
|
|
|
this.updateMate(person);
|
|
|
- return personMapper.update(person) > 0;
|
|
|
+ return personDao.update(person) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -86,14 +89,14 @@ public class PersonServiceImpl implements PersonService {
|
|
|
|
|
|
@Override
|
|
|
public int delete(Long id) {
|
|
|
- int c = personMapper.deleteByIds(Arrays.asList(id));
|
|
|
+ int c = personDao.deleteByIds(Arrays.asList(id));
|
|
|
if (c < 1) {
|
|
|
return c;
|
|
|
}
|
|
|
//更新相关人员的配偶、父母
|
|
|
- personMapper.updateNullMate(id);
|
|
|
- personMapper.updateNullMother(id);
|
|
|
- personMapper.updateNullFather(id);
|
|
|
+ personDao.updateNullMate(id);
|
|
|
+ personDao.updateNullMother(id);
|
|
|
+ personDao.updateNullFather(id);
|
|
|
return c;
|
|
|
}
|
|
|
|
|
@@ -103,18 +106,22 @@ public class PersonServiceImpl implements PersonService {
|
|
|
* @param person
|
|
|
*/
|
|
|
private void updateMate(Person person) {
|
|
|
- if(person.getMateId() != null) {
|
|
|
- Person matePerson = this.findById(person.getMateId());
|
|
|
- if (matePerson != null) {
|
|
|
- if(matePerson.getMateId() == null) {
|
|
|
- matePerson.setMateId(person.getId());
|
|
|
- personMapper.update(matePerson);
|
|
|
- } else if (!person.getMateId().equals(matePerson.getMateId())) {
|
|
|
- log.error("该配偶存在其他配偶");
|
|
|
- } else {
|
|
|
- //
|
|
|
- }
|
|
|
- }
|
|
|
+ if (person.getMateId() == null) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //配偶人员
|
|
|
+ Person matePerson = this.findById(person.getMateId());
|
|
|
+ if (matePerson == null) {
|
|
|
+ log.error("配偶人员{}不存在", person.getMateId());
|
|
|
+ throw new BusinessException("无效的配偶");
|
|
|
+ }
|
|
|
+
|
|
|
+ if(matePerson.getMateId() == null) {
|
|
|
+ matePerson.setMateId(person.getId());
|
|
|
+ personDao.update(matePerson);
|
|
|
+ } else if (!person.getMateId().equals(matePerson.getMateId())) {
|
|
|
+ log.error("该配偶{}的配偶{}不是当前人员", person.getMateId(), matePerson.getMateId());
|
|
|
+ throw new BusinessException("该配偶的配偶不是当前人员");
|
|
|
}
|
|
|
}
|
|
|
}
|