zhouli 10 months ago
parent
commit
2d4d783973

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

@@ -42,19 +42,12 @@ public class TechnicianEntity extends TenantEntity {
 	)
 	private Long id;
 
-	/**
-	 * 姓名
-	 */
 	@Schema(description = "姓名")
 	private String name;
-	/**
-	 * 工号
-	 */
+
 	@Schema(description = "工号")
 	private String number;
-	/**
-	 * 身份证号码
-	 */
+
 	@Schema(description = "身份证号码")
 	private String identityCard;
 

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

@@ -0,0 +1,87 @@
+
+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;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.sky.core.tenant.mp.TenantEntity;
+import org.sky.core.tool.utils.DateUtil;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serial;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 每月实际参研人员名单
+ *
+ * @author Kd
+ * @since 2025-06-29
+ */
+@Data
+@TableName("kd_xm_technician_monthly")
+@EqualsAndHashCode(callSuper = true)
+public class XmTechnicianMonthlyEntity extends TenantEntity {
+
+	@Serial
+	private static final long serialVersionUID = 1L;
+
+	@Schema(description = "所属年月,如:202505")
+	@NotBlank(message = "请选择所属年月")
+	@Size(min = 6, max = 6)
+	private String yearAndMonth;
+
+	@Schema(description = "研发项目ID")
+	@NotBlank(message = "请选择研发项目")
+	private Long xmId;
+
+	@Schema(description = "项目编号")
+	@TableField(exist = false)
+	private String xmbh;
+
+	@NotBlank(message = "项目名称不能为空")
+	@TableField(exist = false)
+	private String xmmc;
+
+	@NotBlank(message = "请选择科研人员")
+	@Schema(description = "科研人员ID")
+	private Long technicianId;
+
+	@Schema(description = "姓名")
+	@TableField(exist = false)
+	private String name;
+
+	@Schema(description = "工号")
+	@TableField(exist = false)
+	private String number;
+
+	@Schema(description = "身份证号码")
+	@TableField(exist = false)
+	private String identityCard;
+
+	@Schema(description = "所属二级单位")
+	@TableField(exist = false)
+	private String secondaryUnit;
+
+	@Schema(description = "部门/科室/项目部")
+	@TableField(exist = false)
+	private String department;
+
+	@Schema(description = "用工性质")
+	@TableField(exist = false)
+	private String nature;
+
+	@Schema(description = "参研情况")
+	@TableField(exist = false)
+	private String situation;
+
+	@Schema(description = "人员类型")
+	@TableField(exist = false)
+	private String personnelType;
+
+}

+ 56 - 16
kd-service/kd-scientific/src/main/java/org/sky/scientific/controller/TechnicianController.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;
@@ -25,12 +26,14 @@ import org.sky.scientific.excel.TechnicianExcel;
 import org.sky.scientific.excel.TechnicianImporter;
 import org.sky.scientific.pojo.dto.TechnicianDTO;
 import org.sky.scientific.pojo.entity.TechnicianEntity;
+import org.sky.scientific.pojo.entity.XmTechnicianMonthlyEntity;
 import org.sky.scientific.pojo.vo.TechnicianVO;
 import org.sky.scientific.service.ITechnicianService;
 import org.sky.scientific.wrapper.TechnicianWrapper;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -43,36 +46,29 @@ import java.util.Map;
 @RestController
 @AllArgsConstructor
 @RequestMapping("/technician")
