Browse Source

船舶动态表增加预警

shxiaoc 10 months ago
parent
commit
760f587cd2

+ 47 - 0
src/main/java/com/steerinfo/dil/controller/TmsshipShipLocationController.java

@@ -8,6 +8,7 @@ import com.steerinfo.dil.service.impl.TmsshipShipLocationServiceImpl;
 import com.steerinfo.dil.service.impl.TmsshipTotalResultServiceImpl;
 import com.steerinfo.dil.util.BaseRESTfulController;
 import com.steerinfo.dil.util.ColumnDataUtil;
+import com.steerinfo.dil.util.DataChange;
 import com.steerinfo.dil.util.PageListAdd;
 import com.steerinfo.framework.controller.RESTfulResult;
 import com.steerinfo.framework.service.pagehelper.PageHelper;
@@ -192,4 +193,50 @@ public class TmsshipShipLocationController extends BaseRESTfulController {
         return success(warnMsg);
     }
 
+    @ApiOperation(value="查询船舶预警")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
+            @ApiImplicitParam(name = "apiId(540)", value = "动态表头", required = false, dataType = "Integer"),
+            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
+            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer")
+    })
+    @PostMapping("/getShipWarningList")
+    public RESTfulResult getShipWarningList(@RequestBody(required=false) Map<String,Object> mapValue,
+                                              Integer apiId,
+                                              Integer pageNum,
+                                              Integer pageSize
+    ){
+        if (mapValue==null){
+            mapValue=new HashMap<>();
+        }
+        if (pageNum!=null && pageSize!=null){
+            PageHelper.startPage(pageNum,pageSize);
+        }
+        //分页数据
+        List<Map<String, Object>> result = tmsshipShipLocationService.selectShipWarningList(mapValue);
+        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, new ArrayList<>(), result);
+        return success(pageList);
+    }
+
+    @PostMapping("/getShipWarningResult")
+    public RESTfulResult getShipWarningResult(@RequestBody(required=false) Map<String,Object> mapValue){
+        if (mapValue == null || mapValue.get("orderId") == null){
+            return failed("参数错误!");
+        }
+        List<Map<String, Object>> list = tmsshipShipLocationService.selectShipWarningList(mapValue);
+        if(list == null || list.size() != 1){
+            return failed("未找到预警信息");
+        }
+        return success(list.get(0));
+    }
+
+    @PostMapping("/updateShipWarning")
+    public RESTfulResult updateShipWarning(@RequestBody(required=false) Map<String,Object> mapValue){
+        if (mapValue == null || mapValue.get("orderId") == null
+            || mapValue.get("trackRemark") == null || StringUtils.isEmpty(mapValue.get("trackRemark").toString())){
+            return failed("参数错误!");
+        }
+        mapValue.put("trackTime", new Date());
+        return success(tmsshipShipLocationService.updateShipWarning(mapValue));
+    }
 }

+ 9 - 0
src/main/java/com/steerinfo/dil/mapper/TmsshipShipLocationMapper.java

@@ -48,4 +48,13 @@ public interface TmsshipShipLocationMapper extends IBaseMapper<TmsshipShipLocati
 
     Map<String, Object> getShipLocationStatus(String shipLocation);
 
+    List<Map<String,Object>> selectShipLocationWarningList();
+
+    int batchInsertShipWarning(List<Map<String, Object>> list);
+
+    List<Map<String,Object>> selectShipWarningList(Map<String,Object> mapVal);
+
+    int updateShipWarning(Map<String,Object> mapVal);
+
+    String getUserInfoById(Map<String,Object> map);
 }

+ 8 - 0
src/main/java/com/steerinfo/dil/service/ITmsshipShipLocationService.java

@@ -69,4 +69,12 @@ public interface ITmsshipShipLocationService{
     List<Map<String,Object>> getShipLocation(BigDecimal locationId);
 
     Map<String, Object> getShipLocationStatus(String shipLocation);
+
+    List<Map<String,Object>> selectShipLocationWarningList();
+
+    int batchInsertShipWarning(List<Map<String, Object>> list);
+
+    List<Map<String,Object>> selectShipWarningList(Map<String,Object> mapVal);
+
+    int updateShipWarning(Map<String,Object> mapVal);
 }

+ 65 - 3
src/main/java/com/steerinfo/dil/service/impl/TmsshipShipLocationServiceImpl.java

@@ -8,13 +8,14 @@ import com.steerinfo.framework.service.impl.BaseServiceImpl;
 import com.steerinfo.dil.model.TmsshipShipLocation;
 import com.steerinfo.dil.mapper.TmsshipShipLocationMapper;
 import com.steerinfo.dil.service.ITmsshipShipLocationService;
