Commit ded7f8a2 authored by 付培阳's avatar 付培阳

消防专家接口修改

parent ba9bef83
......@@ -9,6 +9,7 @@ import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.biz.common.utils.TreeParser;
import com.yeejoin.amos.boot.module.common.api.dto.ExcelDto;
import com.yeejoin.amos.boot.module.common.api.dto.FireChemicalDto;
import com.yeejoin.amos.boot.module.common.api.dto.FireExpertsDto;
import com.yeejoin.amos.boot.module.common.api.entity.DataDictionary;
import com.yeejoin.amos.boot.module.common.api.entity.FireExperts;
......@@ -126,45 +127,17 @@ public class FireExpertsController extends BaseController {
public ResponseModel<IPage<FireExpertsDto>> queryForPage(@RequestParam(value = "current") int current,
@RequestParam(value = "size") int size,
FireExpertsDto fireExpertsDto) {
FireExperts fireExperts = BeanDtoVoUtils.convert(fireExpertsDto, FireExperts.class);
Page<FireExperts> pageBean;
QueryWrapper<FireExperts> fireExpertsQueryWrapper = new QueryWrapper<>();
fireExpertsQueryWrapper.eq("is_delete", false);
Class<? extends FireExperts> aClass = fireExperts.getClass();
Arrays.stream(aClass.getDeclaredFields()).forEach(field -> {
try {
field.setAccessible(true);
Class<?> type = field.getType();
Object o = field.get(fireExperts);
if (o != null) {
String name = NameUtils.camel2Underline(field.getName());
if ("name".equalsIgnoreCase(name)) {
String fileValue = (String) o;
fireExpertsQueryWrapper.like(name, fileValue);
} else if ("expert_code".equalsIgnoreCase(name)) {
String fileValue = (String) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else if (type.equals(Integer.class)) {
Integer fileValue = (Integer) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else if (type.equals(Long.class)) {
Long fileValue = (Long) o;
fireExpertsQueryWrapper.eq(name, fileValue);
} else {
String fileValue = (String) o;
fireExpertsQueryWrapper.like(name, fileValue);
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("系统异常");
}
});
IPage<FireExperts> page;
pageBean = new Page<>(current, size);
page = fireExpertsServiceImpl.page(pageBean, fireExpertsQueryWrapper);
IPage<FireExpertsDto> fireExpertsDtoIPage = BeanDtoVoUtils.iPageDtoStreamFireExperts(page);
return ResponseHelper.buildResponse(fireExpertsDtoIPage);
Page<FireExpertsDto> page = new Page<>();
page.setCurrent(current);
page.setSize(size);
Page<FireExpertsDto> fireExpertsDtoPage = fireExpertsServiceImpl.queryForFireExpertsPage(page, false,
fireExpertsDto.getName(), fireExpertsDto.getExpertCode());
List<FireExpertsDto> fireExpertsDtoList = fireExpertsDtoPage.getRecords().stream().map(item -> {
item.setAge(BeanDtoVoUtils.getAge(item.getBirthdayTime()));
return item;
}).collect(Collectors.toList());
fireExpertsDtoPage.setRecords(fireExpertsDtoList);
return ResponseHelper.buildResponse(fireExpertsDtoPage);
}
/**
......
......@@ -25,8 +25,11 @@ public class FireExpertsServiceImpl extends BaseService<FireExpertsDto, FireExpe
/**
* 分页查询
*/
public Page<FireExpertsDto> queryForFireExpertsPage(Page<FireExpertsDto> page) {
return this.queryForPage(page, null, false);
public Page<FireExpertsDto> queryForFireExpertsPage(Page<FireExpertsDto> page,
@Condition(Operator.eq) Boolean isDelete,
@Condition(Operator.like) String name,
@Condition(Operator.eq) String expertCode) {
return this.queryForPage(page, null, false, isDelete, name, expertCode);
}
/**
......
......@@ -6,6 +6,7 @@ import com.yeejoin.amos.boot.module.common.api.entity.FireExperts;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
......@@ -111,29 +112,21 @@ public class BeanDtoVoUtils {
//由出生日期获得年龄
public static int getAge(Date birthDay) {
Calendar cal = Calendar.getInstance();
if (cal.before(birthDay)) {
throw new IllegalArgumentException("出生日期小于当前时间,无效的日期!");
if (birthDay == null) {
return 0;
}
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH);
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
LocalDate now = LocalDate.now();
Calendar cal = Calendar.getInstance();
cal.setTime(birthDay);
int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH);
int monthBirth = cal.get(Calendar.MONTH) + 1;
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
int age = yearNow - yearBirth;
if (monthNow <= monthBirth) {
if (monthNow == monthBirth) {
if (dayOfMonthNow < dayOfMonthBirth) age--;
} else {
age--;
}
LocalDate birth = LocalDate.of(yearBirth, monthBirth, dayOfMonthBirth);
if (birth.isAfter(now)) {
return 0;
}
int age = birth.until(now).getYears();
return age;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment