Browse Source

每月研发工时分配表

zhouli 10 months ago
parent
commit
cb925a5add

+ 21 - 0
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/dto/XmGoodsDTO.java

@@ -1,10 +1,16 @@
 
 package org.sky.scientific.pojo.dto;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import org.sky.core.tool.utils.DateUtil;
 import org.sky.scientific.pojo.entity.XmGoodsEntity;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import org.springframework.format.annotation.DateTimeFormat;
+
 import java.io.Serial;
+import java.util.Date;
 
 /**
  * 研发项目物料清单 数据传输对象实体类
@@ -18,4 +24,19 @@ public class XmGoodsDTO extends XmGoodsEntity {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
+	@Schema(description = "研发项目名称")
+	private String xmmc;
+
+	@Schema(description = "研发项目编号")
+	private String xmbh;
+
+	@Schema(description = "领取/使用日期,小")
+	@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
+	@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
+	private Date dateMin;
+
+	@Schema(description = "领取/使用日期,大")
+	@DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
+	@JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
+	private Date dateMax;
 }

+ 0 - 9
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/entity/XmGoodsEntity.java

@@ -1,7 +1,6 @@
 
 package org.sky.scientific.pojo.entity;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
@@ -43,14 +42,6 @@ public class XmGoodsEntity extends TenantEntity {
 	@NotNull(message = "请选择研发项目")
 	private Long xmId;
 
-	@Schema(description = "研发项目名称")
-	@TableField(exist = false)
-	private String xmmc;
-
-	@Schema(description = "研发项目编号")
-	@TableField(exist = false)
-	private String xmbh;
-
 	@Schema(description = "类型")
 	private String type;
 

+ 8 - 1
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/vo/XmGoodsVO.java

@@ -1,9 +1,11 @@
 
 package org.sky.scientific.pojo.vo;
 
-import org.sky.scientific.pojo.entity.XmGoodsEntity;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+import org.sky.scientific.pojo.entity.XmGoodsEntity;
+
 import java.io.Serial;
 
 /**
@@ -18,4 +20,9 @@ public class XmGoodsVO extends XmGoodsEntity {
 	@Serial
 	private static final long serialVersionUID = 1L;
 
+	@Schema(description = "研发项目名称")
+ 	private String xmmc;
+
+	@Schema(description = "研发项目编号")
+ 	private String xmbh;
 }

+ 9 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/XmGoodsController.java

@@ -1,6 +1,7 @@
 
 package org.sky.scientific.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
@@ -78,7 +79,7 @@ public class XmGoodsController extends KdController {
 	@ApiOperationSupport(order = 9)
 	@Operation(summary = "研发领料燃料动力明细清单-导出数据", description = "传入xmGoods")
 	public void exportXmGoods(@Parameter(hidden = true) @RequestParam Map<String, Object> xmGoods, KdUser kdUser, HttpServletResponse response) {
-		QueryWrapper<XmGoodsEntity> queryWrapper = Condition.getQueryWrapper(xmGoods, XmGoodsEntity.class);
+		QueryWrapper<XmGoodsDTO> queryWrapper = Condition.getQueryWrapper(xmGoods, XmGoodsDTO.class);
 		//if (!AuthUtil.isAdministrator()) {
 		//	queryWrapper.lambda().eq(XmGoods::getTenantId, kdUser.getTenantId());
 		//}
@@ -87,4 +88,11 @@ public class XmGoodsController extends KdController {
 		ExcelUtil.export(response, "研发项目物料清单数据" + DateUtil.time(), "研发项目物料清单数据表", list, XmGoodsExcel.class);
 	}
 
+	@GetMapping("yanfalingliaodan")
+	@ApiOperationSupport(order = 20)
+	@Operation(summary = "材料燃料动力费用-研发领料单")
+	public R<List<JSONObject>> yanfalingliaodan(XmGoodsDTO dto){
+		return R.data(service.yanfalingliaodan(dto));
+	}
+
 }

+ 3 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmGoodsMapper.java

@@ -35,7 +35,7 @@ public interface XmGoodsMapper extends BaseMapper<XmGoodsEntity> {
 	 * @param queryWrapper 查询条件
 	 * @return List<XmGoodsExcel>
 	 */
-	List<XmGoodsExcel> exportXmGoods(@Param("ew") Wrapper<XmGoodsEntity> queryWrapper);
+	List<XmGoodsExcel> exportXmGoods(@Param("ew") Wrapper<XmGoodsDTO> queryWrapper);
 
 	/**
 	 * 批量删除
@@ -43,4 +43,6 @@ public interface XmGoodsMapper extends BaseMapper<XmGoodsEntity> {
 	 * @return
 	 */
 	int physicalDeleteByIds(List<Long> ids);
+
+	List<XmGoodsVO> yanfalingliaodan(XmGoodsDTO dto);
 }

+ 22 - 4
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmGoodsMapper.xml

@@ -9,8 +9,7 @@
         <result column="year_and_month" property="yearAndMonth"/>
         <result column="use_date" property="useDate"/>
         <result column="xm_id" property="xmId"/>
-        <result column="xmmc" property="xmmc"/>
-        <result column="xmbh" property="xmbh"/>
+
         <result column="type" property="type"/>
         <result column="code" property="code"/>
         <result column="name" property="name"/>
@@ -29,7 +28,8 @@
     </resultMap>
 
     <resultMap id="ResultVoMap" type="org.sky.scientific.pojo.vo.XmGoodsVO" extends="ResultMap">
-
+        <result column="xmmc" property="xmmc"/>
+        <result column="xmbh" property="xmbh"/>
     </resultMap>
 
     <delete id="physicalDeleteByIds">
@@ -48,7 +48,7 @@
         where kxg.is_deleted = 0 and kxg.year_and_month = #{ew.yearAndMonth}
         <if test="ew.xmmc!=null and ew.xmbh!=''">and xm.xmmc like concat('%',#{ew.xmmc},'%')</if>
         <if test="ew.xmbh!=null and ew.xmbh!=''">and xm.xmbh like concat('%',#{ew.xmbh},'%')</if>
-        <if test="ew.type!=null and ew.type!=''">and xm.type = #{ew.type}</if>
+        <if test="ew.type!=null and ew.type!=''">and kxg.type = #{ew.type}</if>
         <if test="ew.code!=null and ew.code!=''">and kxg.code like concat('%',#{ew.code},'%')</if>
         <if test="ew.name!=null and ew.name!=''">and kxg.name like concat('%',#{ew.name},'%')</if>
         <if test="ew.model!=null and ew.model!=''">and kxg.model like concat('%',#{ew.model},'%')</if>
@@ -59,4 +59,22 @@
         SELECT * FROM kd_xm_goods ${ew.customSqlSegment}
     </select>
 
+    <select id="yanfalingliaodan" resultMap="ResultVoMap" resultType="org.sky.scientific.pojo.dto.XmGoodsDTO">
+        SELECT
+            xm.xmbh,xm.xmmc,xg.*
+        FROM kd_xm_goods xg
+        LEFT JOIN
+        (
+            SELECT
+                temp.id,xmbh,
+                COALESCE( (SELECT bgrz.BGHDZ FROM kd_xm_bgrz bgrz WHERE bgrz.XM_ID = temp.id AND bgrz.ZDMC = 'XMMC' AND DATE_FORMAT(bgrz.BGSXSJ,'%Y%m') <![CDATA[<=]]> #{yearAndMonth} ORDER BY bgrz.BGSXSJ DESC LIMIT 1),XMMC) AS xmmc
+            FROM kd_xm temp
+        ) xm on xm.id = xg.xm_id
+        WHERE xg.type = #{type} and xg.year_and_month = #{yearAndMonth}
+          <if test="xmmc!=null">and xm.xmmc like concat('%',#{xmmc},'%')</if>
+          <if test="name!=null">and xg.name like concat('%',#{name},'%')</if>
+          <if test="model!=null">and xg.model like concat('%',#{model},'%')</if>
+          <if test="dateMin!=null and dateMax!=null">and xg.use_date between #{dateMin} and #{dateMax}</if>
+    </select>
+
 </mapper>

+ 9 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/IXmGoodsService.java

@@ -1,6 +1,7 @@
 
 package org.sky.scientific.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import org.sky.scientific.pojo.dto.XmGoodsDTO;
 import org.sky.scientific.pojo.entity.XmGoodsEntity;
@@ -35,7 +36,7 @@ public interface IXmGoodsService extends BaseService<XmGoodsEntity> {
 	 * @param queryWrapper 查询条件
 	 * @return List<XmGoodsExcel>
 	 */
-	List<XmGoodsExcel> exportXmGoods(Wrapper<XmGoodsEntity> queryWrapper);
+	List<XmGoodsExcel> exportXmGoods(Wrapper<XmGoodsDTO> queryWrapper);
 
 	/**
 	 * 导入数据
@@ -57,4 +58,11 @@ public interface IXmGoodsService extends BaseService<XmGoodsEntity> {
 	 * @return
 	 */
 	boolean submit(XmGoodsEntity xmGoods);
+
+	/**
+	 * 研发领料单
+	 * @param dto
+	 * @return
+	 */
+	List<JSONObject> yanfalingliaodan(XmGoodsDTO dto);
 }

+ 59 - 14
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/XmGoodsServiceImpl.java

@@ -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;
 	}
 
 }