ylx 7 yıl önce
ebeveyn
işleme
1419459584

+ 36 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/dao/ContractManagementDao.java

@@ -35,4 +35,40 @@ public class ContractManagementDao {
 	public ContractStatusTracking getContractStatusTrackingByBusinessId(Integer businessId) {
 		return contractManagementMapper.getContractStatusTrackingByBusinessId(businessId);
 	}
+
+	public void insertInformationToAttachment(Map<String, Object> map) {
+		contractManagementMapper.insertInformationToAttachment(map);
+	}
+
+	public void insertInformationToOperationHistory(Map<String, Object> map) {
+		contractManagementMapper.insertInformationToOperationHistory(map);
+	}
+
+	public ContractRecord getLatestContractRecordByBusinessId(Integer businessId) {
+		return contractManagementMapper.getLatestContractRecordByBusinessId(businessId);
+	}
+
+	public void insertInformationToContractRecord(Map<String, Object> map) {
+		contractManagementMapper.insertInformationToContractRecord(map);
+	}
+
+	public void updateContractStatusTracking(Map<String, Object> map) {
+		contractManagementMapper.updateContractStatusTracking(map);
+	}
+
+	public ContractRecord getCurrentContractRecordByBusinessId(Integer businessId, Integer version) {
+		return contractManagementMapper.getCurrentContractRecordByBusinessId(businessId,version);
+	}
+
+	public void updateContractRecord(Map<String, Object> map) {
+		contractManagementMapper.updateContractRecord(map);
+	}
+
+	public void updateOtherContractRecord(Map<String, Object> map) {
+		contractManagementMapper.updateOtherContractRecord(map);
+	}
+
+	public void updateContractStatusTrackingStatusAndContractId(Map<String, Object> map) {
+		contractManagementMapper.updateContractStatusTrackingStatusAndContractId(map);
+	}
 }

+ 10 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/entity/ContractRecord.java

