提交 59452129 编写于 作者: misaka's avatar misaka

采购相关

上级 57cddbb3
package cn.ibizlab.businesscentral.core.extensions.service; package cn.ibizlab.businesscentral.core.extensions.service;
import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence_date_range;
import cn.ibizlab.businesscentral.core.odoo_ir.filter.Ir_sequence_date_rangeSearchContext;
import cn.ibizlab.businesscentral.core.odoo_ir.service.impl.Ir_sequenceServiceImpl; import cn.ibizlab.businesscentral.core.odoo_ir.service.impl.Ir_sequenceServiceImpl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence; import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import java.sql.Timestamp;
import java.util.*; import java.util.*;
/** /**
...@@ -23,56 +30,141 @@ public class Ir_sequenceExService extends Ir_sequenceServiceImpl { ...@@ -23,56 +30,141 @@ public class Ir_sequenceExService extends Ir_sequenceServiceImpl {
/** /**
* 自定义行为[Alter_sequence]用户扩展 * 自定义行为[Alter_sequence]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence alter_sequence(Ir_sequence et) { public Ir_sequence alter_sequence(Ir_sequence et) {
String select_sequence = String.format("select relname from pg_class where relkind='S' and relname='ir_sequence_%03d'", "S", et.getId());
List<JSONObject> sequences = this.select(select_sequence, null);
if (sequences.size() == 0)
return et;
StringBuffer alert_swquence = new StringBuffer();
alert_swquence.append(String.format("alter sequence ir_sequence_%03d", et.getId()));
if (et.getNumberIncrement() != null)
alert_swquence.append(String.format(" increment by %d", et.getNumberIncrement()));
if (et.getNumberNext() != null)
alert_swquence.append(String.format(" restart with %d", et.getNumberNext()));
this.select(alert_swquence.toString(), null);
return super.alter_sequence(et); return super.alter_sequence(et);
} }
/** /**
* 自定义行为[Create_sequence]用户扩展 * 自定义行为[Create_sequence]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence create_sequence(Ir_sequence et) { public Ir_sequence create_sequence(Ir_sequence et) {
String create_sequence = String.format("create sequence ir_sequence_%03d increment by %s start with %s", et.getId(), et.getNumberIncrement(), et.getNumberNext());
this.select(create_sequence, null);
return super.create_sequence(et); return super.create_sequence(et);
} }
/** /**
* 自定义行为[Drop_sequence]用户扩展 * 自定义行为[Drop_sequence]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence drop_sequence(Ir_sequence et) { public Ir_sequence drop_sequence(Ir_sequence et) {
String drop_sequence = String.format("drop sequence if exists ir_sequence_%03d restrict ", et.getId());
this.select(drop_sequence, null);
return super.drop_sequence(et); return super.drop_sequence(et);
} }
/** /**
* 自定义行为[Get_next]用户扩展 * 自定义行为[Get_next]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence get_next(Ir_sequence et) { public Ir_sequence get_next(Ir_sequence et) {
if (et.getUseDateRange() == null && !et.getUseDateRange()) {
int number_next = 0;
//标准 序列
if (StringUtils.compare(et.getImplementation(), "standard") == 0) {
this.select_nextval(et);
number_next = et.getNextVal();
} else {
//no_gap
this.update_nogap(et);
number_next = et.getNumberNext();
}
et.setNextChar(String.format("%s%s%s", et.getPrefix() == null ? "" : et.getPrefix(), String.format("%0" + et.getPadding() + "d", number_next), et.getSuffix() == null ? "" : et.getSuffix()));
} else {
if (true)
throw new RuntimeException("暂未实现");
// 带有时间范围
Ir_sequence_date_rangeSearchContext ctx = new Ir_sequence_date_rangeSearchContext();
ctx.setN_sequence_id_eq(et.getId());
List<Ir_sequence_date_range> sequence_date_ranges = irSequenceDateRangeService.searchDefault(ctx).getContent();
Ir_sequence_date_range sequence_date_range = null;
if (sequence_date_ranges.size() == 0) {
sequence_date_range = new Ir_sequence_date_range();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 0);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
sequence_date_range.setDateFrom(new Timestamp(calendar.getTimeInMillis()));
calendar.add(Calendar.YEAR, 1);
calendar.add(Calendar.DAY_OF_MONTH, -1);
sequence_date_range.setDateTo(new Timestamp(calendar.getTimeInMillis()));
sequence_date_range.setSequenceId(et.getId());
sequence_date_range.setNumberNext(0);
irSequenceDateRangeService.create(sequence_date_range);
} else {
sequence_date_range = sequence_date_ranges.get(0);
}
int number_next = 0;
//标准 序列
if (StringUtils.compare(et.getImplementation(), "standard") == 0) {
irSequenceDateRangeService.select_nextval(sequence_date_range);
number_next = sequence_date_range.getNextVal();
} else {
//no_gap
irSequenceDateRangeService.update_nogap(sequence_date_range);
number_next = sequence_date_range.getNextVal();
}
et.setNextChar(String.format("%s%s%s", et.getPrefix() == null ? "" : et.getPrefix(), String.format("%0" + et.getPadding() + "d", number_next), et.getSuffix() == null ? "" : et.getSuffix()));
}
return super.get_next(et); return super.get_next(et);
} }
/** /**
* 自定义行为[Get_next_by_code]用户扩展 * 自定义行为[Get_next_by_code]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence get_next_by_code(Ir_sequence et) { public Ir_sequence get_next_by_code(Ir_sequence et) {
return super.get_next_by_code(et); if (false) {
et.setCompanyId(0l);
} }
et = this.getOne(new QueryWrapper<Ir_sequence>().setEntity(et));
return super.get_next(et);
}
/** /**
* 自定义行为[Predict_nextval]用户扩展 * 自定义行为[Predict_nextval]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
...@@ -81,24 +173,33 @@ public class Ir_sequenceExService extends Ir_sequenceServiceImpl { ...@@ -81,24 +173,33 @@ public class Ir_sequenceExService extends Ir_sequenceServiceImpl {
public Ir_sequence predict_nextval(Ir_sequence et) { public Ir_sequence predict_nextval(Ir_sequence et) {
return super.predict_nextval(et); return super.predict_nextval(et);
} }
/** /**
* 自定义行为[Select_nextval]用户扩展 * 自定义行为[Select_nextval]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence select_nextval(Ir_sequence et) { public Ir_sequence select_nextval(Ir_sequence et) {
List<JSONObject> data = this.select(String.format("SELECT nextval('ir_sequence_%03d')", et.getId()), null);
int nextval = data.get(0).getInteger("nextval");
et.setNextVal(nextval);
return super.select_nextval(et); return super.select_nextval(et);
} }
/** /**
* 自定义行为[Update_nogap]用户扩展 * 自定义行为[Update_nogap]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Ir_sequence update_nogap(Ir_sequence et) { public Ir_sequence update_nogap(Ir_sequence et) {
et.setNumberNext(et.getNumberNext() + et.getNumberIncrement());
this.update(et);
return super.update_nogap(et); return super.update_nogap(et);
} }
} }
......
package cn.ibizlab.businesscentral.core.extensions.service; package cn.ibizlab.businesscentral.core.extensions.service;
import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence;
import cn.ibizlab.businesscentral.core.odoo_ir.service.impl.Ir_sequence_date_rangeServiceImpl; import cn.ibizlab.businesscentral.core.odoo_ir.service.impl.Ir_sequence_date_rangeServiceImpl;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence_date_range; import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence_date_range;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -39,6 +41,9 @@ public class Ir_sequence_date_rangeExService extends Ir_sequence_date_rangeServi ...@@ -39,6 +41,9 @@ public class Ir_sequence_date_rangeExService extends Ir_sequence_date_rangeServi
@Override @Override
@Transactional @Transactional
public Ir_sequence_date_range select_nextval(Ir_sequence_date_range et) { public Ir_sequence_date_range select_nextval(Ir_sequence_date_range et) {
List<JSONObject> data = this.select(String.format("SELECT nextval('ir_sequence_%03d_%03d')",et.getSequenceId(), et.getId()), null);
int nextval = data.get(0).getInteger("nextval");
et.setNextVal(nextval);
return super.select_nextval(et); return super.select_nextval(et);
} }
/** /**
...@@ -49,6 +54,9 @@ public class Ir_sequence_date_rangeExService extends Ir_sequence_date_rangeServi ...@@ -49,6 +54,9 @@ public class Ir_sequence_date_rangeExService extends Ir_sequence_date_rangeServi
@Override @Override
@Transactional @Transactional
public Ir_sequence_date_range update_nogap(Ir_sequence_date_range et) { public Ir_sequence_date_range update_nogap(Ir_sequence_date_range et) {
Ir_sequence sequence = irSequenceService.get(et.getSequenceId());
et.setNumberNext(et.getNumberNext() + sequence.getNumberIncrement());
this.update(et);
return super.update_nogap(et); return super.update_nogap(et);
} }
} }
......
package cn.ibizlab.businesscentral.core.extensions.service; package cn.ibizlab.businesscentral.core.extensions.service;
import cn.ibizlab.businesscentral.core.odoo_ir.domain.Ir_sequence;
import cn.ibizlab.businesscentral.core.odoo_ir.service.IIr_sequenceService;
import cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_order;
import cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_requisition_line;
import cn.ibizlab.businesscentral.core.odoo_purchase.service.impl.Purchase_requisitionServiceImpl; import cn.ibizlab.businesscentral.core.odoo_purchase.service.impl.Purchase_requisitionServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_requisition; import cn.ibizlab.businesscentral.core.odoo_purchase.domain.Purchase_requisition;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import java.util.*; import java.util.*;
/** /**
...@@ -16,6 +24,9 @@ import java.util.*; ...@@ -16,6 +24,9 @@ import java.util.*;
@Service("Purchase_requisitionExService") @Service("Purchase_requisitionExService")
public class Purchase_requisitionExService extends Purchase_requisitionServiceImpl { public class Purchase_requisitionExService extends Purchase_requisitionServiceImpl {
@Autowired
IIr_sequenceService sequenceService;
@Override @Override
protected Class currentModelClass() { protected Class currentModelClass() {
return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1); return com.baomidou.mybatisplus.core.toolkit.ReflectionKit.getSuperClassGenericType(this.getClass().getSuperclass(), 1);
...@@ -23,62 +34,148 @@ public class Purchase_requisitionExService extends Purchase_requisitionServiceIm ...@@ -23,62 +34,148 @@ public class Purchase_requisitionExService extends Purchase_requisitionServiceIm
/** /**
* 自定义行为[Action_cancel]用户扩展 * 自定义行为[Action_cancel]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition action_cancel(Purchase_requisition et) { public Purchase_requisition action_cancel(Purchase_requisition et) {
//purchase_order cancel
log.warn("purchase_order");
et.setState("cancel");
this.update(et);
return super.action_cancel(et); return super.action_cancel(et);
} }
/** /**
* 自定义行为[Action_done]用户扩展 * 自定义行为[Action_done]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition action_done(Purchase_requisition et) { public Purchase_requisition action_done(Purchase_requisition et) {
List<Purchase_order> orders = purchaseOrderService.selectByRequisitionId(et.getId());
for (Purchase_order order:orders ) {
if(StringUtils.compare(order.getState(),"draft")==0||StringUtils.compare(order.getState(),"sent")==0||StringUtils.compare(order.getState(),"to approve")==0){
throw new RuntimeException("关闭采购申请单前,你必须取消或批准每个RFQ采购订单。") ;
}
}
List<Purchase_requisition_line> lines = purchaseRequisitionLineService.selectByRequisitionId(et.getId());
//移除 line 关联 supplierinfo
log.warn("移除 line 关联 supplierinfo");
et.setState("done");
this.update(et);
return super.action_done(et); return super.action_done(et);
} }
/** /**
* 自定义行为[Action_draft]用户扩展 * 自定义行为[Action_draft]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition action_draft(Purchase_requisition et) { public Purchase_requisition action_draft(Purchase_requisition et) {
et.setName("New");
et.setState("draft");
this.update(et);
return super.action_draft(et); return super.action_draft(et);
} }
/** /**
* 自定义行为[Action_in_progress]用户扩展 * 自定义行为[Action_in_progress]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition action_in_progress(Purchase_requisition et) { public Purchase_requisition action_in_progress(Purchase_requisition et) {
et = this.get(et.getId());
List<Purchase_requisition_line> lines = purchaseRequisitionLineService.selectByRequisitionId(et.getId());
if (lines.size() == 0) {
throw new RuntimeException(String.format("没有明细行,无法确认此申请单 '%s'", et.getName()));
}
if (StringUtils.compare(et.getQuantityCopy(), "none") == 0 && et.getVendorId() != null) {
for (Purchase_requisition_line line : lines) {
if (line.getPriceUnit() <= 0) {
throw new RuntimeException("你无法确认没有单价的单一供应商采购申请单。");
}
if (line.getProductQty() <= 0) {
throw new RuntimeException("你无法确认没有数量的单一供应商采购申请单");
}
//关联 create_supplier_info
log.warn("关联 create_supplier_info");
}
et.setState("ongoing");
} else {
et.setState("in_progress");
}
if (StringUtils.compare(et.getName(), "New") == 0) {
Ir_sequence sequence = new Ir_sequence();
if (StringUtils.compare(et.getQuantityCopy(), "none") != 0) {
sequence.setCode("purchase.requisition.purchase.tender");
} else {
sequence.setCode("purchase.requisition.blanket.order");
}
sequenceService.get_next_by_code(sequence);
et.setName(sequence.getNextChar());
}
this.update(et);
return super.action_in_progress(et); return super.action_in_progress(et);
} }
/** /**
* 自定义行为[Action_open]用户扩展 * 自定义行为[Action_open]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition action_open(Purchase_requisition et) { public Purchase_requisition action_open(Purchase_requisition et) {
et.setState("open");
this.update(et);
return super.action_open(et); return super.action_open(et);
} }
@Override
public boolean remove(Long key) {
Purchase_requisition et = this.get(key);
if(StringUtils.compare(et.getState(),"draft")!=0||StringUtils.compare(et.getState(),"cancel")!=0){
throw new RuntimeException("你只能删除草稿申请单。");
}
purchaseRequisitionLineService.removeByRequisitionId(key);
return super.remove(key);
}
/** /**
* 自定义行为[MasterTabCount]用户扩展 * 自定义行为[MasterTabCount]用户扩展
*
* @param et * @param et
* @return * @return
*/ */
@Override @Override
@Transactional @Transactional
public Purchase_requisition masterTabCount(Purchase_requisition et) { public Purchase_requisition masterTabCount(Purchase_requisition et) {
et = this.get(et.getId());
//采购订单
if (StringUtils.compare(et.getState(), "draft") == 0) {
et.setOrderCount(0);
} else {
Purchase_order order = new Purchase_order();
order.setRequisitionId(et.getId());
et.setOrderCount(purchaseOrderService.count(new QueryWrapper<Purchase_order>().setEntity(order)));
}
return super.masterTabCount(et); return super.masterTabCount(et);
} }
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册