Browse Source

新增事务

liyg 2 years ago
parent
commit
7359bcda16

+ 2 - 0
src/main/java/com/steerinfo/DilApplicationMain.java

@@ -7,6 +7,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 /**
  * @Author zhangnan
@@ -19,6 +20,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @MapperScan({"com.steerinfo.dil.mapper"})
 @EnableDiscoveryClient
 @EnableFeignClients(basePackages="com.steerinfo.dil.feign")
+@EnableTransactionManagement
 public class DilApplicationMain {
     public static void main(String[] args) {
         SpringApplication.run(DilApplicationMain.class,args);

+ 6 - 12
src/main/java/com/steerinfo/dil/controller/TmstrainLoadingResultController.java

@@ -125,18 +125,12 @@ public class TmstrainLoadingResultController extends BaseRESTfulController {
             @ApiImplicitParam(name = "tmstrainLoadingResult", value = "修改车皮装车map", required = false, dataType = "TmstrainWagonLoadResult")
     })
     @PostMapping(value = "/upadteTmstrainLoadingResultByResultId")
-    public RESTfulResult upadteTmstrainLoadingResultByResultId(@RequestBody(required = false) Map<String,Object> map) throws Exception {
-        int i = tmstrainLoadingResultService.updateTmstrainLoadingResult(map);
-        if (i==-1){
-            return  failed("车皮号异常");
-        }else if(i==-2){
-            return  failed("主键异常");
-        }else if(i==-3){
-            return  failed("类型异常");
-        }else if(i==-4){
-            return  failed("采购订单号异常");
-        }else if(i==-5){
-            return  failed("发送计量委托失败");
+    public RESTfulResult upadteTmstrainLoadingResultByResultId(@RequestBody(required = false) Map<String,Object> map) {
+        int i=-1;
+        try{
+            i = tmstrainLoadingResultService.updateTmstrainLoadingResult(map);
+        }catch (Exception e){
+            return  failed(e.getMessage());
         }
         return success(i);
     }

+ 13 - 9
src/main/java/com/steerinfo/dil/service/impl/TmstrainLoadingResultServiceImpl.java

@@ -361,6 +361,7 @@ public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultS
      * @param map
      * @return
      */
+    @Transactional(rollbackFor = {Exception.class})
     @Override
     public int updateTmstrainLoadingResult(Map<String,Object> map) throws Exception{
         TmstrainLoadingResult tmstrainLoadingResult=new TmstrainLoadingResult();
@@ -368,11 +369,11 @@ public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultS
         BigDecimal resultId=DataChange.dataToBigDecimal(map.get("resultId"));
         Integer resultType=(Integer) map.get("resultType");
         if(wagonNo==null || wagonNo.length()!=7 || calculateWagonWeight(wagonNo)<=0){
-            return  -1;
+            throw new Exception("车皮号异常");
         }else if(resultId==null){
-            return  -2;
+            throw new Exception("主键为空");
         }else if(resultType==0){
-            return -3;
+            throw new Exception("类型异常");
         }
         //国产矿未配单仅支持修改部分字段,并且不重新发委托
         List<Map<String,Object>> results=tmstrainLoadingResultMapper.selectByResultId(resultId);
@@ -407,7 +408,7 @@ public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultS
             BigDecimal materialId=DataChange.dataToBigDecimal(record.get("materialId"));
             BigDecimal supplierId=DataChange.dataToBigDecimal(record.get("supplierId"));
             if(purchaseOrderId==null || batchId==null ||materialId==null ||supplierId==null){
-                return  -4;
+                throw new Exception("采购订单号异常");
             }
             tmstrainLoadingResult.setBatchId(batchId);
             tmstrainLoadingResult.setPurchaseOrderRailPlanId(purchaseOrderId);
@@ -428,8 +429,12 @@ public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultS
         }else{
             throw new Exception("没有用户id,请登录再操作!");
         }
-        int count=0;
-        //发送计量委托
+        //更新
+        int count=tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
+        if(count <= 0){
+            throw new Exception("修改失败");
+        }
+        //修改成功,发送计量委托
         List<Map<String, Object>> resultIdList = new ArrayList<>();
         Map<String, Object> map1 = new HashMap<>();
         Map<String, Object> map2 = new HashMap<>();
@@ -438,9 +443,8 @@ public class TmstrainLoadingResultServiceImpl implements ITmstrainLoadingResultS
         map2.put("resultIdList",resultIdList);
         count = tmstrainMeasureCommissionService.batchSendMeasureCommission(map2);
         if(count<=0)
-            return -5;
-        //更新
-        return tmstrainLoadingResultMapper.updateByPrimaryKeySelective(tmstrainLoadingResult);
+           throw new Exception("发送计量委托失败");
+        return count;
     }
 
     /**

+ 4 - 1
src/main/resources/com/steerinfo/dil/mapper/TmstrainMeasureCommissionMapper.xml

@@ -375,7 +375,7 @@
     where TLR.RESULT_ID = #{resultId}
   </select>
 
-<!-- 查询计量 -->
+<!-- 查询计量 -->
   <select id="getLoadResultToSendMC" parameterType="map" resultType="java.util.Map">
     select
            *
@@ -412,12 +412,15 @@
         on RAS2.ARRIVAL_ID = TLR.ARRIVAL_STATION_ID
         left join TMSTRAIN_TOTAL_RESULT TTR
         on TTR.LOADING_ID = TLR.RESULT_ID
+        left join TMSTRAIN_WEIGHT_RESULT TWR
+        on TTR.TOTAL_RESULT_ID=TWR.RESULT_TOTAL_ID
         left join TMSTRAIN_WAGON_UNLOAD_RESULT TWUR
         on (TLR.PURCHASE_ORDER_RAIL_PLAN_ID=TWUR.PURCHASE_ORDER_RAIL_PLAN_ID and  TLR.RESULT_WAGON_NO=TWUR.RESULT_WAGON_NO)
            where TLR.DELETED = 0
              and TLR.RESULT_TYPE = #{resultType}
              and TLR.SEND_REQUEST = 2
              and APO.PURCHASE_ORDER_NO IS NOT NULL
+             and TWR.RESULT_POUND_NO IS NULL
              <if test="con!=null and con!=''.toString()">
              and (
                     APO.PURCHASE_ORDER_NO like concat('%',concat(#{con},'%'))