Browse Source

申请公出开发

anderx 2 years ago
parent
commit
8a0bfb15b7

+ 69 - 27
src/main/java/com/goafanti/common/mapper/PublicReleaseMapper.xml

@@ -38,13 +38,14 @@
     <result column="user_names" jdbcType="VARCHAR" property="userNames" />
     <result column="object_type" jdbcType="INTEGER" property="objectType" />
     <result column="public_type" jdbcType="INTEGER" property="publicType" />
+    <result column="district_name" jdbcType="VARCHAR" property="districtName" />
   </resultMap>
   <sql id="Base_Column_List">
     id, aid, release_start, release_end, remarks, annex_url, `status`, create_time, pid,
     pname, duration, valid_date, supplement, audit_info, `plan`, expected_effect, next_plan,
     `type`, order_no, update_time, update_status, assist, assist_aid, assist_aid_name,
     main_id, main_name, reject_name, assistant_aid, assistant_name, public_again, audit_time,
-    new_user, sign_sum, user_names, object_type, public_type
+    new_user, sign_sum, user_names, object_type, public_type, district_name
   </sql>
   <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
     select
@@ -68,7 +69,8 @@
       main_name, reject_name, assistant_aid,
       assistant_name, public_again, audit_time,
       new_user, sign_sum, user_names,
-      object_type, public_type)
+      object_type, public_type, district_name
+      )
     values (#{aid,jdbcType=VARCHAR}, #{releaseStart,jdbcType=TIMESTAMP}, #{releaseEnd,jdbcType=TIMESTAMP},
       #{remarks,jdbcType=VARCHAR}, #{annexUrl,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
       #{createTime,jdbcType=TIMESTAMP}, #{pid,jdbcType=VARCHAR}, #{pname,jdbcType=VARCHAR},
@@ -80,7 +82,8 @@
       #{mainName,jdbcType=VARCHAR}, #{rejectName,jdbcType=VARCHAR}, #{assistantAid,jdbcType=VARCHAR},
       #{assistantName,jdbcType=VARCHAR}, #{publicAgain,jdbcType=INTEGER}, #{auditTime,jdbcType=TIMESTAMP},
       #{newUser,jdbcType=VARCHAR}, #{signSum,jdbcType=VARCHAR}, #{userNames,jdbcType=VARCHAR},
-      #{objectType,jdbcType=INTEGER}, #{publicType,jdbcType=INTEGER})
+      #{objectType,jdbcType=INTEGER}, #{publicType,jdbcType=INTEGER}, #{districtName,jdbcType=VARCHAR}
+      )
   </insert>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.goafanti.common.model.PublicRelease" useGeneratedKeys="true">
     insert into public_release
@@ -190,6 +193,9 @@
       <if test="publicType != null">
         public_type,
       </if>
+      <if test="districtName != null">
+        district_name,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="aid != null">
@@ -297,6 +303,9 @@
       <if test="publicType != null">
         #{publicType,jdbcType=INTEGER},
       </if>
+      <if test="districtName != null">
+        #{districtName,jdbcType=VARCHAR},
+      </if>
     </trim>
   </insert>
   <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.PublicRelease">
@@ -407,6 +416,9 @@
       <if test="publicType != null">
         public_type = #{publicType,jdbcType=INTEGER},
       </if>
+      <if test="districtName != null">
+        district_name = #{districtName,jdbcType=VARCHAR},
+      </if>
     </set>
     where id = #{id,jdbcType=INTEGER}
   </update>
@@ -446,7 +458,8 @@
       sign_sum = #{signSum,jdbcType=VARCHAR},
       user_names = #{userNames,jdbcType=VARCHAR},
       object_type = #{objectType,jdbcType=INTEGER},
-      public_type = #{publicType,jdbcType=INTEGER}
+      public_type = #{publicType,jdbcType=INTEGER},
+      district_name = #{districtName,jdbcType=VARCHAR}
     where id = #{id,jdbcType=INTEGER}
   </update>
 
@@ -461,16 +474,20 @@
   <select id="listPublicRelease" resultType="com.goafanti.weChat.bo.OutPublicReleaseList">
     select  a.id ,c.name  aname,date_format(a.release_start,'%Y-%m-%d %H:%i:%S') releaseStarts,a.aid,
     date_format(a.release_end ,'%Y-%m-%d %H:%i:%S') releaseEnds,date_format(a.create_time ,'%Y-%m-%d %H:%i:%S') createTimes,a.status,
-    date_format(a.update_time ,'%Y-%m-%d %H:%i:%S') updateTimes,a.update_status updateStatus,x.district_name districtName,
+    date_format(a.update_time ,'%Y-%m-%d %H:%i:%S') updateTimes,a.update_status updateStatus,a.district_name districtName,
     a.assist,a.assist_aid assistAid,a.assist_aid_name assistAidName,a.type,a.main_name mainName,a.reject_name rejectName,
     a.assistant_aid assistantAid ,a.assistant_name assistantName,a.public_again publicAgain,a.user_names userNames
     from public_release a  left join admin c on a.aid =c.id
-    left join (select min(prid)id,min(district_name)district_name from public_release_details group by prid )x on a.id=x.id
-  <if test="type==2">
-    left join department d on c.department_id =d.id
-  </if>
+    <if test="type==4">
+      left join public_release_details b on a.id=b.prid
+      left join user e on b.uid=e.id
+    </if>
+    <if test="type==2">
+      left join department d on c.department_id =d.id
+    </if>
       where 1=1
     <if test="type==0">
+      and a.public_type in (0,2)
       <if test="assist ==0">
         and a.assist in(0,1)
       </if>
@@ -483,37 +500,49 @@
       <if test="assist ==4">
         and a.assist in (2,3)
       </if>
-        <if test="aid !=null">
+      <if test="assistType ==1">
+        and a.assist in(0,1,2)
+      </if>
+      <if test="aid !=null">
         and a.aid= #{aid}
-        </if>
+      </if>
       <if test="statusType ==1">
         and a.status in (0,1,2,4)
       </if>
-	</if>
-	<if test="type==1">
+    </if>
+    <if test="type==1">
+      and a.public_type in (0,2)
       and a.assist in(0,1)
-	and c.reviewer = #{aid}
-	</if>
+      and c.reviewer = #{aid}
+    </if>
     <if test="type==2">
+      and a.public_type in (0,2)
       and a.assist in(0,1)
       and d.manager_id = #{aid}
     </if>
     <if test="type==3">
-        and a.assist in (2,3)
-        <if test="aid !=null">
+      and a.public_type in (0,2)
+      and a.assist=2
+      <if test="aid !=null">
         and a.aid= #{aid}
-        </if>
+      </if>
       and a.type = #{type}
     </if>
-	<if test="clockTime !=null">
-	and a.release_start &lt; #{clockTime} and a.release_end &gt; #{clockTime}
-	</if>
-	<if test="releaseStarts != null and publicEnd != null">
-	and a.release_start  BETWEEN #{releaseStarts} and #{publicEnd}
-	</if>
-	<if test="status !=null">
-	and a.status = #{status}
-	</if>
+    <if test="type==4">
+      and a.assist in(0,1)
+      and e.aid = #{aid}
+      and a.public_type in (1,2)
+    </if>
+    <if test="clockTime !=null">
+      and a.release_start &lt; #{clockTime} and a.release_end &gt; #{clockTime}
+    </if>
+    <if test="releaseStarts != null and publicEnd != null">
+      and a.release_start  BETWEEN #{releaseStarts} and #{publicEnd}
+    </if>
+
+    <if test="status !=null">
+      and a.status = #{status}
+    </if>
     <if test="type==2">
       ORDER BY a.create_time desc
     </if>
@@ -532,8 +561,13 @@
     <if test="type==2">
       left join department d on c.department_id =d.id
     </if>
+    <if test="type==4">
+      left join public_release_details b on a.id=b.prid
+      left join user e on b.uid=e.id
+    </if>
     where 1=1
     <if test="type==0">
+      and a.public_type in (0,2)
       <if test="assist ==0">
         and a.assist in(0,1)
       </if>
@@ -557,20 +591,28 @@
       </if>
     </if>
     <if test="type==1">
+      and a.public_type in (0,2)
       and a.assist in(0,1)
       and c.reviewer = #{aid}
     </if>
     <if test="type==2">
+      and a.public_type in (0,2)
       and a.assist in(0,1)
       and d.manager_id = #{aid}
     </if>
     <if test="type==3">
