|
@@ -3,13 +3,18 @@ package com.dayou.service.impl;
|
|
|
import com.dayou.dto.ItemDTO;
|
|
|
import com.dayou.entity.Item;
|
|
|
import com.dayou.entity.ItemUser;
|
|
|
+import com.dayou.enums.ItemStateEnum;
|
|
|
import com.dayou.mapper.ItemMapper;
|
|
|
import com.dayou.mapper.ItemUserMapper;
|
|
|
import com.dayou.service.IItemService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.dayou.service.IItemStageService;
|
|
|
import com.dayou.service.IItemUserService;
|
|
|
import com.dayou.utils.LoginContext;
|
|
|
+import com.dayou.vo.ItemStageVO;
|
|
|
import com.dayou.vo.ItemStatVO;
|
|
|
+import com.dayou.vo.ItemVO;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -26,6 +31,8 @@ import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.List;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Set;
|
|
@@ -51,21 +58,29 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
|
|
|
@Autowired
|
|
|
private ItemMapper itemMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IItemStageService itemStageService;
|
|
|
+
|
|
|
@Override
|
|
|
@SuppressWarnings("unchecked")
|
|
|
- public Page<Item> selectPage(Page page,Item item,Boolean me){
|
|
|
+ public Page<ItemVO> selectPage(Page page, Item item, Boolean me){
|
|
|
Long userId = null;
|
|
|
if (me){
|
|
|
userId = LoginContext.getUserId();
|
|
|
}
|
|
|
- return itemMapper.getPage(page,item,userId);
|
|
|
- }
|
|
|
+ Page<ItemVO> result = itemMapper.getPage(page, item, userId);
|
|
|
+ List<ItemVO> records = result.getRecords();
|
|
|
+ records.stream().forEach(x->{
|
|
|
+ x.setState(getItemState(x.getId()));
|
|
|
+ });
|
|
|
+ return result;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
- public ItemDTO detail(Long id){
|
|
|
- ItemDTO itemDTO = itemMapper.xDetail(id);
|
|
|
- return itemDTO;
|
|
|
+ public ItemVO detail(Long id){
|
|
|
+ ItemVO itemVO = itemMapper.xDetail(id);
|
|
|
+ return itemVO;
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@@ -107,4 +122,31 @@ public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements II
|
|
|
public ItemStatVO stat() {
|
|
|
return itemMapper.stat();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取项目状态
|
|
|
+ * @param id 项目id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getItemState(Long id){
|
|
|
+ List<ItemStageVO> itemStageVOS = itemStageService.listByItemId(id);
|
|
|
+ if (CollectionUtils.isNotEmpty(itemStageVOS)){
|
|
|
+ LocalDate startDate = itemStageVOS.get(0).getStartDate();
|
|
|
+ LocalDate endDate = itemStageVOS.get(itemStageVOS.size() - 1).getEndDate();
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ if ((now.isAfter(startDate) || now.isEqual(startDate))
|
|
|
+ &&
|
|
|
+ (now.isBefore(endDate) || now.isEqual(endDate))){
|
|
|
+ return ItemStateEnum.PENDING.getName();
|
|
|
+ }
|
|
|
+ if (now.isAfter(endDate)){
|
|
|
+ return ItemStateEnum.COMPLETED.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (now.isBefore(startDate)){
|
|
|
+ return ItemStateEnum.UNPLAYED.getName();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ItemStateEnum.UNPLAYED.getName();
|
|
|
+ }
|
|
|
}
|