-@Tag(name = "技术人员花名册", description = "技术人员花名册接口")
+@Tag(name = "技术人员管理")
 public class TechnicianController extends KdController {
 
 	private final ITechnicianService technicianService;
 
 	@GetMapping("/page")
-	@ApiOperationSupport(order = 3)
+	@ApiOperationSupport(order = 1)
 	@Operation(summary = "分页", description = "传入technician")
 	public R<IPage<TechnicianVO>> page(TechnicianDTO technician, Query query) {
 		IPage<TechnicianVO> pages = technicianService.selectTechnicianPage(Condition.getPage(query), technician);
 		return R.data(pages);
 	}
 
-	@GetMapping("/detail")
-	@ApiOperationSupport(order = 1)
-	@Operation(summary = "详情", description = "传入technician")
-	public R<TechnicianVO> detail(TechnicianEntity technician) {
-		TechnicianEntity detail = technicianService.getOne(Condition.getQueryWrapper(technician));
-		return R.data(TechnicianWrapper.build().entityVO(detail));
-	}
-
-	@PostMapping("/save")
-	@ApiOperationSupport(order = 4)
-	@Operation(summary = "新增", description = "传入technician")
-	public R save(@Valid @RequestBody TechnicianDTO technician) {
-		return R.status(technicianService.saveOrUpdateTechnician(technician));
+	@GetMapping("/page/date-interval")
+	@ApiOperationSupport(order = 2)
+	@Operation(summary = "分页-主要用于查询项目周期内的技术人员数据,传入项目的开始和结束月份,startDate, endDate, 格式:202505")
+	public R<IPage<TechnicianEntity>> pageByDateInterval(@RequestParam HashMap<String,String> param, Query query) {
+		IPage<TechnicianEntity> pages = technicianService.selectTechnicianPageByDateInterval(Condition.getPage(query),param);
+		return R.data(pages);
 	}
 
 	@PostMapping("import")
-	@ApiOperationSupport(order = 12)
+	@ApiOperationSupport(order = 5)
 	@Operation(summary = "导入", description = "传入excel")
 	public R importUser(MultipartFile file, String yearAndMonth) {
 		TechnicianImporter importer = new TechnicianImporter(technicianService, yearAndMonth);
@@ -80,6 +76,13 @@ public class TechnicianController extends KdController {
 		return R.success("操作成功");
 	}
 
+	@PostMapping("/save")
+	@ApiOperationSupport(order = 4)
+	@Operation(summary = "新增", description = "传入technician")
+	public R save(@Valid @RequestBody TechnicianDTO technician) {
+		return R.status(technicianService.saveOrUpdateTechnician(technician));
+	}
+
 	@PostMapping("/update")
 	@ApiOperationSupport(order = 5)
 	@Operation(summary = "修改", description = "传入technician")
@@ -109,4 +112,41 @@ public class TechnicianController extends KdController {
 		return R.status(technicianService.fetchLastMonthData(technician));
 	}
 
+	@GetMapping("xm/monthly/page")
+	@ApiOperationSupport(order = 20)
+	@Operation(summary = "每月实际参研人员名单-分页")
+	public R<IPage<XmTechnicianMonthlyEntity>> meiyueshijicanyuanrenyuanmingdan(XmTechnicianMonthlyEntity entity, Query query){
+		return R.data(technicianService.meiyueshijicanyuanrenyuanmingdan(entity, Condition.getPage(query)));
+	}
+
+	@GetMapping("xm/monthly/yyysbmd")
+	@ApiOperationSupport(order = 21)
+	@Operation(summary = "每月实际参研人员名单-直接引用预算表名单", description = "传入xmId、yearAndMonth")
+	public R<Boolean> zhijieyinyongyusuanbiaomingdan(XmTechnicianMonthlyEntity entity){
+		technicianService.zhijieyinyongyusuanbiaomingdan(entity);
+		return R.success();
+	}
+
+	@PostMapping("xm/monthly/submit")
+	@ApiOperationSupport(order = 22)
+	@Operation(summary = "每月实际参研人员名单-新增")
+	public R<Boolean> submitXmTechnicianMonthly(@RequestBody XmTechnicianMonthlyEntity entity){
+		return R.status(technicianService.submitXmTechnicianMonthly(entity));
+	}
+
+	@DeleteMapping("xm/monthly/remove")
+	@ApiOperationSupport(order = 23)
+	@Operation(summary = "每月实际参研人员名单-删除")
+	public R<Boolean> removeXmTechnicianMonthly(@Parameter(description = "主键集合", required = true) @RequestParam String ids){
+		return R.status(technicianService.physicalDeleteXmTechnicianMonthlyByIds(Func.toLongList(ids)));
+	}
+
+	@PostMapping("xm/monthly/export")
+	@ApiOperationSupport(order = 24)
+	@Operation(summary = "每月实际参研人员名单-导出")
+	public void exportXmTechnicianMonthly(@RequestBody XmTechnicianMonthlyEntity entity, HttpServletResponse response){
+		technicianService.exportXmTechnicianMonthly(entity);
+	}
+
+
 }

+ 4 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.java

@@ -1,6 +1,7 @@
 
 package org.sky.scientific.mapper;
 
+import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import org.sky.core.secure.KdUser;
 import org.sky.scientific.pojo.dto.TechnicianDTO;
@@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -44,6 +46,8 @@ public interface TechnicianMapper extends BaseMapper<TechnicianEntity> {
 
 	List<TechnicianVO> selectByYear(@Param("technician") TechnicianDTO technician);
 
+	List<TechnicianEntity> selectByDateInterval(IPage page, @Param("param") HashMap<String,String> param);
+
 	/**
 	 * 保存 technician 快照
 	 *

+ 29 - 30
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/TechnicianMapper.xml

@@ -164,45 +164,43 @@
                 ) s2 on s1.technician_id = s2.technician_id and s1.year_and_month = s2.latest_month
         ) s on t1.id = s.technician_id
         where t1.is_deleted = 0
-        <if test="technician.name!=null and technician.name!=''">and name like concat(concat('%', #{technician.name}),
-            '%')
-        </if>
-        <if test="technician.number!=null and technician.number!=''">and name like concat(concat('%',
-            #{technician.number}), '%')
-        </if>
-        <if test="technician.identityCard!=null and technician.identityCard!=''">and identity_card like
-            concat(concat('%', #{technician.identityCard}), '%')
-        </if>
-        <if test="technician.secondaryUnit!=null and technician.secondaryUnit!=''">and secondary_unit like
-            concat(concat('%', #{technician.secondaryUnit}), '%')
-        </if>
-        <if test="technician.department!=null and technician.department!=''">and department like concat(concat('%',
-            #{technician.department}), '%')
-        </if>
-        <if test="technician.post!=null and technician.post!=''">and post like concat(concat('%', #{technician.post}),
-            '%')
-        </if>
-        <if test="technician.postLocation!=null and technician.postLocation!=''">and post_location like
-            concat(concat('%', #{technician.postLocation}), '%')
-        </if>
+        <if test="technician.name!=null and technician.name!=''">and name like concat(concat('%', #{technician.name}),'%')</if>
+        <if test="technician.number!=null and technician.number!=''">and name like concat(concat('%',#{technician.number}), '%')</if>
+        <if test="technician.identityCard!=null and technician.identityCard!=''">and identity_card like concat(concat('%', #{technician.identityCard}), '%')</if>
+        <if test="technician.secondaryUnit!=null and technician.secondaryUnit!=''">and secondary_unit like concat(concat('%', #{technician.secondaryUnit}), '%')</if>
+        <if test="technician.department!=null and technician.department!=''">and department like concat(concat('%',#{technician.department}), '%')</if>
+        <if test="technician.post!=null and technician.post!=''">and post like concat(concat('%', #{technician.post}),'%')</if>
+        <if test="technician.postLocation!=null and technician.postLocation!=''">and post_location like concat(concat('%', #{technician.postLocation}), '%')</if>
         <if test="technician.nature!=null and technician.nature!=''">and nature = #{technician.nature}</if>
         <if test="technician.education!=null and technician.education!=''">and education = #{technician.education}</if>
         <if test="technician.degree!=null and technician.degree!=''">and degree = #{technician.degree}</if>
         <if test="technician.rank!=null and technician.rank!=''">and rank = #{technician.rank}</if>
-        <if test="technician.personnelType!=null and technician.personnelType!=''">and personnel_type =
-            #{technician.personnelType}
-        </if>
+        <if test="technician.personnelType!=null and technician.personnelType!=''">and personnel_type = #{technician.personnelType}</if>
         <if test="technician.situation !=null and technician.situation!=''">and situation = #{technician.situation}</if>
-        <if test="technician.practicingRequirement !=null and technician.practicingRequirement!=''">and
-            practicing_requirement like concat(concat('%', #{technician.practicingRequirement}), '%')
-        </if>
-        <if test="technician.hireStartDate!=null and technician.hireEndDate!=''">and hire_Date between
-            #{technician.hireStartDate} and #{technician.hireEndDate}
-        </if>
+        <if test="technician.practicingRequirement !=null and technician.practicingRequirement!=''">and practicing_requirement like concat(concat('%', #{technician.practicingRequirement}), '%')</if>
+        <if test="technician.hireStartDate!=null and technician.hireEndDate!=''">and hire_Date between #{technician.hireStartDate} and #{technician.hireEndDate}</if>
         and LEFT ( year_and_month, 4 ) = #{technician.yearAndMonth}
         order by year_and_month asc, t1.id asc
     </select>
 
+    <select id="selectByDateInterval" resultMap="technicianResultMap" parameterType="java.util.Map">
+        select t1.id, t1.name, t1.number, t1.identity_card, year_and_month ,gender, birthday,ethnic,secondary_unit,department,post,post_location,nature,hire_date,education,degree,school_name,major,rank,practicing_requirement,situation,personnel_type
+        from kd_technician t1
+        JOIN
+        (
+        SELECT s1.*
+        from kd_technician_snapshot s1
+        INNER JOIN (
+            SELECT technician_id, MAX(year_and_month) as latest_month
+            from kd_technician_snapshot
+            where year_and_month <![CDATA[>=]]> #{param.startDate} and year_and_month <![CDATA[<=]]> #{param.endDate}
+            GROUP BY technician_id
+        ) s2 on s1.technician_id = s2.technician_id and s1.year_and_month = s2.latest_month
+        ) s on t1.id = s.technician_id
+        where t1.is_deleted = 0
+        order by year_and_month asc, t1.id asc
+    </select>
+
     <select id="exportTechnician" resultType="org.sky.scientific.excel.TechnicianExcel">
         SELECT *
         FROM kd_technician ${ew.customSqlSegment}
@@ -288,4 +286,5 @@
         WHERE t1.is_deleted = 0
     </select>
 
+
 </mapper>

+ 39 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmTechnicianMonthlyMapper.java

@@ -0,0 +1,39 @@
+
+package org.sky.scientific.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.apache.ibatis.annotations.Param;
+import org.sky.scientific.excel.TechnicianExcel;
+import org.sky.scientific.pojo.dto.TechnicianDTO;
+import org.sky.scientific.pojo.entity.TechnicianEntity;
+import org.sky.scientific.pojo.entity.XmTechnicianMonthlyEntity;
+import org.sky.scientific.pojo.vo.TechnicianVO;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * 每月实际参研人员名单 Mapper 接口
+ *
+ * @author Kd
+ * @since 2025-06-11
+ */
+public interface XmTechnicianMonthlyMapper extends BaseMapper<XmTechnicianMonthlyEntity> {
+
+
+	/**
+	 * 分页
+	 * @param page
+	 * @param entity
+	 * @return
+	 */
+	IPage<XmTechnicianMonthlyEntity> meiyueshijicanyuanrenyuanmingdan(IPage<Object> page, @Param("ew") XmTechnicianMonthlyEntity entity);
+
+	/**
+	 * 批量物理删除
+	 * @param ids
+	 * @return
+	 */
+	Integer physicalDeleteXmTechnicianMonthlyByIds(List<Long> ids);
+}

+ 62 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmTechnicianMonthlyMapper.xml

@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.sky.scientific.mapper.XmTechnicianMonthlyMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="ResultMap" type="org.sky.scientific.pojo.entity.XmTechnicianMonthlyEntity">
+        <result column="id" property="id"/>
+        <result column="tenant_id" property="tenantId"/>
+        <result column="xm_id" property="xmId"/>
+        <result column="XMBH" property="xmbh"/>
+        <result column="XMMC" property="xmmc"/>
+        <result column="technician_id" property="technicianId"/>
+        <result column="name" property="name"/>
+        <result column="number" property="number"/>
+        <result column="identity_card" property="identityCard"/>
+        <result column="secondary_unit" property="secondaryUnit"/>
+        <result column="department" property="department"/>
+        <result column="nature" property="nature"/>
+        <result column="situation" property="situation"/>
+        <result column="personnel_type" property="personnelType"/>
+        <result column="create_user" property="createUser"/>
+        <result column="create_dept" property="createDept"/>
+        <result column="create_time" property="createTime"/>
+        <result column="update_user" property="updateUser"/>
+        <result column="update_time" property="updateTime"/>
+        <result column="status" property="status"/>
+        <result column="is_deleted" property="isDeleted"/>
+    </resultMap>
+
+    <delete id="physicalDeleteXmTechnicianMonthlyByIds">
+        DELETE FROM kd_xm_technician_monthly
+        WHERE id IN
+        <foreach item="id" collection="list" separator="," close=")" open="(" index="">
+            #{id}
+        </foreach>
+    </delete>
+
+    <select id="meiyueshijicanyuanrenyuanmingdan"
+            resultMap="ResultMap">
+        SELECT
+            m.id,m.year_and_month,
+            xm.xm_id, xm.XMBH, xm.XMMC,
+            t.*
+        FROM kd_xm_technician_monthly m
+        LEFT JOIN (
+            SELECT temp.id as xm_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') >= #{ew.yearAndMonth} ORDER BY bgrz.BGSXSJ DESC LIMIT 1), temp.XMMC ) AS XMMC
+            FROM kd_xm temp
+        ) xm ON m.xm_id = xm.xm_id
+        LEFT JOIN (
+            SELECT t1.id AS technician_id,t1.`name`,t1.number,t1.identity_card,ttt.secondary_unit,ttt.department,ttt.nature,ttt.situation,ttt.personnel_type
+            FROM kd_technician t1
+            LEFT JOIN
+            (
+                SELECT kts.* FROM kd_technician_snapshot kts WHERE kts.year_and_month = #{ew.yearAndMonth}
+            ) ttt ON ttt.technician_id = t1.id
+        ) t ON t.technician_id = m.technician_id
+        WHERE m.year_and_month = #{ew.yearAndMonth}
+        <if test="ew.xmId!=null and ew.xmId>0">and xm.xm_id = #{ew.xmId}</if>
+        <if test="ew.technicianId!=null and ew.technicianId!=''">and t.technician_id = #{ew.technicianId}</if>
+    </select>
+</mapper>

+ 0 - 1
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/YsRyrgfyMapper.xml

@@ -25,7 +25,6 @@
         <foreach item="id" collection="list" separator="," close=")" open="(" index="">
             #{id}
         </foreach>
-        />
     </delete>
 
     <select id="selectYsRyrgfyPage" resultMap="ysRyrgfyResultMap">

+ 48 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/ITechnicianService.java

@@ -1,12 +1,16 @@
 package org.sky.scientific.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import org.sky.scientific.pojo.dto.TechnicianDTO;
 import org.sky.scientific.pojo.entity.TechnicianEntity;
+import org.sky.scientific.pojo.entity.XmTechnicianMonthlyEntity;
 import org.sky.scientific.pojo.vo.TechnicianVO;
 import org.sky.scientific.excel.TechnicianExcel;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.sky.core.mp.base.BaseService;
+
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -67,4 +71,48 @@ public interface ITechnicianService extends BaseService<TechnicianEntity> {
 		批量删除
 	 */
 	boolean batchDeleteTechnician(List<TechnicianEntity> technicianList);
+
+	/**
+	 * 每月实际参研人员名单-直接引用预算表名单
+	 * @param entity
+	 * @return
+	 */
+	void zhijieyinyongyusuanbiaomingdan(XmTechnicianMonthlyEntity entity);
+
+
+	/**
+	 * 每月实际参研人员名单-分页
+	 * @param entity
+	 * @param page
+	 * @return
+	 */
+	IPage<XmTechnicianMonthlyEntity> meiyueshijicanyuanrenyuanmingdan(XmTechnicianMonthlyEntity entity, IPage<Object> page);
+
+	/**
+	 * 每月实际参研人员名单-新增或修改
+	 * @param entity
+	 * @return
+	 */
+	boolean submitXmTechnicianMonthly(XmTechnicianMonthlyEntity entity);
+
+	/**
+	 * 每月实际参研人员名单-删除
+	 * @param ids
+	 * @return
+	 */
+	boolean physicalDeleteXmTechnicianMonthlyByIds(List<Long> ids);
+
+	/**
+	 * 每月实际参研人员名单-导出
+	 * @param entity
+	 */
+	void exportXmTechnicianMonthly(XmTechnicianMonthlyEntity entity);
+
+	/**
+	 * 分页-主要用于查询项目周期内的技术人员数据,传入项目的开始和结束日期,startDate, endDate, 格式:20250509
+	 * @param page
+	 * @param param
+	 * @return
+	 */
+	IPage<TechnicianEntity> selectTechnicianPageByDateInterval(IPage<TechnicianEntity> page, HashMap<String,String> param);
 }

+ 100 - 0
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/TechnicianServiceImpl.java

@@ -1,16 +1,27 @@
 
 package org.sky.scientific.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import jakarta.annotation.Resource;
+import jakarta.validation.constraints.Email;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.executor.BatchResult;
+import org.glassfish.jaxb.core.v2.TODO;
 import org.sky.core.log.exception.ServiceException;
 import org.sky.core.mp.base.BaseServiceImpl;
 import org.sky.core.secure.utils.AuthUtil;
+import org.sky.core.secure.utils.SecureUtil;
 import org.sky.core.tool.utils.*;
 import org.sky.scientific.excel.TechnicianExcel;
 import org.sky.scientific.mapper.TechnicianMapper;
+import org.sky.scientific.mapper.XmTechnicianMonthlyMapper;
+import org.sky.scientific.mapper.YsRyrgfyMapper;
 import org.sky.scientific.pojo.dto.TechnicianDTO;
 import org.sky.scientific.pojo.entity.TechnicianEntity;
+import org.sky.scientific.pojo.entity.XmTechnicianMonthlyEntity;
+import org.sky.scientific.pojo.entity.YsRyrgfyEntity;
 import org.sky.scientific.pojo.vo.TechnicianVO;
 import org.sky.scientific.service.ITechnicianService;
 import org.sky.system.cache.DictCache;
@@ -18,8 +29,11 @@ import org.sky.system.pojo.enums.DictEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * 技术人员花名册 服务实现类
@@ -31,6 +45,11 @@ import java.util.Objects;
 @Service
 public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, TechnicianEntity> implements ITechnicianService {
 
+	@Resource
+	private YsRyrgfyMapper ysRyrgfyMapper;
+	@Resource
+	private XmTechnicianMonthlyMapper xmTechnicianMonthlyMapper;
+
 	@Override
 	public boolean saveOrUpdateTechnician(TechnicianEntity technician) {
 		int affectNum = 0;
@@ -131,4 +150,85 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		}
 		return affectNum == technicianList.size();
 	}
+
+	@Transactional
+	@Override
+	public void zhijieyinyongyusuanbiaomingdan(XmTechnicianMonthlyEntity entity) {
+		//先根据xmId查询项目预算中的人员名单
+		List<YsRyrgfyEntity> ysRyrgfyEntityList = ysRyrgfyMapper.selectList(Wrappers.<YsRyrgfyEntity>lambdaQuery().eq(YsRyrgfyEntity::getXmId, entity.getXmId()));
+		if(CollectionUtil.isEmpty(ysRyrgfyEntityList)){
+			throw new ServiceException("该项目没有填写人员人工费用预算");
+		}
+		List<Long> technicianIdList = ysRyrgfyEntityList.stream().map(YsRyrgfyEntity::getTechnicianId).toList();
+		for (Long technicianId : technicianIdList) {
+			XmTechnicianMonthlyEntity monthlyEntity = new XmTechnicianMonthlyEntity();
+			monthlyEntity.setXmId(entity.getXmId());
+			monthlyEntity.setTechnicianId(technicianId);
+			monthlyEntity.setYearAndMonth(entity.getYearAndMonth());
+			monthlyEntity.setCreateUser(SecureUtil.getUserId());
+			monthlyEntity.setUpdateUser(SecureUtil.getUserId());
+//			if(xmTechnicianMonthlyMapper.selectCount(Wrappers.<XmTechnicianMonthlyEntity>lambdaQuery().eq(XmTechnicianMonthlyEntity::getYearAndMonth, entity.getYearAndMonth()).eq(XmTechnicianMonthlyEntity::getTechnicianId, technicianId)) == 0){
+//				xmTechnicianMonthlyMapper.insert(monthlyEntity);
+//			}
+			xmTechnicianMonthlyMapper.insertOrUpdate(monthlyEntity);
+		}
+	}
+
+	@Override
+	public IPage<XmTechnicianMonthlyEntity> meiyueshijicanyuanrenyuanmingdan(XmTechnicianMonthlyEntity entity, IPage<Object> page) {
+		return xmTechnicianMonthlyMapper.meiyueshijicanyuanrenyuanmingdan(page, entity);
+	}
+
+	@Override
+	public boolean submitXmTechnicianMonthly(XmTechnicianMonthlyEntity entity) {
+		int affectNum = 0;
+		entity.setYearAndMonth(entity.getYearAndMonth());
+		entity.setCreateUser(SecureUtil.getUserId());
+		entity.setUpdateUser(SecureUtil.getUserId());
+		if(xmTechnicianMonthlyMapper.selectCount(Wrappers.<XmTechnicianMonthlyEntity>lambdaQuery().eq(XmTechnicianMonthlyEntity::getYearAndMonth, entity.getYearAndMonth()).eq(XmTechnicianMonthlyEntity::getTechnicianId, entity.getTechnicianId())) == 0) {
+			affectNum = xmTechnicianMonthlyMapper.insert(entity);
+		}else{
+			throw new ServiceException("科技人员已是项目在["+entity.getYearAndMonth()+"]的参研人员,请勿重复新增");
+		}
+		return affectNum == 1;
+	}
+
+	@Override
+	public boolean physicalDeleteXmTechnicianMonthlyByIds(List<Long> ids) {
+		if(CollectionUtil.isEmpty(ids)){
+			throw new ServiceException("参数不能为空");
+		}
+		return xmTechnicianMonthlyMapper.physicalDeleteXmTechnicianMonthlyByIds(ids) == ids.size();
+	}
+
+	@Override
+	public void exportXmTechnicianMonthly(XmTechnicianMonthlyEntity entity) {
+
+	}
+
+	@Override
+	public IPage<TechnicianEntity> selectTechnicianPageByDateInterval(IPage<TechnicianEntity> page, HashMap<String,String> param) {
+		if(!param.containsKey("startDate") || !param.containsKey("endDate")){
+			throw new ServiceException("startDate或者endDate为空");
+		}
+		String startDate = param.get("startDate");
+		String endDate = param.get("endDate");
+		if(startDate.contains("-")){
+			startDate = startDate.replace("-", "");
+		}
+		if(endDate.contains("-")){
+			endDate = endDate.replace("-", "");
+		}
+
+		if(startDate.length() == 8){
+			startDate = startDate.substring(0,6);
+		}
+		if(endDate.length() == 8){
+			endDate = endDate.substring(0,6);
+		}
+		param.put("startDate", startDate);
+		param.put("endDate", endDate);
+		List<TechnicianEntity> list = baseMapper.selectByDateInterval(page, param);
+		return page.setRecords(list);
+	}
 }