事务是对数据库的一系列的操作的集合,是一个单一的工作单元,对事务的操作要么都成功,要么都失败。事务管理是事务的重要组成部分,RDBMS 面向企业应用程序,以确保数据完整性和一致性。事务由以下4个属性(ACID):
-
**原子性:**原子性是指事务包含的所有操作要么全部成功,要么全部失败回滚,因此事务的操作如果成功就必须要完全应用到数据库,如果操作失败则不能对数据库有任何影响。
-
一致性:
一致性是指事务必须使数据库从一个一致性状态变换到另一个一致性状态,也就是说一个事务执行之前和执行之后都必须处于一致性状态。
拿转账来说,假设用户A和用户B两者的钱加起来一共是5000,那么不管A和B之间如何转账,转几次账,事务结束后两个用户的钱相加起来应该还得是5000,这就是事务的一致性。
-
隔离性:
隔离性是当多个用户并发访问数据库时,比如操作同一张表时,数据库为每一个用户开启的事务,不能被其他事务的操作所干扰,多个并发事务之间要相互隔离。
即要达到这么一种效果:对于任意两个并发的事务T1和T2,在事务T1看来,T2要么在T1开始之前就已经结束,要么在T1结束之后才开始,这样每个事务都感觉不到有其他事务在并发地执行。
-
**持久性:**持久性是指一个事务一旦被提交了,那么对数据库中的数据的改变就是永久性的,即便是在数据库系统遇到故障的情况下也不会丢失提交事务的操作。
事务的隔离性有四个隔离级别:
(1)读未提交:A用户和B用户都具有共享锁,当A用户获取对表操作的排他锁后,对表进行修改操作,操作完成后,并未提交事务,这时,B用户获取共享锁读取到对该表的数据,此时读取的数据是A用户并未提交的数据,该操作容易造成读取数据是脏数据。
(2)读已提交:A用户和B用户都具有共享锁,B用户正在读取数据,A用户获取对该表行内排他锁后,对数据进行修改操作,并提交,这时B用户两次读取到的数据不一致,出现幻读
(3)可重复读,A用户和B用户都具有共享锁,B用户正在读取数据,A用户获取对该表表内排他锁后,对表进行插入操作,并提交,这时B用户两次读取到的表内数据记录不一致,出现幻读
(4)序列化,将数据存储到硬盘等设备中保存起来。
spring 的事务分为编程式事务管理,和声明式事务管理
隔离级别的可能值:
TransactionDefinition.ISOLATION_DEFAULT
这是默认的隔离级别。
| | 2 |
TransactionDefinition.ISOLATION_READ_COMMITTED
表明能够阻止误读;可以发生不可重复读和虚读。
| | 3 |
TransactionDefinition.ISOLATION_READ_UNCOMMITTED
表明可以发生误读、不可重复读和虚读。
| | 4 |
TransactionDefinition.ISOLATION_REPEATABLE_READ
表明能够阻止误读和不可重复读;可以发生虚读。
| | 5 |
TransactionDefinition.ISOLATION_SERIALIZABLE
表明能够阻止误读、不可重复读和虚读。
|
传播类型的可能值:
TransactionDefinition.PROPAGATION_MANDATORY
支持当前事务;如果不存在当前事务,则抛出一个异常。
| | 2 |
TransactionDefinition.PROPAGATION_NESTED
如果存在当前事务,则在一个嵌套的事务中执行。
| | 3 |
TransactionDefinition.PROPAGATION_NEVER
不支持当前事务;如果存在当前事务,则抛出一个异常。
| | 4 |
TransactionDefinition.PROPAGATION_NOT_SUPPORTED
不支持当前事务;而总是执行非事务性。
| | 5 |
TransactionDefinition.PROPAGATION_REQUIRED
支持当前事务;如果不存在事务,则创建一个新的事务。
| | 6 |
TransactionDefinition.PROPAGATION_REQUIRES_NEW
创建一个新事务,如果存在一个事务,则把当前事务挂起。
| | 7 |
TransactionDefinition.PROPAGATION_SUPPORTS
支持当前事务;如果不存在,则执行非事务性。
| | 8 |
TransactionDefinition.TIMEOUT_DEFAULT
使用默认超时的底层事务系统,或者如果不支持超时则没有。
声明式事务
spring的配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.2.xsd">
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 传播行为 -->
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="taragerid" expression="execution(* com.sheemes.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="taragerid"/>
</aop:config>
<!-- <tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean> 注解式声明事务,在业务层只需要@Transactional(readOnly = true) -->
</beans>
具体的业务操作代码
package com.sheemes.service.impl;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.sheemes.mapper.DpcStatisticperiodtypeMapper;
import com.sheemes.mapper.QualityDataTendingMapper;
import com.sheemes.pojo.DpcStatisticperiodtype;
import com.sheemes.pojo.QtRptMediaList;
import com.sheemes.pojo.QualityDetection;
import com.sheemes.pojo.QualityReportList;
import com.sheemes.service.QualityDataTendingService;
@Service
public class QualityDataTendingServiceImpl implements QualityDataTendingService {
@Autowired
private QualityDataTendingMapper qualityDataTendingMapper;
@Autowired
private DpcStatisticperiodtypeMapper dpcStatisticperiodtypeMapper;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* @name:findQualityRptLists;
* @describe:获取质量报告列表内容返回给Controller
* @params:startTime:起始时间,endTime:终止时间,findType:查询类型,rptType:报告类型,quaRptModel:质量报告模板
* @autor:gaofei;
* @createTime:2019-6-19
* @return:封装QualityReportList属性的pojo对象
*/
@Override
public List<QualityReportList> findQualityRptLists(String findType, String startTime, String endTime,
String rptType, String[] quaRptModelArray,String supplementaryCondition,String supplementaryConditionColumn) {
int findTypeToInt=0;
if(Integer.parseInt(findType)>0) {
findTypeToInt=(Integer.parseInt(findType)-1)*-1;
}else {
findTypeToInt=Integer.parseInt(findType)*-1;
}
String supplementaryConditionValue="";
if("a.CreateType".equals(supplementaryConditionColumn)) {
switch(supplementaryCondition) {
case "手动":supplementaryConditionValue="1";break;
case "自动":supplementaryConditionValue="2";break;
}
}else if("a.RptContentType".equals(supplementaryConditionColumn)) {
switch(supplementaryCondition) {
case "基础报告":supplementaryConditionValue="1";break;
case "复合报告":supplementaryConditionValue="2";break;
}
}else {
supplementaryConditionValue=supplementaryCondition;
}
List<QualityReportList>qualityRptListCollection =qualityDataTendingMapper.findQualityRptLists(findTypeToInt,startTime,endTime,rptType,quaRptModelArray,supplementaryConditionValue,supplementaryConditionColumn);
//对生成的集合对象进行拆箱装箱操作,实现质量管理列表数据的相关字段(CreateType/RptContentType/RptPeriodIndex)修改
List<QualityReportList>qualityRptLists=new ArrayList<>();
for(QualityReportList qualityReportList:qualityRptListCollection) {
QualityReportList qualityReport=new QualityReportList();
qualityReport.setQualityOrderID(qualityReportList.getQualityOrderID());
qualityReport.setRptName(qualityReportList.getRptName());
qualityReport.setMagBusinessType(qualityReportList.getMagBusinessType());
if("1".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("手动");
}else if("2".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("自动");
}
if("1".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("基础报告");
}else if("2".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("复合报告");
}
qualityReport.setRptPeriodType(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("系统默认");
}else if("1".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("夜班");
}else if("2".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("白班");
}else if("3".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("中班");
}
qualityReport.setTemplateType(qualityReportList.getTemplateType());
try {
Date date1=sdf.parse(qualityReportList.getQualityOrderTime());
qualityReport.setQualityOrderTime(sdf.format(date1));
Date date2=sdf.parse(qualityReportList.getOrderModityTime());
qualityReport.setOrderModityTime(sdf.format(date2));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
qualityReport.setQualityOrderType("1-模板");
qualityReport.setTestSummary(qualityReportList.getTestSummary());
qualityReport.setTestPeriod(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getPeriodIndex())) {
qualityReport.setPeriodIndex("自定义");
}else {
qualityReport.setPeriodIndex(qualityReportList.getPeriodIndex());
}
qualityReport.setTestOperator(qualityReportList.getTestOperator());
qualityReport.setInputOperator(qualityReportList.getInputOperator());
qualityReport.setVerifyOperator(qualityReportList.getVerifyOperator());
qualityReport.setResultDesc(qualityReportList.getResultDesc());
qualityReport.setRemark(qualityReportList.getRemark());
qualityReport.setManagerBuinessTypeId(qualityReportList.getManagerBuinessTypeId());
qualityReport.setCreateTypeId(qualityReportList.getCreateTypeId());
qualityReport.setRptContentTypeId(qualityReportList.getRptContentTypeId());
qualityReport.setReportPeriodType(qualityReportList.getReportPeriodType());
qualityReport.setReportPeriodIndex(qualityReportList.getReportPeriodIndex());
qualityReport.setTestPeriodType(qualityReportList.getTestPeriodType());
qualityReport.setTestPeriodId(qualityReportList.getTestPeriodId());;
qualityReport.setQtReportTemplateID(qualityReportList.getQtReportTemplateID());
qualityRptLists.add(qualityReport);
}
return qualityRptLists;
}
/**
* @name:getSupplementaryCondition;
* @describe:获取质量报告列表内容查询的辅助条件返回给controller
* @params:conditionIndex
* @autor:gaofei;
* @createTime:2019-6-19
* @return:SupplementaryCondition
*/
@Override
public List<Map<String, String>> getSupplementaryCondition(int conditionIndex) {
List<Map<String,String>>supplementaryConditions=null;
switch(conditionIndex) {
case 4:{List<Map<String,String>>supplementaryConditionlist=qualityDataTendingMapper.getSupplementaryCondition();
supplementaryConditions=new ArrayList<>();
for(Map<String,String>supplementaryCondition:supplementaryConditionlist) {
Map<String,String>supplementary =new HashMap<>();
supplementary.put("name", (String)supplementaryCondition.get("Name"));
supplementary.put("index", String.valueOf(supplementaryCondition.get("MagBusinessTypeID")));
supplementaryConditions.add(supplementary);
}
};break;
case 5:{
supplementaryConditions=new ArrayList<>();
Map<String,String> createType1 = new HashMap<>();
Map<String,String> createType2 = new HashMap<>();
createType1.put("index", "1");
createType1.put("name", "手动");
createType2.put("index", "2");
createType2.put("name", "自动");
supplementaryConditions.add(createType1);
supplementaryConditions.add(createType2);
};break;
case 6:{
supplementaryConditions=new ArrayList<>();
Map<String,String> rptContentType1 = new HashMap<>();
Map<String,String> rptContentType2 = new HashMap<>();
rptContentType1.put("index", "1");
rptContentType1.put("name", "基础报告");
rptContentType2.put("index", "2");
rptContentType2.put("name", "复合报告");
supplementaryConditions.add(rptContentType1);
supplementaryConditions.add(rptContentType2);
};break;
case 7:{List<DpcStatisticperiodtype>supplementaryConditionObj=dpcStatisticperiodtypeMapper.findallDpcStatisticperiodtype();
supplementaryConditions=new ArrayList<>();
for(DpcStatisticperiodtype supplementaryCondition:supplementaryConditionObj) {
Map<String,String>suppleCdi=new HashMap<>();
suppleCdi.put("index",String.valueOf(supplementaryCondition.getStatperiodtypeid()-1));
suppleCdi.put("name",String.valueOf(supplementaryCondition.getName()));
supplementaryConditions.add(suppleCdi);
}
}break;
default:{
supplementaryConditions=new ArrayList<>();
Map<String,String>map=new HashMap<>();
supplementaryConditions.add(map);
}
}
return supplementaryConditions;
}
/**
* @name:getQualityRptList;
* @describe:获取质量介质信息内容返回给View
* @params:qualityOrderId,sampleTime
* @autor:gaofei;
* @createTime:2019-6-21
* @return:List<QtRptMediaList>
*/
@Override
public List<QtRptMediaList> getQtRptMediaList(String qualityOrderId, String sampleTime) {
return qualityDataTendingMapper.getQtRptMediaList(qualityOrderId,sampleTime);
}
/**
* @name:getQualityDetectionList;
* @describe:获取质量检测内容返回给Controller
* @params:detectionTime;
* @autor:gaofei;
* @createTime:2019-6-24
* @return:QualityDetection
*/
@Override
public List<QualityDetection> getQualityDetectionList(String detectionTime,String qualityOrderId) {
List<QualityDetection> qualitiDetectionList=qualityDataTendingMapper.getQualityDetectionList(detectionTime,qualityOrderId);
List<QualityDetection> qualitiDetectionList1=new ArrayList<>();
for(QualityDetection qualitiDetection:qualitiDetectionList) {
QualityDetection qualitiDetection1=new QualityDetection();
qualitiDetection1.setMonBusinessType(qualitiDetection.getMonBusinessType());
qualitiDetection1.setMonBusinessItem(qualitiDetection.getMonBusinessItem());
qualitiDetection1.setMuBusinessType(qualitiDetection.getMuBusinessType());
qualitiDetection1.setMagObjectType(qualitiDetection.getMagObjectType());
qualitiDetection1.setObjectName(qualitiDetection.getObjectName());
qualitiDetection1.setQualityDataTime(qualitiDetection.getQualityDataTime());
qualitiDetection1.setStatType(qualitiDetection.getStatType());
qualitiDetection1.setPeriodType(qualitiDetection.getPeriodType());
if("0".equals(qualitiDetection.getPeriodIndex())) {
qualitiDetection1.setPeriodIndex("系统默认");//周期序号
}else if("1".equals(qualitiDetection.getPeriodIndex())) {
qualitiDetection1.setPeriodIndex("夜班");
}else if("2".equals(qualitiDetection.getPeriodIndex())) {
qualitiDetection1.setPeriodIndex("白班");
}else if("3".equals(qualitiDetection.getPeriodIndex())) {
qualitiDetection1.setPeriodIndex("中班");
}
qualitiDetection1.setQuallityValue(qualitiDetection.getQuallityValue());
qualitiDetection1.setQualityTarget(qualitiDetection.getQualityTarget());
qualitiDetection1.setTargetValue1(qualitiDetection.getTargetValue1());
qualitiDetection1.setTargetValue2(qualitiDetection.getTargetValue2());
qualitiDetection1.setEstType(qualitiDetection.getEstType());
qualitiDetection1.setOffsetValue(qualitiDetection.getOffsetValue());
qualitiDetection1.setOffsetRatio(qualitiDetection.getOffsetRatio());
if("0".equals(qualitiDetection.getQualityStatus())) {
qualitiDetection1.setQualityStatus("不合格");//质量状态
}else if("1".equals(qualitiDetection.getQualityStatus())){
qualitiDetection1.setQualityStatus("合格");//质量状态
}
qualitiDetection1.setResultDesc(qualitiDetection.getResultDesc());
qualitiDetection1.setSaveTime(qualitiDetection.getSaveTime());
qualitiDetection1.setModifyTime(qualitiDetection.getModifyTime());
qualitiDetection1.setMeteringUnitName(qualitiDetection.getMeteringUnitName());
qualitiDetection1.setInputOperator(qualitiDetection.getInputOperator());
qualitiDetection1.setRemark(qualitiDetection.getRemark());
qualitiDetection1.setMonBusinessTypeID(qualitiDetection.getMonBusinessTypeID());
qualitiDetection1.setMonBusinessItemID(qualitiDetection.getMonBusinessItemID());
qualitiDetection1.setMagObjectID(qualitiDetection.getMagObjectID());
qualitiDetection1.setMagObjectTypeID(qualitiDetection.getMagObjectTypeID());
qualitiDetection1.setMuBusinessTypeID(qualitiDetection.getMuBusinessTypeID());
qualitiDetection1.setStatTypeID(qualitiDetection.getStatTypeID());
qualitiDetection1.setPeriodTypeId(qualitiDetection.getPeriodTypeId());
qualitiDetection1.setQualityTargetID(qualitiDetection.getQualityTargetID());
qualitiDetection1.setEstTypeId(qualitiDetection.getEstTypeId());
qualitiDetectionList1.add(qualitiDetection1);
}
return qualitiDetectionList1;
}
/**
* @name:organizeRptTemlate;
* @describe:住址质量报表模板标题(管理业务类型,报告生成类型,报告内容类型,报告周期类型,报告周期序号,检验周期,周期序号)的返回给Controller
* @params:null;
* @autor:gaofei;
* @createTime:2019-6-24
* @return:封装String属性的JSONArray数组
*/
@Override
public String organizeRptTemlate() {
List<Map<String, String>> magBuinessType =this.getSupplementaryCondition(4);
List<Map<String, Object>> periods =qualityDataTendingMapper.getStatisticPeriodType();
List<Map<String, Object>> testPeriodType =new ArrayList<>();
List<Map<String, Object>> rptPeriodType =new ArrayList<>();
List<Map<String, Object>> rptCreateType =new ArrayList<>();
for(int i=0;i<2;i++) {//创建类型
if(i==0){
Map<String,Object> map1=new HashMap<>();
map1.put("index", "1");
map1.put("name", "手动");
rptCreateType.add(map1);
}else {
Map<String,Object> map2=new HashMap<>();
map2.put("index", "2");
map2.put("name", "自动");
rptCreateType.add(map2);
}
}
List<Map<String, Object>> rptContentType =new ArrayList<>();
for(int i=0;i<2;i++) {//内容类型
if(i==0){
Map<String,Object> map1=new HashMap<>();
map1.put("index", "1");
map1.put("name", "基础报告");
rptContentType.add(map1);
}else {
Map<String,Object> map2=new HashMap<>();
map2.put("index", "2");
map2.put("name", "复合报告");
rptContentType.add(map2);
}
}
List<Map<String, Object>> rptPeriodIndex =new ArrayList<>();
for(int i=0;i<4;i++) {//报告周期序号
if(i==0){
Map<String,Object> map1=new HashMap<>();
map1.put("index", "0");
map1.put("name", "系统默认");
rptPeriodIndex.add(map1);
}else if(i==1) {
Map<String,Object> map2=new HashMap<>();
map2.put("index", "1");
map2.put("name", "夜班");
rptPeriodIndex.add(map2);
}else if(i==2) {
Map<String,Object> map3=new HashMap<>();
map3.put("index", "2");
map3.put("name", "白班");
rptPeriodIndex.add(map3);
}else if(i==3) {
Map<String,Object> map4=new HashMap<>();
map4.put("index", "3");
map4.put("name", "中班");
rptPeriodIndex.add(map4);
}
}
for(Map<String, Object> period:periods) {
String status=String.valueOf( period.get("id"));
rptPeriodType.add(period);//报告周期
switch(status) {//测试周期
case "0":{testPeriodType.add(period);};break;
case "3":{testPeriodType.add(period);};break;
case "4":{testPeriodType.add(period);};break;
case "5":{testPeriodType.add(period);};break;
}
}
String propertylist= "[{\"magBuinessType\":"+JSON.toJSONString(magBuinessType)+",\"testPeriodType\":"+JSON.toJSONString(testPeriodType)+",\"rptPeriodType\":"+JSON.toJSONString(rptPeriodType) +",\"rptCreateType\":"+JSON.toJSONString(rptCreateType)+",\"rptContentType\":"+JSON.toJSONString(rptContentType)+",\"rptPeriodIndex\":"+JSON.toJSONString(rptPeriodIndex)+"}]";
//String propertylist= "[{\"magBuinessType\":"+JSON.toJSONString(magBuinessType)+"}]";
return propertylist;
}
/**
* @name:findQualityRptLists;
* @describe:根据质量管理模板查找到对应的质量报告并返回给Controller
* @params:templateObjName;
* @autor:gaofei;
* @createTime:2019-7-02
* @return:封装QualityReportList属性的list集合
*/
@Override
public List<QualityReportList> findQualityRptLists(String[] quaRptModelArray) {
List<QualityReportList> qualityRpts=qualityDataTendingMapper.findQualityRptLists1(quaRptModelArray);
//对生成的集合对象进行拆箱装箱操作,实现质量管理列表数据的相关字段(CreateType/RptContentType/RptPeriodIndex)修改
List<QualityReportList>qualityRptLists=new ArrayList<>();
for(QualityReportList qualityReportList:qualityRpts) {
QualityReportList qualityReport=new QualityReportList();
qualityReport.setQualityOrderID(qualityReportList.getQualityOrderID());
qualityReport.setRptName(qualityReportList.getRptName());
qualityReport.setMagBusinessType(qualityReportList.getMagBusinessType());
if("1".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("手动");
}else if("2".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("自动");
}
if("1".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("基础报告");
}else if("2".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("复合报告");
}
qualityReport.setRptPeriodType(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("系统默认");
}else if("1".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("夜班");
}else if("2".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("白班");
}else if("3".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("中班");
}
qualityReport.setTemplateType(qualityReportList.getTemplateType());
try {
Date date1=sdf.parse(qualityReportList.getQualityOrderTime());
qualityReport.setQualityOrderTime(sdf.format(date1));
Date date2=sdf.parse(qualityReportList.getOrderModityTime());
qualityReport.setOrderModityTime(sdf.format(date2));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*qualityReport.setQualityOrderTime(qualityReportList.getQualityOrderTime());
qualityReport.setOrderModityTime(qualityReportList.getOrderModityTime());*/
qualityReport.setQualityOrderType("1-模板");
qualityReport.setTestSummary(qualityReportList.getTestSummary());
qualityReport.setTestPeriod(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getPeriodIndex())) {
qualityReport.setPeriodIndex("自定义");
}else {
qualityReport.setPeriodIndex(qualityReportList.getPeriodIndex());
}
qualityReport.setTestOperator(qualityReportList.getTestOperator());
qualityReport.setInputOperator(qualityReportList.getInputOperator());
qualityReport.setVerifyOperator(qualityReportList.getVerifyOperator());
qualityReport.setResultDesc(qualityReportList.getResultDesc());
qualityReport.setRemark(qualityReportList.getRemark());
qualityReport.setManagerBuinessTypeId(qualityReportList.getManagerBuinessTypeId());
qualityReport.setCreateTypeId(qualityReportList.getCreateTypeId());
qualityReport.setRptContentTypeId(qualityReportList.getRptContentTypeId());
qualityReport.setReportPeriodType(qualityReportList.getReportPeriodType());
qualityReport.setReportPeriodIndex(qualityReportList.getReportPeriodIndex());
qualityReport.setTestPeriodType(qualityReportList.getTestPeriodType());
qualityReport.setTestPeriodId(qualityReportList.getTestPeriodId());;
qualityReport.setQtReportTemplateID(qualityReportList.getQtReportTemplateID());
qualityRptLists.add(qualityReport);
}
return qualityRptLists;
}
/**
* @name:findMaxRptlist;
* @describe:查询出最大报告单的报告列表
* @params:null;
* @autor:gaofei;
* @createTime:2019-7-5
* @return:封装QualityReportList属性的JSONArray数组
*/
@Override
public List<QualityReportList> findMaxRptlist() {
List<QualityReportList>qualityRptListCollection =qualityDataTendingMapper.findMaxRptlist();
//对生成的集合对象进行拆箱装箱操作,实现质量管理列表数据的相关字段(CreateType/RptContentType/RptPeriodIndex)修改
List<QualityReportList>qualityRptLists=new ArrayList<>();
for(QualityReportList qualityReportList:qualityRptListCollection) {
QualityReportList qualityReport=new QualityReportList();
qualityReport.setQualityOrderID(qualityReportList.getQualityOrderID());
qualityReport.setRptName(qualityReportList.getRptName());
qualityReport.setMagBusinessType(qualityReportList.getMagBusinessType());
if("1".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("手动");
}else if("2".equals(qualityReportList.getCreateType())) {
qualityReport.setCreateType("自动");
}
if("1".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("基础报告");
}else if("2".equals(qualityReportList.getRptContentType())) {
qualityReport.setRptContentType("复合报告");
}
qualityReport.setRptPeriodType(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("系统默认");
}else if("1".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("夜班");
}else if("2".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("白班");
}else if("3".equals(qualityReportList.getRptPeriodIndex())) {
qualityReport.setRptPeriodIndex("中班");
}
qualityReport.setTemplateType(qualityReportList.getTemplateType());
try {
Date date1=sdf.parse(qualityReportList.getQualityOrderTime());
qualityReport.setQualityOrderTime(sdf.format(date1));
Date date2=sdf.parse(qualityReportList.getOrderModityTime());
qualityReport.setOrderModityTime(sdf.format(date2));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
qualityReport.setQualityOrderType("1-模板");
qualityReport.setTestSummary(qualityReportList.getTestSummary());
qualityReport.setTestPeriod(qualityReportList.getRptPeriodType());
if("0".equals(qualityReportList.getPeriodIndex())) {
qualityReport.setPeriodIndex("自定义");
}else {
qualityReport.setPeriodIndex(qualityReportList.getPeriodIndex());
}
qualityReport.setTestOperator(qualityReportList.getTestOperator());
qualityReport.setInputOperator(qualityReportList.getInputOperator());
qualityReport.setVerifyOperator(qualityReportList.getVerifyOperator());
qualityReport.setResultDesc(qualityReportList.getResultDesc());
qualityReport.setRemark(qualityReportList.getRemark());
qualityReport.setManagerBuinessTypeId(qualityReportList.getManagerBuinessTypeId());
qualityReport.setCreateTypeId(qualityReportList.getCreateTypeId());
qualityReport.setRptContentTypeId(qualityReportList.getRptContentTypeId());
qualityReport.setReportPeriodType(qualityReportList.getReportPeriodType());
qualityReport.setReportPeriodIndex(qualityReportList.getReportPeriodIndex());
qualityReport.setTestPeriodType(qualityReportList.getTestPeriodType());
qualityReport.setTestPeriodId(qualityReportList.getTestPeriodId());;
qualityReport.setQtReportTemplateID(qualityReportList.getQtReportTemplateID());
qualityRptLists.add(qualityReport);
}
return qualityRptLists;
}
/**
* @name:addQualityTendingTemplate;
* @describe:对质量监测项进行添加操作
* @params:qualityRptData;
* @autor:gaofei;
* @createTime:2019-7-5
* @return:String
*/
@Override
public String addQualityTendingTemplate(QualityReportList qualityReport, List<QtRptMediaList> medias, List<QualityDetection> qualityDetection) {
boolean addResult=this.addQualityTendingTemplateByRptMdaDet(qualityReport,medias,qualityDetection);
String status=addResult!=false?"success":"fault";
return status;
}
//添加质量模板
private boolean addQualityTendingTemplateByRptMdaDet(QualityReportList qualityReport, List<QtRptMediaList> medias,
List<QualityDetection> qualityDetection) {
int flag1=qualityDataTendingMapper.addRptTmp(qualityReport);
int flag2=qualityDataTendingMapper.addRMediaTmp(medias);
List<QualityDetection> qualityDetections=new ArrayList<>();
for(QualityDetection detection:qualityDetection) {
int number=detection.getOffsetRatio().indexOf("%");
String offsetRatio="";
if(number!=-1) {
offsetRatio=detection.getOffsetRatio().substring(0, number);
if("".equals(offsetRatio)) {
offsetRatio="0.0";
}
}
QualityDetection qualityDectction=new QualityDetection();
qualityDectction.setMonBusinessTypeID(detection.getMonBusinessTypeID());
qualityDectction.setMonBusinessItemID(detection.getMonBusinessItemID());
qualityDectction.setMagObjectType(detection.getMagObjectType());
qualityDectction.setMagObjectID(detection.getMagObjectID());
qualityDectction.setMuBusinessTypeID(detection.getMuBusinessTypeID());
qualityDectction.setQualityOrderID(detection.getQualityOrderID());
qualityDectction.setStatTypeID(detection.getStatTypeID());
qualityDectction.setPeriodTypeId(detection.getPeriodTypeId());
if("系统默认".equals(detection.getPeriodIndex())) {
qualityDectction.setPeriodIndex("0");//周期序号
}else if("夜班".equals(detection.getPeriodIndex())) {
qualityDectction.setPeriodIndex("1");
}else if("白班".equals(detection.getPeriodIndex())) {
qualityDectction.setPeriodIndex("2");
}else if("中班".equals(detection.getPeriodIndex())) {
qualityDectction.setPeriodIndex("3");
}
qualityDectction.setQualityDataTime(detection.getQualityDataTime());
if(detection.getQuallityValue()==null||"".equals(detection.getQuallityValue())) {
qualityDectction.setQuallityValue("0.0");
}else {
qualityDectction.setQuallityValue(detection.getQuallityValue());
}
qualityDectction.setQualityTargetID(detection.getQualityTargetID());
if(detection.getTargetValue1()==null||"".equals(detection.getTargetValue1())) {
qualityDectction.setTargetValue1("0.0");
}else {
qualityDectction.setTargetValue1(detection.getTargetValue1());
}
if(detection.getTargetValue2()==null || "".equals(detection.getTargetValue2())) {
qualityDectction.setTargetValue2("0.0");
}else {
qualityDectction.setTargetValue2(detection.getTargetValue2());
}
qualityDectction.setEstTypeId(detection.getEstTypeId());
if(detection.getOffsetValue()==null || "".equals(detection.getOffsetValue())) {
qualityDectction.setOffsetValue("0.0");
}else {
qualityDectction.setOffsetValue(detection.getOffsetValue());
}
qualityDectction.setOffsetRatio(offsetRatio);
if("不合格".equals(detection.getQualityStatus())) {
qualityDectction.setQualityStatus("0");//质量状态
}else if("合格".equals(detection.getQualityStatus())){
qualityDectction.setQualityStatus("1");//质量状态
}
qualityDectction.setResultDesc(detection.getResultDesc());
qualityDectction.setSaveTime(detection.getSaveTime());
qualityDectction.setModifyTime(detection.getModifyTime());
qualityDectction.setMeteringUnitName(detection.getMeteringUnitName());
qualityDectction.setInputOperator(detection.getInputOperator());
qualityDectction.setRemark(detection.getRemark());
qualityDectction.setMonBusinessTypeID(detection.getMonBusinessTypeID());
qualityDectction.setMonBusinessItemID(detection.getMonBusinessItemID());
qualityDectction.setMagObjectID(detection.getMagObjectID());
qualityDectction.setMagObjectTypeID(detection.getMagObjectTypeID());
qualityDectction.setMuBusinessTypeID(detection.getMuBusinessTypeID());
qualityDectction.setStatTypeID(detection.getStatTypeID());
qualityDectction.setPeriodTypeId(detection.getPeriodTypeId());
qualityDectction.setQualityTargetID(detection.getQualityTargetID());
qualityDectction.setEstTypeId(detection.getEstTypeId());
qualityDetections.add(qualityDectction);
}
int flag3=qualityDataTendingMapper.addDetectorTmp(qualityDetections);
boolean status=false;
if(flag1!=-1 && flag2!=-1 && flag3!=-1) {
status=true;
}else {
status=false;
}
return status;
}
/**
* @name:updateCostomQualityTemplate;
* @describe:对自定义报告进行修改操作
* @params:qualityRptData;
* @autor:gaofei;
* @createTime:2019-7-9
* @return:String
*/
@Override
public String updateDataTendingTemplate(QualityReportList qualityReport) {
int flag=qualityDataTendingMapper.updateRptTmp(qualityReport);
return flag!=-1?"success":"fault";
}
/**
* @name:deleteRpt;
* @describe:对质量报告项进行删除操作
* @params:qualityOrderIds;
* @autor:gaofei;
* @createTime:2019-7-9
* @return:String
*/
@Override
public String deleteDataTendingTemplate(String[] qualityOrderIds) {
int flag3=qualityDataTendingMapper.deleteDetector(qualityOrderIds);//删除监测项
int flag2=qualityDataTendingMapper.deleteMedia(qualityOrderIds);//删除介质
int flag1=qualityDataTendingMapper.deleteRptTmp(qualityOrderIds);//删除报告
boolean status=false;
if(flag1!=-1 && flag2!=-1 && flag3!=-1) {
status=true;
}else {
status=false;
}
return status==true?"success":"fault";
}
}
以上就是spring事务的声明式用法。也就是在事务管理器中,写好我们要对哪些事务就行事务管理,并注入到spring中,利用spring的AOP面向切面技术,将代理对象切入到目标对象,完成对事务的管理。