订单管理模块(订单导入)

highway
wws 1 year ago
parent 2bae85c25a
commit 1d01cb3621

@ -1,10 +1,14 @@
package com.op.plan.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.op.common.core.domain.R;
import com.op.common.core.utils.DateUtils;
import com.op.plan.domain.dto.SplitOrderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -23,6 +27,9 @@ import com.op.plan.service.IProOrderService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;
import org.springframework.web.multipart.MultipartFile;
import static com.op.common.security.utils.SecurityUtils.getUsername;
/**
* Controller
@ -36,6 +43,53 @@ public class ProOrderController extends BaseController {
@Autowired
private IProOrderService proOrderService;
/**
*
*
* @param file
* @return
* @throws Exception
*/
@Log(title = "订单信息", businessType = BusinessType.IMPORT)
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file) throws Exception {
// 创建接收对象
ExcelUtil<ProOrder> util = new ExcelUtil<>(ProOrder.class);
// 接收表格信息
List<ProOrder> orderList = util.importExcel(file.getInputStream());
return proOrderService.importOrder(orderList);
}
/**
*
*
* @param response
* @throws IOException
*/
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) throws IOException {
ExcelUtil<ProOrder> util = new ExcelUtil<>(ProOrder.class);
List<ProOrder> orderList = new ArrayList<>();
ProOrder example = new ProOrder();
example.setPlanFactoryCode("000000");
example.setOrderCode("000000");
example.setProdCode("000000");
example.setProdDesc("物料名称样例");
example.setQuantity(100L);
example.setUnit("BP");
example.setProdType("white");
example.setStatus("o0");
example.setPlanComplete(DateUtils.getNowDate());
example.setPlanProDate(DateUtils.getNowDate());
example.setCreateTime(DateUtils.getNowDate());
example.setUpdateTime(DateUtils.getNowDate());
orderList.add(example);
util.exportExcel(response, orderList, "订单基本信息");
}
/**
*
*
@ -133,18 +187,17 @@ public class ProOrderController extends BaseController {
/**
* SAP
*
* @param proOrderList
* @return
*/
@Log(title = "同步SAP订单", businessType = BusinessType.INSERT)
@PostMapping("/shopOrderSync")
public void shopOrderSync(List<ProOrder> proOrderList) {
proOrderService.shopOrderSync(proOrderList);
proOrderService.shopOrderSync(proOrderList);
}
/**
*
*/

@ -152,4 +152,18 @@ public interface ProOrderMapper {
* @return
*/
String selectShiftNameById(String shiftId);
/**
*
* @param orderCode
* @return
*/
ProOrder selectProOrderByOrderCode(String orderCode);
/**
* code
* @param order
* @return
*/
int updateProOrderByOrderCode(ProOrder order);
}

@ -1,5 +1,6 @@
package com.op.plan.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.op.plan.domain.ProOrderWorkorder;
import org.apache.ibatis.annotations.Mapper;
@ -69,6 +70,7 @@ public interface ProOrderWorkorderMapper {
* @return
*/
List<ProOrderWorkorder> selectFirWorkOrder(String id);
/**
* code
*
@ -94,9 +96,20 @@ public interface ProOrderWorkorderMapper {
String selectEndWorkOrder(String id);
ProOrderWorkorder selectWorkOrderByCode(String workorderCode);
/**下发生产订单**/
/**
*
**/
public int downProOrderWorkorderByWorkorderIds(String[] workorderIds);
public List<ProOrderWorkorder> getWorkOrderByIds(String[] workorderIds);
/**
* Codelist
*
* @param orderCode
* @return
*/
List<ProOrderWorkorder> selectWorkOrderByOrderCode(String orderCode);
}

@ -110,4 +110,11 @@ public interface IProOrderService {
*/
void shopOrderSync(List<ProOrder> proOrderList);
/**
*
* @param orderList
* @return
*/
AjaxResult importOrder(List<ProOrder> orderList);
}

@ -8,6 +8,7 @@ import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.op.common.core.context.SecurityContextHolder;
import com.op.common.core.exception.CheckedException;
import com.op.common.core.utils.DateUtils;
import com.op.common.core.utils.StringUtils;
import com.op.common.core.utils.uuid.IdUtils;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.log.enums.BusinessType;
@ -113,7 +114,7 @@ public class ProOrderServiceImpl implements IProOrderService {
// 将工单信息更新至数据库
proOrderWorkorderMapper.insertProOrderWorkorder(workOrder);
// 生成批次表信息并更新至数据库
setBatch(workBatch, splitOrderDTO.getFormFields(), workOrder.getWorkorderId(),conver);
setBatch(workBatch, splitOrderDTO.getFormFields(), workOrder.getWorkorderId(), conver);
// 如果存在子节点
if (proOrder.getChildren() != null) {
@ -213,7 +214,7 @@ public class ProOrderServiceImpl implements IProOrderService {
@Override
public void shopOrderSync(List<ProOrder> proOrderList) {
for (ProOrder proOrder:proOrderList) {
for (ProOrder proOrder : proOrderList) {
String shopOrder = proOrder.getOrderCode();
if (StringUtil.isBlank(shopOrder)) {
throw new CheckedException("订单号不能为空!");
@ -225,6 +226,74 @@ public class ProOrderServiceImpl implements IProOrderService {
}
}
/**
*
*
* @param orderList
* @return
*/
@Override
@DS("#header.poolName")
@Transactional
public AjaxResult importOrder(List<ProOrder> orderList) {
// 数据校验
AjaxResult checkResult = checkImportOrder(orderList);
// 如果数据校验成功
if (checkResult.isSuccess()){
// 校验数据是否可编辑
boolean checkEdit = false;
// 反馈数据
StringBuilder errMsg = new StringBuilder();
for (int i = 0; i < orderList.size(); i++) {
// 当前行操作
boolean checkOnly = false;
List<ProOrderWorkorder> workOrderList = proOrderWorkorderMapper.selectWorkOrderByOrderCode(orderList.get(i).getOrderCode());
// 遍历查询工单是否已下达-下达则不允许编辑更新
for (ProOrderWorkorder workOrder : workOrderList) {
if (workOrder.getStatus().equals("w1")) {
checkEdit = true;
checkOnly = true;
}
}
if (checkOnly){
errMsg.append("第"+(i+1)+"行:"+"订单号为:"+orderList.get(i).getOrderCode()+",该订单下工单已下达,不允许更新;"+"<br/>");
return error(500,errMsg.toString());
}else {
// 正常插入与更新操作
for (ProOrder order : orderList) {
// 查询订单是否存在
ProOrder proOrder = proOrderMapper.selectProOrderByOrderCode(order.getOrderCode());
// 如果存在
if (proOrder != null){
order.setUpdateBy(SecurityContextHolder.getUserName());
order.setUpdateTime(DateUtils.getNowDate());
// 通过订单号code更新订单信息
proOrderMapper.updateProOrderByOrderCode(order);
}else {
// 不存在则创建
order.setId(IdUtils.fastSimpleUUID());
order.setOrderType(order.getProdType());
System.out.println(order);
proOrderMapper.insertProOrder(order);
}
}
return success("信息导入成功!");
}
}
// 如果存在不可编辑信息
if (checkEdit){
return error(500,errMsg.toString());
}
return success("信息导入成功");
}
// 校验失败
return checkResult;
}
/**
*
*
@ -313,7 +382,6 @@ public class ProOrderServiceImpl implements IProOrderService {
}
/**
*
*
@ -451,7 +519,7 @@ public class ProOrderServiceImpl implements IProOrderService {
* @param batchList
* @param workOrderId
*/
private void setBatch(ProOrderWorkorderBatch workBatch, List<Batch> batchList, String workOrderId,Long conver) {
private void setBatch(ProOrderWorkorderBatch workBatch, List<Batch> batchList, String workOrderId, Long conver) {
// 工单id
workBatch.setWorkorderId(workOrderId);
@ -462,7 +530,7 @@ public class ProOrderServiceImpl implements IProOrderService {
// 获取批次号
workBatch.setBatchCode(batch.getBatchCode());
// 获取批次数量
workBatch.setBatchQuantity(batch.getBatchQuantity()*conver);
workBatch.setBatchQuantity(batch.getBatchQuantity() * conver);
// 更新至数据库
proOrderWorkorderBatchMapper.insertProOrderWorkorderBatch(workBatch);
}
@ -492,5 +560,63 @@ public class ProOrderServiceImpl implements IProOrderService {
}
}
/**
*
*
* @param orderList
*/
public AjaxResult checkImportOrder(List<ProOrder> orderList) {
// 传入对象不能为空
if (orderList.size()==0 || StringUtils.isNull(orderList)){
return error(500,"导入的订单信息不能为空!信息导入失败!");
}
// 循环遍历校验数据是否为空
for (ProOrder proOrder : orderList) {
// 计划工厂
if (proOrder.getPlanFactoryCode().isEmpty() || proOrder.getPlanFactoryCode() == null) {
return error(500,"计划工厂信息不能为空!信息导入失败!");
}
// 订单号
if (proOrder.getOrderCode().isEmpty() || proOrder.getOrderCode() == null) {
return error(500,"订单号不能为空!信息导入失败!");
}
// 物料号
if (proOrder.getProdCode().isEmpty() || proOrder.getProdCode() == null) {
return error(500,"物料号不能为空!信息导入失败!");
}
// 物料名称
if (proOrder.getProdDesc().isEmpty() || proOrder.getProdDesc() == null) {
return error(500,"物料名称不能为空!信息导入失败!");
}
// 订单数量
if (proOrder.getQuantity() == 0 || proOrder.getProdDesc() == null) {
return error(500,"订单数量不能为0或空信息导入失败");
}
// 单位
if (proOrder.getUnit().isEmpty() || proOrder.getUnit() == null) {
return error(500,"单位不能为空!信息导入失败!");
}
// 订单拆分状态
if (proOrder.getStatus().isEmpty() || proOrder.getStatus() == null) {
return error(500,"拆分状态不能为空!信息导入失败!");
}
// 产品类型
if (proOrder.getProdType().isEmpty() || proOrder.getProdType() == null) {
return error(500,"产品类型不能为空!信息导入失败!");
}
// 计划生产日期
if (proOrder.getPlanProDate() == null || StringUtils.isNull(proOrder.getPlanProDate())) {
return error(500,"计划生产日期不能为空!信息导入失败!");
}
// 计划完成日期
if (proOrder.getPlanComplete() == null || StringUtils.isNull(proOrder.getPlanComplete())) {
return error(500,"计划完成日期不能为空!信息导入失败!");
}
}
return success();
}
}

@ -15,6 +15,10 @@ import org.springframework.stereotype.Service;
import com.op.plan.mapper.ProWetMaterialPlanMapper;
import com.op.plan.service.IProWetMaterialPlanService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import static com.op.common.core.web.domain.AjaxResult.error;
import static com.op.common.core.web.domain.AjaxResult.success;
@ -195,6 +199,8 @@ public class ProWetMaterialPlanServiceImpl implements IProWetMaterialPlanService
proWetMaterialPlanDetailMapper.insertProWetMaterialPlanDetail(createProWetMaterialPlanDetail(proOrderWorkorder, proWetMaterialPlan.getId()));
}
} else {
// TODO 判断工厂code是否是该工厂
// 循环创建湿料计划详情
for (ProOrderWorkorder proOrderWorkorder : proOrderWorkorderList) {
// 将湿料计划详情更新至数据库
@ -272,6 +278,11 @@ public class ProWetMaterialPlanServiceImpl implements IProWetMaterialPlanService
* @return
*/
private ProWetMaterialPlan createProWetMaterialPlan(ProOrderWorkorder proOrderWorkorder) {
//获取当前所选工厂
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String key = "#header.poolName";
ProWetMaterialPlan proWetMaterialPlan = new ProWetMaterialPlan();
// 创建者
proWetMaterialPlan.setCreateBy(SecurityContextHolder.getUserName());
@ -282,11 +293,11 @@ public class ProWetMaterialPlanServiceImpl implements IProWetMaterialPlanService
// 更新时间
proWetMaterialPlan.setUpdateTime(DateUtils.getNowDate());
// 计划状态(1正常0停用)
proWetMaterialPlan.setStatus("1");
//proWetMaterialPlan.setStatus("1");
// TODO 订单类型
//proWetMaterialPlan.setOrderType();
// TODO 计划工厂编码
//proWetMaterialPlan.setFactoryCode(proOrderWorkorder.getFactoryCode());
// 计划工厂编码
proWetMaterialPlan.setFactoryCode(request.getHeader(key.substring(8)));
// 计划日期
proWetMaterialPlan.setPlanTime(proOrderWorkorder.getPlanTime());
// 同步状态(Y已同步N未同步)

@ -129,6 +129,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE bst.Shift_Id = #{shiftId}
</select>
<select id="selectProOrderByOrderCode" parameterType="String" resultMap="ProOrderResult">
<include refid="selectProOrderVo"/>
where order_code = #{orderCode}
</select>
<insert id="insertProOrder" parameterType="ProOrder">
insert into pro_order
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -234,7 +239,37 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</update>
<delete id="deleteProOrderById" parameterType="String">
<update id="updateProOrderByOrderCode" parameterType="ProOrder">
update pro_order
<trim prefix="SET" suffixOverrides=",">
<if test="planFactoryCode != null">plan_factory_code = #{planFactoryCode},</if>
<if test="factoryCode != null">factory_code = #{factoryCode},</if>
<if test="orderType != null">order_type = #{orderType},</if>
<if test="orderCode != null">order_code = #{orderCode},</if>
<if test="prodCode != null">prod_code = #{prodCode},</if>
<if test="prodDesc != null">prod_desc = #{prodDesc},</if>
<if test="quantity != null">quantity = #{quantity},</if>
<if test="quantitySplit != null">quantity_split = #{quantitySplit},</if>
<if test="unit != null">unit = #{unit},</if>
<if test="workerOrder != null">worker_order = #{workerOrder},</if>
<if test="planProDate != null">plan_pro_date = #{planProDate},</if>
<if test="planComplete != null">plan_complete = #{planComplete},</if>
<if test="atrr1 != null">atrr1 = #{atrr1},</if>
<if test="atrr2 != null">atrr2 = #{atrr2},</if>
<if test="atrr3 != null">atrr3 = #{atrr3},</if>
<if test="status != null">status = #{status},</if>
<if test="parentOrder != null">parent_order = #{parentOrder},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="prodType != null">prod_type = #{prodType},</if>
<if test="prodSpc != null">prod_spc = #{prodSpc},</if>
</trim>
where order_code = #{orderCode}
</update>
<delete id="deleteProOrderById" parameterType="String">
delete from pro_order where id = #{id}
</delete>

@ -116,6 +116,11 @@
</foreach>
</select>
<select id="selectWorkOrderByOrderCode" resultMap="ProOrderWorkorderResult">
<include refid="selectProOrderWorkorderVo"/>
where order_code = #{orderCode}
</select>
<insert id="insertProOrderWorkorder" parameterType="ProOrderWorkorder">
insert into pro_order_workorder
<trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save