+      and a.public_type in (0,2)
       and a.assist=2
       <if test="aid !=null">
         and a.aid= #{aid}
       </if>
       and a.type = #{type}
     </if>
+    <if test="type==4">
+      and a.assist in(0,1)
+      and e.aid = #{aid}
+      and a.public_type in (1,2)
+    </if>
 	<if test="clockTime !=null">
 	and a.release_start &lt; #{clockTime} and a.release_end &gt; #{clockTime}
 	</if>

+ 13 - 0
src/main/java/com/goafanti/common/model/PublicRelease.java

@@ -185,6 +185,11 @@ public class PublicRelease implements Serializable {
      */
     private Integer publicType;
 
+    /**
+     * 公出企业地址
+     */
+    private String districtName;
+
     private static final long serialVersionUID = 1L;
 
     public Integer getId() {
@@ -474,4 +479,12 @@ public class PublicRelease implements Serializable {
     public void setPublicType(Integer publicType) {
         this.publicType = publicType;
     }
+
+    public String getDistrictName() {
+        return districtName;
+    }
+
+    public void setDistrictName(String districtName) {
+        this.districtName = districtName;
+    }
 }

+ 1 - 1
src/main/java/com/goafanti/weChat/bo/InputPublicReleaseList.java

@@ -4,7 +4,7 @@ public class InputPublicReleaseList {
 
 	private Integer pageSize;
 	private Integer pageNo;
-//	查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部)
+//	查看类型 0我的公出 1公出审核 2管理员 3协单(技术财税总监看全部) 4 公出企业负责人审核
 	private Integer type;
 	private String clockTime;
 	/**

+ 48 - 31
src/main/java/com/goafanti/weChat/service/impl/PublicReleaseServiceImpl.java

@@ -2,6 +2,7 @@ package com.goafanti.weChat.service.impl;
 
 import java.text.ParseException;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 
 import com.goafanti.admin.service.DepartmentService;
 import com.goafanti.common.dao.*;
@@ -10,6 +11,7 @@ import com.goafanti.weChat.bo.*;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.socket.TextMessage;
 
 import com.goafanti.admin.bo.AdminListBo;
@@ -61,6 +63,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 	private PublicExamineMapper publicExamineMapper;
 
 	@Override
+	@Transactional
 	public Map<String, Object> addPublicRelease(InputPublicRelease in) {
 		Date date =new Date();
 		if (in.getPublicAgain()==null)in.setPublicAgain(0);
@@ -75,6 +78,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 		}
 		publicReleaseMapper.insertSelective(in);
 		List<PublicReleaseDetails> prdList=new ArrayList<>();
+		List<User> users=new ArrayList<>();
 		StringBuffer str =new StringBuffer();
 		if (in.getUids()!=null){
 			List<String> split = Arrays.asList(in.getUids().split(","));
@@ -87,6 +91,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 			for (String s : split) {
 				PublicReleaseDetails prd=new PublicReleaseDetails();
 				User u=userMapper.selectByPrimaryKey(s);
+					users.add(u);
 				str.append(u.getNickname()).append(",");
 				if (u!=null&&u.getShareType()==2){
 					prd.setNewUser(1);
@@ -97,7 +102,6 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 					prd.setMainStatus(1);
 				}else {
 					prd.setMainStatus(0);
-					if(in.getType()==0) pushPublicToNotice(in, my, u);
 				}
 				prd.setPrid(in.getId());
 				prd.setUid(s);
@@ -128,29 +132,13 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 		if (in.getPublicType()==1){
 			upName.setPublicType(1);
 		}
-		publicReleaseMapper.updateByPrimaryKeySelective(upName);
 		addpublicLog(in.getId(), PublicReleaseLog.states.fq.getCode(), "发起外出申请");
-		Map<String, Object> map=addPublicReleaseLog(my, in,userNames,date);
+		Map<String, Object> map=addPublicReleaseLog(my, in,userNames,date,users);
+		publicReleaseMapper.updateByPrimaryKeySelective(upName);
 		return map;
 	}
 
-	private void pushPublicToNotice(InputPublicRelease in, AdminListBo my, User u) {
 
-			StringBuffer str2=new StringBuffer();
-			//如果是白名单只通当事人不审核
-			if (my.getPublicPurview()==1){
-				str2=str2.append(my.getName()).append("业务员(无需审核),发起对您的企业");
-				str2=str2.append("[").append(u.getNickname()).append("]发起公出。");
-				sendNoticeAndSoucket(u.getAid(),3,str2.toString());
-			}else {
-				str2=str2.append(my.getName()).append("(需审核),发起对您的企业");
-				str2=str2.append("[").append(u.getNickname()).append("]发起公出。");
-				sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
-				//不是自己的企业则需要审核并设置非自己客户待审核
-				addPublicExamine(in.getId(), u.getAid());
-				if(in.getPublicType()==null|| in.getPublicType()==0) in.setPublicType(1);
-			}
-	}
 
 	private void addPublicExamine(Integer id, String aid) {
 		PublicExamine pe=new PublicExamine();
@@ -178,23 +166,52 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 	 * @param nickname	客户名称
 	 * @param date	时间
 	 */
-	private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date ) {
+	private Map<String, Object> addPublicReleaseLog(AdminListBo my,PublicRelease in,String nickname,Date date,List<User> users) {
+		//获取公出审核人
 		Admin a=adminMapper.selectByPrimaryKey(my.getReviewer());
 		String openid=a.getOpenId();
 		String str="["+my.getName()+"]发起["+nickname+"]的外出申请,请及时审核。";
-		sendNoticeAndSoucket(a.getId(),1,str);
-		Map<String, Object>map=new HashMap<String, Object>();
-		map.put("data", publicReleaseMapper.selectDtails(in.getId()));
-		if (openid!=null) {
-			Integer res= weChatUtils.addNotice(openid, in.getStatus(),in.getId(),date,my.getName(),"["+my.getName()+"]发起外出申请");
-			if (res!=0) {
+		//默认上级审核
+		AtomicReference<Integer> status= new AtomicReference<>(1);
+		if (my.getPublicPurview()==0){
+			users.forEach(u->{
+				if (!u.getAid().equals(my.getId())){
+					StringBuffer str2=new StringBuffer();
+					str2=str2.append(my.getName()).append("(需审核),准备公出您的企业");
+					str2=str2.append("[").append(u.getNickname()).append("]!!!。");
+					sendEmailAndNoticeAndSoucket(u.getAid(),3,str2.toString());
+					//不是自己的企业则需要审核并设置非自己客户待审核
+					addPublicExamine(in.getId(), u.getAid());
+					if(in.getPublicType()==null|| in.getPublicType()==0) in.setPublicType(1);
+					status.set(0);
+				}
+			});
+		}else {
+			users.forEach(u->{
+				if (!u.getAid().equals(my.getId())){
+					StringBuffer str2=new StringBuffer();
+					str2=str2.append("业务员").append(my.getName()).append("(无需审核),准备公出您的企业");
+					str2=str2.append("[").append(u.getNickname()).append("]!!!");
+					sendNoticeAndSoucket(u.getAid(),3,str2.toString());
+				}
+			});
+
+		}
+			Map<String, Object>map=new HashMap<String, Object>();
+		if (status.get()==1){
+			sendNoticeAndSoucket(a.getId(),1,str);
+			if (openid!=null) {
+				Integer res= weChatUtils.addNotice(openid, in.getStatus(),in.getId(),date,my.getName(),"["+my.getName()+"]发起外出申请");
+				if (res!=0) {
+					sendEmail(my, a,1);
+				}
+				map.put("code", res);
+			}else {
 				sendEmail(my, a,1);
+				map.put("code", 2);
 			}
-			map.put("code", res);
-		}else {
-			sendEmail(my, a,1);
-			map.put("code", 2);
 		}
+			map.put("data", publicReleaseMapper.selectDtails(in.getId()));
 		return map;
 	}
 
@@ -287,7 +304,7 @@ public class PublicReleaseServiceImpl extends BaseMybatisDao<PublicReleaseMapper
 			AdminListBo my = adminMapper.getDeptNameByAid(TokenManager.getAdminId());
 			//新增修改日志
 			//重新发起
-			addPublicReleaseLog(my,in,in.getUserNames(),date);
+			addPublicReleaseLog(my,in,in.getUserNames(),date,null);
 		}else {
 			List<PublicRelease> list = publicReleaseMapper.selectByMainId(in.getId(),3,null);
 			List<PublicRelease> list2 = publicReleaseMapper.selectByMainId(in.getId(),4,null);