|
|
@@ -1,16 +1,15 @@
|
|
|
|
|
|
package org.sky.scientific.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.sky.core.excel.util.ExcelUtil;
|
|
|
import org.sky.core.log.exception.ServiceException;
|
|
|
import org.sky.core.mp.base.BaseServiceImpl;
|
|
|
-import org.sky.core.tool.utils.BeanUtil;
|
|
|
-import org.sky.core.tool.utils.CollectionUtil;
|
|
|
-import org.sky.core.tool.utils.DateUtil;
|
|
|
-import org.sky.core.tool.utils.StringUtil;
|
|
|
+import org.sky.core.tool.utils.*;
|
|
|
import org.sky.scientific.excel.XmGoodsExcel;
|
|
|
import org.sky.scientific.mapper.XmGoodsMapper;
|
|
|
import org.sky.scientific.mapper.XmMapper;
|
|
|
@@ -21,9 +20,8 @@ import org.sky.scientific.service.IXmGoodsService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 研发项目物料清单 服务实现类
|
|
|
@@ -31,6 +29,7 @@ import java.util.Objects;
|
|
|
* @author Kd
|
|
|
* @since 2025-07-17
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class XmGoodsServiceImpl extends BaseServiceImpl<XmGoodsMapper, XmGoodsEntity> implements IXmGoodsService {
|
|
|
|
|
|
@@ -47,7 +46,7 @@ public class XmGoodsServiceImpl extends BaseServiceImpl<XmGoodsMapper, XmGoodsEn
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public List<XmGoodsExcel> exportXmGoods(Wrapper<XmGoodsEntity> queryWrapper) {
|
|
|
+ public List<XmGoodsExcel> exportXmGoods(Wrapper<XmGoodsDTO> queryWrapper) {
|
|
|
List<XmGoodsExcel> xmGoodsList = baseMapper.exportXmGoods(queryWrapper);
|
|
|
//xmGoodsList.forEach(xmGoods -> {
|
|
|
// xmGoods.setTypeName(DictCache.getValue(DictEnum.YES_NO, XmGoods.getType()));
|
|
|
@@ -67,6 +66,9 @@ public class XmGoodsServiceImpl extends BaseServiceImpl<XmGoodsMapper, XmGoodsEn
|
|
|
List<XmGoodsEntity> insertList = new ArrayList<>();
|
|
|
for (XmGoodsExcel excel : data) {
|
|
|
XmGoodsEntity entity = Objects.requireNonNull(BeanUtil.copyProperties(excel, XmGoodsDTO.class));
|
|
|
+ //判断日期是否为当月日期
|
|
|
+ XmCostDetailsServiceImpl.judgeDate(entity.getUseDate(), yearAndMonth);
|
|
|
+
|
|
|
if (!StringUtil.isAllBlank(excel.getXmmc(), excel.getXmbh())) {
|
|
|
//根据项目名称或编号查询xmId
|
|
|
Long xmId = xmMapper.getXmIdByXmmcOrXmbh(yearAndMonth, excel.getXmmc(), excel.getXmbh());
|
|
|
@@ -92,14 +94,57 @@ public class XmGoodsServiceImpl extends BaseServiceImpl<XmGoodsMapper, XmGoodsEn
|
|
|
if (StringUtil.isBlank(xmGoods.getYearAndMonth())) {
|
|
|
throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
}
|
|
|
- //领用日期,必须时当月日期
|
|
|
- if(xmGoods.getUseDate() != null){
|
|
|
- boolean equals = StringUtil.equals(DateUtil.format(xmGoods.getUseDate(), DateUtil.PATTERN_YYYYMM), xmGoods.getYearAndMonth());
|
|
|
- if (!equals) {
|
|
|
- throw new ServiceException("领取日期必须是"+xmGoods.getYearAndMonth()+"月的一天");
|
|
|
+
|
|
|
+ //判断日期是否为当月日期
|
|
|
+ XmCostDetailsServiceImpl.judgeDate(xmGoods.getUseDate(), xmGoods.getYearAndMonth());
|
|
|
+
|
|
|
+ return this.saveOrUpdate(xmGoods);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> yanfalingliaodan(XmGoodsDTO dto) {
|
|
|
+ if(Func.isBlank(dto.getYearAndMonth())){
|
|
|
+ throw new ServiceException("参数yearAndMonth不能为空");
|
|
|
+ }
|
|
|
+ if(Func.isBlank(dto.getType())){
|
|
|
+ throw new ServiceException("参数type为空,或者不在[材料、燃料、动力]之列");
|
|
|
+ }
|
|
|
+ List<XmGoodsVO> list = baseMapper.yanfalingliaodan(dto);
|
|
|
+
|
|
|
+ List<JSONObject> result = new ArrayList<>();
|
|
|
+ if(CollectionUtil.isEmpty(list)){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Map<Long, List<XmGoodsVO>> mapByXmId = list.stream().collect(Collectors.groupingBy(XmGoodsVO::getXmId));
|
|
|
+ for (Long xmId : mapByXmId.keySet()) {
|
|
|
+ List<XmGoodsVO> listByXmId = mapByXmId.get(xmId);
|
|
|
+ Map<Date, List<XmGoodsVO>> mapByDay = listByXmId.stream().collect(Collectors.groupingBy(XmGoodsVO::getUseDate));
|
|
|
+
|
|
|
+ for (XmGoodsVO vo : listByXmId) {
|
|
|
+ String key = xmId+":"+ DateUtil.format(vo.getUseDate(), DateUtil.PATTERN_DATE);
|
|
|
+
|
|
|
+ if(result.isEmpty()){
|
|
|
+
|
|
|
+ ArrayList<XmGoodsVO> vos = new ArrayList<>();
|
|
|
+ vos.add(vo);
|
|
|
+ JSONObject o = new JSONObject();
|
|
|
+ o.put(key, vos);
|
|
|
+ result.add(o);
|
|
|
+ }else {
|
|
|
+ for (JSONObject o : result) {
|
|
|
+ List<XmGoodsVO> voList= null;
|
|
|
+ if(o.containsKey(key)){
|
|
|
+ voList= o.getJSONArray(key).toJavaList(XmGoodsVO.class);
|
|
|
+ }else {
|
|
|
+ voList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ o.put(key, voList);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return this.saveOrUpdate(xmGoods);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|