| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036 |
- <?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="com.management.platform.mapper.ProjectMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.management.platform.entity.Project">
- <id column="id" property="id" />
- <result column="project_name" property="projectName" />
- <result column="company_id" property="companyId" />
- <result column="project_code" property="projectCode" />
- <result column="incharger_id" property="inchargerId" />
- <result column="plan_start_date" property="planStartDate" />
- <result column="plan_end_date" property="planEndDate" />
- <result column="progress" property="progress" />
- <result column="level" property="level" />
- <result column="status" property="status" />
- <result column="finish_date" property="finishDate" />
- <result column="creator_id" property="creatorId" />
- <result column="creator_name" property="creatorName" />
- <result column="create_date" property="createDate" />
- <result column="contract_amount" property="contractAmount" />
- <result column="budget" property="budget" />
- <result column="base_man" property="baseMan" />
- <result column="base_outsourcing" property="baseOutsourcing" />
- <result column="base_risk1" property="baseRisk1" />
- <result column="base_risk2" property="baseRisk2" />
- <result column="base_fee" property="baseFee" />
- <result column="fee_man" property="feeMan" />
- <result column="customer_id" property="customerId" />
- <result column="customer_name" property="customerName" />
- <result column="is_public" property="isPublic" />
- <result column="associate_degrees" property="associateDegrees" />
- <result column="associate_degree_names" property="associateDegreeNames" />
- <result column="task_gp_incharge" property="taskGpIncharge" />
- <result column="category" property="category" />
- <result column="category_name" property="categoryName" />
- <result column="project_desc" property="projectDesc" />
- <result column="project_main_id" property="projectMainId" />
- <result column="project_main_name" property="projectMainName" />
- <result column="provider_ids" property="providerIds" />
- <result column="provider_names" property="providerNames" />
- <result column="current_stage_id" property="currentStageId" />
- <result column="current_stage_name" property="currentStageName" />
- <result column="output_value" property="outputValue" />
- <result column="dept_id" property="deptId" />
- <result column="dept_cascade" property="deptCascade" />
- <result column="bu_id" property="buId" />
- <result column="man_day" property="manDay" />
- <result column="man_day_start_date" property="manDayStartDate" />
- <result column="plate1" property="plate1" />
- <result column="plate2" property="plate2" />
- <result column="plate3" property="plate3" />
- <result column="plate4" property="plate4" />
- <result column="plate5" property="plate5" />
- <result column="plate6" property="plate6" />
- <result column="plate7" property="plate7" />
- <result column="plate8" property="plate8" />
- <result column="plate9" property="plate9" />
- <result column="plate10" property="plate10" />
- <result column="from_outside" property="fromOutside" />
- <result column="approve_id" property="approveId" />
- <result column="reviwer_id" property="reviwerId" />
- </resultMap>
- <!-- 通用查询结果列 -->
- <sql id="Base_Column_List">
- id, project_name, company_id, project_code, incharger_id, plan_start_date, plan_end_date, progress, level, status, finish_date, creator_id, creator_name, create_date, contract_amount, budget, base_man, base_outsourcing, base_risk1, base_risk2, base_fee, fee_man, customer_id, customer_name, is_public, associate_degrees, associate_degree_names, task_gp_incharge, category, category_name, project_desc, project_main_id, project_main_name, provider_ids, provider_names, current_stage_id, current_stage_name, output_value, dept_id, dept_cascade, bu_id, man_day, man_day_start_date, plate1, plate2, plate3, plate4, plate5, plate6, plate7, plate8, plate9, plate10, from_outside, approve_id, reviwer_id
- </sql>
- <insert id="batchInsert">
- insert into project(company_id,project_code,project_name,creator_id,creator_name,create_date)
- values
- <foreach collection="toAddList" separator="," item="res">
- (#{res.companyId},#{res.projectCode},#{res.projectName},#{res.creatorId},#{res.creatorName},#{res.createDate})
- </foreach>
- </insert>
- <resultMap id="BaseResultMap2" type="com.management.platform.entity.vo.ProjectWithStage">
- <result column="id" property="id" />
- <result column="project_name" property="projectName" />
- <result column="project_code" property="projectCode" />
- <result column="startDate" property="startDate" />
- <result column="endDate" property="endDate" />
- <collection property="stageCostList" javaType="java.util.ArrayList"
- ofType="com.management.platform.entity.vo.StageCost"
- select="selectStageSum" column="projectId=id,startDate=startDate,endDate=endDate"></collection>
- </resultMap>
- <resultMap id="CustomerResultMap" type="com.management.platform.entity.vo.CustomerProject" >
- <result column="customer_id" property="customerId" />
- <result column="customer_name" property="customerName" />
- <result column="contract_amount" property="contractAmount" />
- <result column="fee_man" property="feeMan" />
- <result column="project_num" property="projectNum" />
- <result column="project_ids" property="projectIds" />
- <result column="project_names" property="projectNames" />
- </resultMap>
- <select id="selectWithStage" resultType="com.management.platform.entity.vo.ProjectWithStage">
- select id, project_code, project_name,#{startDate} as startDate,#{endDate} as endDate
- from project
- where company_id = #{companyId}
- <if test="projectId != null">
- and id = #{projectId}
- </if>
- <if test="inchargerId!=null">
- and incharger_id = #{inchargerId}
- </if>
- order by is_public desc, id asc
- <if test="startIndex != null">
- limit ${startIndex}, ${endIndex}
- </if>
- </select>
- <select id="selectStageSum" resultType="com.management.platform.entity.vo.StageCost">
- select IFNULL(report.stage, '-') AS stage_name, IFNULL(SUM(report.`cost`),0) AS cost,
- IFNULL(SUM(report.`working_time`), 0) AS working_time,
- IFNULL((SELECT SUM(stages.`stages_time`) from stages WHERE stages.stages_name = report.stage GROUP BY stages_name), 0) AS stages_time,report.`project_id` as projectId
- FROM report
- left join project p on p.id=report.`project_id`
- where report.state = 1
- <if test="inchargerId!=null">
- and p.incharger_id = #{inchargerId}
- </if>
- <if test="projectIds!=null and projectIds.size()>0">
- and p.id in
- <foreach collection="projectIds" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- and report.create_date >= #{startDate}
- and report.create_date <= #{endDate}
- GROUP BY report.`project_id`,report.stage
- </select>
- <!--获取查询者所在公司每个项目的工时成本-->
- <select id="getParticipatedProject" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc,is_public as isPublic, plan_end_date as planEndDate
- FROM project
- WHERE id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- ) or incharger_id = #{userId}
- or creator_id = #{userId}
- or (is_public = 1 and company_id = #{companyId})
- ORDER BY is_public DESC, id DESC
- </select>
- <select id="getOnlyJoinProjects" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc, is_public as isPublic, plan_end_date as planEndDate
- FROM project
- WHERE status = 1 and (id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- )
- or (is_public = 1 and company_id = #{companyId}))
- ORDER BY is_public DESC, id DESC
- </select>
- <!--获取查询者所在公司每个项目的工时成本-->
- <select id="getTimeCost" resultType="java.util.Map">
- SELECT a.id, a.project_main_id as projectMainId, a.project_code as projectCode, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- WHERE a.company_id = #{companyId}
- <if test="projectId != null">
- AND a.id = #{projectId}
- </if>
- <if test="status != null and status != 0">
- AND a.status = #{status}
- </if>
- <if test="categoryId != null">
- AND a.category = #{categoryId}
- </if>
- <if test="projectIds != null">
- and a.id in
- <foreach collection="projectIds" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="userIdList != null and userIdList.size()>0">
- AND b.creator_id in
- <foreach collection="userIdList" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- <choose>
- <when test="filterDeptIds!=null and filterDeptIds.size()>0">
- and b.dept_id in
- <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </when>
- <otherwise>
- <if test="deptIds!=null and deptIds.size()>0">
- and (b.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- <if test="deptRelatedProjectIds.size() > 0">
- or a.id in
- <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
- #{pid}
- </foreach>
- </if>
- <if test="inchargeUserIds != null and inchargeUserIds.size()>0">
- OR a.`incharger_id` IN
- <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
- #{pid}
- </foreach>
- OR b.`group_id` IN(SELECT id FROM task_group WHERE incharger_id IN
- <foreach collection="inchargeUserIds" open="(" item="pid" separator="," close=")">
- #{pid}
- </foreach>
- )
- </if>
- )
- </if>
- </otherwise>
- </choose>
- AND b.state = 1
- GROUP BY a.id
- ORDER BY a.id ASC
- </select>
- <!--获取查询者所在公司每个子项目的工时成本-->
- <select id="getSubProjectTimeCost" resultType="java.util.Map">
- select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
- from sub_project a
- left join project b on b.id=a.project_id
- left join report c on c.sub_project_id=a.id
- where a.company_id=#{companyId}
- and c.state = 1
- <if test="startDate != null and endDate != null">
- and c.create_date between #{startDate} and #{endDate}
- </if>
- <if test="projectId!=null">
- and a.project_id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and b.id in
- <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- group by b.id,a.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="countWithSubProjectTimeCost" resultType="java.lang.Long">
- select count(1) from(select b.project_code as projectCode,b.project_name as projectName,a.code as subProjectCode,a.name as subProjectName,SUM(c.cost) as cost,SUM(c.working_time) as workingTime
- from sub_project a
- left join project b on b.id=a.project_id
- left join report c on c.sub_project_id=a.id
- where a.company_id=#{companyId}
- and c.state = 1
- <if test="startDate != null and endDate != null">
- and c.create_date between #{startDate} and #{endDate}
- </if>
- <if test="projectId!=null">
- and a.project_id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and b.id in
- <foreach collection="inchagerIds" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- group by b.id,a.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>) as total
- </select>
- <!--获取查询者所在公司每个项目的工时成本-->
- <select id="getTimeCostByMainProject" resultType="java.util.Map">
- SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,IFNULL(pm.name,'无主项目') as mainProjectName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- LEFT JOIN project_main pm on pm.id=a.project_main_id
- WHERE a.company_id = #{companyId}
- <if test="projectId != null">
- AND a.id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and b.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- AND b.state = 1
- GROUP BY a.project_main_id
- ORDER BY a.id ASC
- </select>
- <!--获取查询者所在公司每个项目分类的工时成本-->
- <select id="getTimeCostByCategory" resultType="java.util.Map">
- SELECT SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,IFNULL(a.category_name,'未分类')as categoryName,IFNULL(a.category,0) as category
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- WHERE a.company_id = #{companyId}
- <if test="projectCategoryId != null">
- AND a.category = #{projectCategoryId}
- </if>
- <if test="projectIds != null">
- and a.id in
- <foreach collection="projectIds" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="userIdList != null and userIdList.size()>0">
- AND b.creator_id in
- <foreach collection="userIdList" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and b.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- AND b.state = 1
- GROUP BY a.category
- ORDER BY a.category ASC
- </select>
- <!--获取自定义数值的项目统计 -->
- <select id="getCustomDataSum" resultType="java.util.Map">
- SELECT a.id, a.project_code as projectCode, a.project_name AS project, IFNULL(SUM(b.custom_data), 0) AS cost
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- WHERE a.company_id = #{companyId}
- <if test="projectId != null">
- AND a.id = #{projectId}
- </if>
- <if test="userId != null">
- AND b.creator_id = #{userId}
- </if>
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- GROUP BY a.id
- having IFNULL(SUM(b.custom_data), 0) > 0
- ORDER BY SUM(b.custom_data) DESC
- </select>
- <!--获取日报的人员月度工时 -->
- <select id="getTimeCostReport" resultType="java.util.Map">
- SELECT a.working_time as cost, b.id as projectId, b.project_name AS project, a.creator_id as creatorId
- FROM report AS a
- LEFT JOIN project AS b ON a.project_id = b.id
- LEFT JOIN user AS c ON a.creator_id = c.id
- WHERE b.company_id = #{companyId}
- <if test="projectId != null">
- AND b.id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and a.dept_id in
- <foreach collection="deptIds" separator="," close=")" open="(" item="item">
- #{item}
- </foreach>
- </if>
- AND a.state = 1
- </select>
- <!--获取人员的月度总工时 -->
- <select id="getUserMonthTimeCost" resultType="java.util.Map">
- SELECT a.creator_id as creatorId, sum(a.working_time) as cost
- FROM report AS a, user as b
- WHERE a.creator_id = b.id
- and b.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- AND a.state = 1
- group by a.creator_id
- </select>
- <!--获取某个项目每个人分别需要的工时-->
- <select id="getProjectCost" resultType="java.util.Map">
- SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = a.dept_id
- WHERE a.company_id=#{companyId}
- <choose>
- <when test="stateKey!=null and stateKey==1">
- and a.state = 1
- </when>
- <otherwise>
- and (a.state = 1 or a.state =0)
- </otherwise>
- </choose>
- <if test="projectId != null">
- and a.project_id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="userIdList != null and userIdList.size()>0">
- AND a.creator_id in
- <foreach collection="userIdList" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <choose>
- <when test="filterDeptIds!=null and filterDeptIds.size()>0">
- and a.dept_id in
- <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </when>
- <otherwise>
- <if test="deptIds!=null and deptIds.size()>0">
- and a.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </otherwise>
- </choose>
- GROUP BY b.id
- <if test="withDept">
- , a.dept_id
- </if>
- ORDER BY b.id ASC
- <if test="withDept">
- , a.dept_id ASC
- </if>
- </select>
- <!--获取某个项目分类每个人分别需要的工时-->
- <select id="getProjectCostByCategory" resultType="java.util.Map">
- SELECT b.id as creatorId,ifnull(c.category_name,'未分类') as categoryName,ifnull(c.category,0) as category, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = a.dept_id
- left join project c on c.id=a.project_id
- WHERE a.company_id=#{companyId} and a.state = 1
- <if test="curProjectCategoryId != null">
- and c.category = #{curProjectCategoryId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="userId != null">
- AND a.creator_id = #{userId}
- </if>
- GROUP BY c.category, a.dept_id
- ORDER BY c.category ASC, a.dept_id ASC
- </select>
- <!--获取个人每个项目分别需要的工时-->
- <select id="getProjectCostGroupByProject" resultType="java.util.Map">
- SELECT b.id as creatorId,a.project_id as projectId, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = a.dept_id
- WHERE a.company_id=#{companyId} and a.state = 1
- <if test="projectId != null">
- and a.project_id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="userIdList != null and userIdList.size()>0">
- AND a.creator_id in
- <foreach collection="userIdList" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and a.dept_id in
- <foreach collection="deptIds" separator="," close=")" open="(" item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY b.id,a.project_id
- ORDER BY b.id ASC, a.dept_id ASC
- </select>
- <!--获取个人每个项目分类分别需要的工时-->
- <select id="getProjectCostGroupByCategory" resultType="java.util.Map">
- SELECT a.creator_id as creatorId,ifnull(c.category_name,'未分类') as categoryName,ifnull(c.category,0) as category, b.name,a.dept_id as deptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = a.dept_id
- left join project c on c.id=a.project_id
- WHERE a.company_id=#{companyId} and a.state = 1
- <if test="projectCategoryId != null">
- and c.category = #{projectCategoryId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="userIdList != null and userIdList.size()>0">
- AND a.creator_id in
- <foreach collection="userIdList" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and a.dept_id in
- <foreach collection="deptIds" separator="," close=")" open="(" item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY b.id,c.category
- ORDER BY b.id ASC, a.dept_id ASC
- </select>
- <!-- 获取人员在日报填写的自定义数值 -->
- <select id="getProjectCusDataSumItem" resultType="java.util.Map">
- SELECT b.id as creatorId,
- b.name,department.department_name as departmentName,department.corpwx_deptid as corpwxDeptId, IFNULL(SUM(a.custom_data),0) AS cost
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = b.department_id
- WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data <> 0
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="projectId != null">
- AND a.project_id = #{projectId}
- </if>
- <if test="userId != null">
- AND a.creator_id = #{userId}
- </if>
- <if test="deptIds != null">
- AND department.department_id in
- <foreach collection="deptIds" separator="," index="index" close=")" open="(" item="item">
- #{item}
- </foreach>
- </if>
- group by b.id
- ORDER BY b.id ASC
- </select>
- <select id="getProjectCusDataDetailItem" resultType="java.util.Map">
- SELECT b.id as creatorId,project.project_code as projectCode, project.project_name as projectName,
- b.name,department.department_name as departmentName, IFNULL(a.custom_data,0) AS cost, a.create_date as createDate
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = b.department_id
- left join project on project.id = a.project_id
- WHERE a.state = 1 and b.company_id = #{companyId} and a.custom_data <> 0
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="projectId != null">
- AND a.project_id = #{projectId}
- </if>
- <if test="userId != null">
- AND a.creator_id = #{userId}
- </if>
- ORDER BY a.create_date desc
- </select>
- <!--按照项目内的阶段名称分组统计工时-->
- <select id="getCostInStage" resultType="java.util.Map">
- SELECT IFNULL(a.stage, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- WHERE a.project_id = #{projectId}
- AND a.state = 1
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- GROUP BY a.stage
- ORDER BY a.stage ASC
- </select>
- <!--按照项目内的阶段名称分组统计工时-->
- <select id="getCostByGroup" resultType="java.util.Map">
- SELECT IFNULL(tg.name, "未分配") as GroupName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM report AS a
- left join task_group tg on tg.id=a.group_id
- WHERE a.project_id = #{projectId}
- AND a.state = 1
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="gpIds != null">
- AND a.group_id in
- <foreach collection="gpIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY a.group_id
- ORDER BY a.group_id ASC
- </select>
- <!--获取全部人员工时 -->
- <select id="getAllMembCost" resultType="java.util.Map">
- SELECT b.name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney
- FROM user AS b
- left JOIN report AS a ON a.creator_id = b.id
- WHERE a.state = 1
- and b.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <if test="projectId != null">
- AND a.project_id = #{projectId}
- </if>
- GROUP BY b.id
- ORDER BY b.id ASC
- </select>
- <!--分页获取项目成本 -->
- <select id="getAllProjectCost" resultType="java.util.Map">
- SELECT id, project_code as projectCode, project_name as projectName,budget,
- (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
- FROM project WHERE project.`company_id` = #{companyId}
- and (project.status <> 3 or project.status is null)
- <if test="projectId != null">
- and project.id = #{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and project.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- order by project.is_public desc, project.id asc
- <if test="pageStart != null and pageSize != null">
- LIMIT #{pageStart},#{pageSize}
- </if>
- </select>
- <!--分页获取项目收支平衡 -->
- <select id="getProjectInAndOut" resultMap="BaseResultMap">
- SELECT project.id, project_code, project_name,contract_amount, IFNULL(contract.payment, 0) as payment,project_main.name as project_main_name,
- (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
- FROM project
- left join contract on contract.project_id = project.id
- left join project_main on project_main.id = project.project_main_id
- WHERE project.`company_id` = #{companyId}
- and (project.status <> 3 or project.status is null)
- <if test="projectId != null">
- and project.id = #{projectId}
- </if>
- <if test="projectMainId != null">
- and project.project_main_id = #{projectMainId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and project.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- order by is_public desc, project.id asc
- <if test="pageStart != null and pageSize != null">
- LIMIT #{pageStart},#{pageSize}
- </if>
- </select>
- <select id="getProjectExpenseFee" resultType="java.util.Map">
- SELECT project_id as projectId,expense_sheet.type as typeId, expense_main_type.name as typeName, IFNULL(SUM(amount),0) AS amount FROM expense_item
- left join expense_sheet on expense_sheet.id = expense_item.`expense_id`
- left join expense_main_type on expense_main_type.id = expense_sheet.`type`
- WHERE expense_sheet.`company_id` = #{companyId} AND expense_sheet.id = expense_item.`expense_id`
- AND expense_sheet.status = 0
- and project_id in
- <foreach collection="projectIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- GROUP BY project_id, expense_sheet.type
- </select>
- <!--分页获取客户项目的成本利润报表 -->
- <select id="getCustomerProjectInAndOut" resultMap="CustomerResultMap">
- SELECT customer_id, customer_name, COUNT(1) AS project_num, GROUP_CONCAT( project.id) AS project_ids, GROUP_CONCAT( project_name) AS project_names,
- SUM(contract_amount) AS contract_amount ,
- SUM((SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id)) AS fee_man
- FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
- AND (project.status <> 3 OR project.status IS NULL)
- <if test="customerId!=null">
- and project.customer_id=#{customerId}
- </if>
- <if test="projectId!=null">
- and project.id=#{projectId}
- </if>
- GROUP BY customer_id
- <if test="pageStart != null and pageSize != null">
- LIMIT #{pageStart},#{pageSize}
- </if>
- </select>
- <select id="getCustomerProjectInAndOutCount" resultType="java.lang.Integer">
- SELECT COUNT(DISTINCT customer_id) FROM project WHERE project.`company_id` = #{companyId} AND customer_id > 0
- AND (project.status <> 3 OR project.status IS NULL)
- <if test="customerId!=null">
- and project.customer_id=#{customerId}
- </if>
- <if test="projectId!=null">
- and project.id=#{projectId}
- </if>
- </select>
- <!--分页获取项目收支平衡 -->
- <select id="getProjectInAndOutByRange" resultMap="CustomerResultMap">
- SELECT project.id as id, project.id as project_ids, project_code, project_name as project_names,contract_amount,
- (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS fee_man
- FROM project WHERE project.`company_id` = #{companyId}
- and id IN <foreach collection="ids" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </select>
- <select id="getGanttData" resultType="java.util.Map">
- SELECT participation.`user_id`, user.`name`,project.id, project.`project_name`, project.`plan_start_date` as start_date, project.`plan_end_date`,
- TIMESTAMPDIFF(DAY,project.`plan_start_date`, project.`plan_end_date`) AS duration FROM participation
- LEFT JOIN user ON user.id = participation.`user_id`
- LEFT JOIN project ON project.`id` = participation.`project_id`
- WHERE participation.`user_id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- AND project.`status` = 1 and project.plan_start_date is not null and project.plan_end_date is not null
- ORDER BY participation.user_id, project.`plan_start_date`
- </select>
- <select id="getTaskPlanByMemb" resultType="java.util.Map">
- SELECT user.`id` as user_id, user.`name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name, task_executor.id as exe_id,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
- task.task_plan_type as taskPlanType,task_type.color as color, task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- left join task_type on task_type.id = task.task_plan_type
- LEFT JOIN project ON project.`id` = task.`project_id`
- WHERE user.`id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null
- AND (project.`status` = 1 or project.`status` is null)
- <if test="deptId !=null">
- and user.department_id= #{deptId}
- </if>
- <if test="taskStatus != null">
- <choose>
- <when test="taskStatus == 0">
- and task.task_status in (3, 4)
- </when>
- <when test="taskStatus == 1">
- and task.task_status = 1
- </when>
- <when test="taskStatus == 2">
- and task.task_status in (5, 6)
- </when>
- <when test="taskStatus == 3">
- and task.task_status = 2
- </when>
- </choose>
- </if>
- ORDER BY user.id, task.start_date
- </select>
- <select id="getTaskPlanByProject" resultType="java.util.Map">
- SELECT task.executor_id as user_id, task.executor_name as `name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,
- task.task_plan_type as taskPlanType,task_type.color as color,task.is_task_plan as isTaskPlan,task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
- LEFT JOIN task ON task.project_id = project.id
- left join task_type on task_type.id = task.task_plan_type
- <if test="groupName !=null and groupName !='' ">
- LEFT JOIN task_group tg ON tg.project_id = project.id
- </if>
- WHERE project.company_id = #{companyId}
- <if test="projectIds != null">
- and project.`id` IN
- <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </if>
- <if test="groupName !=null and groupName !='' ">
- and tg.name = #{groupName} and task.group_id=tg.id
- </if>
- <if test="taskType !=null ">
- and task.task_plan_type = #{taskType}
- </if>
- <if test="userIds != null">
- and exists(select 1 from task_executor where task.id=task_executor.task_id
- and task_executor.executor_id in <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">#{item}</foreach>)
- </if>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null
- AND project.`status` = 1
- ORDER BY project.id, task.start_date
- </select>
- <!-- 获取某个员工的某时间段内的加班详情 -->
- <select id="getOvertimeDetail" resultType="java.util.Map">
- SELECT report.id AS reportId,date_format(report.`create_date`, '%Y-%m-%d') AS createDate,
- report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.job_number as jobNumber, report.`working_time` AS workingTime,
- IFNULL(report.`overtime_hours`, 0) AS overtimeHours,project.id as projectId,department.corpwx_deptid as corpwxDeptId,
- project.project_name as projectName,project.project_code as projectCode,
- IFNULL(report.overtime_cost, 0) AS cost,
- IFNULL(report_extra_degree.name,'') as degreeName, department.department_name as departmentName,
- (CASE WHEN rwo.`write_off`=1 THEN 1 ELSE 0 END) AS writeOffValue,rwo.creator_name as writeOffUser,date_format(rwo.`create_time`, '%Y-%m-%d %H:%i:%s') as writeOffTime,rwo.reason as writeOffReason
- FROM report LEFT JOIN user ON user.id = report.`creator_id`
- left join project on project.id = report.project_id
- left join report_extra_degree on report_extra_degree.id = report.degree_id
- left join department on department.department_id = report.dept_id
- LEFT JOIN report_write_off rwo ON rwo.`report_id`=report.`id`
- WHERE report.is_overtime = 1
- and report.`state` = 1
- AND report.`create_date` BETWEEN #{startDate} and #{endDate}
- AND user.`company_id` = #{companyId}
- <if test="projectId != null">
- AND report.`project_id` = #{projectId}
- </if>
- <if test="userId != null">
- AND report.`creator_id` = #{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and report.dept_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and report.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="writeOffValue!=null">
- <choose>
- <when test="writeOffValue==1">
- and rwo.write_off=1
- </when>
- <otherwise>
- and (rwo.write_off is null or rwo.write_off=0)
- </otherwise>
- </choose>
- </if>
- order by user.create_time asc, report.create_date desc
- </select>
- <!--获取人员工时-->
- <select id="getUserWorkingTimeList" resultType="java.util.Map">
- SELECT report.`creator_id` AS userId, user.`name` AS username,user.corpwx_userid as corpwxUserId,user.dingding_userid as corpDdUserId,user.job_number as jobNumber,
- user.department_id As deptId,
- ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
- ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
- ifnull(SUM(report.`working_time`),0) AS workingTime,
- ifnull(SUM(report.`overtime_hours`),0) AS overtimeHours
- FROM report LEFT JOIN user ON user.id = report.`creator_id`
- left join project on project.id = report.project_id
- WHERE
- report.`state` = 1
- AND user.`is_active` = 1
- AND report.`create_date` BETWEEN #{startDate} and #{endDate}
- AND user.`company_id` =#{companyId}
- <if test="userId!=null">
- and user.id=#{userId}
- </if>
- <if test="projectId!=null">
- and project.id=#{projectId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and report.dept_id in
- <foreach collection="branchDepartment" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and report.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- group by user.id
- order by user.create_time asc, report.create_date desc
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="findCountWithUser" resultType="java.lang.Long">
- select count(*)
- from (SELECT report.`creator_id` AS userId, user.`name` AS username,
- ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
- ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
- ifnull(SUM(report.`working_time`),0) AS workingTime
- FROM report LEFT JOIN user ON user.id = report.`creator_id`
- left join project on project.id = report.project_id
- WHERE
- report.`state` = 1
- AND user.`is_active` = 1
- AND report.`create_date` BETWEEN #{startDate} and #{endDate}
- AND user.`company_id` =#{companyId}
- <if test="userId!=null">
- and user.id=#{userId}
- </if>
- <if test="projectId!=null">
- and project.id=#{projectId}
- </if>
- <if test="departmentId!=null">
- and report.dept_id=#{departmentId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and report.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- group by user.id
- order by user.create_time asc, report.create_date desc
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>) as total
- </select>
- <!--按照项目内的阶段名称分组统计工时-->
- <select id="getDegreeCost" resultType="java.util.Map">
- SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney, a.project_id AS projectId
- FROM report AS a
- left join report_extra_degree b on b.id = a.degree_id
- WHERE
- a.state = 1
- and a.company_id = #{companyId}
- <if test="departmentIds!=null and departmentIds.size()>0">
- and a.dept_id in
- <foreach collection="departmentIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="projectId != null">
- and a.project_id = #{projectId}
- </if>
- <if test="userId != null and userId!=''">
- and a.creator_id = #{userId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- GROUP BY a.degree_id
- ORDER BY a.degree_id ASC
- </select>
- <!--项目导出数据-->
- <select id="getExportData" resultType="java.util.HashMap" >
- SELECT project.id, project_name, project_code,category_name,is_public,plan_start_date, d.name AS incharger_name,GROUP_CONCAT(u.name) AS participators,
- plan_end_date, progress, LEVEL, STATUS, finish_date, creator_id, creator_name, create_date, contract_amount,
- customer_name, associate_degree_names, provider_names,provider_ids
- FROM project LEFT JOIN sub_project ON sub_project.id = project.`id`
- LEFT JOIN participation c ON c.project_id = project.`id`
- LEFT JOIN user u ON u.id = c.user_id
- LEFT JOIN user d ON d.id = project.`incharger_id`
- WHERE project.`company_id` = #{companyId}
- <if test="userId != null" >
- and (project.creator_id = #{userId} or c.user_id = #{userId})
- </if>
- GROUP BY project.id
- </select>
- <!--按项目分组导出数据-->
- <select id="getExportGroupData" resultType="java.util.Map" >
- SELECT project_code AS projectCode,project_name AS projectName,task_group.`name` AS groupName,task_group.`incharger_id` AS inchargerId,
- GROUP_CONCAT(group_participator.`user_id`) AS participatorIds
- FROM task_group
- LEFT JOIN group_participator ON task_group.id = group_participator.group_id
- LEFT JOIN project ON task_group.project_id = project.id
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- left join project_separate ps on ps.id=project.id
- </if>
- where project.company_id = #{companyId}
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- and ps.project_category_sub=#{projectCategorySub}
- </if>
- GROUP BY task_group.id
- ORDER BY project_id
- </select>
- <!--分页获取项目工时成本预警表 -->
- <select id="getProjectCostAlarm" resultType="java.util.HashMap">
- SELECT project.id, project.`project_code` as projectCode, project.`project_name` as projectName,(SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
- WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId})
- AND project_id=project.id) AS cur_cost, (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost
- WHERE base_id IN(SELECT id FROM project_basecost_setting WHERE company_id=#{companyId} AND alarm_type = 1)
- AND project_id=project.id) AS costLimit,
- (SELECT IFNULL(SUM(cost),0) FROM report WHERE state = 1 AND project_id = project.id) AS feeMan
- FROM project WHERE company_id=#{companyId}
- and (project.status <> 3 or project.status is null)
- <if test="projectId != null">
- and project.id = #{projectId}
- </if>
- <if test="pageStart != null and pageSize != null">
- LIMIT #{pageStart},#{pageSize}
- </if>
- </select>
- <select id="getBaseCostAndRealCost" resultType="java.util.HashMap">
- SELECT project.id,project_code as projectCode, project.`project_name` as projectName,
- (SELECT IFNULL(SUM(base_amount), 0) FROM project_basecost LEFT JOIN project_basecost_setting
- ON project_basecost_setting.id = project_basecost.`base_id` WHERE alarm_type=1 AND company_id=#{companyId} AND project_basecost.`project_id`=project.id) AS baseCost,
- (SELECT IFNULL(SUM(base_amount), 0) FROM project_currentcost LEFT JOIN project_basecost_setting
- ON project_basecost_setting.id = project_currentcost.`base_id` WHERE alarm_type=1 AND company_id=#{companyId} AND project_currentcost.`project_id`=project.id) AS baseCurcost,
- (SELECT IFNULL(SUM(cost), 0) FROM report WHERE report.`company_id` = #{companyId} AND project_id = project.id AND state=1 AND basecost_id >0) AS feeMan
- FROM project WHERE (STATUS <> 3 OR project.status IS NULL) AND company_id=#{companyId}
- <if test="projectId != null">
- and project.id = #{projectId}
- </if>
- <if test="list!=null and list.size()>0">
- and project.id in
- <foreach collection="list" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="pageStart != null and pageSize != null">
- LIMIT #{pageStart},#{pageSize}
- </if>
- </select>
- <select id="getWaitingReviewList" resultType="java.util.Map">
- <choose>
- <when test="stateKey==0">
- SELECT dept_manager.name as userName,`user`.corpwx_userid as corpwxUserId,IFNULL(department.department_id,0) as deptId,department.corpwx_deptid as wxDeptId,COUNT(1) as num
- FROM report AS a
- left join user on user.id = a.creator_id
- JOIN project AS b ON a.project_id=b.id
- left join sub_project as d on d.id = a.sub_project_id
- left join task on task.id = a.task_id
- left join report_extra_degree on report_extra_degree.id = a.degree_id
- left join department on department.department_id = a.audit_deptid
- left join user dept_manager on dept_manager.id = a.audit_dept_managerid
- left join department dept on dept.department_id = a.dept_id
- left join task_group on task_group.id = a.group_id
- left join user u on u.id = a.project_auditor_id
- WHERE a.company_id =#{companyId}
- and a.state = 0
- <if test="startDate!=null and endDate!=null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- AND a.is_dept_audit=1
- <if test="userId!=null">
- and dept_manager.id=#{userId}
- </if>
- <if test="departmentId!=null">
- and dept_manager.department_id=#{departmentId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and dept_manager.department_id in
- <foreach collection="deptIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by a.audit_dept_managerid
- ORDER BY a.create_date desc, a.creator_id asc
- </when>
- <otherwise>
- SELECT u.name as userName,u.corpwx_userid as corpwxUserId,IFNULL(dp.department_id,0) as deptId,dp.corpwx_deptid as wxDeptId,COUNT(1) as num
- FROM report AS a
- left join user on user.id = a.creator_id
- JOIN project AS b ON a.project_id=b.id
- left join sub_project as d on d.id = a.sub_project_id
- left join task on task.id = a.task_id
- left join report_extra_degree on report_extra_degree.id = a.degree_id
- left join department on department.department_id = a.audit_deptid
- left join user dept_manager on dept_manager.id = a.audit_dept_managerid
- left join department dept on dept.department_id = a.dept_id
- left join task_group on task_group.id = a.group_id
- left join user u on u.id = a.project_auditor_id
- left join department dp on u.department_id=dp.department_id
- WHERE a.company_id =#{companyId}
- and a.state = 0
- <if test="startDate!=null and endDate!=null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- AND a.is_dept_audit=0 and a.project_audit_state = 0
- <if test="userId!=null">
- and u.id=#{userId}
- </if>
- <if test="departmentId!=null">
- and u.department_id=#{departmentId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and u.department_id in
- <foreach collection="deptIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by a.project_auditor_id
- ORDER BY a.create_date desc, a.creator_id asc
- </otherwise>
- </choose>
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="findCount" resultType="java.lang.Long">
- select count(1)
- from (<choose>
- <when test="stateKey==0">
- SELECT dept_manager.name as userName,department.department_name as departmentName,COUNT(1) as num
- FROM report AS a
- left join user on user.id = a.creator_id
- JOIN project AS b ON a.project_id=b.id
- left join sub_project as d on d.id = a.sub_project_id
- left join task on task.id = a.task_id
- left join report_extra_degree on report_extra_degree.id = a.degree_id
- left join department on department.department_id = a.audit_deptid
- left join user dept_manager on dept_manager.id = a.audit_dept_managerid
- left join department dept on dept.department_id = a.dept_id
- left join task_group on task_group.id = a.group_id
- left join user u on u.id = a.project_auditor_id
- WHERE a.company_id =#{companyId}
- and a.state = 0
- and u.is_active = 1
- <if test="startDate!=null and endDate!=null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- AND a.is_dept_audit=1
- <if test="userId!=null">
- and dept_manager.id=#{userId}
- </if>
- <if test="departmentId!=null">
- and dept_manager.department_id=#{departmentId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and dept_manager.department_id in
- <foreach collection="deptIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by a.audit_dept_managerid
- ORDER BY a.create_date desc, a.creator_id asc
- </when>
- <otherwise>
- SELECT u.name as userName,dp.department_name as departmentName,COUNT(1) as num
- FROM report AS a
- left join user on user.id = a.creator_id
- JOIN project AS b ON a.project_id=b.id
- left join sub_project as d on d.id = a.sub_project_id
- left join task on task.id = a.task_id
- left join report_extra_degree on report_extra_degree.id = a.degree_id
- left join department on department.department_id = a.audit_deptid
- left join user dept_manager on dept_manager.id = a.audit_dept_managerid
- left join department dept on dept.department_id = a.dept_id
- left join task_group on task_group.id = a.group_id
- left join user u on u.id = a.project_auditor_id
- left join department dp on u.department_id=dp.department_id
- WHERE a.company_id =#{companyId}
- and a.state = 0
- and u.is_active = 1
- <if test="startDate!=null and endDate!=null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- AND a.is_dept_audit=0 and a.project_audit_state = 0
- <if test="userId!=null">
- and u.id=#{userId}
- </if>
- <if test="departmentId!=null">
- and u.department_id=#{departmentId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and u.department_id in
- <foreach collection="deptIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by a.project_auditor_id
- ORDER BY a.create_date desc, a.creator_id asc
- </otherwise>
- </choose>
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>) total
- </select>
- <select id="getUserWorkingTimeStatic" resultType="java.util.Map">
- select us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
- (select SUM(te.plan_hours) from task_executor te
- left join task on task.id=te.task_id
- where te.executor_id=us.id
- <if test="startDate!=null and endDate!=null">
- and task.create_date >=#{startDate} and task.create_date <=#{endDate}
- </if>) as planHours,
- (select SUM(report.working_time) from report
- left join task on task.id=report.task_id
- where report.creator_id=us.id and task_id is not null and report.state=1
- <if test="startDate!=null and endDate!=null">
- and report.create_date >=#{startDate} and report.create_date <=#{endDate}
- </if>) as workingTime
- from user us
- left join department dp on dp.department_id=us.department_id
- where us.company_id=#{companyId}
- and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date < #{startDate} AND is_active = 0)
- <if test="userId!=null and userId!=''">
- and us.id=#{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and us.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and us.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- group by us.id
- order by us.department_id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="findCountWithUserWorkingTime" resultType="java.lang.Long">
- select count(1)
- from(select us.name,dp.department_name as departmentName,
- (select SUM(te.plan_hours) from task_executor te
- left join task on task.id=te.task_id
- where te.executor_id=us.id
- <if test="startDate!=null and endDate!=null">
- and task.create_date >=#{startDate} and task.create_date <=#{endDate}
- </if>) as planHours,
- (select SUM(report.working_time) from report
- left join task on task.id=report.task_id
- where report.creator_id=us.id and task_id is not null
- <if test="startDate!=null and endDate!=null">
- and task.create_date >=#{startDate} and task.create_date <=#{endDate}
- </if>) as workingTime
- from user us
- left join department dp on dp.department_id=us.department_id
- where us.company_id=#{companyId}
- and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date < #{startDate} AND is_active = 0)
- <if test="userId!=null and userId!=''">
- and us.id=#{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and us.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and us.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- group by us.id
- order by us.department_id)as total
- </select>
- <select id="selectWithGroup" resultType="java.util.Map">
- select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- where c.company_id=#{companyId}
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and (c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- <!--或者按分组负责人的匹配-->
- <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
- or a.group_id in
- <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
- #{item}
- </foreach>
- </if>
- )
- </if>
- <if test="groupId!=null">
- and a.group_id=#{groupId}
- </if>
- group by b.name
- order by c.id
- <if test="startIndex!=null and endIndex!=null">
- limit #{startIndex},#{endIndex}
- </if>
- </select>
- <select id="selectCountWithGroup" resultType="java.lang.Long">
- select count(1) from(
- select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- where c.company_id=#{companyId}
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and (c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- <!--或者按分组负责人的匹配-->
- <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
- or a.group_id in
- <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
- #{item}
- </foreach>
- </if>
- )
- </if>
- <if test="groupId!=null">
- and a.group_id=#{groupId}
- </if>
- group by b.name
- order by c.id
- <if test="startIndex!=null and endIndex!=null">
- limit #{startIndex},#{endIndex}
- </if>) as total
- </select>
- <select id="selectWithGroupProject" resultType="java.util.Map">
- select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- left join project_separate ps on ps.id=c.id
- </if>
- where c.company_id=#{companyId}
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- and ps.project_category_sub=#{projectCategorySub}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and (c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- <!--或者按分组负责人的匹配-->
- <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
- or a.group_id in
- <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
- #{item}
- </foreach>
- </if>
- )
- </if>
- <if test="groupId!=null">
- and a.group_id=#{groupId}
- </if>
- group by c.id,b.id
- order by c.id
- <if test="startIndex!=null and endIndex!=null">
- limit #{startIndex},#{endIndex}
- </if>
- </select>
- <select id="selectCountWithGroupProject" resultType="java.lang.Long">
- select count(1) from(
- select SUM(a.working_time) as workingTime,IFNULL(b.name,'未分组') as groupName ,c.project_name as projectName,c.project_code as projectCode
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- left join project_separate ps on ps.id=c.id
- </if>
- where c.company_id=#{companyId}
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="projectCategorySub!=null and projectCategorySub!=''">
- and ps.project_category_sub=#{projectCategorySub}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and (c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- <!--或者按分组负责人的匹配-->
- <if test="taskGroupIds!=null and taskGroupIds.size() > 0">
- or a.group_id in
- <foreach collection="taskGroupIds" close=")" item="item" open="(" separator=",">
- #{item}
- </foreach>
- </if>
- )
- </if>
- <if test="groupId!=null">
- and a.group_id=#{groupId}
- </if>
- group by c.id,b.id
- order by c.id
- <if test="startIndex!=null and endIndex!=null">
- limit #{startIndex},#{endIndex}
- </if>) as total
- </select>
- <select id="getProjectGroupAndCategoryList" resultType="java.util.Map">
- select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
- where c.company_id=#{companyId} and a.state=1
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- <if test="gpNamesList !=null">
- and b.name in
- <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by c.id,b.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="getProjectGroupAndCategoryCount" resultType="java.lang.Long">
- select count(1) from
- (select c.id as projectId,c.project_name as projectName,c.project_code as projectCode,IFNULL(b.name,'未分组') as groupName,SUM(a.working_time) as workingTime,ifnull(b.id,0) as groupId
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
- where c.company_id=#{companyId} and a.state=1
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- <if test="gpNamesList !=null">
- and b.name in
- <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by c.id,b.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>) as total
- </select>
- <select id="getProjectGroupAndCategoryData" resultType="java.util.Map">
- select c.id as projectId,ifnull(b.id,0) as groupId,c.project_name as projectName,c.project_code as projectCode,SUM(a.working_time) as workingTime,IFNULL(f.stages_name,'非阶段') as stagesName
- from report a
- left join task_group b on a.group_id=b.id
- left join project c on a.project_id=c.id
- left join stages f on a.stage=f.stages_name and a.group_id=f.group_id
- where c.company_id=#{companyId} and a.state=1
- <if test="startDate!=null and endDate!=null">
- and a.create_date >=#{startDate} and a.create_date <=#{endDate}
- </if>
- <if test="projectId!=null">
- and c.id=#{projectId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and c.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- <if test="gpNamesList !=null">
- and b.name in
- <foreach collection="gpNamesList" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- group by c.id,f.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="getCostByUserCustom" resultType="java.util.Map">
- SELECT IFNULL(suc.name,'未定义') as name,SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney
- FROM user AS a
- LEFT JOIN report AS b ON a.id = b.creator_id
- LEFT JOIN project AS c ON b.project_id = c.id
- left join user_custom uc on uc.company_id=a.company_id
- left join sub_user_custom suc on suc.name=a.${fieldName} and suc.user_custom_id=uc.id
- WHERE b.state = 1
- AND a.company_id = #{companyId}
- <if test="startDate!=null and endDate!=null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- and uc.id=#{customId}
- <if test="deptIds!=null and deptIds.size()>0">
- and a.department_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- <if test="subCustomName!=null">
- and suc.name=#{subCustomName}
- </if>
- GROUP BY suc.name
- </select>
- <select id="getEmpMonthHours" resultType="java.util.Map">
- select us.id as userId,us.name,us.corpwx_userid as corpwxUserId,us.job_number as jobNumber,dp.department_name as departmentName,dp.corpwx_deptid as corpwxDeptId,
- (select allday from time_type te
- where te.company_id=#{companyId}) as allday,
- (select SUM(report.working_time) from report
- where report.creator_id=us.id and report.state=1
- and report.create_date >=#{startDate} and report.create_date <=#{endDate})
- as workingTime
- from user us
- left join department dp on dp.department_id=us.department_id
- where us.company_id=#{companyId}
- and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date < #{startDate} AND is_active = 0)
- <if test="userId!=null and userId!=''">
- and us.id=#{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and us.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and us.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- group by us.id
- order by us.department_id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="findCountWithEmpMonthHours" resultType="java.lang.Long">
- select count(1)
- from(select us.name,dp.department_name as departmentName,
- (select SUM(report.working_time) from report
- where report.creator_id=us.id
- and report.create_date >=#{startDate} and report.create_date <=#{endDate})
- as workingTime
- from user us
- left join department dp on dp.department_id=us.department_id
- where us.company_id=#{companyId}
- and us.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date < #{startDate} AND is_active = 0)
- <if test="userId!=null and userId!=''">
- and us.id=#{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and us.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and us.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- group by us.id
- order by us.department_id)as total
- </select>
- <!-- 分页查询部门参与项目情况-->
- <select id="selectDeptPartInProjects" resultType="java.util.Map">
- SELECT department.department_id deptId,
- department_name deptName,
- (select count(user.id) from user where user.id NOT IN (SELECT id FROM `user` WHERE company_id=#{companyId} and inactive_date IS NOT NULL AND inactive_date < #{startDate} AND is_active = 0) AND user.department_id = department.department_id group by user.department_id) deptHeadCount,
- pro.projectCount projectCount,
- pro.centerCount centerCount,
- pcon.peopleCount peopleCount
- FROM department
- LEFT JOIN (
- SELECT user.department_id dept_id,COUNT(DISTINCT(report.project_id)) projectCount,
- COUNT(DISTINCT(r.degree_id)) centerCount
- FROM report
- LEFT JOIN report r
- ON report.id = r.id AND r.degree_id != -1
- LEFT JOIN `user`
- ON report.creator_id = user.id
- WHERE report.state = 1
- And report.create_date BETWEEN #{startDate} AND #{endDate}
- GROUP BY dept_id
- ) pro
- on pro.dept_id = department.department_id
- LEFT JOIN (
- SELECT dept_id,sum(p.con) peopleCount
- FROM (
- SELECT user.department_id dept_id,count(DISTINCT project_id)con FROM report
- LEFT JOIN `user`
- ON report.creator_id = user.id
- WHERE report.state = 1
- And report.create_date BETWEEN #{startDate} AND #{endDate}
- GROUP BY report.creator_id,dept_id
- ) p GROUP BY p.dept_id
- ) pcon
- ON pcon.dept_id = department.department_id
- WHERE department.company_id = #{companyId}
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and department.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and department.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="size!=null and start!=null">
- limit #{start},#{size}
- </if>
- </select>
- <!--获取按项目分组的工时成本-->
- <select id="getExportDegreeCost" resultType="java.util.Map">
- SELECT a.id, a.project_code as projectCode, a.project_name AS projectName, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- WHERE a.company_id = #{companyId}
- <if test="projectId != null">
- AND a.id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- <choose>
- <when test="filterDeptIds!=null and filterDeptIds.size()>0">
- and b.dept_id in
- <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </when>
- <otherwise>
- <if test="deptIds!=null and deptIds.size()>0">
- and (b.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- <if test="deptRelatedProjectIds.size() > 0">
- or a.id in
- <foreach collection="deptRelatedProjectIds" open="(" item="pid" separator="," close=")">
- #{pid}
- </foreach>
- </if>
- )
- </if>
- </otherwise>
- </choose>
- AND b.state = 1
- GROUP BY a.id
- ORDER BY a.id ASC
- </select>
- <!--获取某个项目每个维度分别需要的工时-->
- <select id="getDegreeDetailCost" resultType="java.util.Map">
- SELECT b.id as creatorId,a.project_id as projectId, b.name,b.corpwx_userid as corpwxUserId,a.dept_id as deptId,department.corpwx_deptid as corpwxDeptId, IFNULL(department.department_name, '未分配') as departmentName, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney,r.name as degreeName
- FROM report AS a
- JOIN user AS b ON a.creator_id = b.id
- left join department on department.department_id = a.dept_id
- left join report_extra_degree as r on a.degree_id = r.id
- WHERE a.company_id=#{companyId}
- <if test="curProjectId != null">
- and a.project_id = #{curProjectId}
- </if>
- <if test="projectId != null">
- and a.project_id = #{projectId}
- </if>
- <if test="startDate != null and endDate != null">
- AND a.create_date between #{startDate} and #{endDate}
- </if>
- <choose>
- <when test="filterDeptIds!=null and filterDeptIds.size()>0">
- and a.dept_id in
- <foreach collection="filterDeptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </when>
- <otherwise>
- <if test="deptIds!=null and deptIds.size()>0">
- and a.dept_id in
- <foreach collection="deptIds" open="(" item="item" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </otherwise>
- </choose>
- GROUP BY a.project_id,b.id,a.degree_id
- ORDER BY b.id,a.degree_id ASC
- </select>
- <select id="selectNearProject" resultType="com.management.platform.entity.Project">
- SELECT * FROM project
- WHERE STATUS = 1 AND id IN (
- SELECT project_id
- FROM (
- SELECT DISTINCT report.project_id
- FROM report
- WHERE creator_id = #{userId}
- GROUP BY project_id
- ORDER BY MAX(create_time)
- DESC LIMIT 3
- ) p2
- ) AND id IN(SELECT project_id FROM participation WHERE user_id=#{userId})
- </select>
- <select id="getFTEData" resultType="java.util.Map">
- SELECT u.id,u.name userName,d.department_name as departmentName,d.corpwx_deptid as wxdeptId,u.corpwx_userid as wxUserId,IF(u.plate1 IS NULL OR u.plate1='' ,'无',u.plate1) as area,IFNULL(r.projectName,'') as projectName,
- IFNULL(r.projectCode,'') as projectCode,IFNULL(r.workTime,0) as workTime,IFNULL(t.nonProjectWorkingTime,0) as nonProjectWorkingTime
- FROM `user` u
- LEFT JOIN department d on u.department_id=d.department_id
- LEFT JOIN (
- SELECT p.project_name projectName,p.project_code projectCode,report.working_time,report.creator_id,SUM(working_time) workTime
- FROM report
- LEFT JOIN project p
- ON report.project_id = p.id
- LEFT JOIN `user`
- ON user.id = report.creator_id
- WHERE report.state = 1
- AND p.is_public = 0
- AND report.company_id=#{companyId}
- AND
- (
- IF(user.induction_date is not null AND user.induction_date > #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date < #{endDate}
- ,report.create_date BETWEEN user.induction_date AND user.inactive_date
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- and
- IF(user.induction_date is not null AND user.induction_date > #{startDate}
- ,report.create_date BETWEEN user.induction_date AND #{endDate}
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- and
- IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date < #{endDate}
- ,report.create_date BETWEEN #{startDate} AND user.inactive_date
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- )
- GROUP BY user.id,p.id,user.plate1,p.project_name,p.project_code
- ) r
- ON u.id = r.creator_id
- LEFT JOIN (
- SELECT report.creator_id,SUM(working_time) nonProjectWorkingTime
- FROM report
- LEFT JOIN project p
- ON report.project_id = p.id
- LEFT JOIN `user`
- ON user.id = report.creator_id
- WHERE report.state = 1
- AND p.is_public = 1
- AND report.company_id=#{companyId}
- AND
- (
- IF(user.induction_date is not null AND user.induction_date > #{startDate} and user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date < #{endDate}
- ,report.create_date BETWEEN user.induction_date AND user.inactive_date
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- and
- IF(user.induction_date is not null AND user.induction_date > #{startDate}
- ,report.create_date BETWEEN user.induction_date AND #{endDate}
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- and
- IF(user.inactive_date is not null AND user.`is_active`=0 AND user.inactive_date < #{endDate}
- ,report.create_date BETWEEN #{startDate} AND user.inactive_date
- ,report.create_date BETWEEN #{startDate} AND #{endDate} )
- )
- GROUP BY user.id
- ) t
- ON u.id = t.creator_id
- WHERE u.company_id=#{companyId}
- AND (workTime>0 OR u.`is_active`=1)
- <if test="area!=null and area != '' ">
- and u.plate1 = #{area}
- </if>
- <if test="userId!=null and userId != '' ">
- and u.id = #{userId}
- </if>
- <if test="branchDepartment!=null and branchDepartment.size()>0">
- and u.department_id in
- <foreach collection="branchDepartment" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and u.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <!-- <if test="departmentId!=null">-->
- <!-- and u.department_id=#{departmentId}-->
- <!-- </if>-->
- <if test="sortProp!=null and sortProp!=''">
- <choose>
- <when test="sortOrder==0">
- order by id desc
- </when>
- <otherwise>
- order by id
- </otherwise>
- </choose>
- </if>
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <!--获取查询者所在公司每个项目的工时成本-->
- <select id="getTimeCostByToken" resultType="java.util.Map">
- SELECT a.id, a.project_code as projectCode, a.project_name AS project, SUM(b.working_time) AS cost, SUM(b.cost) AS costMoney,a.category_name as categoryName,c.job_number as userJobNumber,d.department_name as departmentName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- JOIN department d on d.department_id=c.department_id
- WHERE a.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- GROUP BY a.id,b.creator_id
- ORDER BY a.id ASC
- </select>
- <!--获取员工的项目分类工时统计数据 -->
- <select id="getMembProjectCateTime" resultType="com.management.platform.entity.vo.UserCateTimeVo">
- SELECT user.id AS userId,user.plate1 as plate1,user.plate2 as plate2,user.plate3 as plate3,user.plate4 as plate4,user.plate5 as plate5, user.`name`, project.`category`, project.`category_name` AS categoryName, SUM(report.`working_time`) AS workingTime
- FROM report
- LEFT JOIN `user` ON user.id = report.`creator_id`
- LEFT JOIN project ON project.id = report.`project_id`
- WHERE report.`company_id` = #{companyId}
- AND report.`create_date` BETWEEN #{startDate} and #{endDate}
- AND report.state = 1
- <if test="departmentId!=null">
- AND user.department_id=#{departmentId}
- </if>
- <if test="subUserCustomName!=null and subUserCustomName!='' and plateString!=null">
- <choose>
- <when test="plateString==1">
- AND user.plate1=#{subUserCustomName}
- </when>
- <when test="plateString==2">
- AND user.plate2=#{subUserCustomName}
- </when>
- <when test="plateString==3">
- AND user.plate3=#{subUserCustomName}
- </when>
- <when test="plateString==4">
- AND user.plate4=#{subUserCustomName}
- </when>
- <otherwise>
- AND user.plate5=#{subUserCustomName}
- </otherwise>
- </choose>
- </if>
- GROUP BY user.id, project.`category`
- </select>
- <select id="userProjectProcessList" resultType="java.util.Map">
- select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
- IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0),0)as residueTime
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on d.department_id=u.department_id
- left join project p on p.id=te.project_id
- where u.company_id=#{companyId} and te.project_id is not null
- <if test="deptId!=null">
- and d.department_id=#{deptId}
- </if>
- <if test="userId!=null and userId!=''">
- and u.id=#{userId}
- </if>
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="listSecond!=null and listSecond.size()>0">
- and d.department_id in
- <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- group by te.executor_id,te.project_id
- order by d.department_id,u.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="userProjectProcessCount" resultType="java.lang.Long">
- select count(1) from (
- select d.department_name as departmentName
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on d.department_id=u.department_id
- left join project p on p.id=te.project_id
- where u.company_id=#{companyId} and te.project_id is not null
- <if test="deptId!=null">
- and d.department_id=#{deptId}
- </if>
- <if test="userId!=null and userId!=''">
- and u.id=#{userId}
- </if>
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="listSecond!=null and listSecond.size()>0">
- and d.department_id in
- <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- group by te.executor_id,te.project_id
- ) as total
- </select>
- <select id="groupExpendProcessList" resultType="java.util.Map">
- SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
- IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) as normalHour,IFNULL(r.overHour,0) as overHour,
- IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
- FROM task_group tg
- LEFT JOIN project p ON p.id=tg.project_id AND p.`company_id`=#{companyId}
- LEFT JOIN (
- SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
- FROM report WHERE state=1
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND create_date BETWEEN #{startDate} AND #{endDate}
- </if>
- <if test="userId!=null and userId!=''">
- and report.creator_id=#{userId}
- </if>
- AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
- WHERE p.company_id=#{companyId}
- <if test="projectIds!=null and projectIds.size()>0">
- AND tg.project_id in
- <foreach collection="projectIds" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- GROUP BY p.id,tg.id ORDER BY p.id
- </select>
- <select id="groupExpendProcessListForChart" resultType="java.util.Map">
- SELECT groupName,SUM(realHour) AS realHour,SUM(realCost) AS realCost,SUM(normalHour) AS normalHour,SUM(overHour) AS overHour,SUM(planHour) AS planHour,SUM(afterSetPlanHour) AS afterSetPlanHour
- FROM (SELECT p.project_name AS projectName,p.id AS projectId,tg.id AS groupId,d.department_name,d.department_id AS deptId,d.corpwx_deptid AS corpwxDeptId,tg.name AS groupName,
- IFNULL(r.realHour,0) AS realHour,IFNULL(r.realCost,0) AS realCost,IFNULL(r.normalHour,0) AS normalHour,IFNULL(r.overHour,0) AS overHour,
- IFNULL(tg.man_day*8,0) AS planHour,IFNULL((SELECT SUM(change_man_day*8) FROM `group_budget_review` WHERE group_id=tg.`id` AND `status`=1),0) AS afterSetPlanHour
- FROM task_group tg
- LEFT JOIN task t ON tg.id = t.group_id
- LEFT JOIN task_executor te ON t.id = te.task_id
- LEFT JOIN `user` u
- ON te.executor_id = u.id AND u.`company_id`=#{companyId}
- LEFT JOIN project p ON p.id=tg.project_id
- LEFT JOIN department d ON d.department_id=u.department_id
- LEFT JOIN (
- SELECT SUM(working_time) AS realHour,SUM(cost) AS realCost,(SUM(working_time)-SUM(overtime_hours)) AS normalHour,SUM(overtime_hours) AS overHour,group_id,dept_id
- FROM report WHERE state=1
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND create_date BETWEEN #{startDate} AND #{endDate}
- </if>
- AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
- WHERE p.company_id=#{companyId}
- <if test="listThird!=null and listThird.size()>0">
- AND tg.project_id in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- <if test="userId!=null and userId!=''">
- and t.executor_id=#{userId}
- </if>
- GROUP BY tg.id ORDER BY p.id,d.department_id) AS t
- <where>
- <if test="listFour!=null and listFour.size()>0">
- t.groupName in
- <foreach collection="listFour" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY t.groupName
- </select>
- <select id="groupExpendProcessListForUser" resultType="java.util.Map">
- SELECT departmentId, departmentName,jobNumber,userName,
- SUM(CASE WHEN groupName='方案设计' THEN workTime ELSE 0 END) AS '方案设计' ,
- SUM(CASE WHEN groupName='研发部' THEN workTime ELSE 0 END) AS '研发部' ,
- SUM(CASE WHEN groupName='研发部工艺调试' THEN workTime ELSE 0 END) AS '研发部工艺调试',
- SUM(CASE WHEN groupName='研发部工艺调试验收' THEN workTime ELSE 0 END) AS '研发部工艺调试验收' ,
- SUM(CASE WHEN groupName='研发部工艺设计' THEN workTime ELSE 0 END) AS '研发部工艺设计' ,
- SUM(CASE WHEN groupName='研发部结构设计' THEN workTime ELSE 0 END) AS '研发部结构设计' ,
- SUM(CASE WHEN groupName='研发部BIM设计' THEN workTime ELSE 0 END) AS '研发部BIM设计' ,
- SUM(CASE WHEN groupName='研发部电气调试验收' THEN workTime ELSE 0 END) AS '研发部电气调试验收' ,
- SUM(CASE WHEN groupName='研发部电气设计' THEN workTime ELSE 0 END) AS '研发部电气设计' ,
- SUM(CASE WHEN groupName='研发部售后' THEN workTime ELSE 0 END) AS '研发部售后' ,
- SUM(CASE WHEN groupName='工程部配合运维' THEN workTime ELSE 0 END) AS '工程部配合运维' ,
- SUM(CASE WHEN groupName='研发部运维' THEN workTime ELSE 0 END) AS '研发部运维' ,
- SUM(CASE WHEN groupName='生产部' THEN workTime ELSE 0 END) AS '生产部' ,
- SUM(CASE WHEN groupName='生产部车间' THEN workTime ELSE 0 END) AS '生产部车间' ,
- SUM(CASE WHEN groupName='生产部电气' THEN workTime ELSE 0 END) AS '生产部电气' ,
- SUM(CASE WHEN groupName='工程部配合调试' THEN workTime ELSE 0 END) AS '工程部配合调试' ,
- SUM(CASE WHEN groupName='工程部' THEN workTime ELSE 0 END) AS '工程部' ,
- SUM(CASE WHEN groupName='工程部售后' THEN workTime ELSE 0 END) AS '工程部售后' ,
- SUM(CASE WHEN groupName='工程部现场安装施工' THEN workTime ELSE 0 END) AS '工程部现场安装施工',
- IFNULL(SUM(workTime),0) AS totalWorkTime
- FROM (
- SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
- FROM task_executor te
- LEFT JOIN task t ON t.id=te.task_id
- LEFT JOIN `user` u ON te.executor_id=u.id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON p.id=tg.project_id
- LEFT JOIN department d ON d.department_id=u.department_id
- LEFT JOIN (
- SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
- FROM report r
- LEFT JOIN task_group tg ON r.group_id=tg.`id`
- WHERE r.state=1 AND r.project_id IS NOT NULL
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND r.create_date BETWEEN #{startDate} AND #{endDate}
- </if> AND r.company_id=#{companyId}
- GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
- WHERE u.company_id=#{companyId}
- <if test="listThird!=null and listThird.size()>0">
- AND tg.project_id in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- <if test="listFour!=null and listFour.size()>0">
- and tg.name in
- <foreach collection="listFour" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY u.`id`,tg.id
- ) AS t
- <where>
- <if test="listFive!=null and listFive.size()>0">
- t.departmentId in
- <foreach collection="listFive" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY t.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="groupExpendProcessListForUserCount" resultType="java.lang.Integer">
- select count(1) from (
- SELECT departmentId,departmentName,jobNumber,userName,IFNULL(SUM(workTime),0) AS totalWorkTime
- FROM (
- SELECT d.`department_id` AS departmentId,d.`department_name` AS departmentName,u.`job_number` AS jobNumber,u.`name` AS userName ,tg.name AS groupName,rr.realHour AS workTime,u.id
- FROM task_executor te
- LEFT JOIN task t ON t.id=te.task_id
- LEFT JOIN `user` u ON te.executor_id=u.id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON p.id=tg.project_id
- LEFT JOIN department d ON d.department_id=u.department_id
- LEFT JOIN (
- SELECT r.creator_id AS creatorId,SUM(r.working_time) AS realHour,tg.id AS groupId
- FROM report r
- LEFT JOIN task_group tg ON r.group_id=tg.`id`
- WHERE r.state=1 AND r.project_id IS NOT NULL
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND r.create_date BETWEEN #{startDate} AND #{endDate}
- </if> AND r.company_id=#{companyId}
- GROUP BY r.creator_id,tg.id ) rr ON rr.groupId=tg.`id` AND rr.creatorId=u.id
- WHERE u.company_id=#{companyId}
- <if test="listThird!=null and listThird.size()>0">
- AND tg.project_id in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- <if test="listFour!=null and listFour.size()>0">
- and tg.name in
- <foreach collection="listFour" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY u.`id`,tg.id
- ) AS t
- <where>
- <if test="listFive!=null and listFive.size()>0">
- t.departmentId in
- <foreach collection="listFive" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY t.id
- ) as total
- </select>
- <select id="groupExpendProcessListForProject" resultType="java.util.Map">
- SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
- SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
- IFNULL(r.realHour,0) AS realHour
- FROM task_executor te
- LEFT JOIN task t ON t.id=te.task_id
- LEFT JOIN `user` u ON te.executor_id=u.id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON p.id=tg.project_id
- LEFT JOIN department d ON d.department_id=u.department_id
- LEFT JOIN (
- SELECT SUM(working_time) AS realHour,group_id,dept_id
- FROM report WHERE state=1
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND create_date BETWEEN #{startDate} AND #{endDate}
- </if>
- AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
- WHERE u.company_id=#{companyId}
- <if test="listThird!=null and listThird.size()>0">
- AND tg.project_id in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- <if test="listFour!=null and listFour.size()>0">
- and tg.name in
- <foreach collection="listFour" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="listFive!=null and listFive.size()>0">
- and d.department_id in
- <foreach collection="listFive" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
- <where>
- realHour>0
- <if test="listThird!=null and listThird.size()>0">
- and
- projectId in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY projectId
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="groupExpendProcessListForProjectCount" resultType="java.lang.Integer">
- select count(1) from (
- SELECT projectName,projectId,projectCode,SUM(realHour) AS workTime FROM (
- SELECT p.project_name AS projectName,p.project_code as projectCode,p.id AS projectId,tg.id AS groupId,tg.name AS groupName,
- IFNULL(r.realHour,0) AS realHour
- FROM task_executor te
- LEFT JOIN task t ON t.id=te.task_id
- LEFT JOIN `user` u ON te.executor_id=u.id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON p.id=tg.project_id
- LEFT JOIN department d ON d.department_id=u.department_id
- LEFT JOIN (
- SELECT SUM(working_time) AS realHour,group_id,dept_id
- FROM report WHERE state=1
- <if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
- AND create_date BETWEEN #{startDate} AND #{endDate}
- </if>
- AND project_id IS NOT NULL AND company_id=#{companyId} GROUP BY group_id) r ON r.group_id=tg.`id`
- WHERE u.company_id=#{companyId}
- <if test="listThird!=null and listThird.size()>0">
- AND tg.project_id in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- AND tg.name IN ('方案设计','研发部','生产部','工程部','生产部电气','生产部车间','工程部现场安装施工','工程部配合调试','研发部工艺设计','研发部结构设计','研发部BIM设计','研发部电气设计','研发部工艺调试验收','研发部电气调试验收')
- <if test="listFour!=null and listFour.size()>0">
- and tg.name in
- <foreach collection="listFour" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- <if test="listFive!=null and listFive.size()>0">
- and d.department_id in
- <foreach collection="listFive" close=")" open="(" separator="," item="item">
- #{item}
- </foreach>
- </if>
- GROUP BY p.id,tg.id ORDER BY p.id,d.department_id) AS f
- <where>
- realHour>0
- <if test="listThird!=null and listThird.size()>0">
- and
- projectId in
- <foreach collection="listThird" separator="," open="(" close=")" item="item">
- #{item}
- </foreach>
- </if>
- </where>
- GROUP BY projectId
- ) as total
- </select>
- <select id="projectExpendProcessList" resultType="java.util.Map">
- select p.id AS projectId,p.project_name as projectName,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate,pc.name as categoryName,p.project_code as projectCode,IFNULL(SUM(te.plan_hours),0) as planHour,
- IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realHour, IFNULL((select SUM(cost) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0) as realCost,
- IFNULL(IFNULL(SUM(te.plan_hours),0)-IFNULL((select SUM(working_time) from report where project_id=p.id and create_date BETWEEN #{startDate} AND #{endDate} and state=1),0),0) as residueHour
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on u.department_id=d.department_id
- left join task t on t.id=te.task_id
- left join project p on p.id=t.project_id
- left join project_category pc on pc.id=p.category
- where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="userId!=null and userId!=''">
- and FIND_IN_SET(#{userId},t.executor_id)
- </if>
- <if test="categoryId!=null">
- and pc.id=#{categoryId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- group by t.project_id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="projectExpendProcessListCount" resultType="java.lang.Long">
- select count(1) from (
- select p.project_name as projectName
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on u.department_id=d.department_id
- left join task t on t.id=te.task_id
- left join project p on p.id=t.project_id
- left join project_category pc on pc.id=p.category
- where u.company_id=#{companyId} and te.project_id is not null and pc.name not in ('报价项目','售后报价项目','研发项目','运维项目','数字化服务项目')
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="userId!=null and userId!=''">
- and te.executor_id=#{userId}
- </if>
- <if test="categoryId!=null">
- and pc.id=#{categoryId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" separator="," item="item">
- #{item}
- </foreach>
- </if>
- group by t.project_id
- ) as total
- </select>
- <select id="userTaskProcessList" resultType="java.util.Map">
- select d.department_name as departmentName,d.corpwx_deptid as corpwxDeptId,u.corpwx_userid as corpwxUserId,t.name as taskName,IFNULL(t.plan_hours,0) as planHour,u.name as userName,u.job_number as jobNumber,p.project_name as projectName,p.project_code as projectCode,
- IFNULL((select SUM(working_time) from report where task_id=te.task_id and state=1),0)as consumeTime,IF((IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))<0,0,(IFNULL(t.plan_hours,0)-IFNULL((SELECT SUM(working_time) FROM report WHERE task_id=te.task_id AND state=1),0))) AS residue
- ,DATE_FORMAT(p.`plan_start_date`,'%Y-%m-%d') AS planStartDate,DATE_FORMAT(p.`plan_end_date`,'%Y-%m-%d') AS planEndDate
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on d.department_id=u.department_id
- left join project p on p.id=te.project_id
- left join task t on te.task_id=t.id
- where u.company_id=#{companyId} and te.project_id is not null
- <if test="deptId!=null">
- and d.department_id=#{deptId}
- </if>
- <if test="userId!=null and userId!=''">
- and u.id=#{userId}
- </if>
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="listSecond!=null and listSecond.size()>0">
- and d.department_id in
- <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
- and ((t.start_date between #{startDate} and #{endDate})
- or
- (t.end_date between #{startDate} and #{endDate}))
- </if>
- group by te.executor_id,t.id
- order by d.department_id,u.id
- <if test="start!=null and size!=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="userTaskProcessListCount" resultType="java.lang.Long">
- select count(1) from (
- select d.department_name as departmentName
- from task_executor te
- left join user u on u.id=te.executor_id
- left join department d on d.department_id=u.department_id
- left join project p on p.id=te.project_id
- left join task t on te.task_id=t.id
- where u.company_id=#{companyId} and te.project_id is not null
- <if test="deptId!=null">
- and d.department_id=#{deptId}
- </if>
- <if test="userId!=null and userId!=''">
- and u.id=#{userId}
- </if>
- <if test="projectId!=null">
- and p.id=#{projectId}
- </if>
- <if test="list!=null and list.size()>0">
- and d.department_id in
- <foreach collection="list" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="listSecond!=null and listSecond.size()>0">
- and d.department_id in
- <foreach collection="listSecond" open="(" close=")" item="item" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="startDate!=null and endDate!=null and startDate!='' and endDate!=''">
- and ((t.start_date between #{startDate} and #{endDate})
- or
- (t.end_date between #{startDate} and #{endDate}))
- </if>
- group by te.executor_id,t.id
- order by d.department_id,u.id
- ) as total
- </select>
- <select id="getOnlyJoinProjectsPage" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName
- FROM project
- WHERE status = 1 and (id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- )
- or (is_public = 1 and company_id = #{companyId}))
- <if test="infoString !=null and infoString!='' ">
- and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
- </if>
- ORDER BY is_public DESC, id ASC
- limit #{pageIndex},#{pageSize}
- </select>
- <select id="getOnlyJoinProjectsTotal" resultType="java.lang.Integer">
- SELECT count(*) total
- FROM project
- WHERE status = 1 and (id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- )
- or (is_public = 1 and company_id = #{companyId}))
- <if test="infoString !=null and infoString!='' ">
- and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
- </if>
- </select>
- <select id="getOnlyJoinProjectsById" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName
- FROM project
- WHERE status = 1 and (id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- )
- or (is_public = 1 and company_id = #{companyId}))
- and id =#{projectId}
- </select>
- <select id="getParticipatedProjectPage" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName
- FROM project
- WHERE id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- ) or incharger_id = #{userId}
- or creator_id = #{userId}
- or (is_public = 1 and company_id = #{companyId})
- <if test="infoString !=null and infoString!='' ">
- and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
- </if>
- ORDER BY is_public DESC, id DESC
- limit #{pageIndex},#{pageSize}
- </select>
- <select id="getParticipatedProjectTotal" resultType="java.lang.Integer">
- SELECT count(*) total
- FROM project
- WHERE id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- ) or incharger_id = #{userId}
- or creator_id = #{userId}
- or (is_public = 1 and company_id = #{companyId})
- <if test="infoString !=null and infoString!='' ">
- and (project_name like CONCAT('%', #{infoString}, '%') or project_code like CONCAT('%', #{infoString}, '%') )
- </if>
- </select>
- <select id="getParticipatedProjectById" resultType="java.util.Map">
- SELECT count(*) total
- FROM project
- WHERE id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- ) or incharger_id = #{userId}
- or creator_id = #{userId}
- or (is_public = 1 and company_id = #{companyId})
- and id =#{projectId}
- </select>
- <select id="getTimeCostGroupByProjectUserSumTime" resultType="java.util.Map">
- SELECT a.id, a.project_code as projectCode, a.project_name AS projectName,a.category_name as categoryName,
- c.name name,sum(b.working_time) AS cost,
- b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
- c.id userId
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- left join department on department.department_id = b.dept_id
- WHERE a.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- group by id,projectCode,projectName,categoryName,name
- ORDER BY a.id ASC
- </select>
- <select id="getTimeCostProjectUserWorkTime" resultType="java.util.Map">
- SELECT a.id, a.project_code as projectCode,a.project_name AS projectName,a.category_name as categoryName,
- c.name name,b.working_time cost,
- b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
- b.create_date createDate,DAY(b.create_date) dayOnly,c.id userId
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- left join department on department.department_id = b.dept_id
- WHERE a.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- ORDER BY a.id ASC ,c.name asc
- </select>
- <select id="getCostTimeByUserSum" resultType="java.util.Map">
- SELECT c.id userId, c.job_number jobNumber,c.name name,sum(b.working_time) AS cost,
- b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- left join department on department.department_id = b.dept_id
- WHERE c.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- group by userId
- </select>
- <select id="getCostTimeByUserForDay" resultType="java.util.Map">
- SELECT c.id userId, c.job_number jobNumber,c.name name,b.working_time AS cost, a.id projectId,a.project_name ,
- b.dept_id as deptId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId, IFNULL(department.department_name, '未分配') as departmentName,
- DAY(b.create_date) dayOnly
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- left join department on department.department_id = b.dept_id
- WHERE c.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- </select>
- <select id="getTotalProjectByTime" resultType="java.util.Map">
- SELECT
- a.id projectId,a.project_name projectName
- FROM project AS a
- LEFT JOIN report AS b ON b.project_id = a.id
- JOIN user AS c ON b.creator_id = c.id
- left join department on department.department_id = b.dept_id
- WHERE c.company_id = #{companyId}
- <if test="startDate != null and endDate != null">
- AND b.create_date between #{startDate} and #{endDate}
- </if>
- AND b.state = 1
- GROUP BY projectId
- </select>
- <select id="selectProjectEestimatedWorkTimeList" resultType="java.util.Map">
- SELECT
- p.id AS projectId,
- p.project_code AS projectCode,
- p.project_name AS projectName,
- CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END AS estimatedWorkTime,
- SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END) AS workTime,
- (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) AS remainWorkTime,
- CASE
- WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
- ELSE ROUND((CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) / (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END), 4)
- END AS remainWorkTimeProportion
- FROM
- project p
- LEFT JOIN
- report r ON p.id = r.project_id
- WHERE
- p.company_id = #{map.companyId}
- AND p.`status` IN (1, 2)
- AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
- <if test="map.projectId!=null">
- AND p.id = #{map.projectId}
- </if>
- GROUP BY
- p.id, p.project_code, p.project_name
- <if test="map.isWarn!=null and map.isWarn==1 ">
- HAVING remainWorkTimeProportion *100 < #{map.warningPercent}
- </if>
- <if test="map.pageIndex!=null and map.pageSize!=null ">
- LIMIT #{map.pageIndex}, #{map.pageSize}
- </if>
- </select>
- <select id="selectProjectEestimatedWorkTimeCount" resultType="java.lang.Integer">
- SELECT
- count(1) total
- FROM
- (
- SELECT
- p.id AS projectId,
- (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) AS remainWorkTime,
- CASE
- WHEN (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END) = 0 THEN NULL
- ELSE ROUND((CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL THEN 0 ELSE r.working_time END)) / (CASE WHEN p.man_day IS NULL THEN 0 ELSE p.man_day * #{map.allday} END), 4)
- END AS remainWorkTimeProportion
- FROM
- project p
- LEFT JOIN
- report r ON p.id = r.project_id
- WHERE
- p.company_id = #{map.companyId}
- AND p.`status` IN (1, 2)
- AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
- <if test="map.projectId!=null">
- AND p.id = #{map.projectId}
- </if>
- GROUP BY
- p.id, p.project_code, p.project_name
- <if test="map.isWarn!=null and map.isWarn==1 ">
- HAVING remainWorkTimeProportion *100 < #{map.warningPercent}
- </if>
- ) a
- </select>
- <select id="selectGroupEestimatedWorkTimeList" resultType="java.util.Map">
- SELECT
- p.id AS projectId,
- p.project_code AS projectCode,
- p.project_name AS projectName,
- g.`name` groupName,
- g.id id,
- CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END AS estimatedWorkTime,
- SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
- CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
- END) AS workTime,
- (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
- CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
- END)) AS remainWorkTime,
- CASE
- WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
- ELSE ROUND((CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
- CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
- END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
- END AS remainWorkTimeProportion
- FROM
- project p
- LEFT JOIN
- report r ON p.id = r.project_id
- LEFT JOIN
- task_group g ON g.project_id =p.id
- WHERE
- p.company_id = #{map.companyId}
- AND p.`status` IN (1, 2)
- AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
- <if test="map.projectId!=null">
- AND p.id = #{map.projectId}
- </if>
- GROUP BY
- p.id,g.`name`,g.id
- <if test="map.isWarn!=null and map.isWarn==1 ">
- HAVING remainWorkTimeProportion *100 < #{map.warningPercent}
- </if>
- <if test="map.pageIndex!=null and map.pageSize!=null ">
- LIMIT #{map.pageIndex}, #{map.pageSize}
- </if>
- </select>
- <select id="selectGroupEestimatedWorkTimeCount" resultType="java.lang.Integer">
- SELECT
- count(*)
- FROM
- (
- SELECT
- p.id AS projectId,
- g.`name` groupName,
- g.id id,
- CASE
- WHEN (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END) = 0 THEN NULL
- ELSE ROUND((CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END - SUM(CASE WHEN r.working_time IS NULL OR g.id IS NULL THEN 0 ELSE
- CASE WHEN r.group_id = g.id THEN r.working_time ELSE 0 END
- END)) / (CASE WHEN g.man_day IS NULL THEN 0 ELSE g.man_day * #{map.allday} END),4)
- END AS remainWorkTimeProportion
- FROM
- project p
- LEFT JOIN
- report r ON p.id = r.project_id
- LEFT JOIN
- task_group g ON g.project_id =p.id
- WHERE
- p.company_id = #{map.companyId}
- AND p.`status` IN (1, 2)
- AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
- <if test="map.projectId!=null">
- AND p.id = #{map.projectId}
- </if>
- GROUP BY
- p.id,g.`name`,g.id
- <if test="map.isWarn!=null and map.isWarn==1 ">
- HAVING remainWorkTimeProportion *100 < #{map.warningPercent}
- </if>
- ) a
- </select>
- <select id="getParticipatedProjectWithMainProjectId" resultType="java.util.Map">
- SELECT id, project_code AS projectCode, project_name AS projectName, status, task_gp_incharge as taskGpIncharge, project_desc as projectDesc,is_public as isPublic, plan_end_date as planEndDate
- FROM project
- WHERE id IN (
- SELECT project_id
- FROM participation
- WHERE user_id = #{userId}
- ) or incharger_id = #{userId}
- or creator_id = #{userId}
- or (is_public = 1 and company_id = #{companyId})
- and project_main_id = #{projectMainId}
- ORDER BY is_public DESC, id DESC
- </select>
- <select id="getProjectInAndOutTotal" resultType="java.lang.Integer">
- SELECT count(*) total
- FROM project
- left join contract on contract.project_id = project.id
- WHERE project.`company_id` = #{companyId}
- and (project.status <> 3 or project.status is null)
- <if test="projectId != null">
- and project.id = #{projectId}
- </if>
- <if test="projectMainId != null">
- and project.project_main_id = #{projectMainId}
- </if>
- <if test="inchagerIds!=null and inchagerIds.size()>0">
- and project.id in
- <foreach collection="inchagerIds" open="(" separator="," close=")" item="item">
- #{item}
- </foreach>
- </if>
- </select>
- <select id="getTaskPlanByGeneralMemb" resultType="java.util.Map">
- SELECT user.`id` as user_id, user.`name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- LEFT JOIN project ON project.`id` = task.`project_id`
- WHERE user.`id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null
- <if test="targetUserId !=null and targetUserId !='' ">
- and user.`id`=#{targetUserId}
- </if>
- AND project.`status` = 1 and task.task_plan=1
- ORDER BY user.id, task.start_date
- </select>
- <select id="getTaskPlanWithLeave" resultType="java.util.Map">
- SELECT user.`id` as user_id, user.`name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- WHERE
- ((IFNULL(task.start_date , task.end_date) between #{startDate} and #{endDate}) or (task.end_date between #{startDate} and #{endDate}))
- and task.end_date is not null and task.task_plan_type=3 and task.task_plan=1
- <if test="targetUserId !=null and targetUserId !='' ">
- and user.`id`=#{targetUserId}
- </if>
- ORDER BY user.id, task.start_date
- </select>
- <select id="getTaskPlanByProManager" resultType="java.util.Map">
- SELECT user.`id` as user_id, user.`name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- LEFT JOIN project ON project.`id` = task.`project_id`
- WHERE user.`id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null and task.is_task_plan=1 and project.incharger_id=#{managerId}
- AND project.`status` = 1 and task.task_plan=1 and task.task_status !=2
- <if test="targetUserId !=null and targetUserId !='' ">
- and user.`id`=#{targetUserId}
- </if>
- ORDER BY user.id, task.start_date
- </select>
- <select id="getTaskPlanByAreaManager" resultType="java.util.Map">
- SELECT user.`id` as user_id, user.`name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,task_executor.id as exe_id,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task_executor.plan_hours as duration, task.task_level as level ,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- LEFT JOIN project ON project.`id` = task.`project_id`
- WHERE user.`id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null and task.check_second_id=#{managerId}
- AND project.`status` = 1 and task.task_plan=1 and task.task_status !=2
- <if test="targetUserId !=null and targetUserId !='' ">
- and user.`id`=#{targetUserId}
- </if>
- ORDER BY user.id, task.start_date
- </select>
- <select id="getTaskPlanByProjectGeneralMemb" resultType="java.util.Map">
- SELECT task.executor_id as user_id, task.executor_name as `name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
- LEFT JOIN task ON task.project_id = project.id
- <if test="groupName !=null and groupName !='' ">
- LEFT JOIN task_group tg ON tg.project_id = project.id
- </if>
- WHERE project.company_id = #{companyId}
- <if test="projectIds != null">
- and project.`id` IN
- <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </if>
- <if test="groupName !=null and groupName !='' ">
- and tg.name = #{groupName} and task.group_id=tg.id
- </if>
- <if test="taskType !=null ">
- and task.task_type = #{taskType}
- </if>
- <if test="targetProjectId !=null ">
- and project.`id` = #{targetProjectId}
- </if>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null
- AND project.`status` = 1
- ORDER BY project.id, task.start_date
- </select>
- <select id="getTaskPlanByProjectManager" resultType="java.util.Map">
- SELECT task.executor_id as user_id, task.executor_name as `name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
- LEFT JOIN task ON task.project_id = project.id
- <if test="groupName !=null and groupName !='' ">
- LEFT JOIN task_group tg ON tg.project_id = project.id
- </if>
- WHERE project.company_id = #{companyId}
- <if test="projectIds != null">
- and project.`id` IN
- <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </if>
- <if test="groupName !=null and groupName !='' ">
- and tg.name = #{groupName} and task.group_id=tg.id
- </if>
- <if test="taskType !=null ">
- and task.task_type = #{taskType}
- </if>
- <if test="targetProjectId !=null ">
- and project.`id` = #{targetProjectId}
- </if>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null and task.is_task_plan=1 and project.incharger_id=#{managerId} and task.task_status !=2
- AND project.`status` = 1
- ORDER BY project.id, task.start_date
- </select>
- <select id="getTaskPlanByProjectAreaManager" resultType="java.util.Map">
- SELECT task.executor_id as user_id, task.executor_name as `name`,project.id, project.`project_name`,task.id as task_id, task.name as task_name,
- task.task_plan_type as taskPlanType,task.is_task_plan as isTaskPlan,
- task.task_status as taskStatus,task.id as taskId,task.task_plan taskPlan,
- IFNULL(task.`start_date`, task.end_date) as start_date, task.`end_date`, task.plan_hours as duration FROM project
- LEFT JOIN task ON task.project_id = project.id
- <if test="groupName !=null and groupName !='' ">
- LEFT JOIN task_group tg ON tg.project_id = project.id
- </if>
- WHERE project.company_id = #{companyId}
- <if test="projectIds != null">
- and project.`id` IN
- <foreach collection="projectIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </if>
- <if test="groupName !=null and groupName !='' ">
- and tg.name = #{groupName} and task.group_id=tg.id
- </if>
- <if test="taskType !=null ">
- and task.task_type = #{taskType}
- </if>
- <if test="targetProjectId !=null ">
- and project.`id` = #{targetProjectId}
- </if>
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- and task.end_date is not null and task.task_plan=1 and task.check_second_id=#{managerId}
- AND project.`status` = 1 and task.task_status !=2
- ORDER BY project.id, task.start_date
- </select>
- <select id="getFTETaskPlanData" resultType="java.util.Map">
- select t.id, u.plate1 area, p.project_code projectCode,p.project_name projectName,u.name userName, sum(daily.work_hour) planHours, date_format(MIN(daily.`allocate_date`) , '%Y-%m-%d') startDate, date_format(MAX(daily.allocate_date),'%Y-%m-%d') endDate
- ,p.category_name categoryName,p.incharger_id inchargerId,p.associate_degree_names associateDegreeNames,tg.name groupName,
- stages.stages_name stagesName,t.name taskName,te.first_auditor_id firstAuditorId, te.second_auditor_id secondAuditorId,t.task_status auditStatus
- ,u.department_id departmentId,u.role_name roleName,t.task_plan_type taskPlanType,u.id userId,u.corpwx_userid as corpwxUserId,department.corpwx_deptid as corpwxDeptId,department.dd_deptid as corpDdDeptId
- from task t
- LEFT JOIN stages ON stages.id = t.stages_id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON t.project_id=p.id
- LEFT JOIN task_daily_allocate daily ON daily.`task_id` = t.id
- LEFT JOIN user u ON u.id= daily.`user_id`
- LEFT JOIN department ON department.department_id = u.department_id
- LEFT JOIN task_executor te ON te.task_id = daily.`task_id` AND te.`executor_id` = daily.`user_id`
- WHERE u.company_id=#{companyId}
- <if test="area!=null and area != '' ">
- and u.plate1 = #{area}
- </if>
- <if test="userId!=null and userId != '' ">
- and u.id = #{userId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and u.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and daily.`allocate_date` BETWEEN #{startDate} AND #{endDate}
- GROUP BY t.id, daily.`user_id`
- <if test="start!=null and size !=null">
- limit #{start},#{size}
- </if>
- </select>
- <select id="getFTETaskPlanDataCount" resultType="java.lang.Integer">
- select count(distinct t.id, daily.`user_id`) from task t
- LEFT JOIN stages ON stages.id = t.stages_id
- LEFT JOIN task_group tg ON tg.id=t.group_id
- LEFT JOIN project p ON t.project_id=p.id
- LEFT JOIN task_daily_allocate daily ON daily.`task_id` = t.id
- LEFT JOIN user u ON u.id= daily.`user_id`
- LEFT JOIN department ON department.department_id = u.department_id
- LEFT JOIN task_executor te ON te.task_id = daily.`task_id` AND te.`executor_id` = daily.`user_id`
- WHERE u.company_id=#{companyId}
- <if test="area!=null and area != '' ">
- and u.plate1 = #{area}
- </if>
- <if test="userId!=null and userId != '' ">
- and u.id = #{userId}
- </if>
- <if test="deptIds!=null and deptIds.size()>0">
- and u.department_id in
- <foreach collection="deptIds" open="(" item="item" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- and daily.`allocate_date` BETWEEN #{startDate} AND #{endDate}
- </select>
- <select id="getRelatedProjectIds" resultType="java.lang.Integer">
- SELECT DISTINCT pl.project_id
- FROM project_leader pl
- WHERE pl.leader_id = #{userId}
- UNION
- SELECT DISTINCT p.id
- FROM project p
- INNER JOIN task t ON t.project_id = p.id
- LEFT JOIN task_executor te ON te.task_id = t.id
- WHERE p.company_id = #{companyId}
- AND (te.first_auditor_id = #{userId} OR te.second_auditor_id = #{userId})
- </select>
- <select id="getExistIds" resultType="java.lang.String">
- select project_code
- from project
- where company_id = #{companyId}
- and project_code in <foreach collection="projectCodes" item="projectCode" separator="," open="(" close=")">#{projectCode}</foreach>
- </select>
- <select id="getexportTaskPlanByMemb" resultType="com.management.platform.entity.vo.GantExportVo">
- SELECT user.`id` as userId,
- user.`name` userName,
- project.`project_name` projectName,
- project.id projectId,
- tda.task_id as allocateTaskId,
- task.id as taskId,
- task.name as taskName,
- task_executor.plan_hours as duration,
- task.task_plan_type as taskPlanType,
- task.task_status as taskStatus,
- d.department_name deptName,
- tda.allocate_date allocateDate,
- SUM(tda.work_hour) as totalWorkHour,
- SUM(tda.over_work_hour) as totalOverWorkHour
- FROM user
- LEFT JOIN task_executor ON user.id = task_executor.`executor_id`
- left join task on task.id = task_executor.task_id
- left join task_type on task_type.id = task.task_plan_type
- LEFT JOIN project ON project.`id` = task.`project_id`
- LEFT join task_daily_allocate tda on tda.user_id=user.id AND tda.task_id = task.id
- LEFT JOIN department d on user.department_id=d.department_id
- <where>
- and task.end_date is not null
- AND (project.`status` = 1 or project.`status` is null)
- <if test="userIds!=null and userIds.size()>0">
- and user.`id` IN
- <foreach collection="userIds" close=")" open="(" separator="," index="" item="item">
- #{item}
- </foreach>
- </if>
- <if test="startDate !=null and startDate!='' and endDate !=null and endDate!=''">
- and ((IFNULL(task.start_date , task.end_date) <= #{endDate}) and (task.end_date >= #{startDate}))
- </if>
- <if test="deptId !=null">
- and user.department_id= #{deptId}
- </if>
- <if test="taskStatus != null">
- <choose>
- <when test="taskStatus == 0">
- and task.task_status in (3, 4)
- </when>
- <when test="taskStatus == 1">
- and task.task_status = 1
- </when>
- <when test="taskStatus == 2">
- and task.task_status in (5, 6)
- </when>
- <when test="taskStatus == 3">
- and task.task_status = 2
- </when>
- </choose>
- </if>
- </where>
- GROUP BY user.`id`,user.`name`,tda.task_id,project.`project_name`,project.id,tda.allocate_date
- ORDER BY user.id, task.start_date
- </select>
- </mapper>
|