@@ -15,6 +15,16 @@ public class ContractRecord {
 	private String status_name;			//状态名称
 	private Long commit_time;			//更新时间,提交时间
 	private String hash;				//hash值?
+	
+	private Boolean ifChecked;			//用于前端进行确认按钮的返回,默认false(显示确认按钮),如果true(表示已经确认过了,变成已确认按钮置灰)♥,如果是null(表示全部要失效)
+	
+	
+	public Boolean getIfChecked() {
+		return ifChecked;
+	}
+	public void setIfChecked(Boolean ifChecked) {
+		this.ifChecked = ifChecked;
+	}
 	public String getStatus_name() {
 		return status_name;
 	}

+ 166 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapper/ContractManagementMapper.xml

@@ -127,4 +127,170 @@
 			sct.business_id=#{businessId}
 	</select>
 	
+	<!-- 将数据插入附件表中 -->
+	<insert id="insertInformationToAttachment">
+		insert into 
+			attachment(attachment_id,
+					   attachment_name,
+					   url,
+					   upload_person_id,
+					   create_time)
+		values(#{attachmentId},
+			   #{attachmentName},
+			   #{url},
+			   #{userId},
+			   #{createTime})
+	</insert>
+	
+	<!-- 将信息插入到操作记录表中 -->
+	<insert id="insertInformationToOperationHistory">
+		insert into 
+			operation_history(operator_type_id,
+							  operator_account,
+							  operator_role,
+							  operator_person,
+							  operator_time,
+							  hash)
+		values(#{operatorTypeId},
+			   #{operatorAccount},
+			   #{operatorRole},
+			   #{operatorPerson},
+			   #{operatorTime},
+			   #{hash})
+	</insert>
+	
+	<!-- 根据业务id号获取最新的合同记录表中的一条信息 -->
+	<select id="getLatestContractRecordByBusinessId" resultType="com.fuzamei.entity.ContractRecord">
+		select 
+			cr.id,
+			cr.business_id,
+			cr.contract_id,
+			cr.contract_name,
+			cr.version,
+			cr.contract_party,
+			cr.upload_department,
+			cr.upload_person,
+			cr.modify_opinion,
+			cr.unconfirm_department,
+			s.status_name,
+			cr.status_id,
+			cr.commit_time,
+			cr.hash
+		from 
+			contract_record cr 
+		left join 
+			status s
+		on 
+			s.status_id=cr.status_id
+		where 
+			cr.business_id=#{businessId}
+		order by
+			cr.version desc
+		limit 1
+	</select>
+	
+	<!-- 将合同记录信息插入到合同记录表中 -->
+	<insert id="insertInformationToContractRecord">
+		insert into 
+			contract_record(business_id,
+							contract_id,
+							contract_name,
+							version,
+							contract_party,
+							upload_department,
+							upload_person,
+							modify_opinion,
+							unconfirm_department,
+							status_id,
+							commit_time,
+							hash)
+		values(#{businessId},
+			   #{contractId},
+			   #{contractName},
+			   #{version},
+			   #{contractParty},
+			   #{uploadDepartment},
+			   #{uploadPerson},
+			   #{modifyOpinion},
+			   #{uncomfirmDepartment},
+			   #{statusId}
+			   #{commitTime},
+			   #{hash})
+	</insert>
+	
+	<!-- 对合同状态跟踪表中的更新时间和合同id号进行修改 -->
+	<update id="updateContractStatusTracking">
+		update 
+			contract_status_tracking
+		set 
+			contract_id=#{contractId},
+			update_time=#{updateTime}
+		where
+			business_id=#{businessId}
+	</update>
+	
+	<!-- 根据业务id和版本号获取当前的一条合同记录详细信息 -->
+	<select id="getCurrentContractRecordByBusinessId" resultType="com.fuzamei.entity.ContractRecord">
+		select 
+			cr.id,
+			cr.business_id,
+			cr.contract_id,
+			cr.contract_name,
+			cr.version,
+			cr.contract_party,
+			cr.upload_department,
+			cr.upload_person,
+			cr.modify_opinion,
+			cr.unconfirm_department,
+			s.status_name,
+			cr.status_id,
+			cr.commit_time,
+			cr.hash
+		from 
+			contract_record cr 
+		left join 
+			status s
+		on 
+			s.status_id=cr.status_id
+		where 
+			cr.business_id=#{businessId} 
+			and cr.version=#{version}
+	</select>
+	
+	<!-- 更新合同记录表的信息 -->
+	<update id="updateContractRecord">
+		update 
+			contract_record
+		set
+			commit_time=#{commitTime},
+			unconfirm_department=#{unconfirmed},
+			status_id=#{statusId}
+		where
+			business_id=#{businessId}
+			and version=#{version}
+	</update>
+	
+	<!-- 在指定业务id下将除了目标version以外的所有信息全部置为作废 -->
+	<update id="updateOtherContractRecord">
+		update 
+			contract_record
+		set
+			status_id=#{statusId},
+			commit_time=#{commitTime}
+		where
+			business_id=#{businessId}
+			and version not in(#{version})
+	</update>
+	
+	<!-- 当整个合同被确认以后,更新合同状态跟踪表中的状态,时间和合同id号 -->
+	<update id="updateContractStatusTrackingStatusAndContractId">
+		update 
+			contract_status_tracking
+		set 
+			contract_id=#{contractId},
+			update_time=#{updateTime},
+			status_id=#{statusId}
+		where
+			business_id=#{businessId}
+	</update>
 </mapper>

+ 20 - 0
ccb_fund_trusteeship/src/main/java/com/fuzamei/mapperInterface/ContractManagementMapper.java

@@ -3,6 +3,8 @@ package com.fuzamei.mapperInterface;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ibatis.annotations.Param;
+
 import com.fuzamei.entity.ContractRecord;
 import com.fuzamei.entity.ContractStatusTracking;
 
@@ -17,5 +19,23 @@ public interface ContractManagementMapper {
 	int findAllContractRecordInformation(Map<String, Object> map);
 
 	ContractStatusTracking getContractStatusTrackingByBusinessId(Integer businessId);
+
+	void insertInformationToAttachment(Map<String, Object> map);
+
+	void insertInformationToOperationHistory(Map<String, Object> map);
+
+	ContractRecord getLatestContractRecordByBusinessId(Integer businessId);
+
+	void insertInformationToContractRecord(Map<String, Object> map);
+
+	void updateContractStatusTracking(Map<String, Object> map);
+
+	ContractRecord getCurrentContractRecordByBusinessId(@Param("businessId") Integer businessId,@Param("version") Integer version);
+
+	void updateContractRecord(Map<String, Object> map);
+
+	void updateOtherContractRecord(Map<String, Object> map);
+
+	void updateContractStatusTrackingStatusAndContractId(Map<String, Object> map);
 	
 }

+ 230 - 1
ccb_fund_trusteeship/src/main/java/com/fuzamei/service/ContractManagementService.java

@@ -1,14 +1,20 @@
 package com.fuzamei.service;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import com.fuzamei.constant.OperationTypeId;
+import com.fuzamei.constant.Role;
+import com.fuzamei.constant.StatusId;
 import com.fuzamei.dao.ContractManagementDao;
 import com.fuzamei.entity.ContractRecord;
 import com.fuzamei.entity.ContractStatusTracking;
+import com.fuzamei.entity.UserDetail;
 import com.fuzamei.utils.PageDTO;
 
 @Service
@@ -17,6 +23,17 @@ public class ContractManagementService {
 	@Autowired
 	private ContractManagementDao contractManagementDao;
 
+	/**
+	 * 
+	* @Title: queryContractStatusTracking
+	* @Description: TODO(将所有的合同跟踪记录信息全部返还给前端)
+	* @param @param map
+	* @param @return    设定文件
+	* @return PageDTO    返回类型
+	* @author ylx
+	* @date 2018年1月9日 下午4:15:03
+	* @throws
+	 */
 	public PageDTO queryContractStatusTracking(Map<String, Object> map) {
 		PageDTO pageDTO = new PageDTO();
 		//分页信息
@@ -28,10 +45,39 @@ public class ContractManagementService {
 		return pageDTO;
 	}
 
+	/**
+	 * 
+	* @Title: queryContractRecord
+	* @Description: TODO(将某个业务id号下的合同记录表的全部信息返回给Action)
+	* @param @param map
+	* @param @return    设定文件
+	* @return PageDTO    返回类型
+	* @author ylx
+	* @date 2018年1月9日 下午4:14:20
+	* @throws
+	 */
 	public PageDTO queryContractRecord(Map<String, Object> map) {
+		UserDetail userDetail = (UserDetail) map.get("userDetail");
+		String roleName = userDetail.getRole_name().get(0);
 		PageDTO pageDTO = new PageDTO();
 		//分页信息
 		List<ContractRecord> list = contractManagementDao.queryContractRecord(map);
+		for (ContractRecord contractRecord : list) {
+			//获取未确认部门的信息
+			String unconfirmed = contractRecord.getUnconfirm_department();
+			Integer statusId = contractRecord.getStatus_id();
+			//如果状态为已生效或废弃直接置为null
+			if(statusId==StatusId.VALID||statusId==StatusId.DUMPED){
+				contractRecord.setIfChecked(null);//按钮全部失效
+				continue;
+			}
+			//如果未确认部门里面不包含当前用户的角色信息,说明该用户已经对该信息进行过了确认,因此将按钮置灰
+			if(!unconfirmed.contains(roleName)&&statusId==StatusId.INVALID){
+				contractRecord.setIfChecked(true);//按钮显示已确认并置灰
+			}else{
+				contractRecord.setIfChecked(false);//表示确认按钮还存在
+			}
+		}
 		//查询符合map中条件的条数
 		int count = contractManagementDao.findAllContractRecordInformation(map);
 		pageDTO.setRows(list);
@@ -39,11 +85,194 @@ public class ContractManagementService {
 		return pageDTO;
 	}
 
+	/**
+	 * 
+	* @Title: getContractStatusTrackingByBusinessId
+	* @Description: TODO(通过业务id获取合同状态跟踪表中的全部详细信息)
+	* @param @param businessId
+	* @param @return    设定文件
+	* @return ContractStatusTracking    返回类型
+	* @author ylx
+	* @date 2018年1月9日 上午10:33:08
+	* @throws
+	 */
 	public ContractStatusTracking getContractStatusTrackingByBusinessId(Integer businessId) {
+		if(businessId==null){
+			throw new RuntimeException("业务id不能为空");
+		}
 		return contractManagementDao.getContractStatusTrackingByBusinessId(businessId);
 	}
 
-	public void uploadContractByUser(Map<String, Object> mapToService) {
+	/**
+	 * 
+	* @Title: uploadContractByUser
+	* @Description: TODO(上传新合同时,需要在附件表插数据,合同记录表插入一条数据,合同状态跟踪表更新数据,操作记录表插入一条数据)
+	* @param @param map    设定文件
+	* @return void    返回类型
+	* @author ylx
+	* @date 2018年1月9日 上午11:56:04
+	* @throws
+	 */
+	@Transactional(rollbackFor=Exception.class)
+	public void uploadContractByUser(Map<String, Object> map) {
 		long currentTime = System.currentTimeMillis();
+		UserDetail userDetail =(UserDetail) map.get("userDetail");
+		ContractStatusTracking contractStatusTracking =(ContractStatusTracking) map.get("contractStatusTracking");
+		ContractRecord contractRecord =(ContractRecord) map.get("contractRecord");
+		Integer contractId = (Integer) map.get("contractId");
+		String contractName = (String) map.get("contractName");
+		String url = (String) map.get("url");
+		Integer version = contractRecord.getVersion()+1;//获取最新的版本信息号,并加1表示当前要插入的合同信息的最新版本号
+		String modifyOpinion = (String) map.get("modifyOpinion");
+		String hash=(String) map.get("hash");
+		//将数据插入到合同记录表contractRecord
+		Map<String, Object> mapToContractRecord=new LinkedHashMap<String, Object>();
+		mapToContractRecord.put("businessId", contractStatusTracking.getBusiness_id());
+		mapToContractRecord.put("contractId", contractId);
+		mapToContractRecord.put("contractName", contractName);
+		mapToContractRecord.put("version", version);						//版本号写活♥
+		mapToContractRecord.put("contractParty", contractStatusTracking.getContract_party());
+		mapToContractRecord.put("uploadDepartment", userDetail.getOrganization_name());
+		mapToContractRecord.put("uploadPerson", userDetail.getPerson_name());
+		mapToContractRecord.put("modifyOpinion", modifyOpinion);			//这个根据前台传过来的进入插入
+		//这个按照这个格式【管理人&省分行业务主管部门&省分行法律部】先写死新上传的肯定待审核部门是三个
+		mapToContractRecord.put("uncomfirmDepartment", Role.ADMIN+"&"+Role.BUSINESS_CHIEF_DEP_OF_PBB+"&"+Role.LAW_DEP_OF_PBB);
+		mapToContractRecord.put("statusId", StatusId.INVALID);						//刚刚提交必定是未生效(19)
+		mapToContractRecord.put("commitTime", currentTime);
+		mapToContractRecord.put("hash", hash);
+		contractManagementDao.insertInformationToContractRecord(mapToContractRecord);
+		
+		//将数据封装插入到附件表中attachment
+		Map<String, Object> mapToAttachment=new LinkedHashMap<String, Object>();
+		mapToAttachment.put("attachmentId", contractId);
+		mapToAttachment.put("attachmentName", contractName);
+		mapToAttachment.put("url", url);
+		mapToAttachment.put("userId", userDetail.getUser_id());
+		mapToAttachment.put("createTime", currentTime);
+		contractManagementDao.insertInformationToAttachment(mapToAttachment);
+		
+		//将数据插入到操作记录表中operationHistory
+		Map<String, Object> mapToOperationHistory=new LinkedHashMap<String, Object>();
+		mapToOperationHistory.put("operatorTypeId", OperationTypeId.CONTRACT_UPLOAD);		//operatorTypeId=1004表示【合同上传】
+		mapToOperationHistory.put("operatorRole", userDetail.getOrganization_name());		//当前用户的上传部门,写活♥
+		mapToOperationHistory.put("operatorAccount", userDetail.getAccount());				//当前操作账号写活♥
+		mapToOperationHistory.put("operatorPerson", userDetail.getPerson_name());			//当前操作人先写活♥
+		mapToOperationHistory.put("operatorTime", currentTime);								//操作时间为当前操作时间
+		mapToOperationHistory.put("hash", "to be calculated from operation");				//如何计算操作的hash值????============================>>待定TODO
+		contractManagementDao.insertInformationToOperationHistory(mapToOperationHistory);
+		
+		//新的合同上传以后,contractStatusTracking的信息也要进行修改(合同换成最新的,更新时间这两项)
+		Map<String, Object> mapToContractStatusTracking=new LinkedHashMap<String, Object>();
+		mapToContractStatusTracking.put("contractId", contractId);
+		mapToContractStatusTracking.put("businessId", contractStatusTracking.getBusiness_id());
+		mapToContractStatusTracking.put("updateTime", currentTime);
+		contractManagementDao.updateContractStatusTracking(mapToContractStatusTracking);
+	}
+
+	/**
+	 * 
+	* @Title: getLatestContractRecordByBusinessId
+	* @Description: TODO(获取最新版本号的合同记录详细信息)
+	* @param @param businessId
+	* @param @return    设定文件
+	* @return ContractRecord    返回类型
+	* @author ylx
+	* @date 2018年1月9日 上午11:01:42
+	* @throws
+	 */
+	public ContractRecord getLatestContractRecordByBusinessId(Integer businessId) {
+		/*if(businessId==null){
+			throw new RuntimeException("业务id不能为空");
+		}*/
+		return contractManagementDao.getLatestContractRecordByBusinessId(businessId);
+	}
+
+	/**
+	 * 
+	* @Title: getCurrentContractRecordByBusinessId
+	* @Description: TODO(根据业务id号和版本号确认得到唯一一条合同记录信息)
+	* @param @param businessId
+	* @param @param version
+	* @param @return    设定文件
+	* @return ContractRecord    返回类型
+	* @author ylx
+	* @date 2018年1月9日 下午2:11:53
+	* @throws
+	 */
+	public ContractRecord getCurrentContractRecordByBusinessId(Integer businessId, Integer version) {
+		return contractManagementDao.getCurrentContractRecordByBusinessId(businessId,version);
+	}
+
+	/**
+	 * 
+	* @Title: updateContractByUser
+	* @Description: TODO(当用户点击确认按钮的时候产生的一系列更新操作)
+	* @param @param mapToService    设定文件
+	* @return void    返回类型
+	* @author ylx
+	* @date 2018年1月9日 下午2:12:36
+	* @throws
+	 */
+	@Transactional(rollbackFor=Exception.class)
+	public void updateContractByUser(Map<String, Object> map) {
+		long currentTime = System.currentTimeMillis();
+		UserDetail userDetail = (UserDetail) map.get("userDetail");
+		ContractRecord contractRecord = (ContractRecord) map.get("contractRecord");
+		String unconfirmed = contractRecord.getUnconfirm_department();
+		String currentUserRole = userDetail.getRole_name().get(0);//获取当前用户角色名
+		if(!unconfirmed.contains(currentUserRole)){//判断当前用户是否已经确认过
+			throw new RuntimeException("您已确认过了");
+		}
+		unconfirmed = unconfirmed.replace(currentUserRole, "");//将当前角色在字符串中截掉
+		Integer businessId = contractRecord.getBusiness_id();
+		Integer version = contractRecord.getVersion();
+		Integer contractId = contractRecord.getContract_id();//被确认的合同id号,一旦被确认,合同记录跟踪表的合同id号以被确认的那个合同id号为准
+		
+		if(unconfirmed.contains(Role.ADMIN)||unconfirmed.contains(Role.BUSINESS_CHIEF_DEP_OF_PBB)||unconfirmed.contains(Role.LAW_DEP_OF_PBB)){
+			//如果字符串中还含有其它角色信息,那说明其他部门还没有全部确认,该合同的状态信息暂时还不需要进行变动
+			//所有部门都还没有全部确认,只要更改待确认部门信息即可
+			Map<String, Object> mapToContractRecord=new LinkedHashMap<String, Object>();
+			mapToContractRecord.put("businessId", businessId);
+			mapToContractRecord.put("version", version);
+			mapToContractRecord.put("commitTime", currentTime);//当前的状态更新时间
+			mapToContractRecord.put("unconfirmed", unconfirmed);//修改待确认部门
+			mapToContractRecord.put("statusId", StatusId.INVALID);//将状态值仍然为未生效【19】
+			contractManagementDao.updateContractRecord(mapToContractRecord);
+		}else{
+			//接下来的操作是所有部门都已经确认的情况下的操作
+			Map<String, Object> mapToContractRecord=new LinkedHashMap<String, Object>();
+			mapToContractRecord.put("businessId", businessId);
+			mapToContractRecord.put("version", version);
+			mapToContractRecord.put("commitTime", currentTime);//当前的状态更新时间
+			mapToContractRecord.put("unconfirmed", "--");//将待确认部门置为空
+			mapToContractRecord.put("statusId", StatusId.VALID);//将状态值改为生效【20】
+			contractManagementDao.updateContractRecord(mapToContractRecord);
+			
+			//当所有部门全部确认了以后,除了被确认的合同记录状态为【生效】该业务id下的其它所有合同记录的状态全部为【作废状态】
+			Map<String, Object> mapToOtherContractRecord=new LinkedHashMap<String, Object>();
+			mapToOtherContractRecord.put("businessId", businessId);
+			mapToOtherContractRecord.put("version", version);
+			mapToOtherContractRecord.put("commitTime", currentTime);
+			mapToOtherContractRecord.put("statusId", StatusId.DUMPED);//其它所有状态改为【作废】
+			contractManagementDao.updateOtherContractRecord(mapToOtherContractRecord);
+			
+			//总表中的合同状态跟踪表也要进行相应的更新
+			Map<String, Object> mapToContractStatusTracking=new LinkedHashMap<String, Object>();
+			mapToContractStatusTracking.put("businessId", businessId);
+			mapToContractStatusTracking.put("contractId", contractId);
+			mapToContractStatusTracking.put("updateTime", currentTime);
+			mapToContractStatusTracking.put("statusId", StatusId.CONFIRMED);	//此时所有人都已经确认的情况下将【合同状态跟踪表】状态代码变成已确认【8】
+			contractManagementDao.updateContractStatusTrackingStatusAndContractId(mapToContractStatusTracking);//更新合同状态跟踪表中的信息
+		}
+		
+		//将操作记录插入到操作记录表中
+		Map<String, Object> mapToOperationHistory=new LinkedHashMap<String, Object>();
+		mapToOperationHistory.put("operatorTypeId", OperationTypeId.CONTRACT_CONFIRM);		//operatorTypeId=1005表示【合同确认】
+		mapToOperationHistory.put("operatorRole", userDetail.getOrganization_name());		//当前用户的上传部门,写活♥
+		mapToOperationHistory.put("operatorAccount", userDetail.getAccount());				//当前操作账号写活♥
+		mapToOperationHistory.put("operatorPerson", userDetail.getPerson_name());			//当前操作人先写活♥
+		mapToOperationHistory.put("operatorTime", currentTime);								//操作时间为当前操作时间
+		mapToOperationHistory.put("hash", "to be calculated from operation");				//如何计算操作的hash值????============================>>待定TODO
+		contractManagementDao.insertInformationToOperationHistory(mapToOperationHistory);
 	}
 }

+ 117 - 4
ccb_fund_trusteeship/src/main/java/com/fuzamei/web/ContractManagementAction.java

@@ -1,10 +1,16 @@
 package com.fuzamei.web;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URLEncoder;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -19,11 +25,13 @@ import com.alibaba.fastjson.JSON;
 import com.fuzamei.constant.HintMSG;
 import com.fuzamei.constant.Role;
 import com.fuzamei.constant.StatusId;
+import com.fuzamei.entity.ContractRecord;
 import com.fuzamei.entity.ContractStatusTracking;
 import com.fuzamei.entity.UserDetail;
 import com.fuzamei.service.AttachmentService;
 import com.fuzamei.service.ContractManagementService;
 import com.fuzamei.service.UserAuthoricationService;
+import com.fuzamei.utils.HashXiZhiUtil;
 import com.fuzamei.utils.JSONUtil;
 import com.fuzamei.utils.PageDTO;
 import com.fuzamei.utils.RelativePathUtil;
@@ -128,13 +136,14 @@ public class ContractManagementAction {
 			Map<String,Object> map = JSON.parseObject(data, Map.class);
 			int userId = ValidationUtil.checkAndAssignInt(map.get("userId"));
 			//只有管理员,省分行业务主管部门,省分行法律部才有权限可以查看
-			userAuthoricationService.checkUserAuthority(userId, Role.ADMIN,Role.BUSINESS_CHIEF_DEP_OF_PBB,Role.LAW_DEP_OF_PBB);
+			UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId, Role.ADMIN,Role.BUSINESS_CHIEF_DEP_OF_PBB,Role.LAW_DEP_OF_PBB);
 			int page = ValidationUtil.checkMinAndAssignInt(map.get("page"),1);
 			//这里的businessId是必查条件,所以不能默认为null,应该强制转换成int类型
 			Integer businessId = ValidationUtil.checkAndAssignInt(map.get("businessId"));
 			Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
 			mapToService.put("startPage", (page - 1) * ROW_NUM);
 			mapToService.put("businessId", businessId);
+			mapToService.put("userDetail", userDetail);
 			mapToService.put("rowNum", ROW_NUM); // 默认每页显示数据是10条,可根据需求修改分页数量
 			PageDTO pageDto=contractManagementService.queryContractRecord(mapToService);
 			return JSONUtil.getJsonMap(200, true, HintMSG.QUERY_SUCCESS, pageDto);
@@ -172,14 +181,23 @@ public class ContractManagementAction {
 			Integer businessId = ValidationUtil.checkAndAssignInt(bId);
 			String modifyOpinion = ValidationUtil.checkBlankAndAssignString(mOpinion);
 			ContractStatusTracking contractStatusTracking = contractManagementService.getContractStatusTrackingByBusinessId(businessId);
-			if(contractStatusTracking==null) throw new RuntimeException("无该合同信息");
+			ContractRecord contractRecord = contractManagementService.getLatestContractRecordByBusinessId(businessId);
+			if(contractStatusTracking==null || contractRecord==null) throw new RuntimeException("无该合同信息");
 			//如果已经确认过报错
-			if(contractStatusTracking.getStatus_id()==StatusId.CONFIRMED) throw new RuntimeException("合同已确认");//已确认id是8
+			if(contractStatusTracking.getStatus_id()==StatusId.CONFIRMED) throw new RuntimeException("合同已确认,不能提交");//已确认id是8
 			
 			//确定好上传的文件的顶级父级路径=======================================================================>>待定TODO
 			String path = request.getServletContext().getRealPath("");			//SP是系统分隔符
 			String relativePath = RelativePathUtil.formatPath("/"+userId, "");	//生成文件的相对保存路径
 			
+			//暂时生成一个临时文件
+			String tempPath = path+"/temp~~~~~"+filename;
+			File tempFile = new File(tempPath);
+			file.transferTo(tempFile);
+			
+			String hash = HashXiZhiUtil.getMD5Checksum(tempPath);//文件hash的计算待定
+			tempFile.delete();//将临时文件先删除
+			
 			int contractId = attachmentService.generateAtachmentId();//生成不重复的附件id号
 			
 			Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
@@ -187,7 +205,10 @@ public class ContractManagementAction {
 			mapToService.put("contractName", filename);
 			mapToService.put("modifyOpinion", modifyOpinion);
 			mapToService.put("userDetail", userDetail);
-			mapToService.put("hash", "to be calculated");	//文件hash待定
+			mapToService.put("contractStatusTracking", contractStatusTracking);
+			mapToService.put("contractRecord", contractRecord);
+			mapToService.put("url", relativePath+filename);
+			mapToService.put("hash", hash);	//文件hash待定
 			contractManagementService.uploadContractByUser(mapToService);
 			
 			String pathFile=path+relativePath+filename;
@@ -206,6 +227,98 @@ public class ContractManagementAction {
 		}
 	}
 	
+	/**
+	 * 
+	* @Title: downloadContractFiles
+	* @Description: TODO(下载合同文件)
+	* @param @param request
+	* @param @param response
+	* @param @param url
+	* @param @param uId
+	* @param @return    设定文件
+	* @return Map<String,Object>    返回类型
+	* @author ylx
+	* @date 2018年1月9日 上午11:43:14
+	* @throws
+	 */
+	@RequestMapping(value="/downloadContractFiles")
+	@ResponseBody
+	private Map<String, Object> downloadContractFiles(HttpServletRequest request,HttpServletResponse response,
+			@RequestParam("url") String url,
+			@RequestParam("userId") Object uId) {
+		try {
+			int userId=ValidationUtil.checkAndAssignInt(uId);
+//			userAuthoricationService.checkUserAuthority(userId,Role.ADMIN,Role.BUSINESS_CHIEF_DEP_OF_PBB,Role.LAW_DEP_OF_PBB);	//查看用户非空和权限
+			userAuthoricationService.checkUserAuthority(userId);//(暂时将权限对所有人全部放开)
+			url=ValidationUtil.checkBlankAndAssignString(url);							//对传过来的url进行非空校验
+			String fileName = request.getServletContext().getRealPath("")+url; 		//SP是系统分隔符
+			//如果文件不存在直接抛出异常
+			if(!new File(fileName).exists()){
+				throw new RuntimeException(HintMSG.FILE_NOT_FOUND);
+			}
+			InputStream bis = new BufferedInputStream(new FileInputStream(new File(fileName)));  
+			String filename = url.substring(url.lastIndexOf("/")+1);  //截取文件名
+			filename = URLEncoder.encode(filename,"UTF-8");
+			response.addHeader("Content-Disposition", "attachment;filename=" + filename);    
+			response.setContentType("multipart/form-data");   
+			BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
+			int len = 0;  
+			while((len = bis.read()) != -1){  
+				out.write(len);  
+				out.flush(); 
+			}  
+			out.close();
+			bis.close();
+			return JSONUtil.getJsonMap(200, true, HintMSG.DOWNLOAD_SUCCESS, null);
+		} catch (Exception e) {
+			return JSONUtil.getJsonMap(500, false, HintMSG.DOWNLOAD_FAIL+":"+e.getMessage(), null);
+		}
+	}
+	
+	/**
+	 * 
+	* @Title: confirmContractContent
+	* @Description: TODO(对合同进行确认)
+	* @param @param data
+	* 前端传过来的json数据格式
+	{
+		"userId":"xxx",
+		"businessId":"",
+		"version":""
+	}
+	* @param @return    设定文件
+	* @return Map<String,Object>    返回类型
+	* @author ylx
+	* @date 2018年1月9日 上午11:48:05
+	* @throws
+	 */
+	@RequestMapping(value="/confirmContractContent")
+	@ResponseBody
+	private Map<String, Object> confirmContractContent(@RequestBody String data){
+		try {
+			System.out.println("对合同记录表进行确认....");
+			@SuppressWarnings("unchecked")
+			Map<String,Object> map = JSON.parseObject(data, Map.class);
+			int userId = ValidationUtil.checkAndAssignInt(map.get("userId"));
+			UserDetail userDetail = userAuthoricationService.checkUserAuthority(userId,Role.ADMIN,Role.BUSINESS_CHIEF_DEP_OF_PBB,Role.LAW_DEP_OF_PBB);	//查看用户非空和权限
+			Integer businessId = ValidationUtil.checkAndAssignInt(map.get("businessId"));
+			Integer version = ValidationUtil.checkAndAssignInt(map.get("version"));
+			ContractStatusTracking contractStatusTracking = contractManagementService.getContractStatusTrackingByBusinessId(businessId);
+			ContractRecord contractRecord = contractManagementService.getCurrentContractRecordByBusinessId(businessId,version);//根据业务id和版本号获取当前合同记录信息
+			if(contractStatusTracking==null || contractRecord==null) throw new RuntimeException("无该合同信息");
+			//如果已经确认过报错
+			if(contractStatusTracking.getStatus_id()==StatusId.CONFIRMED) throw new RuntimeException("合同已确认,不能再确认");//已确认id是8
+			
+			Map<String, Object> mapToService = new LinkedHashMap<String, Object>();
+			mapToService.put("contractRecord", contractRecord);	//文件hash待定
+			mapToService.put("userDetail", userDetail);	//文件hash待定
+			contractManagementService.updateContractByUser(mapToService);
+			
+			return JSONUtil.getJsonMap(200, true, HintMSG.OPERATION_SUCCESS, null);
+		} catch (Exception e) {
+			return JSONUtil.getJsonMap(500, false, HintMSG.OPERATION_FAIL+":"+e.getMessage(), null);
+		}
+	}
 	
 	
 }