package com.steerinfo.dil.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.steerinfo.dil.mapper.TmstruckMeasureCommissionMapper; import com.steerinfo.dil.model.TmstruckMeasureCommission; import com.steerinfo.dil.service.ITmstruckMeasureCommissionService; import com.steerinfo.dil.util.DataChange; import com.steerinfo.dil.util.HTTPRequestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.io.IOException; import java.math.BigDecimal; import java.util.*; /** * TmstruckMeasureCommission服务实现: * @author generator * @version 1.0-SNAPSHORT 2021-09-09 10:28 * 类描述 * 修订历史: * 日期:2021-09-09 * 作者:generator * 参考: * 描述:TmstruckMeasureCommission服务实现 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @Service(value = "tmstruckMeasureCommissionService") public class TmstruckMeasureCommissionServiceImpl implements ITmstruckMeasureCommissionService{ @Autowired private TmstruckMeasureCommissionMapper tmstruckMeasureCommissionMapper; /** * 查询计量委托 0 :计皮 1:计毛 * @param map orderTypee 订单类型 type 是计皮还是计毛 * @return */ @Override public List> getAllMeasureCommission(Map map) { Integer orderType = (Integer) map.get("orderTypee"); switch (orderType){ case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: return tmstruckMeasureCommissionMapper.getMeasureCommission(map); case 9: break; case 10: break; case 11: } return null; } /** * 添加计毛委托 并发送计毛委托 * @param map {orderTypee: 订单类型 * resultTotalId:总实绩ID orderId: 订单ID * 总实绩ID orderNumber:运输订单号} * @return */ public int addMaoMeasureCommission(Map map){ int i = addMeasureCommission(map, 1); // 添加计毛委托 //发送数据给计量系统 必要数据 orderTypee:订单类型 type: 1:计毛 |0:计皮 resultTotalId: 总实绩Id map.put("type", 1); i += sendMeasureCommissionMes(map); return i; } /** * 添加计皮委托 并发送计皮委托 * @param map {orderTypee: 订单类型 resultTotalId:总实绩ID orderId: 订单ID * orderNumber:运输订单号} * @return */ public int addPiMeasureCommission(Map map){ int i = addMeasureCommission(map, 0); // 添加计皮委托 //发送数据给计量系统 必要数据 orderTypee:订单类型 type: 1:计毛 |0:计皮 resultTotalId: 总实绩Id map.put("type", 0); i += sendMeasureCommissionMes(map); return i; } /** * 新增计毛、计皮委托 * @return */ @Override public int addMeasureCommission(Map map, Integer type) { TmstruckMeasureCommission tmstruckMeasureCommission = new TmstruckMeasureCommission(); //生成主键Id tmstruckMeasureCommission.setCommssionId(tmstruckMeasureCommissionMapper.selectMaxId()); //添加物资ID tmstruckMeasureCommission.setMaterialId(DataChange.dataToBigDecimal(map.get("materialId"))); //添加汽车衡Id if(map.get("grossPlaceId") != null){ tmstruckMeasureCommission.setCalculateId(DataChange.dataToBigDecimal(map.get("grossPlaceId"))); } if(map.get("tarePlaceId") != null){ tmstruckMeasureCommission.setCalculateId(DataChange.dataToBigDecimal(map.get("tarePlaceId"))); } //添加实绩总表Id tmstruckMeasureCommission.setResultTotalId(DataChange.dataToBigDecimal(map.get("resultTotalId"))); //添加计量类型 tmstruckMeasureCommission.setCommssionType(new BigDecimal(type)); tmstruckMeasureCommission.setInsertTime(new Date()); tmstruckMeasureCommission.setInsertUsername("admin"); return tmstruckMeasureCommissionMapper.insertSelective(tmstruckMeasureCommission); } /** * 查询计量委托并向计量系统发送数据 调用他们接口 * 1:销售订单;2:焦炭发运计划;3:水渣发运计划;4:内转到异地库;5:采购辅料订单;6:采购老区燃料订单; * 7:采购新区燃料订单;8:采购进口矿(万州-厂内);9:采购内转(达州-厂内);10:采购内转(老区-厂内); 11:厂内内转 * @param map orderTypee 订单类型 type 计皮0还是计毛1类型 orderId 订单ID */ public int sendMeasureCommissionMes(Map map){ Map measureCommission = null; //查询计量委托 BigDecimal orderType = DataChange.dataToBigDecimal(map.get("orderTypee")); Integer type = (Integer) map.get("type"); switch (orderType.intValue()){ case 1: if(type == 0) { // measureCommission = tmstruckMeasureCommissionMapper.selectMakesureTareForSaleByOrderNumber(map); }else { // measureCommission = tmstruckMeasureCommissionMapper.selectMakesureGrossForSaleByOrderNumber(map); } break; case 2: break; case 3: break; case 10: case 11: case 4: if(type == 0) { measureCommission = tmstruckMeasureCommissionMapper.selectMakesureTareForConvertedByOrderNumber(map); }else { measureCommission = tmstruckMeasureCommissionMapper.selectMakesureGrossForConvertedByOrderNumber(map); } break; case 5: case 6: case 7: case 8: case 9: if(type == 0) { measureCommission = tmstruckMeasureCommissionMapper.purchaseMaoMeasure(map); measureCommission.put("isRelationEAS", true); measureCommission.put("flowTo", "出厂"); measureCommission.put("isDel", false); measureCommission.put("isInsert", true); measureCommission.put("IsAssembly", false); measureCommission.put("deliveryMethod", "磅重交货"); measureCommission.put("packagesNum", 0); }else { measureCommission = tmstruckMeasureCommissionMapper.purchaseMaoMeasure(map); measureCommission.put("isRelationEAS", true); measureCommission.put("flowTo", "进厂"); measureCommission.put("isDel", false); measureCommission.put("isInsert", true); measureCommission.put("IsAssembly", false); measureCommission.put("deliveryMethod", "磅重交货"); measureCommission.put("packagesNum", 0); } } /*访问接口发送数据*/ return sendMesToMeasure(measureCommission); } /** * 访问计量接口方法 * @param map * @return */ public int sendMesToMeasure(Map map){ List> sendMap = new ArrayList<>(); sendMap.add(map); JSONObject jsonObject = new JSONObject(); jsonObject.put("data", sendMap); String url = "http://172.16.33.122:44325/api/logistics/TareApplyFor"; String jsonData = null; try { jsonData = HTTPRequestUtils.send(url, jsonObject, "utf-8"); } catch (IOException e) { e.printStackTrace(); } if(!"null".equals(jsonData)){ System.out.println(jsonData); HashMap hashMap = JSON.parseObject(jsonData, HashMap.class); boolean success = (boolean) hashMap.get("success"); System.out.println(hashMap.get("msg")); if(success){ return 1; } } return 0; } }