use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.
the class ContractController method add.
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public Result add(String contract, String contractSign, String requisitionForms) {
if (contract == null || "".equals(contract)) {
return ResultGenerator.genFailResult("合同信息为空!");
}
if (contractSign == null || "".equals(contractSign)) {
return ResultGenerator.genFailResult("合同审核初始化信息为空!");
}
if (requisitionForms == null || "".equals(requisitionForms)) {
return ResultGenerator.genFailResult("订单信息为空!");
}
Contract contract1 = JSONObject.parseObject(contract, Contract.class);
if (contract1 == null) {
return ResultGenerator.genFailResult("Contract对象JSON解析失败!");
}
// Condition condition = new Condition(Contract.class);
// condition.createCriteria().andCondition("contract_num = ", contract1.getContractNum());
// List<Contract> list = contractService.findByCondition(condition);
List<Contract> list = contractService.isContractExist(contract1.getContractNum());
if (list.size() != 0) {
logger.error("合同编号已存在");
return ResultGenerator.genFailResult("合同编号已存在!请换一个编号");
}
contract1.setCreateTime(new Date());
contractService.saveAndGetID(contract1);
Integer contractId = contract1.getId();
// /插入contract审核记录
ContractSign contractSignObj = new ContractSign();
contractSignObj.setContractId(contractId);
contractSignObj.setCreateTime(new Date());
contractSignObj.setSignContent(contractSign);
// /新增合同签核记录时,插入空值
contractSignObj.setCurrentStep("");
contractSignService.save(contractSignObj);
// 插入需求单记录
List<MachineOrderWrapper> machineOrderWapperList = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
if (machineOrderWapperList != null) {
// 是内贸还是外贸的订单
String salesDepartment = null;
User machineOrderCreator = null;
for (int i = 0; i < machineOrderWapperList.size(); i++) {
OrderDetail temp = machineOrderWapperList.get(i).getOrderDetail();
MachineOrder orderTemp = machineOrderWapperList.get(i).getMachineOrder();
orderDetailService.saveAndGetID(temp);
orderTemp.setOrderDetailId(temp.getId());
orderTemp.setContractId(contractId);
orderTemp.setStatus(Constant.ORDER_INITIAL);
Condition condition2 = new Condition(Contract.class);
condition2.createCriteria().andCondition("order_num = ", orderTemp.getOrderNum()).andCondition("valid = ", 1);
List<MachineOrder> orderList = machineOrderService.findByCondition(condition2);
if (orderList.size() != 0) {
logger.error("订单号已存在!请换一个");
return ResultGenerator.genFailResult("订单号已存在!请换一个");
}
machineOrderService.saveAndGetID(orderTemp);
// 初始化需求单审核记录
OrderSign orderSignData = machineOrderWapperList.get(i).getOrderSign();
OrderSign orderSign = new OrderSign();
orderSign.setSignContent(orderSignData.getSignContent());
orderSign.setOrderId(orderTemp.getId());
orderSign.setCreateTime(new Date());
orderSign.setCurrentStep("");
// 是内贸还是外贸 --> 因为要查询订单是哪个部门,所以要细化到外贸一部还是二部
if (salesDepartment == null) {
machineOrderCreator = userService.findById(orderTemp.getCreateUserId());
if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_DOMESTIC)) {
salesDepartment = Constant.STR_DEPARTMENT_DOMESTIC;
} else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_1)) {
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
} else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_2)) {
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_2;
} else if (machineOrderCreator.getRoleId() == Constant.ROLE_ID_FOREIGN_DIRECTOR) {
/**
* 外贸总监的MarketGroupName部门为空, 外贸总监录的订单,也算为一部的。
* 外贸经理的MarketGroupName部门为外贸二部
*/
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
}
orderSign.setSalesDepartment(salesDepartment);
}
orderSignService.saveAndGetID(orderSign);
// 第一个轮到签核的人也发消息推送 --> 此时为未提交状态,不需要发推送
}
} else {
// 手动回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return ResultGenerator.genFailResult("需求单为空!");
}
// 返回ID给前端,前端新增合同时不关闭页面。
return ResultGenerator.genSuccessResult(contract1.getId());
}
use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.
the class ContractController method update.
@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String contract, String requisitionForms) {
Contract contract1 = JSONObject.parseObject(contract, Contract.class);
List<MachineOrderWrapper> machineOrderWapperlist = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
// 先获取当前合同的所有订单
List<MachineOrderDetail> originalOrderList = machineOrderService.selectOrder(null, contract1.getId(), null, null, null, null, null, null, null, null, null, null, null, null, null, false);
// /删除该合同下,不在本次保存范围内的需求单
for (MachineOrderDetail item : originalOrderList) {
boolean exist = false;
/**
* web有时会发来有问题的requisitionForms
*/
if (machineOrderWapperlist == null) {
logger.error("machineOrderWapperlist is null, return;");
return ResultGenerator.genFailResult("machineOrderWapperlist is null, nothing updated");
}
if (requisitionForms.isEmpty() || requisitionForms == null) {
logger.error("requisitionForms is empty/null, return;");
return ResultGenerator.genFailResult("requisitionForms is empty/null, nothing updated");
}
for (MachineOrderWrapper wapperItem : machineOrderWapperlist) {
// null
if (item.getId().equals(wapperItem.getMachineOrder().getId())) {
exist = true;
break;
}
}
if (!exist) {
// 删除需求单审核记录
OrderSign orderSign = orderSignService.findBy("orderId", item.getId());
if (orderSign != null) {
orderSignService.deleteById(orderSign.getId());
}
// 删除需求单 ....
/**
* 同时要删除对应的设计单.
* 比如,在更新订单时,改了订单号,旧的订单会被删除,此时如果没有删除对应设计单,会无法删除订单。
* 后来改为订单审核完成才生成设计单,上述情形应该不存在了。
*/
deleteDDIbyOrder(item);
machineOrderService.deleteById(item.getId());
// 删除detail
orderDetailService.deleteById(item.getOrderDetailId());
}
}
for (MachineOrderWrapper item : machineOrderWapperlist) {
// 是内贸还是外贸的订单
String salesDepartment = null;
User machineOrderCreator = null;
MachineOrder orderTemp = item.getMachineOrder();
OrderChangeRecord changeRecord = item.getOrderChangeRecord();
if (orderTemp.getId() != null && orderTemp.getId() != 0) {
// 更新,只对initial和reject状态的需求单就是更新,其他状态的需求单不做更新
OrderDetail temp = item.getOrderDetail();
if (orderTemp.getStatus().equals(Constant.ORDER_REJECTED)) {
orderTemp.setStatus(Constant.ORDER_INITIAL);
}
if (orderTemp.getStatus().equals(Constant.ORDER_INITIAL)) {
orderDetailService.update(temp);
machineOrderService.update(orderTemp);
commonService.syncMachineOrderStatusInDesignDepInfo(orderTemp);
// 在改单之后,在重新提交之前,允许修改改单原因,即:改单原因不仅仅在改单时允许修改,在上述情况下也允许修改。
if (null != changeRecord) {
orderChangeRecordService.update(changeRecord);
}
}
} else {
// 新增
OrderDetail temp = item.getOrderDetail();
orderDetailService.saveAndGetID(temp);
orderTemp.setOrderDetailId(temp.getId());
orderTemp.setContractId(contract1.getId());
orderTemp.setStatus(Constant.ORDER_INITIAL);
machineOrderService.saveAndGetID(orderTemp);
// 初始化需求单审核记录
OrderSign orderSignData = item.getOrderSign();
OrderSign orderSign = new OrderSign();
orderSign.setSignContent(orderSignData.getSignContent());
orderSign.setOrderId(orderTemp.getId());
orderSign.setCreateTime(new Date());
// 是内贸还是外贸一部,二部
if (salesDepartment == null) {
machineOrderCreator = userService.findById(orderTemp.getCreateUserId());
if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_DOMESTIC)) {
salesDepartment = Constant.STR_DEPARTMENT_DOMESTIC;
} else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_1)) {
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
} else if (machineOrderCreator.getMarketGroupName().equals(Constant.STR_DEPARTMENT_FOREIGN_2)) {
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_2;
} else if (machineOrderCreator.getRoleId() == Constant.ROLE_ID_FOREIGN_DIRECTOR) {
/**
* 外贸总监的MarketGroupName部门为空, 外贸总监录的订单,也算为一部的。
* 外贸经理的MarketGroupName部门为外贸二部
*/
salesDepartment = Constant.STR_DEPARTMENT_FOREIGN_1;
}
orderSign.setSalesDepartment(salesDepartment);
}
orderSignService.save(orderSign);
}
}
// 前端只要操作了“保存”,合同的状态回到“CONTRACT_INITIAL”状态
contract1.setStatus(Constant.CONTRACT_INITIAL);
contract1.setUpdateTime(new Date());
contractService.update(contract1);
// 检查需求单中的销售员和合同中销售员是否一致,如果不一致则更新需求单中的销售员
for (MachineOrderWrapper item : machineOrderWapperlist) {
if (!item.getMachineOrder().getSellman().equals(contract1.getSellman())) {
MachineOrder order = new MachineOrder();
order.setId(item.getMachineOrder().getId());
// 只更新销售员
order.setSellman(contract1.getSellman());
machineOrderService.update(order);
}
}
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.
the class ContractController method updateValid.
@PostMapping("/updateValid")
public Result updateValid(@RequestParam Integer id) {
if (id < 1) {
return ResultGenerator.genFailResult("合同编号不正确,请检查!");
}
Contract contractObj = new Contract();
contractObj.setId(id);
contractObj.setIsValid((Constant.ValidEnum.INVALID.getValue()).toString());
contractObj.setUpdateTime(new Date());
contractService.update(contractObj);
return ResultGenerator.genSuccessResult();
}
use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.
the class ContractController method changeOrder.
/**
* 联系单审核通过才允许改单,
* 改单后新生成的订单不用再审批,因为联系单已经审核过了。
*/
@PostMapping("/changeOrder")
@Transactional(rollbackFor = Exception.class)
public Result changeOrder(String contract, String contractSign, String requisitionForms) {
logger.info("changeOrder=======:");
logger.info(requisitionForms);
if (contract == null || "".equals(contract)) {
return ResultGenerator.genFailResult("合同信息为空!");
}
if (contractSign == null || "".equals(contractSign)) {
return ResultGenerator.genFailResult("合同审核初始化信息为空!");
}
if (requisitionForms == null || "".equals(requisitionForms)) {
return ResultGenerator.genFailResult("订单信息为空!");
}
Contract contract1 = JSONObject.parseObject(contract, Contract.class);
if (contract1 == null) {
return ResultGenerator.genFailResult("Contract对象JSON解析失败!");
}
// 更改合同的状态为“改单”
contract1.setStatus(Constant.CONTRACT_CHANGED);
contract1.setUpdateTime(new Date());
contractService.update(contract1);
Integer contractId = contract1.getId();
// /插入新的contract审核记录
ContractSign contractSignObj = new ContractSign();
contractSignObj.setContractId(contractId);
contractSignObj.setCreateTime(new Date());
contractSignObj.setSignContent(contractSign);
// /插入空值
contractSignObj.setCurrentStep("");
contractSignService.save(contractSignObj);
// 新增的改单处理
// 返回新增的改单的ID号给前端,前端新增改单时不关闭页面。
int newMachineOrderId = 0;
List<MachineOrderWrapper> machineOrderWrapperList = JSONObject.parseArray(requisitionForms, MachineOrderWrapper.class);
for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
MachineOrder machineOrder = orderItem.getMachineOrder();
// 检查时候存在有效的需求单,如果需求单中存在ID,则表示其已经在数据库中存在;修复同一个合同中多次改单(未提交审核)出现重复的需求单的问题
if (machineOrder.getStatus().equals(Constant.ORDER_INITIAL) && machineOrder.getOriginalOrderId() != 0 && (machineOrder.getId() == null || machineOrder.getId() == 0)) {
// 插入新增改单项的detail
OrderDetail temp = orderItem.getOrderDetail();
orderDetailService.saveAndGetID(temp);
machineOrder.setOrderDetailId(temp.getId());
machineOrder.setContractId(contract1.getId());
// 改单的前提是原订单已审核完成,联系单已经审核通过,所以不需要再重新审核,
machineOrder.setStatus(Constant.ORDER_CHANGE_FINISHED);
machineOrder.setCreateTime(new Date());
machineOrderService.saveAndGetID(machineOrder);
// /设计单里的状态 也要改 -->改的地方多,统一放在定时器里去更新状态-->废弃,因为订单可能很多
newMachineOrderId = machineOrder.getId();
/**
* 为了让改单后的新订单也能看到签核的时间等,改单新生成的订单,也有对应的审核记录,
* 审核内容和步骤,来自于旧的审核记录。(和原订单的一样的签核记录)
*/
// 初始化需求单审核记录
OrderSign orderSignData = orderItem.getOrderSign();
OrderSign orderSign = new OrderSign();
orderSign.setSignContent(orderSignData.getSignContent());
orderSign.setOrderId(machineOrder.getId());
orderSign.setCreateTime(orderSignData.getCreateTime());
orderSign.setCurrentStep(orderSignData.getCurrentStep());
orderSign.setUpdateTime(orderSignData.getUpdateTime());
orderSignService.save(orderSign);
// 改单记录(插入或者修改)
OrderChangeRecord changeRecord = orderItem.getOrderChangeRecord();
if (changeRecord.getId() == null) {
changeRecord.setChangeTime(new Date());
orderChangeRecordService.save(changeRecord);
} else {
changeRecord.setChangeTime(new Date());
orderChangeRecordService.update(changeRecord);
}
}
}
for (MachineOrderWrapper orderItem : machineOrderWrapperList) {
MachineOrder machineOrder = orderItem.getMachineOrder();
/**
* 一个合同下,多个订单,多个改单
* 前面已经被改好的改单,状态为 ORDER_CHANGED, 改好后的订单 状态为 ORDER_CHANGE_FINISHED
* 改单刚刚开始时(还在改单中),状态为 ORDER_CHANGE_ING, 由前端传过来,
* 这种情况表示正在改单,要把状态设置为 ORDER_CHANGED,其他的照旧处理
* 之所以分 ORDER_CHANGE_ING、ORDER_CHANGED,是因为为了修复 多个订单都改单的情况下,对应的机器数量会处理不对
* 一个订单改单-不改机器数量:OK
* 一个订单改单-新增机器数量:OK
* 一个订单改单-减少机器数量:OK
*
* 2个订单都改单-不改机器数量:OK
* 2个订单都改单-新增机器数量:ok
* 2个订单都改单-减少机器数量:OK
*/
if (machineOrder.getStatus().equals(Constant.ORDER_CHANGE_ING)) {
// 更新了被改的需求单为“改单”,持久化至数据库
machineOrder.setUpdateTime(new Date());
machineOrder.setStatus(Constant.ORDER_CHANGED);
machineOrderService.update(machineOrder);
// 获取被改单对应机器,设置改单状态(machine)
Condition tempCondition = new Condition(Machine.class);
tempCondition.createCriteria().andCondition("order_id = ", machineOrder.getId());
// /被改订单的
List<Machine> machineList = machineService.findByCondition(tempCondition);
// 寻找对应新生成的需求单,比较机器数
MachineOrder newOrder = null;
for (MachineOrderWrapper wrapper : machineOrderWrapperList) {
if (wrapper.getMachineOrder().getOriginalOrderId().equals(machineOrder.getId())) {
newOrder = wrapper.getMachineOrder();
break;
}
}
if (newOrder != null) {
// 改单后,机器数量不变或者变少了,需要把这部分机器设置为取消(无论是否已生产)
if (newOrder.getMachineNum() <= machineList.size()) {
logger.info("改单后,机器数量不变或者变少了, 新订单的机器数: " + newOrder.getMachineNum());
// step1 按新订单的机器数量,把 被改订单的机器 挂到新生成的订单
for (int m = 0; m < newOrder.getMachineNum(); m++) {
Machine machine = machineList.get(m);
// /初始化、取消状态,直接将机器的上的需求单号直接绑定到新需求单。 其他状态的机器则改为 改单
logger.info("新生成的订单号" + newOrder.getOrderNum() + "的 【实际的】 机器编号: " + machine.getNameplate() + ",状态: " + machine.getStatus());
if (machine.getStatus().equals(Constant.MACHINE_INITIAL) || machine.getStatus().equals(Constant.MACHINE_CANCELED)) {
} else {
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
// /有改单状态的机器,通知全部安装组长
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(newOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
msg.setType(ServerToClientMsg.MsgType.ORDER_CHANGE);
mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_STATUS_CHANGE, JSON.toJSONString(msg));
}
machine.setOrderId(newOrder.getId());
machine.setUpdateTime(new Date());
machineService.update(machine);
}
// //step2把被改订单里剩下的机器设置为取消
/**
* 因为在改单时不确定哪些机子在生产了,所以管理员根据需要可以在"生产管理"页面,根据实际情况调整机器铭牌号。
*/
tempCondition.createCriteria().andCondition("order_id = ", machineOrder.getId());
List<Machine> machineToBeCancelledList = machineService.findByCondition(tempCondition);
for (Machine machine : machineToBeCancelledList) {
// 如果机器数量不变,这里为0
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
machine.setUpdateTime(new Date());
logger.info("把剩下的机器设置为取消 " + machine.getNameplate());
machineService.update(machine);
}
} else {
/**
* 改单后,机器数量增加了,需要新增机器 ,原先:多出部分机器在审核完成以后自动添加
* --> 2020-0409:有联系单后不再需要审核订单了,所以需要在此生成机器。
*/
logger.info("改单前,原订单机器数量: " + machineList.size());
logger.info("改单后,机器数量增加到了: " + newOrder.getMachineNum());
// //step1 把 被改订单的机器 全部之间挂到新生成的订单,即旧订单就没机器了。
for (int n = 0; n < machineList.size(); n++) {
Machine machine = machineList.get(n);
// /初始化、取消状态,直接将机器的上的需求单号直接绑定到新需求单。 其他状态的机器则改为 改单 (为啥这样?全部改成改单不行吗)
logger.info("新生成的订单号" + newOrder.getOrderNum() + "的 【实际的】 机器编号: " + machine.getNameplate() + ",状态: " + machine.getStatus());
if (machine.getStatus().equals(Constant.MACHINE_INITIAL) || machine.getStatus().equals(Constant.MACHINE_CANCELED)) {
} else {
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
// /有改单状态的机器,通知全部安装组长
ServerToClientMsg msg = new ServerToClientMsg();
msg.setOrderNum(newOrder.getOrderNum());
msg.setNameplate(machine.getNameplate());
msg.setType(ServerToClientMsg.MsgType.ORDER_CHANGE);
mqttMessageHelper.sendToClient(Constant.S2C_MACHINE_STATUS_CHANGE, JSON.toJSONString(msg));
}
machine.setOrderId(newOrder.getId());
machine.setUpdateTime(new Date());
machineService.update(machine);
}
// //step2 再补足 新增的机器
int haveToCreate = newOrder.getMachineNum() - machineList.size();
logger.info("订单" + newOrder.getOrderNum() + ",需要新增机器台数:" + haveToCreate);
for (int c = 0; c < haveToCreate; c++) {
Machine machine = new Machine();
machine.setMachineStrId(Utils.createMachineBasicId() + c);
machine.setOrderId(newOrder.getId());
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_INITIAL)));
machine.setMachineType(newOrder.getMachineType());
machine.setCreateTime(new Date());
if (newOrder.getAllUrgent() == null || !newOrder.getAllUrgent()) {
machine.setIsUrgent(false);
} else {
machine.setIsUrgent(true);
}
machineService.save(machine);
logger.info("have created machine's id: " + machine.getId());
}
}
/* 20180323精简了算法,对于被改的需求单,除了初始化和取消状态的机器保持状态不变,其他机器都设置为该到为状态
if (newOrder.getMachineNum() >= machineOrder.getMachineNum()) {
for (Machine machine : machineList) {
///初始化状态,直接将机器的上的需求单号直接绑定到新需求单
if (machine.getStatus().equals(Constant.MACHINE_INITIAL)) {
} else {
machine.setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
}
machine.setOrderId(newOrder.getId());
machine.setUpdateTime(new Date());
machineService.update(machine);
}
} else {
List<Machine> originalInitialMachine = new ArrayList<>();
List<Machine> originalInitialedMachine = new ArrayList<>();
List<Machine> originalOtherMachine = new ArrayList<>();
for (Machine machine : machineList) {
if (machine.getStatus().equals(Constant.MACHINE_CONFIGURED)
||machine.getStatus().equals(Constant.MACHINE_PLANING)
|| machine.getStatus().equals( Constant.MACHINE_INSTALLING)
|| machine.getStatus().equals(Constant.MACHINE_INSTALLED)
|| machine.getStatus().equals(Constant.MACHINE_SPLITED)) {
///查找已配置、计划中、生产中、被拆单、生产完成的机器
originalInitialedMachine.add(machine);
} else if (machine.getStatus().equals(Constant.MACHINE_INITIAL)) {
///初始化状态,未开始计划
originalInitialMachine.add(machine);
} else {
originalOtherMachine.add(machine);
}
}
int addedNum = 0;
//生产中的机器优先处理
for (int i = 0; i < originalInitialedMachine.size(); i++) {
if (addedNum < newOrder.getMachineNum()) {
originalInitialedMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
addedNum++;
} else {
originalInitialedMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
}
originalInitialedMachine.get(i).setOrderId(newOrder.getId());
//更新
machineService.update(originalInitialedMachine.get(i));
}
//未计划的机器其次处理
for (int i = 0; i < originalInitialMachine.size(); i++) {
if (addedNum < newOrder.getMachineNum()) {
///TODO:是否可以保持“MACHINE_INITIAL”状态不变,因为此时机器还没有计划,也就是说没有对其设置安装流程
//originalInitialMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
addedNum++;
originalInitialMachine.get(i).setOrderId(newOrder.getId());
machineService.update(originalInitialMachine.get(i));
} else {
//删除
machineService.deleteById(originalInitialMachine.get(i).getId());
}
}
//目前只有删除状态的机器(MACHINE_CANCELED)
for (int i = 0; i < originalOtherMachine.size(); i++) {
if (addedNum < newOrder.getMachineNum()) {
originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CHANGED)));
originalOtherMachine.get(i).setOrderId(newOrder.getId());
machineService.update(originalInitialMachine.get(i));
addedNum++;
} else {
originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
machineService.update(originalInitialMachine.get(i));
}
///对于删除状态的机器不做处理
// else {
// originalOtherMachine.get(i).setStatus(Byte.parseByte(String.valueOf(Constant.MACHINE_CANCELED)));
// machineService.update(originalInitialMachine.get(i));
// }
}
}
*/
} else {
// /在同一个合同中没有找到新的需求单,抛出异常
throw new RuntimeException();
}
}
}
return ResultGenerator.genSuccessResult(newMachineOrderId);
}
use of com.eservice.api.model.contract.Contract in project sinsim by WilsonHu.
the class MachineOrderController method exportToSaleExcel.
@PostMapping("/exportToSaleExcel")
public Result exportToSaleExcel(Integer id, Integer contract_id, String order_num, String contract_num, String status, String sellman, String customer, String marketGroupName, // 这个是查询创建日期
String query_start_time, // 这个是查询创建日期
String query_finish_time, // 这个是查询审核日期
String queryStartTimeSign, // 这个是查询审核日期
String queryFinishTimeSign, String machine_name, String oderSignCurrentStep, String searchDepartment, @RequestParam(defaultValue = "true") Boolean is_fuzzy) {
List<MachineOrderDetail> list = machineOrderService.selectOrder(id, contract_id, order_num, contract_num, status, sellman, customer, marketGroupName, query_start_time, query_finish_time, queryStartTimeSign, queryFinishTimeSign, machine_name, oderSignCurrentStep, searchDepartment, is_fuzzy);
HSSFWorkbook wb = null;
FileOutputStream out = null;
String downloadPath = "";
/*
返回给docker外部下载
*/
String downloadPathForNginx = "";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
try {
// 生成一个空的Excel文件
wb = new HSSFWorkbook();
Sheet sheet1 = wb.createSheet("销售报表");
// 设置标题行格式
HSSFCellStyle headcellstyle = wb.createCellStyle();
HSSFFont headfont = wb.createFont();
headfont.setFontHeightInPoints((short) 10);
// 粗体显示
headfont.setBold(true);
headcellstyle.setFont(headfont);
Row row;
// 新创建一行,行号为row+1
row = sheet1.createRow(0);
int columnSum = 22;
for (int c = 0; c < columnSum; c++) {
// 列头
// 创建一个单元格,列号为col+1
row.createCell(c);
sheet1.setColumnWidth(c, 4500);
sheet1.getRow(0).getCell(c).setCellStyle(headcellstyle);
}
// 第一行为标题
int columnX = 0;
sheet1.getRow(0).getCell(columnX++).setCellValue("客户");
sheet1.getRow(0).getCell(columnX++).setCellValue("国家");
sheet1.getRow(0).getCell(columnX++).setCellValue("部门");
sheet1.getRow(0).getCell(columnX++).setCellValue("合同号");
sheet1.getRow(0).getCell(columnX++).setCellValue("订单号");
// sheet1.getRow(0).getCell(3).setCellValue("铭牌号");
sheet1.getRow(0).getCell(columnX++).setCellValue("机器信息");
sheet1.getRow(0).getCell(columnX++).setCellValue("台数");
sheet1.getRow(0).getCell(columnX++).setCellValue("单价");
sheet1.getRow(0).getCell(columnX++).setCellValue("装置");
sheet1.getRow(0).getCell(columnX++).setCellValue("装置数量");
sheet1.getRow(0).getCell(columnX++).setCellValue("装置总价");
sheet1.getRow(0).getCell(columnX++).setCellValue("优惠金额");
sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(美元)");
sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(人民币)");
sheet1.getRow(0).getCell(columnX++).setCellValue("订单总金额(欧元)");
// sheet1.getRow(0).getCell(columnX++).setCellValue("币种");
sheet1.getRow(0).getCell(columnX++).setCellValue("销售员");
// 销售费
sheet1.getRow(0).getCell(columnX++).setCellValue("业务费");
sheet1.getRow(0).getCell(columnX++).setCellValue("付款方式");
sheet1.getRow(0).getCell(columnX++).setCellValue("毛利");
sheet1.getRow(0).getCell(columnX++).setCellValue("订单类型");
sheet1.getRow(0).getCell(columnX++).setCellValue("保修费");
sheet1.getRow(0).getCell(columnX++).setCellValue("签核完成时间");
DataFormat dataFormat = wb.createDataFormat();
CellStyle cellStyle;
HSSFCellStyle wrapStyle = wb.createCellStyle();
wrapStyle.setWrapText(true);
// 第二行开始,填入值
// 各订单的装置数量-合计
int allOrdersEquipmentCount = 0;
// 各订单的装置总价-合计
int allOrdersEquipemntAmountCount = 0;
// 各订单的优惠金额-合计
int allOrdersDiscountCount = 0;
// 各订单订单总金额(美元) 合计
int allOrdersTotalPriceCount_USD = 0;
// 各订单订单总金额(人民币)合计
int allOrdersTotalPriceCount_RMB = 0;
// 各订单订单总金额(欧元)合计
int allOrdersTotalPriceCount_EUR = 0;
cellStyle = wb.createCellStyle();
// 金额格式
cellStyle.setDataFormat(dataFormat.getFormat("#,##0.00"));
for (int i = 0; i < list.size(); i++) {
String dateStringSignFinish = "未完成签核";
int r = i + 1;
MachineOrderDetail mod = list.get(i);
// 新创建一行
row = sheet1.createRow(r);
for (int c = 0; c < columnSum; c++) {
// 创建列单元格
row.createCell(c);
}
// 合同的内容也用到
Contract contract = contractService.findById(list.get(i).getContractId());
if (contract == null) {
logger.error("异常,根据合同ID号,查找不到合同");
return ResultGenerator.genFailResult("异常,根据合同ID号,查找不到合同");
}
// 签核也用到:签核完成时间
List<OrderSign> orderSignList = orderSignService.getOrderSignListByOrderId(mod.getOrderSign().getOrderId());
OrderSign orderSign = null;
List<SignContentItem> signContentItemList = null;
if (orderSignList.size() > 0) {
// 订单的签核记录只有在新增合同-订单时,才创建订单的签核记录,所以这里 getOrderSignListByOrderId其实只返回一个签核记录
orderSign = orderSignList.get(orderSignList.size() - 1);
if (orderSign.getCurrentStep() == null) {
logger.warn("异常,orderSign.getCurrentStep()为null, 比如测试数据手动乱改动时可能出现");
}
if (orderSign.getCurrentStep() != null && orderSign.getCurrentStep().equals("签核完成")) {
// 如果签核完成,取最后一个角色的签核时间
signContentItemList = JSON.parseArray(orderSign.getSignContent(), SignContentItem.class);
// 注意订单签核没有enable开关
if (signContentItemList.get(signContentItemList.size() - 1).getDate() != null) {
dateStringSignFinish = formatter.format(signContentItemList.get(signContentItemList.size() - 1).getDate());
} else {
logger.warn("signContentItemList.get(signContentItemList.size()-1).getDate() 是 null,比如测试数据手动乱改动时可能出现");
}
}
}
columnX = 0;
// 客户
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getCustomer());
sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
// 国家
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getCountry());
// 部门
sheet1.getRow(r).getCell(columnX++).setCellValue(contract.getMarketGroupName());
// 合同号
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getContractNum());
sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
//
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getOrderNum());
sheet1.getRow(r).getCell(columnX++).setCellStyle(wrapStyle);
// sheet1.getRow(r).getCell(3).setCellValue(mod.getNameplate());//
MachineType mt = mod.getMachineType();
if (mt != null) {
// 机器信息
String machineInfo = mt.getName() + "/" + mod.getNeedleNum() + "/" + mod.getHeadNum() + "/" + mod.getHeadDistance() + "/" + mod.getxDistance() + "/" + mod.getyDistance() + "/" + mod.getElectricTrim() + "/" + mod.getElectricPc();
//
sheet1.getRow(r).getCell(columnX++).setCellValue(machineInfo);
}
//
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getMachineNum());
//
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getMachinePrice());
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
List<Equipment> epArray = JSON.parseArray(mod.getEquipment(), Equipment.class);
String strEp = "";
// 订单内 各种装置数量之和
int equipmentCount = 0;
int epPriceAmount = 0;
for (Equipment itemEquipment : epArray) {
strEp += itemEquipment.getName() + ":" + itemEquipment.getNumber() + "个" + "\r\n";
epPriceAmount += itemEquipment.getPrice() * itemEquipment.getNumber();
equipmentCount += itemEquipment.getNumber();
}
allOrdersEquipmentCount += equipmentCount;
allOrdersEquipemntAmountCount += epPriceAmount;
// sheet1.getRow(r).getCell(columnX).setCellStyle(wrapStyle);
// 装置
sheet1.getRow(r).getCell(columnX++).setCellValue(new HSSFRichTextString(strEp));
// 装置数量
sheet1.getRow(r).getCell(columnX++).setCellValue(equipmentCount);
// 装置总价
sheet1.getRow(r).getCell(columnX).setCellValue(epPriceAmount);
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
// 优惠金额
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getDiscounts());
allOrdersDiscountCount += Integer.valueOf(mod.getDiscounts());
Double totalAmount = Double.parseDouble(mod.getMachinePrice()) * mod.getMachineNum() + epPriceAmount * mod.getMachineNum() - // 优惠金额 (需求单总价格优惠金额)
Double.parseDouble(mod.getOrderTotalDiscounts()) - // 每台的优惠金额
Double.parseDouble(mod.getDiscounts()) * mod.getMachineNum();
// - Double.parseDouble(mod.getIntermediaryPrice())*mod.getMachineNum();//每台的居间费用 和总价无关
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
if (mod.getCurrencyType().equals("美元")) {
allOrdersTotalPriceCount_USD += totalAmount;
// 总金额(美元)
sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
columnX++;
//
columnX++;
}
if (mod.getCurrencyType().equals("人民币")) {
allOrdersTotalPriceCount_RMB += totalAmount;
columnX++;
// 总金额(人民币)
sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
columnX++;
}
if (mod.getCurrencyType().equals("欧元")) {
allOrdersTotalPriceCount_EUR += totalAmount;
columnX++;
columnX++;
// 总金额(欧元)
sheet1.getRow(r).getCell(columnX).setCellValue(totalAmount);
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
}
// sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getCurrencyType());//币种
// 销售员
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getSellman());
// 销售费 业务费
sheet1.getRow(r).getCell(columnX).setCellValue(mod.getBusinessExpense());
sheet1.getRow(r).getCell(columnX++).setCellStyle(cellStyle);
// 付款方式
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getPayMethod());
// 毛利率
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getGrossProfit());
// 订单类型
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getOrderType());
// 保修费
sheet1.getRow(r).getCell(columnX++).setCellValue(mod.getWarrantyFee());
// 签核完成时间
sheet1.getRow(r).getCell(columnX++).setCellValue(dateStringSignFinish);
}
// 最后一行 汇总
// 新创建一行
Row rowSum = sheet1.createRow(list.size() + 1);
for (int c = 0; c < columnSum; c++) {
// 创建列单元格
rowSum.createCell(c);
}
// 各订单的装置数量-合计
rowSum.getCell(9).setCellValue(allOrdersEquipmentCount);
// 各订单的装置总价 合计
rowSum.getCell(10).setCellValue(allOrdersEquipemntAmountCount);
rowSum.getCell(10).setCellStyle(cellStyle);
// 优惠金额 合计
rowSum.getCell(11).setCellValue(allOrdersDiscountCount);
// 订单总金额(美元) 合计
rowSum.getCell(12).setCellValue(allOrdersTotalPriceCount_USD);
rowSum.getCell(12).setCellStyle(cellStyle);
// 订单总金额(人民币)合计
rowSum.getCell(13).setCellValue(allOrdersTotalPriceCount_RMB);
rowSum.getCell(13).setCellStyle(cellStyle);
// 订单总金额(欧元)合计
rowSum.getCell(14).setCellValue(allOrdersTotalPriceCount_EUR);
rowSum.getCell(14).setCellStyle(cellStyle);
downloadPath = reportOutputPath + "销售报表" + ".xls";
downloadPathForNginx = "/report/" + "销售报表" + ".xls";
out = new FileOutputStream(downloadPath);
wb.write(out);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if ("".equals(downloadPath)) {
return ResultGenerator.genFailResult("异常导出失败!");
} else {
return ResultGenerator.genSuccessResult(downloadPathForNginx);
}
}
Aggregations