Browse Source

1.完成协定方使用权限查询。增加机构权限查询。

zjh 2 years ago
parent
commit
9a92f8dfef

+ 207 - 37
cbkj_web_api/src/main/resources/mappers/myData/TPersonalPrescriptionMapper.xml

@@ -283,63 +283,233 @@
             UNION
             UNION
             SELECT t.*
             SELECT t.*
             FROM t_personal_prescription AS t
             FROM t_personal_prescription AS t
-            <if test="deptName != null and deptName != ''">
+            <if test="(deptName != null and deptName != '') and ( insName == null or insName == '' )">
                 ,sys_department as dept,t_personal_rule_auth as rule
                 ,sys_department as dept,t_personal_rule_auth as rule
+                WHERE
+                (t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
+                or (t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode} and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
             </if>
             </if>
-            WHERE t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
-            <include refid="personalPreWhere"/>
-            <if test="preOwnerName != null and preOwnerName != ''">
-                AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+
+            <if test="(deptName != null and deptName != '') and (insName != null and insName != '') ">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                ) or
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                )
+
+            </if>
+
+            <if test="(insName != null and insName != '') and (deptName == null or deptName == '')">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.APP_ID=t.DEPT_ID and dept.INS_CODE = t.INS_CODE
+                and ins.APP_ID=dept.APP_ID and ins.INS_CODE =  dept.INS_CODE
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                ) or(
+                rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                )
+
             </if>
             </if>
-            <if test="deptName != null and deptName != ''">
-              and (rule.pers_pre_id=t.PERS_PRE_ID and
-              rule.dept_id=dept.DEP_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') ) or
-                (rule.pers_pre_id=t.PERS_PRE_ID and
-                rule.dept_id=dept.DEP_ORIGIN_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') )
+            <if test="(insName == null or insName == '') and (deptName == null or deptName == '')">
+                WHERE
+                t.IS_DEL = '0' AND t.IS_SHARE = '0' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
             </if>
             </if>
+
+
+
+
+
         </if>
         </if>
         <if test="shareType != null and shareType.contains('1'.toString())">
         <if test="shareType != null and shareType.contains('1'.toString())">
             UNION
             UNION
             SELECT t.*
             SELECT t.*
             FROM t_personal_prescription AS t
             FROM t_personal_prescription AS t
-            <if test="deptName != null and deptName != ''">
+            <if test="(deptName != null and deptName != '') and ( insName == null or insName == '' )">
                 ,sys_department as dept,t_personal_rule_auth as rule
                 ,sys_department as dept,t_personal_rule_auth as rule
+                WHERE
+                (t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
+                or (t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode} and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
             </if>
             </if>
-            WHERE t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
-            <include refid="personalPreWhere"/>
-            <if test="preOwnerName != null and preOwnerName != ''">
-                AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+
+            <if test="(deptName != null and deptName != '') and (insName != null and insName != '') ">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                ) or
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                )
+
             </if>
             </if>
-            <if test="deptName != null and deptName != ''">
-                and (rule.pers_pre_id=t.PERS_PRE_ID and
-                rule.dept_id=dept.DEP_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') ) or
-                (rule.pers_pre_id=t.PERS_PRE_ID and
-                rule.dept_id=dept.DEP_ORIGIN_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') )
+
+            <if test="(insName != null and insName != '') and (deptName == null or deptName == '')">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.APP_ID=t.DEPT_ID and dept.INS_CODE = t.INS_CODE
+                and ins.APP_ID=dept.APP_ID and ins.INS_CODE =  dept.INS_CODE
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                ) or(
+                rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                )
+
+            </if>
+            <if test="(insName == null or insName == '') and (deptName == null or deptName == '')">
+                WHERE
+                t.IS_DEL = '0' AND t.IS_SHARE = '1' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
             </if>
             </if>
         </if>
         </if>
         <if test="shareType != null and shareType.contains('2'.toString())">
         <if test="shareType != null and shareType.contains('2'.toString())">
             UNION
             UNION
             SELECT t.*
             SELECT t.*
             FROM t_personal_prescription AS t
             FROM t_personal_prescription AS t
-            <if test="deptName != null and deptName != ''">
+            <if test="(deptName != null and deptName != '') and ( insName == null or insName == '' )">
                 ,sys_department as dept,t_personal_rule_auth as rule
                 ,sys_department as dept,t_personal_rule_auth as rule
+                WHERE
+                (t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
+                or (t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode} and rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                <include refid="personalPreWhere"/>
+                )
             </if>
             </if>
-            WHERE t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
-            <include refid="personalPreWhere"/>
-            <if test="preOwnerName != null and preOwnerName != ''">
-                AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
-            </if>
-            <if test="deptName != null and deptName != ''">
-                and (rule.pers_pre_id=t.PERS_PRE_ID and
-                rule.dept_id=dept.DEP_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') ) or
-                (rule.pers_pre_id=t.PERS_PRE_ID and
-                rule.dept_id=dept.DEP_ORIGIN_ID AND t.INS_CODE = dept.INS_CODE AND t.APP_ID = dept.APP_ID
-                and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%') )
+
+            <if test="(deptName != null and deptName != '') and (insName != null and insName != '') ">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                ) or
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and dept.DEP_NAME LIKE CONCAT('%',TRIM(#{deptName}),'%')
+                and t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%')
+                )
+
+            </if>
+
+            <if test="(insName != null and insName != '') and (deptName == null or deptName == '')">
+                ,sys_department as dept,t_personal_rule_auth as rule,sys_institution as ins
+                WHERE
+                (rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ID
+                and dept.APP_ID=t.DEPT_ID and dept.INS_CODE = t.INS_CODE
+                and ins.APP_ID=dept.APP_ID and ins.INS_CODE =  dept.INS_CODE
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                ) or(
+                rule.pers_pre_id=t.PERS_PRE_ID and rule.dept_id=dept.DEP_ORIGIN_ID and ins.INS_CODE=dept.INS_CODE and dept.APP_ID=ins.APP_ID
+                and ins.INS_NAME LIKE CONCAT('%',TRIM(#{insName}),'%') and t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
+                )
+
+            </if>
+            <if test="(insName == null or insName == '') and (deptName == null or deptName == '')">
+                WHERE
+                t.IS_DEL = '0' AND t.IS_SHARE = '2' AND t.INS_CODE = #{insCode}
+                <include refid="personalPreWhere"/>
+                <if test="preOwnerName != null and preOwnerName != ''">
+                    AND t.PRE_OWNER_NAME LIKE CONCAT('%',TRIM(#{preOwnerName}),'%')
+                </if>
             </if>
             </if>
         </if>
         </if>
         <if test="shareType != null and shareType.contains('3'.toString())">
         <if test="shareType != null and shareType.contains('3'.toString())">