From 885148352b2903da9aa85253d5954d22b501cfd2 Mon Sep 17 00:00:00 2001 From: cwchen <1048842385@qq.com> Date: Wed, 27 Aug 2025 17:52:36 +0800 Subject: [PATCH] =?UTF-8?q?SQL=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmw/subContractor/dao/SubContractDao.java | 14 ++-- .../com/bonus/bmw/team/dao/TeamBasicDao.java | 10 +-- .../SubContractor/SubContractMapper.xml | 68 +++++++-------- .../mapper/person/BasePersonMapper.xml | 84 +++++++++---------- .../main/resources/mapper/team/TeamMapper.xml | 8 +- 5 files changed, 92 insertions(+), 92 deletions(-) diff --git a/modules/bmw/src/main/java/com/bonus/bmw/subContractor/dao/SubContractDao.java b/modules/bmw/src/main/java/com/bonus/bmw/subContractor/dao/SubContractDao.java index 9b4855c..2c19d97 100644 --- a/modules/bmw/src/main/java/com/bonus/bmw/subContractor/dao/SubContractDao.java +++ b/modules/bmw/src/main/java/com/bonus/bmw/subContractor/dao/SubContractDao.java @@ -19,25 +19,25 @@ public interface SubContractDao { List list(@Param("params")Map params, @Param("offset") Integer offset, @Param("limit") Integer limit); - @Select("SELECT id,contract_name AS contractName FROM bm_sub_contract where contract_name = #{name} and is_active = '1'") + @Select("SELECT \"id\", \"contract_name\" AS contractName FROM \"ynrealname\".\"bm_sub_contract\" where \"contract_name\" = #{name} and \"is_active\" = '1'") SubContractBean getByName(String name); - @Options(useGeneratedKeys = true, keyProperty = "id") - @Insert("INSERT INTO `bm_sub_contract`(`pro_id`, `sub_id`, `contract_name`, `contract_money`, `IS_ACTIVE`) VALUES (#{proId}, #{subId}, #{contractName}, #{contractMoney}, '1')") + @SelectKey(statement = "SELECT @@IDENTITY", keyProperty = "id", before = false, resultType = Long.class) + @Insert("INSERT INTO \"ynrealname\".\"bm_sub_contract\"(\"pro_id\", \"sub_id\", \"contract_name\", \"contract_money\", \"is_active\") VALUES (#{proId}, #{subId}, #{contractName}, #{contractMoney}, '1')") int save(SubContractBean o); - @Select("select id,NAME AS companyName,type_id as unitType,legal_person as represent,`legal_phone` as representPhone, `legal_idnumber` as representIdNumber, register_date as registerDate, address from `pm_company` where id = #{id}") + @Select("select \"id\", \"name\" AS companyName, \"type_id\" as unitType, \"legal_person\" as represent, \"legal_phone\" as representPhone, \"legal_idnumber\" as representIdNumber, \"register_date\" as registerDate, \"address\" from \"ynrealname\".\"pm_company\" where \"id\" = #{id}") SubContractBean getCompanyById(Long id); int update(SubContractBean o); - @Select("select ID as companyId,NAME as companyName from pm_company where IS_ACTIVE = '1'") + @Select("select \"id\" as companyId, \"name\" as companyName from \"ynrealname\".\"pm_company\" where \"is_active\" = '1'") List getCompanyKeyValue(); - @Update("update bm_sub_contract set is_active = '0' where id = #{id}") + @Update("update \"ynrealname\".\"bm_sub_contract\" set \"is_active\" = '0' where \"id\" = #{id}") int delete(Long id); - @Update("update bm_sub_relation set is_active = '0' where sub_contract_id = #{id}") + @Update("update \"ynrealname\".\"bm_sub_relation\" set \"is_active\" = '0' where \"sub_contract_id\" = #{id}") int deleteRelation(Long id); List getTeamAndPersonList(@Param("params")Map params); diff --git a/modules/bmw/src/main/java/com/bonus/bmw/team/dao/TeamBasicDao.java b/modules/bmw/src/main/java/com/bonus/bmw/team/dao/TeamBasicDao.java index 69fb5f6..105b526 100644 --- a/modules/bmw/src/main/java/com/bonus/bmw/team/dao/TeamBasicDao.java +++ b/modules/bmw/src/main/java/com/bonus/bmw/team/dao/TeamBasicDao.java @@ -15,11 +15,11 @@ public interface TeamBasicDao { List list(@Param("params")Map params, @Param("offset") Integer offset, @Param("limit") Integer limit); - @Select("SELECT id,NAME AS subCompanyName FROM pm_dept where name = #{companyName}") + @Select("SELECT \"id\", \"name\" AS subCompanyName FROM \"ynrealname\".\"pm_dept\" where \"name\" = #{companyName}") SubCompanyBean getCompanyByName(String companyName); - @Options(useGeneratedKeys = true,keyProperty = "id") - @Insert("INSERT INTO `bm_sub_team`(`team_name`, `sub_id`, `team_idnumber`, `IS_ACTIVE`) VALUES (#{teamName}, #{subId}, #{foremanIdNumber}, '1')") + @SelectKey(statement = "SELECT @@IDENTITY", keyProperty = "id", before = false, resultType = Long.class) + @Insert("INSERT INTO \"ynrealname\".\"bm_sub_team\"(\"team_name\", \"sub_id\", \"team_Idnumber\", \"is_active\") VALUES (#{teamName}, #{subId}, #{foremanIdNumber}, '1')") int save(TeamBean o); TeamBean getById(Long id); @@ -28,7 +28,7 @@ public interface TeamBasicDao { List getTeamSelect(); - @Update("update `bm_sub_team` set is_active = '0' where id = #{id}") + @Update("update \"ynrealname\".\"bm_sub_team\" set \"is_active\" = '0' where \"id\" = #{id}") int delete(Long id); List personList(@Param("params")Map params); @@ -55,6 +55,6 @@ public interface TeamBasicDao { int addPerson(List listTeam); - @Select("select count(1) from bm_sub_team WHERE team_name = #{teamName} and is_active = '1'") + @Select("select count(1) from \"ynrealname\".\"bm_sub_team\" WHERE \"team_name\" = #{teamName} and \"is_active\" = '1'") int getTeamNumberByName(TeamBean o); } diff --git a/modules/bmw/src/main/resources/mapper/SubContractor/SubContractMapper.xml b/modules/bmw/src/main/resources/mapper/SubContractor/SubContractMapper.xml index 99f3243..619999d 100644 --- a/modules/bmw/src/main/resources/mapper/SubContractor/SubContractMapper.xml +++ b/modules/bmw/src/main/resources/mapper/SubContractor/SubContractMapper.xml @@ -4,7 +4,7 @@ - where bsc."IS_ACTIVE" = '1' + where bsc."is_active" = '1' AND po."id" in (${params.orgAll}) @@ -16,10 +16,10 @@ and ( - bs."sub_name" like concat('%', #{params.keyWord}, '%') - or bp."name" like concat('%', #{params.keyWord}, '%') - or su."username" like concat('%', #{params.keyWord}, '%') - or bsc."contract_name" like concat('%', #{params.keyWord}, '%') + bs."sub_name" like '%' || #{params.keyWord} || '%' + or bp."name" like '%' || #{params.keyWord} || '%' + or su."username" like '%' || #{params.keyWord} || '%' + or bsc."contract_name" like '%' || #{params.keyWord} || '%' ) @@ -131,7 +131,7 @@ select count(1) from ( LEFT JOIN "ynrealname"."bm_sub_team" bst ON bst."id" = bsr3."v" and bst."is_active" = '1' LEFT JOIN "ynrealname"."bm_team_user_relation" btur ON btur."team_id" = bst."id" and btur."is_active" = '1' - GROUP BY bsc."id" + GROUP BY bsc."id", bsc."contract_name", bs."sub_name", bp."name", bsc."is_complete", bsc."contract_money", su."username" OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY @@ -152,12 +152,12 @@ select count(1) from ( and bst."sub_id" = #{params.subId} and bsr."value" is null - and bst."team_name" like concat('%', #{params.keyWord}, '%') + and bst."team_name" like '%' || #{params.keyWord} || '%' and bst."id" in (${params.teamIds}) - GROUP BY bst."id" + GROUP BY bst."id", bst."team_name" @@ -214,24 +214,24 @@ select count(1) from ( bsc."sub_id" as subId, bst."id" as teamId, bst."team_name" AS teamName, - WM_CONCAT( bw."NAME" ) AS person + WM_CONCAT( bw."name" ) AS person FROM "ynrealname"."bm_sub_contract" bsc LEFT JOIN "ynrealname"."bm_sub_relation" bsr ON bsr."sub_contract_id" = bsc."id" AND bsr."type" = '3' - AND bsr."IS_ACTIVE" = '1' + AND bsr."is_active" = '1' LEFT JOIN "ynrealname"."bm_sub_team" bst ON bst."id" = bsr."value" AND bst."is_active" = '1' LEFT JOIN "ynrealname"."bm_team_user_relation" btur ON btur."team_id" = bst."id" - AND btur."IS_ACTIVE" = '1' + AND btur."is_active" = '1' LEFT JOIN "ynrealname"."bm_worker" bw ON btur."id_number" = bw."id_number" - AND bw."IS_ACTIVE" = '1' + AND bw."is_active" = '1' WHERE - bsc."IS_ACTIVE" = '1' + bsc."is_active" = '1' AND bst."team_name" IS NOT NULL and bsc."id" = #{params.id} GROUP BY - bst."id" + bsc."id", bsc."sub_id", bst."id", bst."team_name" OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY @@ -243,39 +243,39 @@ select count(1) from ( "ynrealname"."bm_sub_contract" bsc LEFT JOIN "ynrealname"."bm_sub_relation" bsr ON bsr."sub_contract_id" = bsc."id" AND bsr."type" = '3' - AND bsr."IS_ACTIVE" = '1' + AND bsr."is_active" = '1' LEFT JOIN "ynrealname"."bm_sub_team" bst ON bst."id" = bsr."value" AND bst."is_active" = '1' LEFT JOIN "ynrealname"."bm_team_user_relation" btur ON btur."team_id" = bst."id" - AND btur."IS_ACTIVE" = '1' + AND btur."is_active" = '1' LEFT JOIN "ynrealname"."bm_worker" bw ON btur."id_number" = bw."id_number" - AND bw."IS_ACTIVE" = '1' + AND bw."is_active" = '1' LEFT JOIN "ynrealname"."bm_worker_contract" bwc ON bw."id_number" = bwc."idCard" and bwc."is_active" = '1' and bwc."is_audit" = '1' WHERE - bsc."IS_ACTIVE" = '1' + bsc."is_active" = '1' and bsc."id"= #{params.id} select bw."name",bw."id_number" as idNumber,bw."sex",td."value" as postName, - bw."phone",bw."worker_skill" as workerSkill,face."photo_path" as facePhoto, - aoto."photo_path" as aotoPhoto,bst."id" as teamId,bw."ein_status" as exitStatus + bw."phone",bw."worker_skill" as workerSkill,face.PHOTO_PATH as facePhoto, + aoto.PHOTO_PATH as aotoPhoto,bst.id as teamId,bw."ein_status" as exitStatus from "ynrealname"."bm_worker" bw - LEFT JOIN "ynrealname"."bm_sub_team" bst ON bst."team_idnumber" = bw."id_number" and bst."is_active" = '1' - left join "ynrealname"."bm_worker_photo" face on face."id_number" = bw."id_number" - and face."photo_type" = 3 and face."is_active" = 1 - left join "ynrealname"."bm_worker_photo" aoto on aoto."id_number" = bw."id_number" - and aoto."photo_type" = 5 and aoto."is_active" = 1 - left join "ynrealname"."t_dict" td on td."id" = bw."post_id" and td."is_active" = '1' - where bw."is_active" = 1 + LEFT JOIN "ynrealname"."bm_sub_team" bst ON bst.team_Idnumber = bw."id_number" and bst.is_active = '1' + left join "ynrealname"."bm_worker_photo" face on face.ID_NUMBER = bw."id_number" + and face.PHOTO_TYPE = 3 and face.IS_ACTIVE = 1 + left join "ynrealname"."bm_worker_photo" aoto on aoto.ID_NUMBER = bw."id_number" + and aoto.PHOTO_TYPE = 5 and aoto.IS_ACTIVE = 1 + left join "ynrealname"."t_dict" td on td.id = bw."post_id" and td.is_active = '1' + where bw.IS_ACTIVE = 1 and ( - bw."id_number" like '%' || #{params.keyWord} || '%' - or bw."name" like '%' || #{params.keyWord} || '%' - or td."value" like '%' || #{params.keyWord} || '%' + bw."id_number" like concat('%',#{params.keyWord},'%') + or bw."name" like concat('%',#{params.keyWord},'%') + or td."value" like concat('%',#{params.keyWord},'%') ) - GROUP BY bw."id_number", bw."name", bw."sex", td."value", bw."phone", bw."worker_skill", face."photo_path", aoto."photo_path", bst."id", bw."ein_status" + GROUP BY bw."id_number", bw."name", bw."sex", td."value", bw."phone", bw."worker_skill", face.PHOTO_PATH, aoto.PHOTO_PATH, bst.id, bw."ein_status" @@ -175,8 +175,8 @@ bw."expiry_date" AS expiryDate, bw."post_id" AS postId, bw."phone", - bwp."bank_name" AS bankName, - bwp."bank_card" AS bankCard, + bwp.BANK_NAME AS bankName, + bwp.BANK_CARD AS bankCard, bw."person_type" AS personType, bw."worker_skill" AS workerSkill, bw."urgent_person" AS urgentPerson, @@ -188,11 +188,11 @@ bw."address_phone" as addressPhone FROM "ynrealname"."bm_worker" bw - LEFT JOIN "ynrealname"."bm_worker_bank" bwp ON bw."id_number" = bwp."id_number" - AND bwp."is_active" = '1' + LEFT JOIN "ynrealname"."bm_worker_bank" bwp ON bw.id_number = bwp.ID_NUMBER + AND bwp.is_active = '1' WHERE - bw."is_active" = '1' - AND bw."id_number" = #{idNumber} + bw.is_active = '1' + AND bw.id_number = #{idNumber} diff --git a/modules/bmw/src/main/resources/mapper/team/TeamMapper.xml b/modules/bmw/src/main/resources/mapper/team/TeamMapper.xml index 4e28091..bca8788 100644 --- a/modules/bmw/src/main/resources/mapper/team/TeamMapper.xml +++ b/modules/bmw/src/main/resources/mapper/team/TeamMapper.xml @@ -10,8 +10,8 @@ and ( - bs."sub_name" like concat('%', #{params.keyWord}, '%') or - bw."name" like concat('%', #{params.keyWord}, '%') + bs."sub_name" like '%' || #{params.keyWord} || '%' or + bw."name" like '%' || #{params.keyWord} || '%' ) @@ -58,7 +58,7 @@ LEFT JOIN "ynrealname"."bm_team_user_relation" btur ON btur."team_id" = bst."id" AND btur."is_active" = '1' LEFT JOIN "ynrealname"."bm_worker" bw1 ON bw1."id_number" = btur."id_number" AND bw1."is_active" = '1' AND bw1."ein_status" = '1' - GROUP BY bst."id" + GROUP BY bst."id", bst."team_name", bs."sub_name", bw."name", bst."team_Idnumber", bw."phone" order by bst."id" desc OFFSET #{offset} ROWS FETCH NEXT #{limit} ROWS ONLY @@ -84,7 +84,7 @@ and (bs."id" = #{params.subId} or bs."id" is null) - and bw."name" like concat('%',#{params.keyWord},'%') + and bw."name" like '%' || #{params.keyWord} || '%'