Commit 4fae35bd by 高晓磊

销售记录后台导入,必要关联数据全部新建

parent 702d83bc
......@@ -34,4 +34,6 @@ public interface DinasTypeDao extends BaseDao {
List<KObject> getByRegionalCompanyId(UUID regionalCompanyId);
List<KObject> getStationsById(List<UUID> dinasTypeIds, List<UUID> regionalCompanyIds);
KObject insertNoInfo(String name, KObject station, KObject organization);
}
......@@ -31,4 +31,6 @@ public interface RetailInfoDao extends BaseDao {
Long selectBuyCountByIdCard(String idCard, UUID uuid);
BigDecimal selectBuyAmountByIdCard(String idCard, UUID fromString);
KObject insertNoInfo(String name, KObject station, KObject organization);
}
......@@ -13,6 +13,8 @@ public interface StationDao extends BaseDao {
Page<KObject> listStationInfoPaging(Page<KObject> page, Integer stationStatus);
KObject createNoInfoStation(String stationName, KObject organization);
UUID create(KObject kObject);
int selectCountByName(String stationName);
......@@ -28,4 +30,6 @@ public interface StationDao extends BaseDao {
List<KObject> queryStationByRegionalCompany(UUID uuid);
List<KObject> getStationCameraById(UUID id1);
KObject insertProductionLine(String productionLineName, KObject station);
}
......@@ -121,6 +121,27 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
}
@Override
public KObject insertNoInfo(String name, KObject station, KObject organization) {
KClass bean = Amino.getStaticMetadataContext().getBean(ENTITY, KClass.class);
KObject staff = AminoContextHolder.getContext().getStaff();
KObject kObject = bean.newInstance();
kObject.set(BaseConstants.ID,UUID.randomUUID());
kObject.set("dinasTypeName",name);
kObject.set("type",name.contains("砂")?0:1);
kObject.set("regionalCompany",organization);
kObject.set("reason","导入时新增,请重新维护");
kObject.set(BaseConstants.CREATOR, staff);
kObject.set(BaseConstants.CREATE_TIME, new Date());
kObject.set(BaseConstants.DEL, false);
template.save(kObject);
//勾选和场站的关系
checkedStation(kObject.getUuid("id"),station.getUuid("id"));
return kObject;
}
@Override
public DetachedCriteria addRegionalCompanyFilter(DetachedCriteria detachedCriteria) {
KObject currentLoginRegionalCompany = getCurrentLoginRegionalCompany();
if (currentLoginRegionalCompany != null && currentLoginRegionalCompany. getString("type").equals(OrganizationTypeEnum.REGIONAL_COMPANY.name())) {
......@@ -132,10 +153,8 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
@Override
public List<KObject> getByName(String name, UUID id) {
// UUID departmentId = AminoContextHolder.getContext().getStaff().get("department").getUuid("id");
KClass bean = Amino.getStaticMetadataContext().getBean(ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
// detachedCriteria.add(Restrictions.eq("department.id", departmentId));
detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.add(Restrictions.eq("dinasTypeName", name));
if (id != null) {
......
......@@ -22,10 +22,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.*;
public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, RetailInfoConstant {
......@@ -143,6 +142,34 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
}
@Override
public KObject insertNoInfo(String name, KObject station, KObject organization) {
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class);
KObject kObject = bean.newInstance();
kObject.set("station", station);
kObject.set("regionalCompany", organization);
kObject.set("retailInfoName", name);
kObject.set("idCard", getRandom());
kObject.set("address", "请维护");
kObject.set("reason", "系统新增数据,请修改实际情况");
kObject.set("id", UUID.randomUUID());
kObject.set(BaseConstants.CREATE_TIME, new Date());
kObject.set(BaseConstants.DEL, false);
template.save(kObject);
return kObject;
}
private String getRandom() {
StringBuilder s = new StringBuilder();
SecureRandom random = new SecureRandom();
s.append(random.nextInt(9) + 1);
for (int i = 0; i < 17; i++) {
s.append(random.nextInt(10));
}
return s.toString();
}
@Override
public UUID create(KObject kObject) {
WarehouseUser warehouseUser = WarehouseUserContextHolder.getContext().getWarehouseUser();
......
......@@ -102,7 +102,6 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
kobject.set(BaseConstants.MODIFIER,staff);
kobject.set(BaseConstants.DEL,false);
// template.deleteAll(id.get("productionLines").toList());
KObject productions = kobject.get("productionLines");
if(null!=productions){
......@@ -121,6 +120,39 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
}
@Override
public KObject createNoInfoStation(String stationName, KObject organization) {
KObject staff = AminoContextHolder.getContext().getStaff();
KClass kClass = Amino.getApplicationMetadataContext().getBean(StationConstant.ENTITY, KClass.class);
KObject kObject = kClass.newInstance();
kObject.set("regionalCompany",organization);
kObject.set("stationName",stationName);
kObject.set("id",UUID.randomUUID());
kObject.set("stationAddress","导入数据_请重新维护");
kObject.set("stationCoordinate","100,100");
kObject.set("linkMan","请维护");
kObject.set("telephone","13276544444");
kObject.set("stationStatus","1");
kObject.set(BaseConstants.CREATOR,staff);
kObject.set(BaseConstants.CREATE_TIME, new Date());
kObject.set(BaseConstants.DEL,false);
this.insert(kObject);
return kObject;
}
@Override
public KObject insertProductionLine(String productionLineName, KObject station) {
KClass kClass = Amino.getApplicationMetadataContext().getBean(ProductionLineConstant.ENTITY, KClass.class);
KObject kObject = kClass.newInstance();
kObject.set("id",UUID.randomUUID());
kObject.set("station",station);
kObject.set("name",productionLineName);
template.save(ProductionLineConstant.ENTITY,kObject);
return kObject;
}
@Override
public UUID create(KObject kObject) {
KObject staff = AminoContextHolder.getContext().getStaff();
......@@ -147,6 +179,8 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
return save;
}
@Override
public int selectCountByName(String stationName) {
String departmentId = AminoContextHolder.getContext().getStaff().get("department").getUuid("id").toString();
......
......@@ -228,6 +228,7 @@ public class DischargingDaoImpl extends AbstractBaseDao implements DischargingDa
dis.add(criterion);
}
detachedCriteria.add(Restrictions.and(dis));
detachedCriteria.addOrder(Order.desc("dischargingTime"));
return detachedCriteria;
}
......
......@@ -52,6 +52,10 @@ public interface SalesRecordConstant {
public static final String PAYMENTSOURCE = "paymentSource";
//销售单号
public static final String DEALBILLCODE = "dealBillCode";
//毛重
public static final String GROSS_WEIGHT = "grossWeight";
//皮重
public static final String TARE_WEIGHT = "tareWeight";
/** 审批状态*/
public static final String APPROVE_STATE = "approveState";
/**
......@@ -66,5 +70,5 @@ public interface SalesRecordConstant {
* 负责人
*/
public static final String PIC = "pic";
}
......@@ -16,4 +16,6 @@ public interface SalesRecordDao {
void saveAstTransportRecord(KObject salesRecord, KObject cardInfo);
KObject findCardByPlateNumber(String string, KObject kObject);
void insertList(List<KObject> salesRecordInfos);
}
......@@ -9,7 +9,6 @@ import com.beecode.amino.core.Amino;
import com.beecode.bcp.serial.Serial;
import com.beecode.bcp.type.KClass;
import com.beecode.inz.common.BaseConstants;
import com.beecode.inz.common.util.DateTimeUtils;
import com.beecode.util.DateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.hibernate.HibernateException;
......@@ -27,65 +26,65 @@ import com.xyst.dinas.sales.constant.SalesRecordConstant;
import com.xyst.dinas.sales.dao.SalesRecordDao;
public class SalesRecordDaoImpl implements SalesRecordDao, SalesRecordConstant {
@Autowired
private HibernateOperations template;
@Autowired
private HibernateOperations template;
@Override
public KObject load(UUID id) {
// TODO Auto-generated method stub
return (KObject) template.load(ENTITY, id);
}
@Override
public KObject load(UUID id) {
// TODO Auto-generated method stub
return (KObject) template.load(ENTITY, id);
}
@Override
public UUID insert(KObject entity) {
return (UUID) template.save(entity);
}
@Override
public UUID insert(KObject entity) {
return (UUID) template.save(entity);
}
@Override
public List<Map<String, Object>> getAllSalesRecordByDate(String dateNow ,String dateBefore) {
// TODO Auto-generated method stub
String sql = "select ss.project_id,ss.purchase_sand_company_id,ss.station_id,ss.dinas_type_id,sum(ss.deal_amount),sum(ss.amount) from xyst_dinas_sales_record ss where (ss.deal_time >= :startDate and ss.deal_time < :endDate ) GROUP BY ss.project_id,ss.purchase_sand_company_id,ss.station_id,ss.dinas_type_id";
return (List<Map<String, Object>>)template.execute(new HibernateCallback<List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> doInHibernate(Session session) throws HibernateException {
@SuppressWarnings("unchecked")
Query<Tuple> query = session.createNativeQuery(sql,Tuple.class);
query.setParameter("endDate", dateNow);
query.setParameter("startDate", dateBefore);
List<Tuple> resultList = query.getResultList();
if (resultList.isEmpty())
return null;
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for(Tuple resule:resultList) {
Map<String, Object> map=new HashMap<String,Object>();
map.put("project_id", Convert.toUUID(resule.get(0)));
map.put("purchase_sand_company_id", Convert.toUUID(resule.get(1)));
map.put("station_id", Convert.toUUID(resule.get(2)));
map.put("dinas_type_id", Convert.toUUID(resule.get(3)));
map.put("deal_amount", resule.get(4,BigDecimal.class));
map.put("amount", resule.get(5,BigDecimal.class));
list.add(map);
}
return list;
}
});
}
@Override
public List<Map<String, Object>> getAllSalesRecordByDate(String dateNow, String dateBefore) {
// TODO Auto-generated method stub
String sql = "select ss.project_id,ss.purchase_sand_company_id,ss.station_id,ss.dinas_type_id,sum(ss.deal_amount),sum(ss.amount) from xyst_dinas_sales_record ss where (ss.deal_time >= :startDate and ss.deal_time < :endDate ) GROUP BY ss.project_id,ss.purchase_sand_company_id,ss.station_id,ss.dinas_type_id";
return template.execute(new HibernateCallback<List<Map<String, Object>>>() {
@Override
public List<Map<String, Object>> doInHibernate(Session session) throws HibernateException {
@SuppressWarnings("unchecked")
Query<Tuple> query = session.createNativeQuery(sql, Tuple.class);
query.setParameter("endDate", dateNow);
query.setParameter("startDate", dateBefore);
List<Tuple> resultList = query.getResultList();
if (resultList.isEmpty())
return null;
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (Tuple resule : resultList) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("project_id", Convert.toUUID(resule.get(0)));
map.put("purchase_sand_company_id", Convert.toUUID(resule.get(1)));
map.put("station_id", Convert.toUUID(resule.get(2)));
map.put("dinas_type_id", Convert.toUUID(resule.get(3)));
map.put("deal_amount", resule.get(4, BigDecimal.class));
map.put("amount", resule.get(5, BigDecimal.class));
list.add(map);
}
return list;
}
});
}
@Override
public void saveAstTransportRecord(KObject salesRecord, KObject cardInfo) {
KClass bean = Amino.getStaticMetadataContext().getBean(TRANSPORT_RECORD_ENTITY, KClass.class);
KObject kObject = bean.newInstance();
kObject.set(BaseConstants.ID,UUID.randomUUID());
kObject.set(BaseConstants.DEL,false);
kObject.set(BaseConstants.DISCARD,false);
Serial serial = (Serial)Amino.getApplicationMetadataContext().getBean(TRANSPORT_RECORD_ENTITY_SERIAL);
kObject.set(BaseConstants.ID, UUID.randomUUID());
kObject.set(BaseConstants.DEL, false);
kObject.set(BaseConstants.DISCARD, false);
Serial serial = (Serial) Amino.getApplicationMetadataContext().getBean(TRANSPORT_RECORD_ENTITY_SERIAL);
String s = serial.generateString(kObject);
kObject.set("billCode",s+ DateUtil.convertTimeToString(salesRecord.getDate(SalesRecordConstant.DEALTIME)));
kObject.set(BaseConstants.CREATE_TIME,new Date());
kObject.set(REGIONALCOMPANY,salesRecord.get(REGIONALCOMPANY));
kObject.set("saleRecord",salesRecord);
kObject.set("transportVehicle",cardInfo);
kObject.set("confirmStatus",0);
kObject.set("billCode", s + DateUtil.convertTimeToString(salesRecord.getDate(SalesRecordConstant.DEALTIME)));
kObject.set(BaseConstants.CREATE_TIME, new Date());
kObject.set(REGIONALCOMPANY, salesRecord.get(REGIONALCOMPANY));
kObject.set("saleRecord", salesRecord);
kObject.set("transportVehicle", cardInfo);
kObject.set("confirmStatus", 0);
}
@Override
......@@ -93,11 +92,21 @@ public class SalesRecordDaoImpl implements SalesRecordDao, SalesRecordConstant {
KClass bean = Amino.getStaticMetadataContext().getBean(TRANSPORT_VEHICLE_ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq("plateNumber", string));
detachedCriteria.add(Restrictions.eq(REGIONALCOMPANY+"."+BaseConstants.ID, kObject.getUuid(BaseConstants.ID)));
detachedCriteria.add(Restrictions.eq(REGIONALCOMPANY + "." + BaseConstants.ID, kObject.getUuid(BaseConstants.ID)));
List<?> byCriteria = template.findByCriteria(detachedCriteria);
if(CollectionUtils.isNotEmpty(byCriteria)&&byCriteria.size()>0){
if (CollectionUtils.isNotEmpty(byCriteria) && byCriteria.size() > 0) {
return (KObject) byCriteria.get(0);
}
return null;
}
@Override
public void insertList(List<KObject> salesRecordInfos) {
template.execute(session -> {
for (KObject d : salesRecordInfos) {
session.save(d);
}
return null;
});
}
}
\ No newline at end of file
package com.xyst.dinas.sales.internal.service;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.biz.dao.DinasOrganizationDao;
import com.xyst.dinas.biz.dao.DinasTypeDao;
import com.xyst.dinas.biz.dao.StationDao;
import com.xyst.dinas.biz.dao.*;
import com.xyst.dinas.biz.service.PlanningCycleService;
import com.xyst.dinas.biz.dao.ProductionLineDao;
import com.xyst.dinas.biz.dao.RetailInfoDao;
import com.xyst.dinas.contract.internal.dao.ContractDao;
import com.xyst.dinas.contract.service.ContractService;
import com.xyst.dinas.project.dao.ProjectFiledDao;
......@@ -39,253 +18,564 @@ 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.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
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
public class SalesRecordServiceImpl implements SalesRecordService {
final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private SalesRecordDao salesRecordDao;
@Autowired
private ProjectFiledDao projectFiledDao;
@Autowired
DinasOrganizationDao dinasOrganizationDao;
@Autowired
ContractDao contractDao;
@Autowired
PurchaseSandCompanyDao purchaseSandCompanyDao;
@Autowired
StationDao stationDao;
@Autowired
ProductionLineDao ProductionLineDao;
@Autowired
RetailInfoDao retailInfoDao;
@Autowired
DinasTypeDao dinasTypeDao;
@Autowired
InventoryService inventoryService;
@Autowired
ContractService contractService;
@Autowired
SalesPlanDao salesPlanDao;
@Autowired
NeedPlanDao needPlanDao;
@Autowired
PlanningCycleService planningCycleService;
@Autowired
NeedPlanServiceImpl needPlanServiceImpl;
@Autowired
@Qualifier(SalesRecordConstant.ENTITY)
private KClass salesRecordClass;
final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private SalesRecordDao salesRecordDao;
@Autowired
private ProjectFiledDao projectFiledDao;
@Autowired
DinasOrganizationDao dinasOrganizationDao;
@Autowired
ContractDao contractDao;
@Autowired
PurchaseSandCompanyDao purchaseSandCompanyDao;
@Autowired
StationDao stationDao;
@Autowired
ProductionLineDao ProductionLineDao;
@Autowired
RetailInfoDao retailInfoDao;
@Autowired
DinasTypeDao dinasTypeDao;
@Autowired
InventoryService inventoryService;
@Autowired
ContractService contractService;
@Autowired
SalesPlanDao salesPlanDao;
@Autowired
NeedPlanDao needPlanDao;
@Autowired
PlanningCycleService planningCycleService;
@Autowired
NeedPlanServiceImpl needPlanServiceImpl;
@Autowired
ProductionLineDao productionLineDao;
@Autowired
@Qualifier(SalesRecordConstant.ENTITY)
private KClass salesRecordClass;
@Transactional
@Override
public String saveSalesRecordService(List<SalesRecordInfo> salesRecordInfoList) {
String state = "success";
try {
Date thentime = new Date();
List<UUID> salesRecordIdList = new ArrayList<UUID>();
for (SalesRecordInfo salesRecordInfo : salesRecordInfoList) {
// 获取项目KObject
KObject project = null;
project = entityExistenceCheck("项目",
projectFiledDao.load(UUID.fromString(dataExistenceCheck("项目", salesRecordInfo.getProject()))), true);
// 获取区域公司KObject
KObject regionalCompany = null;
regionalCompany = entityExistenceCheck("区域公司", dinasOrganizationDao
.load(UUID.fromString(dataExistenceCheck("区域公司", salesRecordInfo.getRegionalCompany()))), true);
// 获取合同KObject
KObject contract = null;
contract = entityExistenceCheck("合同",
contractDao.load(UUID.fromString(dataExistenceCheck("合同", salesRecordInfo.getContract()))), true);
// 获取购砂单位KObject
KObject purchaseSandCompany = null;
// 获取散户KObject
KObject retailInfo = null;
if ((CustomerTypeEnum.PurchaseSandCompany.name()).equals(salesRecordInfo.getCustomerType())) {
purchaseSandCompany = entityExistenceCheck("购砂单位", purchaseSandCompanyDao.load(
UUID.fromString(dataExistenceCheck("购砂单位", salesRecordInfo.getPurchaseSandCompany()))), true);
} else {
retailInfo = entityExistenceCheck("散户", retailInfoDao
.load(UUID.fromString(dataExistenceCheck("散户", salesRecordInfo.getRetailInfo()))), true);
}
// 获取场站KObject
KObject station = null;
station = entityExistenceCheck("场站",
stationDao.load(UUID.fromString(dataExistenceCheck("场站", salesRecordInfo.getStation()))), true);
// 获取生产线KObject
KObject productionLine = null;
productionLine = entityExistenceCheck("生产线", ProductionLineDao
.load(UUID.fromString(dataExistenceCheck("生产线", salesRecordInfo.getProductionLine()))), true);
// 获取砂石类型
KObject dinasType = null;
dinasType = entityExistenceCheck("砂石类型",
dinasTypeDao.load(UUID.fromString(dataExistenceCheck("砂石类型", salesRecordInfo.getDinasType()))), true);
Date modifyTime = generateDate("修改时间", "yyyy-MM-dd", salesRecordInfo.getModifyTime());
Date dealtime = generateDate("销售时间", "yyyy-MM-dd", salesRecordInfo.getDealTime());
// 获取销售台账Kobject
KObject salesRecord = salesRecordClass.newInstance();
salesRecord.set(SalesRecordConstant.ID, UUID.randomUUID());
salesRecord.set(SalesRecordConstant.CREATETIME, thentime);
salesRecord.set(SalesRecordConstant.MODIFYTIME, modifyTime);
salesRecord.set(SalesRecordConstant.PROJECT, project);
salesRecord.set(SalesRecordConstant.REGIONALCOMPANY, regionalCompany);
salesRecord.set(SalesRecordConstant.CONTRACT, contract);
if (CustomerTypeEnum.PurchaseSandCompany.name().equals(salesRecordInfo.getCustomerType())) {
salesRecord.set(SalesRecordConstant.PURCHASESANDCOMPANY, purchaseSandCompany);
} else if (null != salesRecordInfo.getRetailInfo()) {
salesRecord.set(SalesRecordConstant.RETAILINFO, retailInfo);
}
salesRecord.set(SalesRecordConstant.STATION, station);
salesRecord.set(SalesRecordConstant.PRODUCTIONLINE, productionLine);
salesRecord.set(SalesRecordConstant.DINASTYPE, dinasType);
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE,
dataExistenceCheck("客户类型", salesRecordInfo.getCustomerType()));
salesRecord.set(SalesRecordConstant.DEALTIME, dealtime);
salesRecord.set(SalesRecordConstant.SYNCTIME, thentime);
salesRecord.set(SalesRecordConstant.CARINFO, dataExistenceCheck("车辆信息", salesRecordInfo.getCarInfo()));
salesRecord.set(SalesRecordConstant.DEALAMOUNT,
salesRecordInfo.getDealAmount() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getDealAmount()));
salesRecord.set(SalesRecordConstant.PRICE, salesRecordInfo.getPrice() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getPrice()));
salesRecord.set(SalesRecordConstant.AMOUNT, salesRecordInfo.getAmount() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getAmount()));
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE,
dataExistenceCheck("付款来源", salesRecordInfo.getPaymentSource()));
salesRecord.set(SalesRecordConstant.DEALBILLCODE,
dataExistenceCheck("销售单号", salesRecordInfo.getDealBillCode()));
salesRecord.set(SalesRecordConstant.DISCARD, false);
salesRecord.set(SalesRecordConstant.DEL, false);
BigDecimal DEALAMOUNT = BigDecimal.ZERO
.subtract(new BigDecimal(salesRecord.getDouble(SalesRecordConstant.DEALAMOUNT)));
// 付款来源未定,暂时按使用预付款处理。
BigDecimal AMOUNT;
if (PayMentSourceEnum.Advance.name().equals(salesRecordInfo.getPaymentSource())) {
AMOUNT = BigDecimal.ZERO
.subtract(new BigDecimal(salesRecord.getDouble(SalesRecordConstant.AMOUNT)));
} else {
AMOUNT = BigDecimal.ZERO;
}
if (CustomerTypeEnum.PurchaseSandCompany.name().equals(salesRecordInfo.getCustomerType())) {
// 更新合同子表合同砂石余量(吨)-更新合同表付款余额、销售总量信息
boolean flag = contractService.modifyInventory(UUID.fromString(salesRecordInfo.getContract()),
UUID.fromString(salesRecordInfo.getDinasType()), DEALAMOUNT, AMOUNT);
if (!flag) {
throw new SyncException("销售台账信息存储报出错:合同子表中无此砂石类型数据");
}
// 更新销售计划
UUID planningCycleId = planningCycleService
.getPlanningCycleObjBySum(regionalCompany.getString("planningCycle"), dealtime);
KObject salesPlan = entityExistenceCheck("销售计划", salesPlanDao.querySalesPlanByPlan(
UUID.fromString(salesRecordInfo.getRegionalCompany()), planningCycleId), false);
BigDecimal actualSaleTotalAmount = salesPlan.get("actualSaleTotalAmount") == null ? BigDecimal.ZERO
: new BigDecimal(salesPlan.getInt("actualSaleTotalAmount"));
salesPlan.set("actualSaleTotalAmount", actualSaleTotalAmount.subtract(DEALAMOUNT));
salesPlanDao.update(salesPlan);
boolean flag1 = salesPlanDao.updateSalesPlanAmount(salesPlan, dinasType.getUuid("id"), contract.getUuid("id"),
project.getUuid("id"), purchaseSandCompany.getUuid("id"), DEALAMOUNT);
if (!flag1) {
//throw new SyncException("销售台账信息存储报出错:销售计划子表更新数据报错");
}
KObject needPlanAmount = entityExistenceCheck("需用计划",
needPlanServiceImpl.queryNeedPlanAmountByDinasType(planningCycleId, contract.getUuid("id"),
dinasType.getUuid("id")), false);
if (needPlanAmount != null) {
BigDecimal effectiveSale = needPlanAmount.get("effectiveSale") == null ? BigDecimal.ZERO
: new BigDecimal(needPlanAmount.getInt("needPlanAmount"));
needPlanAmount.set("effectiveSale", effectiveSale.subtract(DEALAMOUNT));
needPlanDao.update(needPlanAmount);
}
@Transactional
@Override
public String saveSalesRecordService(List<SalesRecordInfo> salesRecordInfoList) {
String state = "success";
try {
Date thentime = new Date();
List<UUID> salesRecordIdList = new ArrayList<UUID>();
for (SalesRecordInfo salesRecordInfo : salesRecordInfoList) {
// 获取项目KObject
KObject project = null;
project = entityExistenceCheck("项目",
projectFiledDao.load(UUID.fromString(dataExistenceCheck("项目", salesRecordInfo.getProject()))),true);
// 获取区域公司KObject
KObject regionalCompany = null;
regionalCompany = entityExistenceCheck("区域公司", dinasOrganizationDao
.load(UUID.fromString(dataExistenceCheck("区域公司", salesRecordInfo.getRegionalCompany()))),true);
// 获取合同KObject
KObject contract = null;
contract = entityExistenceCheck("合同",
contractDao.load(UUID.fromString(dataExistenceCheck("合同", salesRecordInfo.getContract()))),true);
// 获取购砂单位KObject
KObject purchaseSandCompany = null;
// 获取散户KObject
KObject retailInfo = null;
if ((CustomerTypeEnum.PurchaseSandCompany.name()).equals(salesRecordInfo.getCustomerType())) {
purchaseSandCompany = entityExistenceCheck("购砂单位", purchaseSandCompanyDao.load(
UUID.fromString(dataExistenceCheck("购砂单位", salesRecordInfo.getPurchaseSandCompany()))),true);
} else {
retailInfo = entityExistenceCheck("散户", retailInfoDao
.load(UUID.fromString(dataExistenceCheck("散户", salesRecordInfo.getRetailInfo()))),true);
}
// 获取场站KObject
KObject station = null;
station = entityExistenceCheck("场站",
stationDao.load(UUID.fromString(dataExistenceCheck("场站", salesRecordInfo.getStation()))),true);
// 获取生产线KObject
KObject productionLine = null;
productionLine = entityExistenceCheck("生产线", ProductionLineDao
.load(UUID.fromString(dataExistenceCheck("生产线", salesRecordInfo.getProductionLine()))),true);
// 获取砂石类型
KObject dinasType = null;
dinasType = entityExistenceCheck("砂石类型",
dinasTypeDao.load(UUID.fromString(dataExistenceCheck("砂石类型", salesRecordInfo.getDinasType()))),true);
Date modifyTime = generateDate("修改时间", "yyyy-MM-dd", salesRecordInfo.getModifyTime());
Date dealtime = generateDate("销售时间", "yyyy-MM-dd", salesRecordInfo.getDealTime());
// 获取销售台账Kobject
KObject salesRecord = salesRecordClass.newInstance();
salesRecord.set(SalesRecordConstant.ID, UUID.randomUUID());
salesRecord.set(SalesRecordConstant.CREATETIME, thentime);
salesRecord.set(SalesRecordConstant.MODIFYTIME, modifyTime);
salesRecord.set(SalesRecordConstant.PROJECT, project);
salesRecord.set(SalesRecordConstant.REGIONALCOMPANY, regionalCompany);
salesRecord.set(SalesRecordConstant.CONTRACT, contract);
if (CustomerTypeEnum.PurchaseSandCompany.name().equals(salesRecordInfo.getCustomerType())) {
salesRecord.set(SalesRecordConstant.PURCHASESANDCOMPANY, purchaseSandCompany);
} else if (null != salesRecordInfo.getRetailInfo()) {
salesRecord.set(SalesRecordConstant.RETAILINFO, retailInfo);
}
salesRecord.set(SalesRecordConstant.STATION, station);
salesRecord.set(SalesRecordConstant.PRODUCTIONLINE, productionLine);
salesRecord.set(SalesRecordConstant.DINASTYPE, dinasType);
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE,
dataExistenceCheck("客户类型", salesRecordInfo.getCustomerType()));
salesRecord.set(SalesRecordConstant.DEALTIME, dealtime);
salesRecord.set(SalesRecordConstant.SYNCTIME, thentime);
salesRecord.set(SalesRecordConstant.CARINFO, dataExistenceCheck("车辆信息", salesRecordInfo.getCarInfo()));
salesRecord.set(SalesRecordConstant.DEALAMOUNT,
salesRecordInfo.getDealAmount() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getDealAmount()));
salesRecord.set(SalesRecordConstant.PRICE, salesRecordInfo.getPrice() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getPrice()));
salesRecord.set(SalesRecordConstant.AMOUNT, salesRecordInfo.getAmount() == null ? BigDecimal.ZERO
: new BigDecimal(salesRecordInfo.getAmount()));
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE,
dataExistenceCheck("付款来源", salesRecordInfo.getPaymentSource()));
salesRecord.set(SalesRecordConstant.DEALBILLCODE,
dataExistenceCheck("销售单号", salesRecordInfo.getDealBillCode()));
salesRecord.set(SalesRecordConstant.DISCARD, false);
salesRecord.set(SalesRecordConstant.DEL, false);
BigDecimal DEALAMOUNT = BigDecimal.ZERO
.subtract(new BigDecimal(salesRecord.getDouble(SalesRecordConstant.DEALAMOUNT)));
// 付款来源未定,暂时按使用预付款处理。
BigDecimal AMOUNT;
if(PayMentSourceEnum.Advance.name().equals(salesRecordInfo.getPaymentSource())) {
AMOUNT = BigDecimal.ZERO
.subtract(new BigDecimal(salesRecord.getDouble(SalesRecordConstant.AMOUNT)));
}else {
AMOUNT = BigDecimal.ZERO;
}
if (CustomerTypeEnum.PurchaseSandCompany.name().equals(salesRecordInfo.getCustomerType())) {
// 更新合同子表合同砂石余量(吨)-更新合同表付款余额、销售总量信息
boolean flag = contractService.modifyInventory(UUID.fromString(salesRecordInfo.getContract()),
UUID.fromString(salesRecordInfo.getDinasType()), DEALAMOUNT, AMOUNT);
if (!flag) {
throw new SyncException("销售台账信息存储报出错:合同子表中无此砂石类型数据");
}
// 更新销售计划
UUID planningCycleId = planningCycleService
.getPlanningCycleObjBySum(regionalCompany.getString("planningCycle"), dealtime);
KObject salesPlan = entityExistenceCheck("销售计划", salesPlanDao.querySalesPlanByPlan(
UUID.fromString(salesRecordInfo.getRegionalCompany()), planningCycleId),false);
BigDecimal actualSaleTotalAmount = salesPlan.get("actualSaleTotalAmount") == null ? BigDecimal.ZERO
: new BigDecimal(salesPlan.getInt("actualSaleTotalAmount"));
salesPlan.set("actualSaleTotalAmount", actualSaleTotalAmount.subtract(DEALAMOUNT));
salesPlanDao.update(salesPlan);
boolean flag1=salesPlanDao.updateSalesPlanAmount(salesPlan, dinasType.getUuid("id"), contract.getUuid("id"),
project.getUuid("id"), purchaseSandCompany.getUuid("id"), DEALAMOUNT);
if (!flag1) {
//throw new SyncException("销售台账信息存储报出错:销售计划子表更新数据报错");
}
KObject needPlanAmount = entityExistenceCheck("需用计划",
needPlanServiceImpl.queryNeedPlanAmountByDinasType(planningCycleId, contract.getUuid("id"),
dinasType.getUuid("id")),false);
if(needPlanAmount != null) {
BigDecimal effectiveSale = needPlanAmount.get("effectiveSale") == null ? BigDecimal.ZERO
: new BigDecimal(needPlanAmount.getInt("needPlanAmount"));
needPlanAmount.set("effectiveSale", effectiveSale.subtract(DEALAMOUNT));
needPlanDao.update(needPlanAmount);
}
}
// 此处为Jason格式,多重嵌套
// 更新库存量
{
JSONObject params = new JSONObject();
JSONArray datas = new JSONArray();
JSONObject param = new JSONObject();
JSONArray data = new JSONArray();
JSONObject item = new JSONObject();
item.put("stationId", station.get("id"));
item.put("dinasTypeId", dinasType.get("id"));
item.put("stationName", "");
item.put("dinasTypeName", "");
item.put("amount", BigDecimal.ZERO.subtract(DEALAMOUNT));
data.put(item);
param.put("regionalCompany", regionalCompany.getUuid("id"));
param.put("data", data);
datas.put(param);
params.put("datas", datas);
inventoryService.modifyInventory(params.toString(), false, true);
}
UUID salesRecordId = salesRecordDao.insert(salesRecord);
}
// 此处为Jason格式,多重嵌套
// 更新库存量
{
JSONObject params = new JSONObject();
JSONArray datas = new JSONArray();
JSONObject param = new JSONObject();
JSONArray data = new JSONArray();
JSONObject item = new JSONObject();
item.put("stationId", station.get("id"));
item.put("dinasTypeId", dinasType.get("id"));
item.put("stationName", "");
item.put("dinasTypeName", "");
item.put("amount", BigDecimal.ZERO.subtract(DEALAMOUNT));
data.put(item);
param.put("regionalCompany", regionalCompany.getUuid("id"));
param.put("data", data);
datas.put(param);
params.put("datas", datas);
inventoryService.modifyInventory(params.toString(), false, true);
}
UUID salesRecordId = salesRecordDao.insert(salesRecord);
//将地磅记录同时保存到运输记录,需要判断是配送还是自提,或者直接根据车牌号判断,如果非配送的车牌应该在派单中没有记录
saveAstTransportRecord(salesRecord);
salesRecordIdList.add(salesRecordId);
}
}
} catch (SyncException e) {
state = "failure";
throw new SyncException("销售台账信息存储报出错:" + e.getMessage());
}
return state;
}
} catch (SyncException e) {
state = "failure";
throw new SyncException("销售台账信息存储报出错:" + e.getMessage());
}
return state;
}
private void saveAstTransportRecord(KObject salesRecord) {
String salesRecordCard = salesRecord.getString(SalesRecordConstant.CARINFO);
if(StringUtils.isEmpty(salesRecordCard)){
if (StringUtils.isEmpty(salesRecordCard)) {
return;
}
//根据车牌查询是否有对应的派单信息, 如果没有是否还需要同步?
//就算没有查到派单也可以同步,只是脏数据
//查询运输车辆是否维护过该车牌,如果还没有那就不要这条记录了,可能是散户的
KObject kObject = salesRecordDao.findCardByPlateNumber(salesRecordCard,salesRecord.get(SalesRecordConstant.REGIONALCOMPANY));
if(kObject==null){
KObject kObject = salesRecordDao.findCardByPlateNumber(salesRecordCard, salesRecord.get(SalesRecordConstant.REGIONALCOMPANY));
if (kObject == null) {
return;
}
salesRecordDao.saveAstTransportRecord(salesRecord,kObject);
salesRecordDao.saveAstTransportRecord(salesRecord, kObject);
}
private String dataExistenceCheck(String name, String value) {
String result = null;
if (null != value && "" != value) {
result = value;
} else {
throw new SyncException("[" + name + "]信息为空!请确认");
}
return result;
}
String result = null;
if (null != value && "" != 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) {
Workbook wb = null;
HashMap<String, Object> error1 = new HashMap<>();
HashSet<String> strings = new HashSet<>();
try {
error1.put("error",true);
//验证文件名是否正确,并生成对应的Workbook对象
String filename = file.getOriginalFilename();
InputStream is = file.getInputStream();
if (filename.contains(".xls")) {
wb = new XSSFWorkbook(is);
} else if (filename.contains(".xlsx")) {
wb = new HSSFWorkbook(is);
} else {
strings.add("文件格式不正确");
return error1;
}
} catch (Exception e) {
e.printStackTrace();
}
if (wb == null) {
return null;
}
//解析Excel并生成相应对象
Sheet sheet = wb.getSheetAt(0);
if (sheet == null) {
strings.add("未找到sheet页");
return error1;
}
int lastRowNum = sheet.getLastRowNum();
if (lastRowNum == 0) {
strings.add("数据为空");
return error1;
}
strings=cellValidate(sheet,lastRowNum);
if(strings.size()>0){
error1.put("error",true);
error1.put("message",strings);
return error1;
}
HashSet<KObject> organizations = new HashSet<>();
HashSet<KObject> stations = new HashSet<>();
HashSet<KObject> dinasTypes = new HashSet<>();
HashSet<KObject> retailInfos = new HashSet<>();
Set<String> noExist = createNoExist(sheet, lastRowNum, organizations, stations, dinasTypes, retailInfos, strings);
if(noExist!=null && !noExist.isEmpty()){
strings.addAll(noExist);
}
if(strings.size()>0){
error1.put("error",true);
error1.put("message",strings);
return error1;
}
error1.clear();
return error1;
}
private Set<String> createNoExist(Sheet sheet ,int lastRowNum,Set<KObject> organizations,Set<KObject> stations,Set<KObject> dinasTypes,Set<KObject> retailInfos,Set<String> strings){
Row row;
List<KObject> saleRecord = new ArrayList<>();
KObject organization = null;
KObject station = null;
KObject productionLine = null;
KObject dinasType = null;
KObject retailInfo = null;
//添加数据
for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
row = sheet.getRow(rowNum);
//集团名称
String orgName = row.getCell(0).getStringCellValue().trim();
Optional<KObject> hasOrg = organizations.stream().filter(a -> a.getString("name").equals(orgName)).findFirst();
if(!hasOrg.isPresent()){
organization = dinasOrganizationDao.queryOrganizationByName(orgName);
if(organization==null||organization.isNull()||organization.isEmpty()){
//如果没有所属集团,应该报错
strings.add("请创建集团:"+orgName);
continue;
}
organizations.add(organization);
}
//场站名称
String stationName = row.getCell(1).getStringCellValue().trim();
Optional<KObject> hasStation = stations.stream().filter(a -> a.getString("stationName").equals(stationName)).findFirst();
if(!hasStation.isPresent()){
assert organization != null;
List<KObject> kObjects = stationDao.listStationInfoByRegionalCompany(organization.getUuid("id"));
Optional<KObject> filterStation = kObjects.stream().filter(a -> a.getString("stationName").equals(stationName)).findFirst();
if(!filterStation.isPresent()){
//创建场站
station = stationDao.createNoInfoStation(stationName, organization);
stations.add(station);
}else {
station = filterStation.get();
stations.add(station);
}
}else {
station= hasStation.get();
}
//生产线名称
String productionLineName = row.getCell(2).getStringCellValue().trim();
KObject productions = station.get("productionLines");
if(null!=productions&&!productions.isNull()){
List<KObject> kObjects = productions.toList();
Optional<KObject> name = kObjects.stream().filter(a -> productionLineName.equals(a.getString("name"))).findFirst();
if(!name.isPresent()){
productionLine = stationDao.insertProductionLine(productionLineName, station);
kObjects.add(productionLine);
}else {
productionLine = name.get();
ArrayList<KObject> kObjects1 = new ArrayList<>();
kObjects1.add(productionLine);
station.set("productionLines",kObjects1);
}
}
String dinasTypeName = row.getCell(3).getStringCellValue().trim();
//砂石类型
Optional<KObject> dinasTypeName1 = dinasTypes.stream().filter(a -> a.getString("dinasTypeName").equals(dinasTypeName)).findFirst();
if(!dinasTypeName1.isPresent()) {
List<KObject> byName = dinasTypeDao.getByName(dinasTypeName, null);
if (byName == null || byName.size() < 1) {
KObject kObject = dinasTypeDao.insertNoInfo(dinasTypeName, station, organization);
dinasTypes.add(kObject);
dinasType=kObject;
} else {
dinasTypes.add(byName.get(0));
dinasType=byName.get(0);
}
}else {
dinasTypes.add(dinasTypeName1.get());
dinasType=dinasTypeName1.get();
}
//散户名称
String retailName = row.getCell(6).getStringCellValue().trim();
Optional<KObject> retailInfoName1 = retailInfos.stream().filter(a -> a.getString("retailInfoName").equals(retailName)).findFirst();
if(!retailInfoName1.isPresent()){
List<KObject> retailInfoName = retailInfoDao.getByName(retailName, null);
if(retailInfoName!=null && retailInfoName.size()>0){
retailInfos.add(retailInfoName.get(0));
retailInfo= retailInfoName.get(0);
}else {
KObject k = retailInfoDao.insertNoInfo(retailName,station,organization);
retailInfos.add(k);
retailInfo= k;
}
}else {
retailInfo = retailInfoName1.get();
}
String carNumber = row.getCell(5).getStringCellValue();
String billCode = row.getCell(4).getStringCellValue();
BigDecimal grossWeight = BigDecimal.valueOf(row.getCell(9).getNumericCellValue());
BigDecimal tareWeight = BigDecimal.valueOf(row.getCell(10).getNumericCellValue());
BigDecimal dealAmount = BigDecimal.valueOf(row.getCell(11).getNumericCellValue());
BigDecimal price = BigDecimal.valueOf(row.getCell(13).getNumericCellValue());
BigDecimal amount = BigDecimal.valueOf(row.getCell(14).getNumericCellValue());
KObject record = createRecord(organization, retailInfo, station, productionLine, dinasType, carNumber, billCode, grossWeight, tareWeight, dealAmount, price, amount);
saleRecord.add(record);
}
if(strings.size()>0){
return strings;
}
salesRecordDao.insertList(saleRecord);
return null;
}
private KObject createRecord(KObject regionalCompany,KObject retailInfo,KObject station,KObject productionLine,KObject dinasType,String carNum,
String billCode,BigDecimal grossWeight,BigDecimal tareWeight,BigDecimal dealAmount,BigDecimal price,BigDecimal amount){
KObject salesRecord = salesRecordClass.newInstance();
salesRecord.set(SalesRecordConstant.ID, UUID.randomUUID());
salesRecord.set(SalesRecordConstant.CREATETIME, new Date());
salesRecord.set(SalesRecordConstant.MODIFYTIME, new Date());
salesRecord.set(SalesRecordConstant.REGIONALCOMPANY, regionalCompany);
// salesRecord.set(SalesRecordConstant.PROJECT, null);
// salesRecord.set(SalesRecordConstant.CONTRACT, null);
salesRecord.set(SalesRecordConstant.RETAILINFO, retailInfo);
salesRecord.set(SalesRecordConstant.STATION, station);
salesRecord.set(SalesRecordConstant.PRODUCTIONLINE, productionLine);
salesRecord.set(SalesRecordConstant.DINASTYPE, dinasType);
salesRecord.set(SalesRecordConstant.CUSTOMERTYPE,CustomerTypeEnum.RetailInfo.name());
salesRecord.set(SalesRecordConstant.DEALTIME, new Date());
salesRecord.set(SalesRecordConstant.SYNCTIME, new Date());
salesRecord.set(SalesRecordConstant.CARINFO, carNum);
salesRecord.set(SalesRecordConstant.DEALAMOUNT, dealAmount);
salesRecord.set(SalesRecordConstant.PRICE, price);
salesRecord.set(SalesRecordConstant.AMOUNT, amount);
salesRecord.set(SalesRecordConstant.PAYMENTSOURCE,PayMentSourceEnum.Cash.name());
salesRecord.set(SalesRecordConstant.DEALBILLCODE,billCode);
salesRecord.set(SalesRecordConstant.GROSS_WEIGHT,grossWeight);
salesRecord.set(SalesRecordConstant.TARE_WEIGHT,tareWeight);
salesRecord.set(SalesRecordConstant.DISCARD, false);
salesRecord.set(SalesRecordConstant.DEL, false);
return salesRecord;
}
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 HashSet<String> cellValidate(Sheet sheet,int lastRowNum){
Cell cell;
HashSet<String> strings = new HashSet<>();
//校验
for (int rowNum = 1; rowNum <= lastRowNum; rowNum++) {
Row row = sheet.getRow(rowNum);
//集团名称 场站名称 生产线名称 物资 流水号 车号 客户 毛重司磅员 皮重司磅员 毛重 皮重 净重 扣重 单价 金额 毛重时间 皮重时间 余额
//前9列全是string 集团名称 场站名称 生产线名称 物资 流水号 车号 客户 毛重司磅员 皮重司磅员
for (int i = 0; i<9;i++) {
cell = row.getCell(i);
boolean b = validateCellStringValueIsNotNull(cell);
if(!b){
strings.add("第"+(rowNum+1)+"行,第"+(i+1)+"列,数据为空或者格式错误");
}
}
//中间6列全是数字 毛重 皮重 净重 扣重 单价 金额
for (int i = 9; i<15;i++) {
cell = row.getCell(i);
boolean b = validateCellNumberValueIsNotNull(cell);
if(!b){
strings.add("第"+(rowNum+1)+"行,第"+(i+1)+"列,数据为空或者格式错误");
}
}
//最后2列为时间类型
for (int i = 16; i<18;i++) {
cell = row.getCell(i);
boolean b = validateCellDateValueIsNotNull(cell);
if(!b){
strings.add("第"+(rowNum+1)+"行,第"+(i+1)+"列,数据为空或者格式错误");
}
}
}
return strings;
}
private Date generateDate(String name, String pattern, String value) {
return generateDate(name, pattern, value, true);
}
/**
* 校验是否为空并且为字符类型
* @param cell
* @return
*/
private boolean validateCellStringValueIsNotNull(Cell cell){
if(cell==null){
return false;
}
try {
RichTextString richStringCellValue = cell.getRichStringCellValue();
return richStringCellValue != null && !StringUtils.isBlank(richStringCellValue.toString());
}catch (Exception e){
return false;
}
}
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;
}
/**
* 校验是否为空并且是数字类
* @param cell
* @return
*/
private boolean validateCellNumberValueIsNotNull(Cell cell){
if(cell==null){
return false;
}
try {
CellType cellTypeEnum = cell.getCellTypeEnum();
return cellTypeEnum.compareTo(CellType.NUMERIC) == 0;
}catch (Exception e){
return false;
}
}
/**
* 校验是否为空并且是时间类型
* @param cell
* @return
*/
private boolean validateCellDateValueIsNotNull(Cell cell){
if(cell==null){
return false;
}
try {
Date dateCellValue = cell.getDateCellValue();
return dateCellValue !=null;
}catch (Exception e){
return false;
}
}
private UUID getUUid(){
return UUID.randomUUID();
}
}
package com.xyst.dinas.sales.service;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import com.xyst.dinas.sales.web.info.SalesRecordInfo;
import org.springframework.web.multipart.MultipartFile;
public interface SalesRecordService {
......@@ -14,4 +15,6 @@ public interface SalesRecordService {
* @return 返回存储状态 failure/失败 success/成功
*/
String saveSalesRecordService(List<SalesRecordInfo> salesRecordList);
HashMap<String,Object> qualityReportExcelImport(MultipartFile file);
}
package com.xyst.dinas.sales.web;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,7 +11,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.beecode.inz.basis.team.pojo.ResponseObj;
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.springframework.web.multipart.MultipartFile;
@RestController
public class SalesRecordController {
......@@ -34,4 +35,22 @@ public class SalesRecordController {
}
}
/**
* create by: 导入销售记录,没有的数据全部新建
* create time: 2019/12/7 12:22
*/
@PostMapping("/reportExcelImport")
public ResponseObj reportExcelImport(MultipartFile file) {
if(file == null){
return ResponseObj.error(500, "附件为空",null);
}
HashMap<String, Object> stringObjectHashMap = salesRecordService.qualityReportExcelImport(file);
if(stringObjectHashMap!=null&&!stringObjectHashMap.isEmpty()){
if(stringObjectHashMap.containsKey("message")) {
return ResponseObj.error(500,"导入失败",stringObjectHashMap.get("message"));
}
}
return ResponseObj.success("success");
}
}
......@@ -61,11 +61,21 @@
<attribute id='9ed97388-563a-4634-a555-b56bb1664dd0' name='carInfo' columnName='car_info' title='车辆信息' type='string' default='' precision='' isArray='false'>
<annotation id='9f44e7df-2ecb-490d-a420-2f53f09e3c38' attributeId='fe172826-06ad-4e73-9a8c-5dbab39d0394' name='length' value='20'></annotation>
</attribute>
<attribute id='d307fa81-7819-4216-887c-2a0fdffd3190' name='dealAmount' columnName='deal_amount' title='销售数量' type='fixnum' default='' precision='' isArray='false'>
<attribute id='d307fa81-7819-4216-887c-2a0fdffd3190' name='dealAmount' columnName='deal_amount' title='净重' type='fixnum' default='' precision='' isArray='false'>
<annotation id='8f3f5db5-4480-4a68-9399-cbec70cd118a' attributeId='cf1e0d8f-784b-4587-83a3-1167fc10042f' name='length' value='100'></annotation>
<annotation id='c342cc44-eabb-4f24-8872-b3cd6085b269' attributeId='1faca45c-ea26-47cc-a2ef-ae00daf88586' name='precision' value='12'></annotation>
<annotation id='ae5380d7-75c6-44ff-862f-c9d6c3af409d' attributeId='88762e9e-7c48-40e0-aac1-abcf20e9071a' name='scale' value='4'></annotation>
</attribute>
<attribute id='c4a69b63-8456-4e68-a7d3-b775bf2709c3' name='grossWeight' columnName='gross_weight' title='毛重' type='fixnum' default='' precision='' isArray='false'>
<annotation id='39f8e296-529b-4dfc-8d22-9a553d3a667f' attributeId='c484caff-a78f-415c-a00d-80aa30cea477' name='length' value='100'></annotation>
<annotation id='a30c74ee-a692-4975-a98e-37b81061b580' attributeId='39eea597-3d56-4309-82c4-9017051c19bd' name='precision' value='12'></annotation>
<annotation id='db9cf1ad-638b-44b9-9334-fee88d616a0f' attributeId='a0ce7d48-bd5b-4b52-8385-db55db584e52' name='scale' value='4'></annotation>
</attribute>
<attribute id='39139a55-c45f-4545-873a-225e19efd651' name='tareWeight' columnName='tare_weight' title='皮重' type='fixnum' default='' precision='' isArray='false'>
<annotation id='d665032d-1bac-4ae4-b021-d87275102644' attributeId='b6798e45-f786-40a9-b838-e58de645c77a' name='length' value='100'></annotation>
<annotation id='c2e4e3b4-0ac0-42e5-adc1-bc70e8610579' attributeId='3e7fc89a-6e4b-4660-aa98-b9c10d53d0bc' name='precision' value='12'></annotation>
<annotation id='ed5158d4-b302-4341-ba5b-f301365753a4' attributeId='e176d706-6093-4ee5-bc9f-bbb3c964960f' name='scale' value='4'></annotation>
</attribute>
<attribute id='35c5c23b-bb32-4e2d-909a-712cfadd3519' name='price' columnName='price' title='单价' type='fixnum' default='' precision='' isArray='false'>
<annotation id='5efadf89-6201-4ee6-9088-473404a74f6d' attributeId='e846437b-1583-4068-9690-262ec2c98b61' name='length' value='100'></annotation>
<annotation id='d81f33ea-7612-45c3-9bdd-089af6abd635' attributeId='a5d530ef-9a7d-433e-93c3-240c9fbc7178' name='precision' value='12'></annotation>
......
......@@ -419,6 +419,70 @@
</m:property>
<m:property>
<m:key>scale</m:key>
<m:value>4</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>gross_weight</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>c4a69b63-8456-4e68-a7d3-b775bf2709c3</m:id>
<m:name>grossWeight</m:name>
<m:title>毛重</m:title>
<m:type>fixnum</m:type>
<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>4</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>tare_weight</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>39139a55-c45f-4545-873a-225e19efd651</m:id>
<m:name>tareWeight</m:name>
<m:title>皮重</m:title>
<m:type>fixnum</m:type>
<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>
......
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