+import com.steerinfo.framework.utils.base.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * TmsshipShipLocation服务实现:
@@ -146,4 +147,65 @@ public class TmsshipShipLocationServiceImpl implements ITmsshipShipLocationServi
     public Map<String, Object> getShipLocationStatus(String shipLocation) {
         return tmsshipShipLocationMapper.getShipLocationStatus(shipLocation);
     }
+
+    @Override
+    public List<Map<String, Object>> selectShipLocationWarningList() {
+        return tmsshipShipLocationMapper.selectShipLocationWarningList();
+    }
+
+    @Override
+    public int batchInsertShipWarning(List<Map<String, Object>> list) {
+        return tmsshipShipLocationMapper.batchInsertShipWarning(list);
+    }
+
+    @Override
+    public List<Map<String, Object>> selectShipWarningList(Map<String, Object> mapVal) {
+        return tmsshipShipLocationMapper.selectShipWarningList(mapVal);
+    }
+
+    @Override
+    public int updateShipWarning(Map<String, Object> mapVal) {
+        mapVal.put("insertUserName", "");
+        if(mapVal.get("userId") != null && !mapVal.get("userId").toString().trim().isEmpty()){
+            mapVal.put("insertUserName", tmsshipShipLocationMapper.getUserInfoById(mapVal));
+        }
+        return tmsshipShipLocationMapper.updateShipWarning(mapVal);
+    }
+
+    @Scheduled(fixedRate = 1000*60*60*12)
+    public void createShipWarning(){
+        try {
+            System.out.println("开始生成船舶预警"+ DateUtils.getCommonDateStr(new Date()));
+            List<Map<String, Object>> columnList = tmsshipShipLocationMapper.selectShipLocationWarningList();
+            List<Map<String, Object>> list = new ArrayList<>();
+            if(columnList != null && !columnList.isEmpty()) {
+                for (Map<String, Object> map : columnList) {
+                    String locationRouteTime = map.get("locationRouteTime").toString();
+                    Map<String, Object> insertMap = new HashMap<String, Object>();
+                    if(locationRouteTime != null && !locationRouteTime.isEmpty()){
+                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                        Date locationRouteTimeDate = sdf.parse(locationRouteTime);
+                        long starTime=locationRouteTimeDate.getTime();
+                        long endTime=(new Date()).getTime();
+                        long num=endTime-starTime;//时间戳相差的毫秒数
+                        //超过15天提醒
+                        if((num/(24*60*60*1000)) > 15){
+                            insertMap.put("abnormalContent", map.get("materialName") +" \""+ map.get("foreignShipName") +"\" "+map.get("capacityName")
+                                    +",离港日期"+ map.get("locationRouteTime") +",离港已超过十五天。");
+                            insertMap.put("abnormalType", "离港超时");
+                            insertMap.put("abnormalTime", new Date());
+                            insertMap.put("abnormalStatus", "未处理");
+                            insertMap.put("orderId", map.get("orderId"));
+                            list.add(insertMap);
+                        }
+                    }
+                }
+            }
+            if(!list.isEmpty()){
+                tmsshipShipLocationMapper.batchInsertShipWarning(list);
+            }
+        } catch (Exception e) {
+            System.out.println("生成船舶预警出错:" + e.getMessage());
+        }
+    }
 }

+ 101 - 0
src/main/resources/com/steerinfo/dil/mapper/TmsshipShipLocationMapper.xml

@@ -524,4 +524,105 @@
     ORDER BY TSL.INSERT_TIME desc)
     where rownum = 1
   </select>
+
+  <select id="selectShipLocationWarningList" resultType="java.util.Map">
+    SELECT DISTINCT
+    ttr.ORDER_ID                     as "orderId",
+    tsl.INSERT_TIME                  as "insertTime",
+    tsl.LOCATION_ID                  as "locationId",
+    rm.MATERIAL_NAME                 as "materialName",
+    dbi.INFACTORY_SHIP_NAME as "infactoryShipName",--进厂船名
+    db.RESULT_FOREIGN_SHIP_NAME      as "foreignShipName",
+    rc.CAPACITY_NUMBER               as "capacityName",
+    rps.PORT_NAME                    as "startPortName",
+    rpe.PORT_NAME                    as "arrivePortName",
+    oic.INSTRUCTION_PLANNED_LOADING  as "planWeight",
+    tlsr.RESULT_ACTUAL_INSTALLATIONS as "realWeight",
+    tsl.LOCATION_VALUE               as "shipLocation",
+    tsl.LOCATION_STATUS              as "locationStatus",
+    to_char(tlsr.RESULT_OUT_PORT_TIME,'yyyy-mm-dd')        as "locationRouteTime",
+    tsl.LOCATION_MEMO                as "locationMemo"
+    FROM TMSSHIP_SHIP_LOCATION tsl
+    LEFT JOIN TMSSHIP_TOTAL_RESULT ttr
+    ON tsl.TOTAL_RESULT_ID = ttr.RESULT_ID
+    LEFT JOIN OMSSHIP_INSTRUCTIONS_CAPACITY oic
+    ON oic.INSTRUCTIONS_CAPACITY_ID = ttr.ORDER_ID
+    LEFT JOIN OMSSHIP_SHIPMENT_INSTRUCTIONS osi
+    ON oic.INSTRUCTIONS_ID = osi.SHIPMENT_INSTRUCTIONS_ID
+    LEFT JOIN DIL_BATCH_INFACOTRY dbi --批次中间表
+    ON osi.BATCH_ID=dbi.BATCH_INFACOTRY_ID
+    LEFT JOIN DIL_BATCH db
+    ON dbi.BATCH_ID = db.BATCH_ID
+    LEFT JOIN AMSSHIP_DELIVERY_ATTORNEY ada
+    ON ada.BATCH_ID=dbi.BATCH_INFACOTRY_ID
+    LEFT JOIN RMS_MATERIAL rm
+    ON db.MATERIAL_ID = rm.MATERIAL_ID
+    LEFT JOIN TMSSHIP_LOAD_SHIP_RESULT tlsr
+    ON ttr.RESULT_ID = tlsr.TOTAL_RESULT_ID
+    LEFT JOIN RMS_PORT rps
+    ON ada.DOWN_SWIM_PORT_ID = rps.PORT_ID
+    LEFT JOIN RMS_PORT rpe
+    ON ada.PORT_ID = rpe.PORT_ID
+    LEFT JOIN RMS_CAPACITY rc
+    ON rc.CAPACITY_ID = oic.CAPACITY_ID
+    LEFT JOIN AMSSHIP_DELIVERY_NOTICE ADN
+    ON ADN.BATCH_ID=dbi.BATCH_INFACOTRY_ID
+    left join BMSSHIP_WARNING bw
+    on ttr.ORDER_ID = bw.orderId
+    WHERE tsl.DELETED = 0 and tlsr.DELETED = 0 and ada.DELETED=0 and oic.DELETED=0 and osi.DELETED=0 and adn.DELETED=0 and bw.orderId is null
+    order By db.RESULT_FOREIGN_SHIP_NAME
+  </select>
+  <insert id="batchInsertShipWarning" parameterType="java.util.List">
+    insert into BMSSHIP_WARNING
+    (orderId,
+     abnormalContent,
+     abnormalTime,
+     abnormalType,
+     abnormalStatus)
+    ( <foreach collection="list" item="item" separator="union all">
+    select
+    #{item.orderId,jdbcType=DECIMAL},
+    #{item.abnormalContent,jdbcType=VARCHAR},
+    #{item.abnormalTime,jdbcType=TIMESTAMP},
+    #{item.abnormalType,jdbcType=VARCHAR},
+    #{item.abnormalStatus,jdbcType=VARCHAR} from dual
+  </foreach> )
+  </insert>
+
+  <select id="selectShipWarningList" parameterType="map" resultType="java.util.Map">
+    SELECT t.orderId as "orderId",
+           t.abnormalContent as "abnormalContent",
+           TO_CHAR(t.abnormalTime, 'yyyy-mm-dd') as "abnormalTime",
+           t.trackRemark as "trackRemark",
+           TO_CHAR(t.trackTime, 'yyyy-mm-dd hh24:mi:ss') as "trackTime",
+           t.abnormalType as "abnormalType",
+           t.abnormalStatus as "abnormalStatus",
+           t.deleted as "deleted",
+           t.insertUserName as "insertUserName"
+    FROM BMSSHIP_WARNING t
+        where t.deleted = 0
+        <if test="abnormalContent != null and abnormalContent != ''">
+          and instr(t.abnormalContent, #{abnormalContent}) > 0
+        </if>
+        <if test="orderId != null">
+          and t.orderId = #{orderId}
+        </if>
+    order By t.abnormalTime desc
+  </select>
+
+  <update id="updateShipWarning" parameterType="map">
+    update BMSSHIP_WARNING
+    set
+      trackRemark = #{trackRemark,jdbcType=VARCHAR},
+      trackTime = #{trackTime,jdbcType=TIMESTAMP},
+      abnormalStatus = '已备注',
+      insertUserName = #{insertUserName,jdbcType=VARCHAR}
+    where orderId = #{orderId,jdbcType=DECIMAL}
+  </update>
+
+  <select id="getUserInfoById" resultType="java.lang.String">
+    SELECT so.ORG_NAME || su.USER_NAME FROM SSO.SYS_USER su, SSO.SYS_ORG so
+    WHERE su.USER_ID = #{userId} AND su.ORG_CODE = so.ORG_CODE
+      FETCH NEXT 1 ROWS ONLY
+  </select>
 </mapper>