Browse Source

000000014

zhoulisky 6 months ago
parent
commit
3ce065608a

+ 12 - 1
kd-service-api/kd-scientific-api/src/main/java/org/sky/scientific/pojo/entity/CgZlEntity.java

@@ -1,6 +1,7 @@
 
 package org.sky.scientific.pojo.entity;
 
+import com.baomidou.mybatisplus.annotation.FieldFill;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
@@ -66,22 +67,28 @@ public class CgZlEntity extends TenantEntity {
 	@Schema(description = "授权日")
 	@DateTimeFormat(pattern = DateUtil.PATTERN_DATE)
 	@JsonFormat(pattern = DateUtil.PATTERN_DATE)
-	@NotNull(message = "请选择授权日")
+//	@NotNull(message = "请选择授权日")
+	@TableField(fill = FieldFill.UPDATE)
 	private Date shouquanRq;
 
 	@Schema(description = "申请单位")
+	@TableField(fill = FieldFill.UPDATE)
 	private String sqdw;
 
 	@Schema(description = "专利权人")
+	@TableField(fill = FieldFill.UPDATE)
 	private String zlqr;
 
 	@Schema(description = "共有权人")
+	@TableField(fill = FieldFill.UPDATE)
 	private String gyqr;
 
 	@Schema(description = "发明人")
+	@TableField(fill = FieldFill.UPDATE)
 	private String fmr;
 
 	@Schema(description = "法律状态")
+	@TableField(fill = FieldFill.UPDATE)
 	private String flzt;
 
 	@Schema(description ="项目名称")
@@ -92,15 +99,19 @@ public class CgZlEntity extends TenantEntity {
 	private String xmbh;
 
 	@Schema(description = "项目id")
+	@TableField(fill = FieldFill.UPDATE)
 	private Long xmId;
 
 	@Schema(description = "附件")
+	@TableField(fill = FieldFill.UPDATE)
 	private String attachment;
 
 	@Schema(description = "收件人邮箱")
+	@TableField(fill = FieldFill.UPDATE)
 	private String sjryx;
 
 	@Schema(description = "专利提醒功能给,未发送,已发送")
+	@TableField(fill = FieldFill.UPDATE)
 	private String zltxgn;
 
 	@Schema(description =  "研发项目id集合", hidden = true)

+ 52 - 23
kd-service/kd-scientific/src/main/java/org/sky/scientific/mapper/XmTechnicianMapper.xml

@@ -302,30 +302,59 @@
 
     <select id="meiyueyanfaxiangmurengongfenpeihuizongbiao" resultType="org.sky.scientific.pojo.vo.XmSalaryVO">
         SELECT
-        xm.xm_id,m.XMBH,m.XMMC,
-        xm.year_and_month,
-        (SELECT IFNULL(SUM(work_hours),0) FROM kd_attendance_records r WHERE r.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) and LEFT(work_date,6)= xm.year_and_month) AS attendanceHours,
-        (SELECT IFNULL(SUM(work_hours),0) FROM kd_xm_technician_hours kxth WHERE kxth.xm_id = xm.xm_id AND LEFT(work_date,6)=xm.year_and_month) AS workHours,
-        (SELECT IFNULL(sum(s.average_monthly_salary),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS average_monthly_salary,
-        (SELECT IFNULL(sum(s.pension_insurance),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS pension_insurance,
-        (SELECT IFNULL(sum(s.medical_insurance),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS medical_insurance,
-        (SELECT IFNULL(sum(s.unemployment_insurance),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS unemployment_insurance,
-        (SELECT IFNULL(sum(s.injury_insurance),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS injury_insurance,
-        (SELECT IFNULL(sum(s.maternity_insurance),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS maternity_insurance,
-        (SELECT IFNULL(sum(s.provident_fund),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS provident_fund,
-        (SELECT IFNULL(sum(s.bonus),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS bonus,
-        (SELECT IFNULL(sum(s.benefit),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS benefit,
-        (SELECT IFNULL(sum(s.pension_insurance_bc),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS pension_insurance_bc,
-        (SELECT IFNULL(sum(s.medical_insurance_bc),0) FROM kd_salary s WHERE s.unicode in (select distinct (tmp.unicode) from kd_xm_technician tmp WHERE tmp.xm_id = xm.xm_id and tmp.year_and_month = xm.year_and_month) AND s.year_and_month = xm.year_and_month) AS medical_insurance_bc
-        FROM kd_xm_technician xm
-        LEFT JOIN (
-            SELECT temp.id, XMBH,
-                COALESCE(get_xm_info(temp.id, 'XMMC', #{ew.yearAndMonth}), temp.XMMC ) AS XMMC
-            FROM kd_xm as  temp
-        ) m ON m.id = xm.xm_id
-        WHERE xm.tenant_id = #{ew.tenantId} and xm.year_and_month = #{ew.yearAndMonth}
+            t.xm_id,
+            m.xmbh,
+            m.xmmc,
+            -- 工资薪金总和(每个人的工资×研发占比)
+            ROUND(SUM(COALESCE(s.average_monthly_salary, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS averageMonthlySalary,
+            -- 社保总和(每个人的社保×研发占比)
+            ROUND(SUM((COALESCE(s.pension_insurance, 0) + COALESCE(s.medical_insurance, 0) + COALESCE(s.unemployment_insurance, 0) + COALESCE(s.injury_insurance, 0) + COALESCE(s.maternity_insurance, 0)) * COALESCE(rd_ratio.ratio, 0)), 2) AS totalInsurance,
+            -- 公积金总和(每个人的公积金×研发占比)
+            ROUND(SUM(COALESCE(s.provident_fund, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS providentFund,
+            -- 奖金总和(每个人的公积金×研发占比)
+            ROUND(SUM(COALESCE(s.bonus, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS bonus,
+            -- 福利费总和(每个人的福利费×研发占比)
+            ROUND(SUM(COALESCE(s.benefit, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS benefit,
+            -- 补充养老保险总和(每个人的补充养老保险×研发占比)
+            ROUND(SUM(COALESCE(s.pension_insurance_bc, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS pensionInsuranceBc,
+            -- 补充医疗保险总和(每个人的补充医疗保险×研发占比)
+            ROUND(SUM(COALESCE(s.medical_insurance_bc, 0) * COALESCE(rd_ratio.ratio, 0)), 2) AS medicalInsuranceBc
+        FROM kd_xm_technician t
+        -- 计算研发占比的子查询
+        INNER JOIN (
+            SELECT
+                rd.tenant_id,rd.unicode,rd.work_year_month,rd.xm_id,
+            -- 研发占比 = 研发工时 / 考勤工时
+                CASE WHEN COALESCE(att.attendance_hours, 0) > 0 THEN LEAST(rd.rd_hours / att.attendance_hours, 1.0) ELSE 0 END AS ratio,
+                rd.rd_hours,att.attendance_hours
+            FROM (
+                -- 计算每个人的研发工时
+                SELECT
+                    tenant_id,unicode,LEFT(work_date, 6) AS work_year_month, xm_id,SUM(work_hours) AS rd_hours
+                FROM kd_xm_technician_hours
+                GROUP BY tenant_id, unicode, LEFT(work_date, 6), xm_id
+            ) rd
+            LEFT JOIN (
+                -- 计算每个人的考勤工时
+                SELECT
+                    tenant_id, unicode,LEFT(work_date, 6) AS work_year_month, SUM(work_hours) AS attendance_hours
+                FROM kd_attendance_records
+                GROUP BY tenant_id, unicode, LEFT(work_date, 6)
+            ) att ON rd.tenant_id = att.tenant_id AND rd.unicode = att.unicode AND rd.work_year_month = att.work_year_month
+        ) rd_ratio ON t.tenant_id = rd_ratio.tenant_id AND t.unicode = rd_ratio.unicode AND t.year_and_month = rd_ratio.work_year_month AND t.xm_id = rd_ratio.xm_id
+
+        -- 关联工资数据
+        LEFT JOIN kd_salary s ON t.tenant_id = s.tenant_id AND t.unicode = s.unicode AND t.year_and_month = s.year_and_month
+
+        left join
+        (
+            select
+                temp.id, XMBH ,
+                COALESCE(get_xm_info(temp.id, 'XMMC', #{ew.yearAndMonth}), temp.XMMC) as XMMC from kd_xm temp
+        ) m on m.id = t.xm_id
+        WHERE t.tenant_id = #{ew.tenantId} and t.year_and_month = #{ew.yearAndMonth}
         <if test="ew.xmmc!=null and ew.xmmc!=''">and m.XMMC like concat('%',#{ew.xmmc},'%')</if>
-        GROUP BY xm.xm_id
+        GROUP BY t.xm_id
     </select>
 
     <select id="meiyueyanfaxiangmurengongfenpeihuizongbiaoByYear" resultType="org.sky.scientific.pojo.vo.XmSalaryVO">

+ 5 - 2
kd-service/kd-scientific/src/main/java/org/sky/scientific/service/impl/TechnicianServiceImpl.java

@@ -607,6 +607,9 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		} else {
 			throw new ServiceException("参数yearAndMonth格式错误,yyyyMM或yyyy");
 		}
+		for (XmSalaryVO vo : list) {
+			vo.setTotal(vo.getAverageMonthlySalary().add(vo.getTotalInsurance()).add(vo.getProvidentFund()).add(vo.getBonus()).add(vo.getBenefit()).add(vo.getPensionInsuranceBc()).add(vo.getMedicalInsuranceBc()));
+		}
 		return page.setRecords(list);
 	}
 
@@ -618,9 +621,9 @@ public class TechnicianServiceImpl extends BaseServiceImpl<TechnicianMapper, Tec
 		list.forEach(temp -> {
 			temp.setXh(index.getAndIncrement() + "");
 			//社保合计
-			temp.setTotalInsurance(temp.getPensionInsurance().add(temp.getMedicalInsurance()).add(temp.getUnemploymentInsurance()).add(temp.getInjuryInsurance()).add(temp.getMaternityInsurance()));
+//			temp.setTotalInsurance(temp.getPensionInsurance().add(temp.getMedicalInsurance()).add(temp.getUnemploymentInsurance()).add(temp.getInjuryInsurance()).add(temp.getMaternityInsurance()));
 			//合计=工资+社保合计+公积金+奖金+福利费+补充养老保险+补充医疗保险
-			temp.setTotal(temp.getAverageMonthlySalary().add(temp.getTotalInsurance()).add(temp.getProvidentFund()).add(temp.getBonus()).add(temp.getBenefit()).add(temp.getPensionInsuranceBc()).add(temp.getMedicalInsuranceBc()));
+//			temp.setTotal(temp.getAverageMonthlySalary().add(temp.getTotalInsurance()).add(temp.getProvidentFund()).add(temp.getBonus()).add(temp.getBenefit()).add(temp.getPensionInsuranceBc()).add(temp.getMedicalInsuranceBc()));
 		});
 
 		InputStream templateFileName = this.getClass().getClassLoader().getResourceAsStream("export-template/研发费用管理/人员人工费用/每月研发项目人工分配汇总表.xls");

+ 3 - 2
kd-service/kd-system/src/main/java/org/sky/system/service/impl/UserServiceImpl.java

@@ -65,7 +65,8 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
 	@Transactional(rollbackFor = Exception.class)
 	public boolean submit(User user) {
 		if (StringUtil.isBlank(user.getTenantId())) {
-			user.setTenantId(KdConstant.ADMIN_TENANT_ID);
+//			user.setTenantId(KdConstant.ADMIN_TENANT_ID);
+			user.setTenantId(AuthUtil.getTenantId());
 		}
 		String tenantId = user.getTenantId();
 		Tenant tenant = SysCache.getTenant(tenantId);
@@ -78,7 +79,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
 			}
 			Long tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId));
 			if (accountNumber != null && accountNumber > 0 && accountNumber <= tenantCount) {
-				throw new ServiceException("当前租户已到最大账号额度!");
+				throw new ServiceException("企业已到最大账号额度!");
 			}
 		}
 		if (Func.isNotEmpty(user.getPassword())) {