Commit 43c8d5f5 by 高晓磊

地磅同步,修改购砂单位的逻辑(出现不签合同的大客户的情况)

parent f74dedff
......@@ -249,9 +249,9 @@ ext {
javax_persistence_api: "javax.persistence:javax.persistence-api:2.2",
jboss_javax_transaction_api: "org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:1.1.1.Final",
hibernate_common_annotations: "org.hibernate.common:hibernate-commons-annotations:5.0.4.Final",
net_byte_buddy: "net.bytebuddy:byte-buddy:1.8.15"
net_byte_buddy: "net.bytebuddy:byte-buddy:1.8.15",
thumbnailator: "net.coobird:thumbnailator:0.4.8"
]
}
......@@ -411,6 +411,7 @@ configurations.all {
force lib.hibernate_common_annotations
force lib.jboss_javax_transaction_api
force lib.net_byte_buddy
force lib.thumbnailator
exclude group: "c3p0", module: "c3p0"
exclude group: "dom4j", module: "dom4j"
......
......@@ -3,6 +3,7 @@ package com.xyst.dinas.finance.internal.service;
import java.math.BigDecimal;
import java.util.UUID;
import com.xyst.dinas.project.service.PurchaseSandCompanyService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
......@@ -24,16 +25,30 @@ public class ArtificialRechargeServiceImpl implements ArtificialRechargeService
@Autowired
private WarningService warningService;
@Autowired
private PurchaseSandCompanyService purchaseSandCompanyService;
@Override
@Transactional
public Object adjustContractBalance(JSONObject jsonObject) {
try{
try {
if (!jsonObject.has("contractId")) {
//如果没有选合同,默认将金额带入到购砂单位
UUID purchaseSandId1 = UUID.fromString(jsonObject.getString("purchaseSandId"));
KObject byId = purchaseSandCompanyService.getById(purchaseSandId1);
BigDecimal advanceBalance = byId.getBigDecimal("advanceBalance");
if (advanceBalance == null) {
advanceBalance = BigDecimal.ZERO;
}
BigDecimal rechargeAmount = advanceBalance.add(jsonObject.getBigDecimal("rechargeAmount"));
byId.set("advanceBalance", rechargeAmount);
return ResponseObj.success();
}
UUID contractId = UUID.fromString(jsonObject.getString("contractId"));
KObject contract = contractDao.load(contractId);
if (FundTypeEnum.ADVANCE.name().equals(jsonObject.getString("fundType"))) {
contract.set("advanceBalance", contract.getBigDecimal("advanceBalance") == null ? new BigDecimal("0").add(jsonObject.getBigDecimal("rechargeAmount")) : contract.getBigDecimal("advanceBalance").add(jsonObject.getBigDecimal("rechargeAmount")));
} else if(FundTypeEnum.DEPOSIT.name().equals(jsonObject.getString("fundType"))){
} else if (FundTypeEnum.DEPOSIT.name().equals(jsonObject.getString("fundType"))) {
contract.set("depositBalance", contract.getBigDecimal("depositBalance") == null ? new BigDecimal("0").add(jsonObject.getBigDecimal("rechargeAmount")) : contract.getBigDecimal("depositBalance").add(jsonObject.getBigDecimal("rechargeAmount")));
}
contractDao.update(contract);
......@@ -41,7 +56,7 @@ public class ArtificialRechargeServiceImpl implements ArtificialRechargeService
warn.setWarningCalculate(new StockAmountWarnCalculate(contract.getDouble("advanceBalance")));
warn.warn();
return ResponseObj.success();
} catch(Exception e){
} catch (Exception e) {
return ResponseObj.error();
}
......
package com.xyst.dinas.finance.web;
import org.json.JSONArray;
import com.xyst.dinas.finance.service.ArtificialRechargeService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.xyst.dinas.finance.service.ArtificialRechargeService;
import com.xyst.dinas.finance.service.BankRechargeDetailService;
import com.xyst.dinas.finance.service.ExpenseAdjustService;
import org.springframework.web.bind.annotation.*;
/**
* 人工充值
......
package com.xyst.dinas.project.dao;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
......@@ -13,4 +14,5 @@ public interface PurchaseSandCompanyDao {
void updateEnableStatus(String modelPath, boolean enable, UUID id);
void updateAdvanceBalance(KObject kObjects, BigDecimal advanceBalance);
}
package com.xyst.dinas.project.internal.dao;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
......@@ -55,4 +56,14 @@ public class PurchaseSandCompanyDaoImpl implements PurchaseSandCompanyDao, Purch
});
}
@Override
public void updateAdvanceBalance(KObject kObject, BigDecimal advanceBalance) {
BigDecimal advanceBalance1 = kObject.getBigDecimal("advanceBalance");
if(advanceBalance1==null){
advanceBalance1=BigDecimal.ZERO;
}
kObject.set("advanceBalance",advanceBalance1.subtract(advanceBalance));
template.update(kObject);
}
}
......@@ -29,6 +29,15 @@
<annotation id='0baa0800-831f-4857-b5f6-297ede314d3d' attributeId='ff4de660-27c0-4194-9a90-4e85b0a93d67' name='length' value='100'>
</annotation>
</attribute>
<attribute id='f939574e-9048-4bbe-b6dd-05e71c959bb5' name='plateNumber' columnName='plate_number' title='车牌号' type='string' default='' precision='' isArray='false'>
<annotation id='b20d06ff-608d-43ff-8b60-10d7f3dfefa6' attributeId='fa2260e3-469c-4a8a-be99-5af1c4edc0af' name='length' value='100'>
</annotation>
</attribute>
<attribute id='df8e7c28-f9e0-448b-9b4b-ed6672ad0603' name='advanceBalance' columnName='advance_balance' title='预付款余额' type='fixnum' default='' precision='' isArray='false'>
<annotation id='def63ca3-7912-4d39-bf4a-f8d336ff740e' attributeId='271e8c52-b776-4f8b-855d-09af5ad75040' name='length' value='100'></annotation>
<annotation id='bc4da75a-dcd1-46f4-ae12-4d7d234f1e96' attributeId='e11978e0-9a48-4605-a2d4-0e314e5d4e31' name='precision' value='12'></annotation>
<annotation id='684298d0-aa28-4607-9c1d-63f35ea361c2' attributeId='11df3d8e-9ec1-4bce-8701-e4a5f5a3f721' name='scale' value='2'></annotation>
</attribute>
<attribute id='63bc034a-9a4c-41df-b0a4-b62bd8b05882' name='regionalCompany' columnName='regional_company' title='区域公司' type='com.xyst.dinas.biz.datamodel.xystOrganization' default='' precision='' isArray='false'>
<annotation id='6d9ba751-13b0-47ad-9c0b-f37623ea7e28' attributeId='b215857b-a8b8-4ffc-88c9-c7bb46bed28c' name='length' value='undefined'>
</annotation>
......
......@@ -107,6 +107,30 @@
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations>
<m:annotation>
<m:type>bcp.type.constraint.StringLength</m:type>
<m:value>30</m:value>
</m:annotation>
<m:annotation>
<m:type>javax.persistence.Column</m:type>
<m:properties>
<m:property>
<m:key>name</m:key>
<m:value>plate_number</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>6e1784e7-5dc2-40a9-9cb6-9d2abda2292f</m:id>
<m:name>plateNumber</m:name>
<m:title>车牌号</m:title>
<m:type>string</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations>
<m:annotation>
......@@ -156,6 +180,38 @@
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations>
<m:annotation>
<m:type>bcp.type.constraint.Numeric</m:type>
<m:properties>
<m:property>
<m:key>precision</m:key>
<m:value>12</m:value>
</m:property>
<m:property>
<m:key>scale</m:key>
<m:value>2</m:value>
</m:property>
</m:properties>
</m:annotation>
<m:annotation>
<m:type>javax.persistence.Column</m:type>
<m:properties>
<m:property>
<m:key>name</m:key>
<m:value>advance_balance</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>5ea9c8c3-989d-4534-afd9-ae8cae3dcdb1</m:id>
<m:name>advanceBalance</m:name>
<m:title>预付款余额</m:title>
<m:type>fixnum</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
</m:attributes>
</m:class>
</content>
......
......@@ -148,6 +148,26 @@
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>advanceBalance</m:name>
<m:title>预付款余额</m:title>
<m:type>fixnum</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>plateNumber</m:name>
<m:title>车牌号</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc>车牌号</m:desc>
</m:field>
<m:field>
<m:name>discard</m:name>
<m:title>废弃</m:title>
<m:type>boolean</m:type>
......
......@@ -51,6 +51,17 @@
<property name="contactNumber" type="nstring" not-null="false">
<column name="contact_number" length="100"></column>
</property>
<property name="plateNumber" type="nstring" not-null="false">
<column name="plate_number" length="100">
<comment>车牌号,没有合同的大客户才有这个值</comment>
</column>
</property>
<property name="advanceBalance" type="big_decimal" not-null="false">
<column name="advance_balance" precision="12" scale="4">
<comment>预付款余额,对应没有合同的大客户</comment>
</column>
</property>
<many-to-one name="regionalCompany" entity-name="com.xyst.dinas.biz.datamodel.xystOrganization" fetch="select">
<column name="regional_company" not-null="false"></column>
</many-to-one>
......
......@@ -236,6 +236,7 @@ public class SalesPlanDao {
detachedCriteria.add(Restrictions.eq("purchaseSandUnit.id", purchaseSandUnitId));
detachedCriteria.add(Restrictions.eq("master.planningCycle.id", planningCycleId));
detachedCriteria.add(Restrictions.eq("project.id", projectId));
detachedCriteria.add(Restrictions.eq(BaseConstants.MASTER+"."+SalesPlanConstant.APPROVE_STATE, BizProcessState.DONE_WITH_AGREE.getValue()));
return (List<KObject>) template.findByCriteria(detachedCriteria);
}
......@@ -391,5 +392,27 @@ public class SalesPlanDao {
}
/**
* 根据车牌号获取本周期下的已有的销售计划
* @param carNum
* @param station
* @return
*/
public List<KObject> getSaleByCarNum(String carNum, KObject station) {
KClass bean = Amino.getStaticMetadataContext().getBean(SalesPlanConstant.ENTITY_DETAIL, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
dinasTypeDao.addRegionalCompanyFilter(detachedCriteria);
detachedCriteria.createAlias("master", "master");
detachedCriteria.createAlias(BaseConstants.MASTER+".planningCycle", "planningCycle");
detachedCriteria.createAlias("station", "station");
detachedCriteria.createAlias("contract", "contract");
detachedCriteria.add(Restrictions.le("planningCycle.startTime", new Date()));
detachedCriteria.add(Restrictions.ge("planningCycle.endTime", new Date()));
detachedCriteria.add(Restrictions.eq("station.id", station.getUuid("id")));
detachedCriteria.add(Restrictions.eq(BaseConstants.MASTER+"."+SalesPlanConstant.APPROVE_STATE, BizProcessState.DONE_WITH_AGREE.getValue()));
detachedCriteria.add(Restrictions.like("contract.carInfo", "%"+carNum+"%"));
return (List<KObject>) template.findByCriteria(detachedCriteria);
}
}
......@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.UUID;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
public interface SalesRecordDao {
......@@ -18,4 +19,6 @@ public interface SalesRecordDao {
KObject findCardByPlateNumber(String string, KObject kObject);
void insertList(List<KObject> salesRecordInfos);
void updateActualTransportationById(SalesRecordInfo salesRecordInfo);
}
......@@ -10,7 +10,9 @@ import com.beecode.bcp.serial.Serial;
import com.beecode.bcp.type.KClass;
import com.beecode.inz.common.BaseConstants;
import com.beecode.util.DateUtil;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
......@@ -85,6 +87,7 @@ public class SalesRecordDaoImpl implements SalesRecordDao, SalesRecordConstant {
kObject.set("saleRecord", salesRecord);
kObject.set("transportVehicle", cardInfo);
kObject.set("confirmStatus", 0);
template.save(kObject);
}
@Override
......@@ -109,4 +112,21 @@ public class SalesRecordDaoImpl implements SalesRecordDao, SalesRecordConstant {
return null;
});
}
@Override
public void updateActualTransportationById(SalesRecordInfo salesRecordInfo) {
if(StringUtils.isNotBlank(salesRecordInfo.getTransportTypeId())){
KObject kObject = (KObject)template.get(TRANSPORT_RECORD_ENTITY, UUID.fromString(salesRecordInfo.getTransportTypeId()));
if(kObject!=null&&!kObject.isNull()){
BigDecimal actualTransportation = kObject.getBigDecimal("actualTransportation");
if(actualTransportation==null){
actualTransportation=BigDecimal.ZERO;
}
actualTransportation = actualTransportation.add(BigDecimal.valueOf(salesRecordInfo.getDealAmount()));
kObject.set("actualTransportation",actualTransportation);
template.update(kObject);
}
}
}
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import java.util.stream.Collectors;
import javax.transaction.Transactional;
import com.beecode.inz.basis.util.JsonUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -215,7 +216,7 @@ public class InventoryServiceImpl implements InventoryService {
List<StationDinasTypePriceDetail> price = null;
StationDinasTypeRelation item = null;
if(priceList != null) {
price = priceList.stream().filter(StationDinasTypePriceDetail -> StationDinasTypePriceDetail.getDinasTypeId().equals(dinasType.getUuid("id")) && StationDinasTypePriceDetail.getStationId().equals(station.getUuid("id")) ).collect(Collectors.toList());
price = priceList.stream().filter(stationDinasTypePriceDetail -> stationDinasTypePriceDetail.getDinasTypeId().equals(dinasType.getUuid("id")) && stationDinasTypePriceDetail.getStationId().equals(station.getUuid("id")) ).collect(Collectors.toList());
if(price.size() > 0) {
item = new StationDinasTypeRelation(station.getUuid("id"), dinasType.getUuid("id"), price.get(0).getDinasPrice());
} else {
......@@ -256,14 +257,15 @@ public class InventoryServiceImpl implements InventoryService {
return result;
}
public Double getStockAmountByDinas(UUID stationId,String dinasTypeName) {
@Override
public Double getStockAmountByDinas(UUID stationId, String dinasTypeName) {
return inventoryDao.getStockAmountByDinas(stationId, dinasTypeName);
}
@Override
public List<StationDinasTypeRelation> getItemListByStationId(UUID stationId) {
public List<Map<String, Object>> getItemListByStationId(UUID stationId) {
List<KObject> itemListByStationId = inventoryDao.getItemListByStationId(stationId);
List<StationDinasTypeRelation> result = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
for(KObject item : itemListByStationId) {
if(item.getBigDecimal("price")==null || item.getBigDecimal("price").compareTo(BigDecimal.ZERO)<1){
continue;
......@@ -275,7 +277,11 @@ public class InventoryServiceImpl implements InventoryService {
r.setDinasTypeName(item.get("dinasType").getString("dinasTypeName"));
r.setAmount(item.getBigDecimal("amount"));
r.setPrice(item.getBigDecimal("price"));
result.add(r);
String s = JsonUtil.beanToJson(r);
Map<String, Object> stringObjectMap = JsonUtil.jsonToMap(s, String.class, Object.class);
stringObjectMap.put("saleType",2);
stringObjectMap.put("transportType",2);
result.add(stringObjectMap);
}
return result;
}
......
......@@ -547,7 +547,22 @@ public class SalesPlanServiceImpl implements SalesPlanService {
//根据需用计划中计划周期和合同获取销售计划
ArrayList<Map<String, Object>> maps = new ArrayList<>();
List<KObject> saleTempByCarNum = salesPlanDao.getSaleTempByCarNum(carNum, station);
//没有需用计划却提了销售计划的可能,线下提销售计划
List<KObject> saleDetails = salesPlanDao.getSaleByCarNum(carNum, station);
for (KObject saleDetail : saleDetails) {
KObject sale = saleDetail.get("master");
KObject contract = saleDetail.get("contract");
KObject planningCycle = sale.get("planningCycle");
KObject project = saleDetail.get("project");
KObject purchaseSandUnit = saleDetail.get("purchaseSandUnit");
KObject dinasType = saleDetail.get("dinasType");
KObject inventory = inventoryDao.getItemByStationIdAndDinasTypeId(station.getUuid("id"), dinasType.getUuid("id"));
//车牌号 本次周期 本次周期id 所属项目名称 所属项目编号 所属项目id 砂石类型 本周期需用量 需用计划id 本周期分配总量 销售计划id 本周期已拉取量 生产线A库存 生产线B库存
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
setSalePlanHashMap(contract,carNum, null, planningCycle, project, dinasType,Collections.singletonList(saleDetail), null, inventory, stringObjectHashMap, 1);
maps.add(stringObjectHashMap);
}
for (KObject plan : plans) {
KObject needPlanDetails = plan.get("NeedPlanDetails");
KObject contract = plan.get("contract");
......@@ -562,7 +577,7 @@ public class SalesPlanServiceImpl implements SalesPlanService {
KObject inventory = inventoryDao.getItemByStationIdAndDinasTypeId(station.getUuid("id"), dinasTypeId);
HashMap<String, Object> stringObjectHashMap = new HashMap<>();
//销售计划
setSalePlanHashMap(contract,carNum, plan, planningCycle, project, dinasTypeListByNeedPlanInfo, needPlanDetail, inventory, stringObjectHashMap, 1);
setSalePlanHashMap(contract,carNum, plan, planningCycle, project,dinasType, dinasTypeListByNeedPlanInfo, needPlanDetail, inventory, stringObjectHashMap, 1);
maps.add(stringObjectHashMap);
}
}
......@@ -571,7 +586,7 @@ public class SalesPlanServiceImpl implements SalesPlanService {
//车牌号 本次周期 本次周期id 所属项目名称 所属项目编号 所属项目id 砂石类型 本周期需用量 需用计划id 本周期分配总量 销售计划id 本周期已拉取量
for (KObject salePlanTemp : saleTempByCarNum) {
Map<String, Object> stringObjectHashMap = new HashMap<>();
KObject project = salePlanTemp.get("project");
KObject planningCycle = salePlanTemp.get("planningCycle");
KObject salesPlanTempDetails = salePlanTemp.get("SalesPlanTempDetails");
......@@ -579,6 +594,7 @@ public class SalesPlanServiceImpl implements SalesPlanService {
KObject contract = salePlanTemp.get("contract");
for (KObject saleTempDetail : saleTempDetails) {
Map<String, Object> stringObjectHashMap = new HashMap<>();
KObject dinasType = saleTempDetail.get("dinasType");
KObject inventory = inventoryDao.getItemByStationIdAndDinasTypeId(station.getUuid("id"), dinasType.getUuid("id"));
setSalePlanTempHashMap(contract,carNum, planningCycle, project, stringObjectHashMap, dinasType, saleTempDetail, inventory, 0);
......@@ -589,6 +605,7 @@ public class SalesPlanServiceImpl implements SalesPlanService {
return maps;
}
private void setSalePlanTempHashMap(KObject contract,String carNum, KObject planningCycle, KObject project, Map<String, Object> stringObjectHashMap, KObject dinasType, KObject saleTempDetail, KObject inventory, int saleType) {
//车牌号
stringObjectHashMap.put("carNum", carNum);
......@@ -602,6 +619,12 @@ public class SalesPlanServiceImpl implements SalesPlanService {
stringObjectHashMap.put("projectCode", project.getString("projectNum"));
//项目id
stringObjectHashMap.put("projectId", project.getUuid("id"));
//收货方名称
stringObjectHashMap.put("consignee", contract.get("purchaseSandUnit").getString("name"));
//供货方名称
stringObjectHashMap.put("supplier", saleTempDetail.get("master").get("station").getString("stationName"));
//地址
stringObjectHashMap.put("shippingAddress", contract.getString("addrReceive"));
//合同id
stringObjectHashMap.put("contractId", contract.getUuid("id"));
//砂石类型名称
......@@ -638,20 +661,33 @@ public class SalesPlanServiceImpl implements SalesPlanService {
stringObjectHashMap.put("canSaleTitle","砂石价格未维护,请联系场站人员维护");
}else{
stringObjectHashMap.put("canSale",true);
}
//销售类型
stringObjectHashMap.put("saleType", saleType);
//运输类型
stringObjectHashMap.put("transportType", 0);
stringObjectHashMap.put("canSale",true);
}
private void setSalePlanHashMap(KObject contract, String carNum, KObject plan, KObject planningCycle, KObject project, List<KObject> dinasTypeListByNeedPlanInfo, KObject needPlanDetail, KObject inventory, final HashMap<String, Object> stringObjectHashMap, Integer saleType) {
KObject dinasType = needPlanDetail.get("dinasType");
private void setSalePlanHashMap(KObject contract, String carNum, KObject plan, KObject planningCycle, KObject project, KObject dinasType, List<KObject> dinasTypeListByNeedPlanInfo, KObject needPlanDetail, KObject inventory, final HashMap<String, Object> stringObjectHashMap, Integer saleType) {
UUID dinasTypeId = dinasType.getUuid("id");
if(needPlanDetail!=null && !needPlanDetail.isNull()&& !needPlanDetail.isEmpty()){
//需用计划砂石id
stringObjectHashMap.put("needPlanDetailId", needPlanDetail.getUuid("id"));
//本周期已拉取量
stringObjectHashMap.put("effectiveSale", needPlanDetail.getBigDecimal("effectiveSale"));
//本周期需用量
BigDecimal needPlanAmount = needPlanDetail.getBigDecimal("needPlanAmount");
stringObjectHashMap.put("needPlanAmount", needPlanAmount);
}else{
//需用计划砂石id
stringObjectHashMap.put("needPlanDetailId", null);
//本周期已拉取量
stringObjectHashMap.put("effectiveSale", null);
//本周期需用量
stringObjectHashMap.put("needPlanAmount", null);
}
//车牌号
stringObjectHashMap.put("carNum", carNum);
//计划周期
......@@ -666,18 +702,19 @@ public class SalesPlanServiceImpl implements SalesPlanService {
stringObjectHashMap.put("projectId", project.getUuid("id"));
//合同id
stringObjectHashMap.put("contractId", contract.getUuid("id"));
//收货方地址
stringObjectHashMap.put("shippingAddress", contract.getString("addrReceive"));
//砂石类型名称
stringObjectHashMap.put("dinasTypeName", dinasType.getString("dinasTypeName"));
//砂石类型id
stringObjectHashMap.put("dinasTypeId", dinasTypeId);
//本次需用量
stringObjectHashMap.put("needPlanAmount", needPlanAmount);
if(plan!=null && !plan.isNull()&& !plan.isEmpty()){
//需用计划id
stringObjectHashMap.put("needPlanId", plan.getUuid("id"));
//需用计划砂石id
stringObjectHashMap.put("needPlanDetailId", needPlanDetail.getUuid("id"));
//本周期已拉取量
stringObjectHashMap.put("effectiveSale", needPlanDetail.getBigDecimal("effectiveSale"));
}else{
stringObjectHashMap.put("needPlanId", null);
}
//本周期分配量
dinasTypeListByNeedPlanInfo.stream().filter(
a -> a.get("dinasType").getUuid("id").toString().equals(dinasTypeId.toString()))
......@@ -687,7 +724,25 @@ public class SalesPlanServiceImpl implements SalesPlanService {
stringObjectHashMap.put("planAmount", planAmount);
stringObjectHashMap.put("salePlanId", uuid);
stringObjectHashMap.put("salePlanDetailId", a.getUuid("id"));
//收货方名称
stringObjectHashMap.put("consignee", a.get("purchaseSandUnit").getString("name"));
//供货方名称
stringObjectHashMap.put("supplier", a.get("station").getString("stationName"));
});
//库存id
UUID id = inventory.getUuid("id");
stringObjectHashMap.put("inventoryId", id);
//库存量(吨)
BigDecimal price = inventory.getBigDecimal("price");
//单价
stringObjectHashMap.put("price", price);
//销售类型
stringObjectHashMap.put("saleType", saleType);
stringObjectHashMap.put("transportType", 0);
//获取砂石今日库存
if(!stringObjectHashMap.containsKey("planAmount")){
stringObjectHashMap.put("canSale",false);
......@@ -695,12 +750,6 @@ public class SalesPlanServiceImpl implements SalesPlanService {
}else {
stringObjectHashMap.put("canSale",true);
}
//库存id
UUID id = inventory.getUuid("id");
stringObjectHashMap.put("inventoryId", id);
//库存量(吨)
BigDecimal price = inventory.getBigDecimal("price");
BigDecimal amount = inventory.getBigDecimal("amount");
stringObjectHashMap.put("inventoryAmount", amount);
if(amount.compareTo(BigDecimal.ZERO)<1){
......@@ -712,11 +761,7 @@ public class SalesPlanServiceImpl implements SalesPlanService {
}else{
stringObjectHashMap.put("canSale",true);
}
//单价
stringObjectHashMap.put("price", price);
//销售类型
stringObjectHashMap.put("saleType", saleType);
stringObjectHashMap.put("transportType", 0);
}
......
......@@ -2,7 +2,11 @@ package com.xyst.dinas.sales.internal.service;
import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.biz.dao.*;
import com.beecode.inz.basis.util.JsonUtil;
import com.xyst.dinas.biz.dao.DinasOrganizationDao;
import com.xyst.dinas.biz.dao.DinasTypeDao;
import com.xyst.dinas.biz.dao.ProductionLineDao;
import com.xyst.dinas.biz.dao.StationDao;
import com.xyst.dinas.biz.service.PlanningCycleService;
import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.contract.internal.dao.ContractDao;
......@@ -17,7 +21,6 @@ import com.xyst.dinas.sales.dao.SalesRecordDao;
import com.xyst.dinas.sales.service.InventoryService;
import com.xyst.dinas.sales.service.SalesRecordService;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
import com.xyst.dinas.sales.web.info.SyncException;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
......@@ -33,7 +36,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.transaction.Transactional;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
@Transactional
......@@ -50,7 +52,7 @@ public class SalesRecordServiceImpl implements SalesRecordService {
@Autowired
StationDao stationDao;
@Autowired
ProductionLineDao ProductionLineDao;
ProductionLineDao productionLineDao;
@Autowired
RetailInfoService retailInfoService;
@Autowired
......@@ -68,20 +70,20 @@ public class SalesRecordServiceImpl implements SalesRecordService {
@Autowired
NeedPlanServiceImpl needPlanServiceImpl;
@Autowired
ProductionLineDao productionLineDao;
@Autowired
@Qualifier(SalesRecordConstant.ENTITY)
private KClass salesRecordClass;
@Transactional
@Override
public String saveSalesRecordService(SalesRecordInfo salesRecordInfo, KObject station) {
public HashMap<String, Object> saveSalesRecordService(SalesRecordInfo salesRecordInfo, KObject station) {
logger.info("开始同步地磅记录,传输参数为:"+ JsonUtil.beanToJson(salesRecordInfo));
HashMap<String, Object> returnMap = new HashMap<>(12);
try {
Date thentime = new Date();
// 获取砂石类型
KObject dinasType = null;
KObject dinasType;
dinasType = dinasTypeDao.load(UUID.fromString(salesRecordInfo.getDinasTypeId()));
KObject regionalCompany = null;
KObject regionalCompany;
//获取区域公司
regionalCompany = station.get("regionalCompany");
......@@ -97,10 +99,16 @@ public class SalesRecordServiceImpl implements SalesRecordService {
salesRecord.set(SalesRecordConstant.GROSS_WEIGHT_PERSON, salesRecordInfo.getGrossWeightPerson());
salesRecord.set(SalesRecordConstant.TARE_WEIGHT_PERSON, salesRecordInfo.getTareWeightPerson());
salesRecord.set(SalesRecordConstant.SYNCTIME, thentime);
salesRecord.set(SalesRecordConstant.DEALTIME, salesRecordInfo.getGrossWeightTime());
salesRecord.set(SalesRecordConstant.DEALBILLCODE, salesRecordInfo.getDealBillCode());
salesRecord.set(SalesRecordConstant.CARINFO, salesRecordInfo.getCarNum());
salesRecord.set(SalesRecordConstant.PRICE, salesRecordInfo.getPrice());
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE, salesRecordInfo.getPaymentSource());
Integer paymentSource = salesRecordInfo.getPaymentSource();
if(paymentSource==0){
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE,PayMentSourceEnum.Advance );
}else{
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE,PayMentSourceEnum.Cash );
}
salesRecord.set(SalesRecordConstant.TRANSPORT_TYPE, salesRecordInfo.getTransportType());
Integer saleType = salesRecordInfo.getSaleType();
salesRecord.set(SalesRecordConstant.SALE_TYPE, saleType);
......@@ -110,12 +118,33 @@ public class SalesRecordServiceImpl implements SalesRecordService {
salesRecord.set(SalesRecordConstant.DEALAMOUNT, salesRecordInfo.getDealAmount());
//如果是散客则全部新增
if (2 == saleType) {
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE,CustomerTypeEnum.RetailInfo.name());
if (2 == saleType || 3 == saleType) {
if (3 == saleType) {
//获取购砂单位名称
List<KObject> kObjects = purchaseSandCompanyDao.queryPurchaseSandCompanyByName(salesRecordInfo.getRetailName(), station.get("regionalCompany").getUuid("id"));
if (kObjects == null || kObjects.isEmpty()) {
returnMap.put("code", 10034);
returnMap.put("message", "没有找到对应的收货方,请联系管理员维护");
return returnMap;
}
if(paymentSource==0) {
KObject kObject = kObjects.get(0);
//获取购砂单位的余额
BigDecimal advanceBalance = kObject.getBigDecimal("advanceBalance");
if (advanceBalance == null || advanceBalance.compareTo(salesRecord.getBigDecimal(SalesRecordConstant.DEALAMOUNT)) < 1) {
returnMap.put("code", 10035);
returnMap.put("message", "余额不足:" + advanceBalance);
return returnMap;
}
//修改购砂单位的余额,
purchaseSandCompanyDao.updateAdvanceBalance(kObject, salesRecord.getBigDecimal(SalesRecordConstant.DEALAMOUNT));
}
}
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE, CustomerTypeEnum.RetailInfo.name());
retailInfoService.create(station, dinasType, salesRecordInfo.getCarNum(), salesRecordInfo.getRetailName(), salesRecordInfo.getCarNum(), salesRecordInfo.getDealAmount(), salesRecordInfo.getAmount());
} else {
//如果不为2则必定有合同 项目 购砂单位 区域公司
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE,CustomerTypeEnum.PurchaseSandCompany.name());
//如果不为2和3则必定有合同 项目 购砂单位 区域公司
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE, CustomerTypeEnum.PurchaseSandCompany.name());
// 获取项目KObject
KObject project;
KObject contract;
......@@ -133,36 +162,46 @@ public class SalesRecordServiceImpl implements SalesRecordService {
salesRecord.set(SalesRecordConstant.REGIONALCOMPANY, regionalCompany);
salesRecord.set(SalesRecordConstant.CONTRACT, contract);
salesRecord.set(SalesRecordConstant.PURCHASESANDCOMPANY, purchaseSandCompany);
salesRecord.set(SalesRecordConstant.DEALAMOUNT,salesRecordInfo.getDealAmount() == null ? BigDecimal.ZERO: BigDecimal.valueOf(salesRecordInfo.getDealAmount()));
salesRecord.set(SalesRecordConstant.DEALAMOUNT, salesRecordInfo.getDealAmount() == null ? BigDecimal.ZERO : BigDecimal.valueOf(salesRecordInfo.getDealAmount()));
salesRecord.set(SalesRecordConstant.DISCARD, false);
salesRecord.set(SalesRecordConstant.DEL, false);
BigDecimal dealAmount = BigDecimal.ZERO.subtract(BigDecimal.valueOf(salesRecord.getDouble(SalesRecordConstant.DEALAMOUNT)));
BigDecimal amount;
if (Integer.valueOf(0).equals(salesRecordInfo.getPaymentSource())) {
if (Integer.valueOf(0).equals(paymentSource)) {
amount = BigDecimal.ZERO.subtract(BigDecimal.valueOf(salesRecord.getDouble(SalesRecordConstant.AMOUNT)));
} else {
amount = BigDecimal.ZERO;
}
if(paymentSource==0) {
//查询合同余额,如果扣减后小于0则不允许交易
KObject kObject = contractService.queryContract(UUID.fromString(salesRecordInfo.getContractId()));
BigDecimal advanceBalance = kObject.getBigDecimal("advanceBalance");
if (advanceBalance == null || advanceBalance.compareTo(salesRecord.getBigDecimal(SalesRecordConstant.DEALAMOUNT)) < 1) {
returnMap.put("code", 10035);
returnMap.put("message", "余额不足:" + advanceBalance);
return returnMap;
}
// 更新合同子表合同砂石余量(吨)-更新合同表付款余额、销售总量信息
contractService.modifyInventory(UUID.fromString(salesRecordInfo.getContractId()),
UUID.fromString(salesRecordInfo.getDinasTypeId()), dealAmount, amount);
}
//根据销售类型判断修改需用计划还是临时销售计划
//
if(saleType==0){
if (saleType == 0) {
//为0时是临时销售计划,salePlanId存储的值也是临时销售计划的值
String salePlanTempId = salesRecordInfo.getSalePlanId();
salesPlanDao.updateSalesPlanTempAmount(salePlanTempId,dealAmount);
}else if(saleType==1) {
salesPlanDao.updateSalesPlanTempAmount(salePlanTempId, dealAmount);
} else if (saleType == 1) {
// 为1时是需用计划和销售计划
KObject salesPlan = salesPlanDao.load(UUID.fromString(salesRecordInfo.getSalePlanId()));
BigDecimal actualSaleTotalAmount = salesPlan.getBigDecimal("actualSaleTotalAmount") == null ? BigDecimal.ZERO: (salesPlan.getBigDecimal("actualSaleTotalAmount"));
if(salesPlan!=null){
BigDecimal actualSaleTotalAmount = salesPlan.getBigDecimal("actualSaleTotalAmount") == null ? BigDecimal.ZERO : (salesPlan.getBigDecimal("actualSaleTotalAmount"));
salesPlan.set("actualSaleTotalAmount", actualSaleTotalAmount.subtract(dealAmount));
salesPlanDao.update(salesPlan);
salesPlanDao.updateSalesPlanDetailAmount(salesRecordInfo.getSalePlanDetailId(),salesRecordInfo.getDealAmount());
salesPlanDao.updateSalesPlanDetailAmount(salesRecordInfo.getSalePlanDetailId(), salesRecordInfo.getDealAmount());
}
if (StringUtils.isNotBlank(salesRecordInfo.getNeedPlanDetailId())) {
KObject needPlanDetail = needPlanDao.queryDetailById(UUID.fromString(salesRecordInfo.getNeedPlanDetailId()));
if (needPlanDetail != null) {
BigDecimal effectiveSale = needPlanDetail.getBigDecimal("effectiveSale") == null ? BigDecimal.ZERO : needPlanDetail.getBigDecimal("effectiveSale");
......@@ -171,6 +210,7 @@ public class SalesRecordServiceImpl implements SalesRecordService {
}
}
}
}
// 此处为Jason格式,多重嵌套
// 更新库存量
{
......@@ -193,21 +233,30 @@ public class SalesRecordServiceImpl implements SalesRecordService {
}
UUID salesRecordId = salesRecordDao.insert(salesRecord);
if(salesRecordInfo.getTransportType()==1){
if (salesRecordInfo.getTransportType() == 1) {
//修改运输单的值
// updateTransport();
updateTransport(salesRecordInfo);
//将地磅记录同时保存到运输记录
saveAstTransportRecord(salesRecord);
}
return salesRecordId.toString();
returnMap.put("code", 200);
returnMap.put("id", salesRecordId.toString());
returnMap.put("message", "新增成功");
return returnMap;
} catch (Exception e) {
e.printStackTrace();
throw new SyncException("销售台账信息存储报出错:" + e.getMessage());
returnMap.put("code", 10031);
returnMap.put("message", "系统内部错误");
return returnMap;
}
}
private void updateTransport(SalesRecordInfo salesRecordInfo){
salesRecordDao.updateActualTransportationById(salesRecordInfo);
}
private void saveAstTransportRecord(KObject salesRecord) {
String salesRecordCard = salesRecord.getString(SalesRecordConstant.CARINFO);
if (StringUtils.isEmpty(salesRecordCard)) {
......@@ -223,49 +272,6 @@ public class SalesRecordServiceImpl implements SalesRecordService {
salesRecordDao.saveAstTransportRecord(salesRecord, kObject);
}
private String dataExistenceCheck(String name, String value) {
String result = null;
if (null != value && !"".equals(value)) {
result = value;
} else {
throw new SyncException("[" + name + "]信息为空!请确认");
}
return result;
}
private KObject entityExistenceCheck(String name, KObject daoValue, boolean flag) {
KObject result = null;
if (null != daoValue) {
result = daoValue;
} else {
if (flag) {
throw new SyncException("[" + name + "]信息为空!请确认");
} else {
logger.info("[" + name + "]信息为空!请确认!!");
result = null;
}
}
return result;
}
private Date generateDate(String name, String pattern, String value) {
return generateDate(name, pattern, value, true);
}
private Date generateDate(String name, String pattern, String value, Boolean notNull) {
if ((null == value || value.length() <= 0) && notNull) {
throw new SyncException(name + "不能为空");
}
SimpleDateFormat format = new SimpleDateFormat(pattern);
Date result = null;
try {
result = format.parse(value);
} catch (Exception e) {
throw new SyncException(name + "[" + value + "]不是要求的[" + pattern + "]格式,转换失败");
}
return result;
}
@Override
public HashMap<String, Object> qualityReportExcelImport(MultipartFile file) {
......@@ -331,9 +337,9 @@ public class SalesRecordServiceImpl implements SalesRecordService {
List<KObject> saleRecord = new ArrayList<>();
KObject organization = null;
KObject station = null;
KObject station;
KObject productionLine = null;
KObject dinasType = null;
KObject dinasType;
KObject retailInfo = null;
//添加数据
for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
......@@ -404,7 +410,7 @@ public class SalesRecordServiceImpl implements SalesRecordService {
//散户名称
String retailName = row.getCell(6).getStringCellValue().trim();
Optional<KObject> retailInfoName1 = retailInfos.stream().filter(a -> a.getString("retailInfoName").equals(retailName)).findFirst();
// Optional<KObject> retailInfoName1 = retailInfos.stream().filter(a -> a.getString("retailInfoName").equals(retailName)).findFirst();
// if (!retailInfoName1.isPresent()) {
// List<KObject> retailInfoName = retailInfoService.getByName(retailName, null);
// if (retailInfoName != null && retailInfoName.size() > 0) {
......@@ -552,8 +558,4 @@ public class SalesRecordServiceImpl implements SalesRecordService {
return false;
}
}
private UUID getUUid() {
return UUID.randomUUID();
}
}
package com.xyst.dinas.sales.service;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.beecode.bcp.type.KObject;
......@@ -14,7 +15,7 @@ public interface InventoryService {
public ResponseObj<String> modifyInventory(String body, boolean isLog, boolean autoCalculate);
public List<InventoryLog> queryLog(UUID regionalCompany);
List<StationDinasTypeRelation> getItemListByStationId(UUID stationId);
List<Map<String, Object>> getItemListByStationId(UUID stationId);
Object queryWarnSettingById(UUID id);
......
......@@ -9,7 +9,6 @@ import org.json.JSONObject;
import org.springframework.lang.Nullable;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.sales.entity.SalesPlanDetail;
import com.xyst.dinas.sales.web.request.SaleaPlanDetailQuery;
public interface SalesPlanService {
......@@ -90,4 +89,5 @@ public interface SalesPlanService {
List<KObject> getSealTempDinasTypeListByNeedPlanInfo(UUID purchaseSandUnitId, UUID planningCycleId, UUID projectId);
List<Map<String, Object>> querySalesPlanByCarNum(KObject station, String carNum);
}
package com.xyst.dinas.sales.service;
import java.util.HashMap;
import java.util.List;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
......@@ -16,7 +15,7 @@ public interface SalesRecordService {
* @param station
* @return
*/
String saveSalesRecordService(SalesRecordInfo salesRecordList, KObject station);
HashMap<String, Object> saveSalesRecordService(SalesRecordInfo salesRecordList, KObject station);
HashMap<String,Object> qualityReportExcelImport(MultipartFile file);
}
......@@ -127,6 +127,14 @@ public class SalesRecordInfo {
* 销售单号
*/
private String dealBillCode;
/**
* 运输单id
*/
private String transportTypeId;
/**
* 收货方,作为没有合同的购砂单位使用
*/
private String consignee;
/**
* 配送方式 0自提(运输公司自己拿) 1配送(砂石公司指派车辆) 2散客(没有车牌号,不知何处来. 不知何处去)
......@@ -138,6 +146,21 @@ public class SalesRecordInfo {
*/
private Integer saleType;
public String getTransportTypeId() {
return transportTypeId;
}
public void setTransportTypeId(String transportTypeId) {
this.transportTypeId = transportTypeId;
}
public String getConsignee() {
return consignee;
}
public void setConsignee(String consignee) {
this.consignee = consignee;
}
public String getProjectId() {
return projectId;
......
......@@ -6,6 +6,7 @@ dependencies {
compile lib.spring_web
compile lib.spring_boot_autoconfigure
compile lib.jackson_datatype_jdk8
compile lib.thumbnailator
compile lib.jackson_datatype_jsr310
compile lib.json
compile "com.beecode:bap2.participant:${aminoVersion}"
......
......@@ -89,7 +89,6 @@ public class VehicleDispatchServiceImpl implements VehicleDispatchService {
kobject.set(VehicleDispatchConstant.STATION, load.get(VehicleDispatchConstant.STATION));
kobject.set(VehicleDispatchConstant.PLAN_AMOUNT, load.getBigDecimal(VehicleDispatchConstant.PLAN_AMOUNT));
} else {
load = vehicleDispatchDao.load(SalesPlanConstant.ENTITY_TEMP_DETAIL, sealDetailId);
planningCycle = load.get(BaseConstants.MASTER).get(VehicleDispatchConstant.PLANNING_CYCLE);
kobject.set(VehicleDispatchConstant.PURCHASE_SAND_UNIT, load.get(BaseConstants.MASTER).get(VehicleDispatchConstant.CONTRACT).get(VehicleDispatchConstant.PURCHASE_SAND_UNIT));
......@@ -188,6 +187,8 @@ public class VehicleDispatchServiceImpl implements VehicleDispatchService {
Map<String, Object> stringObjectHashMap = new HashMap<String, Object>();
//车牌号
stringObjectHashMap.put("carNum", carNum);
//车牌号
stringObjectHashMap.put("transportTypeId", dispatch.getUuid("id"));
//计划周期
stringObjectHashMap.put("planningCycleTitle", planningCycle.getString("title"));
//计划id
......@@ -200,6 +201,12 @@ public class VehicleDispatchServiceImpl implements VehicleDispatchService {
stringObjectHashMap.put("projectId", project.getUuid("id"));
//合同id
stringObjectHashMap.put("contractId", contract.getUuid("id"));
//收货方名称
stringObjectHashMap.put("consignee", contract.get("purchaseSandUnit").getString("name"));
//供货方名称
stringObjectHashMap.put("supplier", station.getString("stationName"));
//地址
stringObjectHashMap.put("shippingAddress", contract.getString("addrReceive"));
//砂石类型名称
stringObjectHashMap.put("dinasTypeName", dinasType.getString("dinasTypeName"));
//砂石类型id
......
......@@ -15,19 +15,14 @@ import com.xyst.dinas.sales.service.SalesRecordService;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
import com.xyst.dinas.transport.service.VehicleDispatchService;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.math.BigDecimal;
import java.util.*;
@RestController
......@@ -60,7 +55,7 @@ public class WeighbridgeSyncController {
* @param salesRecordList 销售台账队列
* @return
*/
@PostMapping(value = "/weighbridgeSync/saveSalesRecord", consumes = "application/json")
@PostMapping(value = "/weighbridgeSync/saveSalesRecord")
public Object saveSalesRecord(@RequestParam String weighbridgeCode, @RequestBody SalesRecordInfo salesRecordList) {
//根据地磅id查询场站
if (StringUtils.isBlank(weighbridgeCode)) {
......@@ -73,7 +68,8 @@ public class WeighbridgeSyncController {
if (salesRecordList == null) {
return ResponseObj.error("传递的销售台账数据条数为0!请确认!");
} else {
return ResponseObj.success("新增成功", salesRecordService.saveSalesRecordService(salesRecordList, station));
HashMap<String, Object> stringObjectHashMap = salesRecordService.saveSalesRecordService(salesRecordList, station);
return ResponseObj.response((Integer) stringObjectHashMap.get("code"),stringObjectHashMap.get("message").toString(),stringObjectHashMap.get("id"));
}
}
......@@ -85,9 +81,8 @@ public class WeighbridgeSyncController {
* @return
*/
@PostMapping("/weighbridgeSync/getSalePlanDetail")
public Object approveSalesPlan(@RequestParam String weighbridgeCode, @RequestParam String carNum) {
public Object approveSalesPlan(@RequestParam String weighbridgeCode, @RequestParam(value = "carNum",required = false) String carNum) {
//根据地磅id查询场站
if (StringUtils.isBlank(weighbridgeCode)) {
return ResponseObj.error(500, "地磅唯一编码不能为空");
}
......@@ -95,58 +90,53 @@ public class WeighbridgeSyncController {
if (station == null) {
return ResponseObj.error(500, "没有查询到地磅匹配的场站");
}
if (StringUtils.isBlank(carNum)) {
return ResponseObj.error(500, "车牌号不能为空");
}
HashMap<String, Object> returnMap = new HashMap<>(4);
returnMap.put("code",200);
returnMap.put("message","查询成功");
if(StringUtils.isNotBlank(carNum)){
//根据车牌查询所属合同和销售计划
List<Map<String, Object>> salesPlan = salesPlanService.querySalesPlanByCarNum(station, carNum);
Collection<? extends Map<String, Object>> maps = vehicleDispatchService.vehicleDispatchService(station, carNum);
if (maps != null) {
salesPlan.addAll(maps);
}
return ResponseObj.success("查询成功", salesPlan);
if(salesPlan == null || salesPlan.isEmpty()){
return getDinasReturn(station, returnMap);
}else{
returnMap.put("saleType",1);
returnMap.put("data",salesPlan);
return returnMap;
}
}else{
return getDinasReturn(station, returnMap);
}
}
/**
* 根据车牌号和地磅唯一编码获取本场站下本车辆今日销售计划和临时销售计划
*
* @param
* @return
*/
@PostMapping("/weighbridgeSync/uploadFile")
public Object getDinasTypePrice(@RequestParam String weighbridgeCode,
@RequestParam String recordId,
@RequestParam("files")
MultipartFile[] file) {
if (null == file || file.length < 1) {
return ResponseObj.error(500, "文件不能为空");
@RequestMapping(value = "weighbridgeSync/uploadFile", method = RequestMethod.POST)
public ResponseObj<UUID> upload(@RequestParam(name = "belongId", required = false) String belongId,
@RequestParam("files") MultipartFile[] files,
@RequestHeader(name = HttpHeaders.USER_AGENT, required = false) String userAgent,
@RequestParam (name = "weighbridgeCode") String weighbridgeCode ) {
if (null == files || files.length < 1) {
return ResponseObj.response(500, "文件不能为空",null);
}
//根据地磅id查询场站
if (StringUtils.isBlank(weighbridgeCode)) {
return ResponseObj.error(500, "地磅唯一编码不能为空");
return ResponseObj.response(500, "地磅唯一编码不能为空",null);
}
KObject station = stationService.getStationByWeighbridge(weighbridgeCode);
if (station == null) {
return ResponseObj.error(500, "没有查询到地磅匹配的场站");
return ResponseObj.response(500, "没有查询到地磅匹配的场站",null);
}
//根据查询地磅id
if (StringUtils.isBlank(recordId)) {
return ResponseObj.error(500, "地磅记录不能为空");
}
KObject itemByStationIdAndDinasTypeId = inventoryService.getItemByStationIdAndDinasTypeId(station.getUuid("id"), UUID.fromString("dinasTypeId"));
BigDecimal price = itemByStationIdAndDinasTypeId.getBigDecimal("price");
return ResponseObj.success("查询成功", price);
if (StringUtils.isBlank(belongId)) {
return ResponseObj.response(500, "地磅记录不能为空",null);
}
@RequestMapping(value = "files", method = RequestMethod.POST)
public ResponseObj<UUID> upload(@RequestParam(name = "belongId", required = false) UUID belongId,
@RequestParam("files") MultipartFile[] files,
@RequestHeader(name = HttpHeaders.USER_AGENT, required = false) String userAgent) {
if (belongId == null) {
belongId = UUID.randomUUID();
}
checkFileUpload(files);
try {
for (MultipartFile file : files) {
......@@ -156,7 +146,7 @@ public class WeighbridgeSyncController {
.toFile(file1);
FileInputStream
fileInputStream = new FileInputStream(file1);
AttachmentInfo info = generateInfo(belongId, "saleRecord", true, userAgent, file.getOriginalFilename(), file1.length());
AttachmentInfo info = generateInfo(UUID.fromString(belongId), file.getOriginalFilename(), file1.length());
return ResponseObj.response(200,"保存成功", attachmentService.insert(info, fileInputStream));
}
} catch (IOException e) {
......@@ -166,111 +156,49 @@ public class WeighbridgeSyncController {
}
/**
* FileItem类对象创建
* 查询全部售卖的砂石类型和价格
*
* @param inputStream inputStream
* @param fileName fileName
* @return FileItem
* @param
* @return
*/
private FileItem createFileItem(InputStream inputStream, String fileName) {
FileItemFactory factory = new DiskFileItemFactory(16, null);
String textFieldName = "file";
FileItem item = factory.createItem(textFieldName, MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
//使用输出流输出输入流的字节
try (OutputStream os = item.getOutputStream()) {
while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
inputStream.close();
} catch (IOException e) {
throw new IllegalArgumentException("文件上传失败");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException ignored) {
}
}
}
return item;
@PostMapping("/weighbridgeSync/getAllDinasType")
public Object getAllDinasType(@RequestParam String weighbridgeCode) {
//根据地磅id查询场站
if (StringUtils.isBlank(weighbridgeCode)) {
return ResponseObj.error(500, "地磅唯一编码不能为空");
}
public static File byte2File(byte[] buf, String filePath, String fileName) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File dir = new File(filePath);
if (!dir.exists() && dir.isDirectory()) {
dir.mkdirs();
KObject station = stationService.getStationByWeighbridge(weighbridgeCode);
if (station == null) {
return ResponseObj.error(500, "没有查询到地磅匹配的场站");
}
file = new File(filePath + File.separator + fileName);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(buf);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
HashMap<String, Object> returnMap = new HashMap<>(3);
returnMap.put("code",200);
returnMap.put("message","查询成功");
return getDinasReturn(station, returnMap);
}
}
return file;
}
// outputStream转inputStream
public ByteArrayInputStream parse(OutputStream out) throws Exception {
ByteArrayOutputStream baos;
baos = (ByteArrayOutputStream) out;
return new ByteArrayInputStream(baos.toByteArray());
private Object getDinasReturn(KObject station, HashMap<String, Object> returnMap) {
List<Map<String,Object>> allDinasTypes = inventoryService.getItemListByStationId(station.getUuid("id"));
if(allDinasTypes==null || allDinasTypes.isEmpty()){
returnMap.put("code",10032);
returnMap.put("message","没有场站的砂石数据,请联系管理员维护");
returnMap.put("data",null);
}
private String getFileNameByIE(String fileName) {
String[] fileNameArray = fileName.split("\\\\");
return fileNameArray[fileNameArray.length - 1];
returnMap.put("saleType",2);
returnMap.put("data",allDinasTypes);
return returnMap;
}
private boolean isIE(String userAgent) {
if (userAgent != null) {
userAgent = userAgent.toLowerCase();
return userAgent.contains("msie") || userAgent.contains("trident") || userAgent.contains("edge");
}
return false;
}
private AttachmentInfo generateInfo(UUID belongId, String category, boolean anonymous, String userAgent, String fileName, Long fileSize) {
private AttachmentInfo generateInfo(UUID belongId, String fileName, Long fileSize) {
AttachmentInfo attachmentInfo = new AttachmentInfo();
attachmentInfo.setBelongId(belongId);
if (category != null && !"".equals(category)) {
attachmentInfo.setCategory(category);
}
if (anonymous) {
attachmentInfo.setCategory("saleRecord");
attachmentInfo.setFileName(UUID.randomUUID() + "." + Utils.getFileType(Objects.requireNonNull(fileName)));
} else if (isIE(userAgent)) {// macOS系统存在含‘\’文件名的文件所以分开写
attachmentInfo.setFileName(getFileNameByIE(Objects.requireNonNull(fileName)));
} else {
attachmentInfo.setFileName(fileName);
}
// macOS系统存在含‘\’文件名的文件所以分开写
attachmentInfo.setFileType(Utils.getFileType(Objects.requireNonNull(fileName)));
attachmentInfo.setSize(fileSize);
return attachmentInfo;
......@@ -284,31 +212,10 @@ public class WeighbridgeSyncController {
}
private void checkFileUpload(MultipartFile file) {
Assert.isTrue(!AttachmentConstants.FileCheck.NOTSUPPORTFILETYPE.contains(Utils.getFileType(file.getOriginalFilename())),
Assert.isTrue(!AttachmentConstants.FileCheck.NOTSUPPORTFILETYPE.contains(Utils.getFileType(Objects.requireNonNull(file.getOriginalFilename()))),
"不支持的文件类型");
Assert.isTrue(file.getSize() < AttachmentConstants.FileCheck.MAXLENGTH, "单个文件大小不能超过30m!");
}
/**
* 查询全部售卖的砂石类型和价格
*
* @param
* @return
*/
@PostMapping("/weighbridgeSync/getAllDinasType")
public Object getAllDinasType(@RequestParam String weighbridgeCode) {
//根据地磅id查询场站
if (StringUtils.isBlank(weighbridgeCode)) {
return ResponseObj.error(500, "地磅唯一编码不能为空");
}
KObject station = stationService.getStationByWeighbridge(weighbridgeCode);
if (station == null) {
return ResponseObj.error(500, "没有查询到地磅匹配的场站");
}
List<StationDinasTypeRelation> allDinasTypes = inventoryService.getItemListByStationId(station.getUuid("id"));
return ResponseObj.success("查询成功", allDinasTypes);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment