|
@@ -1,10 +1,29 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
-import com.yh.saas.plugin.yiliangyiyun.entity.SaleOrder;
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
+import com.baomidou.mybatisplus.mapper.Wrapper;
|
|
|
+import com.baomidou.mybatisplus.plugins.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.winsea.svc.base.workflow.entity.Workflow;
|
|
|
+import com.yh.saas.common.support.util.IdGenerator;
|
|
|
+import com.yh.saas.plugin.base.service.ICommonBillOperateHisService;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.NumberConstant;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.entity.*;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.exception.*;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.SaleOrderMapper;
|
|
|
-import com.yh.saas.plugin.yiliangyiyun.service.ISaleOrderService;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.service.*;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.util.GeTuiUtils;
|
|
|
+import com.yh.saas.toolkit.workflow.service.IWorkflowService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -16,5 +35,356 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class SaleOrderServiceImpl extends ServiceImpl<SaleOrderMapper, SaleOrder> implements ISaleOrderService {
|
|
|
+ @Autowired
|
|
|
+ private ITransactionRecordService transactionRecordService;
|
|
|
+ @Autowired
|
|
|
+ private ICommonBillOperateHisService billOperateHisService;
|
|
|
+ @Autowired
|
|
|
+ private IPriceChangeRecordService priceChangeRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IWarehouseInOutInfoService warehouseInOutInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IWorkflowService workflowService;
|
|
|
+ @Autowired
|
|
|
+ private GeTuiUtils geTuiUtils;
|
|
|
+ @Autowired
|
|
|
+ private ICustomerInfoService customerInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 成交
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String deal(SaleOrder saleOrder) {
|
|
|
+ //状态改为已成交
|
|
|
+ saleOrder.setStatusFlag(StatusEnum.ORDER_DEALED.getFlag());
|
|
|
+ saleOrder.setStatus(StatusEnum.ORDER_DEALED.getName());
|
|
|
+ //更新销售订单表
|
|
|
+ this.updateById(saleOrder);
|
|
|
+ //向成交记录表插入数据
|
|
|
+ TransactionRecord transactionRecord=new TransactionRecord();
|
|
|
+ transactionRecord.setId(IdGenerator.generateUUID());
|
|
|
+ transactionRecord.setOrderId(saleOrder.getId());
|
|
|
+ transactionRecord.setCompId(saleOrder.getCompId());
|
|
|
+ //标识为0 成交
|
|
|
+ transactionRecord.setRecordFlag("0");
|
|
|
+ transactionRecord.setTransactionPrice(saleOrder.getTransactionPrice());
|
|
|
+ transactionRecord.setBasis(saleOrder.getBasis());
|
|
|
+ transactionRecord.setTurnover(saleOrder.getTransactionsNumber());
|
|
|
+ transactionRecordService.insert(transactionRecord);
|
|
|
+ //向改价记录表插入数据
|
|
|
+ PriceChangeRecord priceChangeRecord=new PriceChangeRecord();
|
|
|
+ priceChangeRecord.setId(IdGenerator.generateUUID());
|
|
|
+ priceChangeRecord.setCompId(saleOrder.getCompId());
|
|
|
+ priceChangeRecord.setOrderId(saleOrder.getId());
|
|
|
+ priceChangeRecord.setPrice(saleOrder.getTransactionPrice());
|
|
|
+ priceChangeRecord.setPriceType("成交价");
|
|
|
+ priceChangeRecordService.insert(priceChangeRecord);
|
|
|
+ geTuiUtils.pushByCid("成交通知","您的合同已成交,成交价:"+saleOrder.getTransactionPrice()+"元/吨",saleOrder.getCommonId());
|
|
|
+ return saleOrder.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更改
|
|
|
+ * @param saleOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String editStatus(SaleOrder saleOrder) {
|
|
|
+ //查询销售订单信息
|
|
|
+ SaleOrder saleOrder1=this.selectById(saleOrder.getId());
|
|
|
+ if (saleOrder1 != null) {
|
|
|
+ //0补充定金
|
|
|
+ if (saleOrder.getFlag() == 0) {
|
|
|
+ saleOrder1.setFreezingDeposit(saleOrder1.getFreezingDeposit() + saleOrder.getMoney());
|
|
|
+ saleOrder1.setDefaultDeposit(saleOrder1.getDefaultDeposit() - saleOrder.getMoney());
|
|
|
+ //更改销售订单信息
|
|
|
+ this.updateById(saleOrder1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ //1解冻定金
|
|
|
+ else if (saleOrder.getFlag() == 1) {
|
|
|
+ saleOrder1.setFreezingDeposit(0.0f);
|
|
|
+ //更改销售订单信息
|
|
|
+ this.updateById(saleOrder1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ //2 完成
|
|
|
+ else if (saleOrder.getFlag() == 2) {
|
|
|
+ saleOrder1.setStatusFlag(StatusEnum.ORDER_COMPLETED.getFlag());
|
|
|
+ saleOrder1.setStatus(StatusEnum.ORDER_COMPLETED.getName());
|
|
|
+ //更改销售订单信息
|
|
|
+ this.updateById(saleOrder1);
|
|
|
+ // 插入操作历史
|
|
|
+ String staffName = this.billOperateHisService.getStaffAndName();
|
|
|
+ // 插入操作历史
|
|
|
+ this.billOperateHisService.saveBillOperateHis(saleOrder1.getId(), NumberConstant.CONSTANT_PURCHASE, staffName, null,
|
|
|
+ saleOrder1.getStatus(), null, "");
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ //3更改基差
|
|
|
+ else {
|
|
|
+ saleOrder1.setBasis(saleOrder.getBasis());
|
|
|
+ //更改销售订单信息
|
|
|
+ this.updateById(saleOrder1);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 平仓
|
|
|
+ * @param saleOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String closePosition(SaleOrder saleOrder) {
|
|
|
+ //修改主表信息
|
|
|
+ boolean one = this.updateById(saleOrder);
|
|
|
+ //向平仓记录表插入数据
|
|
|
+ TransactionRecord transactionRecord=new TransactionRecord();
|
|
|
+ transactionRecord.setId(IdGenerator.generateUUID());
|
|
|
+ transactionRecord.setOrderId(saleOrder.getId());
|
|
|
+ transactionRecord.setCompId(saleOrder.getCompId());
|
|
|
+ //标识为1 平仓
|
|
|
+ transactionRecord.setRecordFlag("1");
|
|
|
+ transactionRecord.setTransactionPrice(saleOrder.getTransactionPrice());
|
|
|
+ transactionRecord.setBasis(saleOrder.getBasis());
|
|
|
+ transactionRecord.setTurnover(saleOrder.getTransactionsNumber());
|
|
|
+ boolean two = transactionRecordService.insert(transactionRecord);
|
|
|
+ geTuiUtils.pushByCid("平仓通知","您的合同:" + saleOrder.getContractNo() + " 平仓成功",saleOrder.getCommonId());
|
|
|
+ if (one && two) {
|
|
|
+ return "OK";
|
|
|
+ } else {
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户点价
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String pointPrice(String id, Float unitPrice) throws ParseException, ServiceException {
|
|
|
+ //查询销售订单信息
|
|
|
+ SaleOrder saleOrder = this.selectById(id);
|
|
|
+ if (saleOrder != null) {
|
|
|
+ String format = "HH:mm:ss";
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
|
|
+ // 三个不可改价时间(8:00-11:30/12:30-15:00/20:00-23:00)
|
|
|
+ Date startTime = new SimpleDateFormat(format).parse("08:00:00");
|
|
|
+ Date endTime = new SimpleDateFormat(format).parse("11:30:00");
|
|
|
+ Date startTimeNext = new SimpleDateFormat(format).parse("12:30:00");
|
|
|
+ Date endTimeNext = new SimpleDateFormat(format).parse("15:00:00");
|
|
|
+ Date startTimeFinal = new SimpleDateFormat(format).parse("20:00:00");
|
|
|
+ Date endTimeFinal = new SimpleDateFormat(format).parse("23:00:00");
|
|
|
+ Date now = new SimpleDateFormat(format).parse(formatter.format(new Date()));
|
|
|
+ // 定义时间段
|
|
|
+ boolean result = belongCalendar(now, startTime, endTime);
|
|
|
+ boolean resultNext = belongCalendar(now, startTimeNext, endTimeNext);
|
|
|
+ boolean resultFinal = belongCalendar(now, startTimeFinal, endTimeFinal);
|
|
|
+ //判断三个时间段内不可点价
|
|
|
+ if (result || resultNext || resultFinal) {
|
|
|
+ throw new AppServiceException(ExceptionDefinition.POINT_PRICE_TIME_ERROR);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ saleOrder.setUnitPrice(unitPrice);
|
|
|
+ //更改销售订单信息
|
|
|
+ this.updateById(saleOrder);
|
|
|
+ //向改价记录表插入数据
|
|
|
+ PriceChangeRecord priceChangeRecord = new PriceChangeRecord();
|
|
|
+ priceChangeRecord.setId(IdGenerator.generateUUID());
|
|
|
+ priceChangeRecord.setOrderId(saleOrder.getId());
|
|
|
+ priceChangeRecord.setPrice(unitPrice);
|
|
|
+ priceChangeRecord.setPriceType("点价");
|
|
|
+ priceChangeRecordService.insert(priceChangeRecord);
|
|
|
+ return "OK";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 判断时间是否在时间段内
|
|
|
+ *
|
|
|
+ * @param nowTime
|
|
|
+ * @param beginTime
|
|
|
+ * @param endTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean belongCalendar(Date nowTime, Date beginTime,
|
|
|
+ Date endTime) {
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ date.setTime(nowTime);
|
|
|
+
|
|
|
+ Calendar begin = Calendar.getInstance();
|
|
|
+ begin.setTime(beginTime);
|
|
|
+
|
|
|
+ Calendar end = Calendar.getInstance();
|
|
|
+ end.setTime(endTime);
|
|
|
+
|
|
|
+ if (date.after(begin) && date.before(end)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 销售订单列表
|
|
|
+ * @param saleOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<SaleOrder> selectSaleOrder(SaleOrder saleOrder) {
|
|
|
+ Map<String, Object> pageView = new HashMap<>();
|
|
|
+ pageView.put("startRecord", (saleOrder.getCurrentPage() - 1)
|
|
|
+ * saleOrder.getPageSize());
|
|
|
+ //公司id
|
|
|
+ pageView.put("compId", saleOrder.getCompId());
|
|
|
+ pageView.put("commonId", saleOrder.getCommonId());
|
|
|
+ pageView.put("searchKeyWord", saleOrder.getSearchKeyWord());
|
|
|
+ pageView.put("searchType", saleOrder.getSearchType());
|
|
|
+ pageView.put("pcFlag",saleOrder.getPcFlag());
|
|
|
+ pageView.put("pageSize", saleOrder.getPageSize());
|
|
|
+ pageView.put("currentPage", saleOrder.getCurrentPage());
|
|
|
+ // 查询销售订单总数
|
|
|
+ Integer dataCount = baseMapper.getCountByCondition(pageView);
|
|
|
+ List<SaleOrder> dataList = baseMapper.getListByCondition(pageView);
|
|
|
+ if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
+ for (SaleOrder saleOrdera : dataList) {
|
|
|
+ //定义已出库量
|
|
|
+ String stockOutQuantity = "";
|
|
|
+ //查询出库量
|
|
|
+ List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
|
|
|
+ .eq("contract_no",saleOrdera.getContractNo())
|
|
|
+ .eq("in_out_flag","1")
|
|
|
+ .eq("status_flag","3")
|
|
|
+ .eq("delete_flag","0"));
|
|
|
+ if (!CollectionUtils.isEmpty(warehouseInOutInfoList)) {
|
|
|
+ for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList) {
|
|
|
+ if (StringUtils.isEmpty(stockOutQuantity)) {
|
|
|
+ stockOutQuantity = "0";
|
|
|
+ }
|
|
|
+ stockOutQuantity = String.valueOf(Float.valueOf(stockOutQuantity) + warehouseInOutInfo.getNetWeight());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询改价记录
|
|
|
+ List<PriceChangeRecord> priceChangeRecordList = priceChangeRecordService.selectList(new EntityWrapper<PriceChangeRecord>()
|
|
|
+ .eq("order_id",saleOrdera.getId())
|
|
|
+ .eq("delete_flag","0"));
|
|
|
+ //查询成交记录
|
|
|
+ List<TransactionRecord> transactionRecordList = transactionRecordService.selectList(new EntityWrapper<TransactionRecord>()
|
|
|
+ .eq("order_id",saleOrdera.getId())
|
|
|
+ .eq("record_flag","0")
|
|
|
+ .eq("delete_flag","0"));
|
|
|
+ //查询平仓记录
|
|
|
+ List<TransactionRecord> closePositionList = transactionRecordService.selectList(new EntityWrapper<TransactionRecord>()
|
|
|
+ .eq("order_id",saleOrdera.getId())
|
|
|
+ .eq("record_flag","1")
|
|
|
+ .eq("delete_flag","0"));
|
|
|
+ //查询客户信息
|
|
|
+ Wrapper<CustomerInfo> customerInfoWrapper = new EntityWrapper<>();
|
|
|
+ customerInfoWrapper.andNew().eq("comp_name",saleOrdera.getCustomer()).or()
|
|
|
+ .eq("customer_name",saleOrdera.getCustomer());
|
|
|
+ customerInfoWrapper.eq("delete_flag","0");
|
|
|
+ CustomerInfo customerInfo=customerInfoService.selectOne(customerInfoWrapper);
|
|
|
+ if (customerInfo!=null){
|
|
|
+ saleOrdera.setCustomerInfo(customerInfo);
|
|
|
+ }
|
|
|
+ saleOrdera.setStockOutQuantityList(warehouseInOutInfoList);
|
|
|
+ saleOrdera.setTransactionRecordList(transactionRecordList);
|
|
|
+ saleOrdera.setClosePositionList(closePositionList);
|
|
|
+ saleOrdera.setPriceChangeRecordList(priceChangeRecordList);
|
|
|
+ saleOrdera.setStockOutQuantity(stockOutQuantity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Page<SaleOrder> page = new Page<>();
|
|
|
+ page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
|
|
|
+ page.setTotal(dataCount == null ? 0 : dataCount);
|
|
|
+ page.setCurrent(saleOrder.getCurrentPage());
|
|
|
+ page.setSize(saleOrder.getPageSize());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加销售订单
|
|
|
+ * @param saleOrder
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String insertSaleOrder(SaleOrder saleOrder) {
|
|
|
+ //新增主键id
|
|
|
+ saleOrder.setId(IdGenerator.generateUUID());
|
|
|
+ // 操作主表数据
|
|
|
+ boolean one = this.insert(saleOrder);
|
|
|
+ boolean isStartWorkflow = StringUtils.isBlank(saleOrder.getWorkflowId());
|
|
|
+ // 不是退回的单子
|
|
|
+ if (isStartWorkflow) {
|
|
|
+ Workflow workflow = workflowService
|
|
|
+ .findLatestWorkflowByBusinessCode("PURCHASE-ORDER-APPROVE");
|
|
|
+ // 没配置审核流程,直接结束并处理信息
|
|
|
+ if (workflow == null) {
|
|
|
+ throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
|
|
|
+ }
|
|
|
+ // 开启审核流
|
|
|
+ else {
|
|
|
+ // 设置状态 已提交审核
|
|
|
+ saleOrder.setWorkflowId(workflow.getId());
|
|
|
+ this.updateById(saleOrder);
|
|
|
+ workflowService.startInstance(workflow.getId(), saleOrder.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 退回的单子 再启用
|
|
|
+ else {
|
|
|
+ this.updateById(saleOrder);
|
|
|
+ workflowService.activateInstance(saleOrder.getWorkflowId(), saleOrder.getId());
|
|
|
+ }
|
|
|
+ if (one) {
|
|
|
+ return "OK";
|
|
|
+ }else{
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除销售订单
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteSaleOrder(String id) {
|
|
|
+ //删除销售订单
|
|
|
+ SaleOrder saleOrder = this.selectById(id);
|
|
|
+ this.deleteById(saleOrder.getId());
|
|
|
+ //删除改价记录
|
|
|
+ List<PriceChangeRecord> priceChangeRecordList = priceChangeRecordService.selectList(new EntityWrapper<PriceChangeRecord>()
|
|
|
+ .eq(PriceChangeRecord.QueryFiles.ORDER_ID, id));
|
|
|
+ if (!CollectionUtils.isEmpty(priceChangeRecordList)) {
|
|
|
+ for (PriceChangeRecord priceChangeRecord : priceChangeRecordList) {
|
|
|
+ priceChangeRecordService.deleteById(priceChangeRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除成交记录
|
|
|
+ List<TransactionRecord> transactionRecordList = transactionRecordService.selectList(new EntityWrapper<TransactionRecord>()
|
|
|
+ .eq(TransactionRecord.QueryFiles.ORDER_ID, id));
|
|
|
+ if (!CollectionUtils.isEmpty(transactionRecordList)) {
|
|
|
+ for (TransactionRecord transactionRecord : transactionRecordList) {
|
|
|
+ transactionRecordService.deleteById(transactionRecord.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 编辑销售订单
|
|
|
+ * @param saleOrder
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public String editSaleOrder(SaleOrder saleOrder) {
|
|
|
+ boolean one = this.updateById(saleOrder);
|
|
|
+ if (one) {
|
|
|
+ return "OK";
|
|
|
+ } else {
|
|
|
+ return "NG";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|