1.修改建垛关联ID

2.增加导出垛码接口
master
x_z 3 years ago
parent fcb3c60142
commit 82104ad475

@ -10,6 +10,7 @@ import com.glxp.udi.admin.req.inout.DeleteRequest;
import com.glxp.udi.admin.req.product.AddStackCodeRequest;
import com.glxp.udi.admin.req.product.FilterStackCodeRequest;
import com.glxp.udi.admin.res.PageSimpleResponse;
import com.glxp.udi.admin.res.product.StackCodeResponse;
import com.glxp.udi.admin.service.product.StackCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
@ -82,7 +83,8 @@ public class StackCodeController {
return ResultVOUtils.error(500, "条码重复!");
}
}
StackCode stackCode = stackCodeService.addCode(addStackCodeRequest);
StackCodeResponse stackCode = stackCodeService.addCode(addStackCodeRequest);
return ResultVOUtils.success(stackCode);
}

@ -4,21 +4,24 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.glxp.udi.admin.annotation.AuthRuleAnnotation;
import com.glxp.udi.admin.common.enums.ResultEnum;
import com.glxp.udi.admin.common.res.BaseResponse;
import com.glxp.udi.admin.common.util.ResultVOUtils;
import com.glxp.udi.admin.constant.ConstantStatus;
import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.req.info.DeleteRequest;
import com.glxp.udi.admin.req.product.ImportStackOrderRequest;
import com.glxp.udi.admin.req.product.StackOrderFilterRequest;
import com.glxp.udi.admin.req.product.StackUploadRequest;
import com.glxp.udi.admin.res.PageSimpleResponse;
import com.glxp.udi.admin.res.product.StackOrderResponse;
import com.glxp.udi.admin.service.auth.CustomerService;
import com.glxp.udi.admin.common.util.ResultVOUtils;
import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.req.product.StackOrderFilterRequest;
import com.glxp.udi.admin.res.PageSimpleResponse;
import com.glxp.udi.admin.service.product.StackCodeService;
import com.glxp.udi.admin.service.product.StackOrderService;
import com.glxp.udi.admin.common.enums.ResultEnum;
import com.glxp.udi.admin.vo.StackCodeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult;
@ -26,7 +29,13 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.*;
@Slf4j
@ -56,7 +65,7 @@ public class StackOrderController {
BeanUtil.copyProperties(stackOrder, response);
//查询此垛的扫码数量
Long codeNum = stackOrderService.countCode(stackOrder.getOrderId());
Long codeNum = stackOrderService.countCode(stackOrder.getId().toString());
response.setCodeNum(codeNum);
responses.add(response);
});
@ -109,11 +118,11 @@ public class StackOrderController {
}
stackOrderEntity.setCustomerId(customerService.getCustomerId() + "");
String stackOrderId = stackOrderService.insertOrder(stackOrderEntity);
String orderId = stackOrderService.insertOrder(stackOrderEntity);
//绑定垛号
stackUploadRequest.getStackCodeEntityList().forEach(stackCode -> stackCode.setOrderIdFk(stackOrderId));
stackUploadRequest.getStackCodeEntityList().forEach(stackCode -> stackCode.setOrderIdFk(orderId));
stackCodeService.batchInsert(stackUploadRequest.getStackCodeEntityList());
return ResultVOUtils.success(stackOrderId);
return ResultVOUtils.success(orderId);
}
/**
@ -188,5 +197,47 @@ public class StackOrderController {
return ResultVOUtils.success("导入成功");
}
/**
*
*
* @param response
*/
@GetMapping("/udims/stack/order/exportStackOrder")
public void exportStackOrder(@RequestParam String orderId, @RequestParam String customerId,
HttpServletResponse response) {
try {
//查询垛码
List<StackCodeVo> codeList = stackCodeService.getExportData(orderId);
if (CollUtil.isEmpty(codeList)) {
return;
}
stackOrderService.updateExportStatus(ConstantStatus.ORDER_EXPORT_ED, Integer.valueOf(orderId));
String fileName = codeList.get(0).getOrderId() + "码详情.xlsx";
//保存导出文件的文件夹
String folderPath = filePath + "/stack/order/export/" + customerId + "/";
File file = new File(folderPath);
if (!file.exists()) {
file.mkdirs();
}
file = new File(folderPath + fileName);
EasyExcel.write(file, StackCodeVo.class).sheet().doWrite(codeList);
InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath()));
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
inputStream.close();
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
ServletOutputStream os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
} catch (Exception e) {
log.error("导出垛码数据异常", e);
}
}
}

@ -2,6 +2,7 @@ package com.glxp.udi.admin.dao.product;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.udi.admin.entity.product.StackCode;
import com.glxp.udi.admin.vo.StackCodeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@ -39,4 +40,12 @@ public interface StackCodeDao extends BaseMapper<StackCode> {
* @param list
*/
void batchInsert(List<StackCode> list);
/**
*
*
* @param orderId
* @return
*/
List<StackCodeVo> getExportData(@Param("orderId") String orderId);
}

@ -15,4 +15,12 @@ public interface StackOrderDao extends BaseMapper<StackOrder> {
* @return
*/
String selectOrderIdById(@Param("id") Integer id);
/**
*
*
* @param exportStatus
* @param id
*/
void updateExportStatus(@Param("exportStatus") Integer exportStatus, @Param("id") Integer id);
}

@ -0,0 +1,17 @@
package com.glxp.udi.admin.res.product;
import com.glxp.udi.admin.entity.product.StackCode;
import lombok.Data;
/**
*
*/
@Data
public class StackCodeResponse extends StackCode {
/**
*
*/
private String stackId;
}

@ -13,8 +13,10 @@ import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.entity.udid.UdiEntity;
import com.glxp.udi.admin.req.product.AddStackCodeRequest;
import com.glxp.udi.admin.req.product.FilterStackCodeRequest;
import com.glxp.udi.admin.res.product.StackCodeResponse;
import com.glxp.udi.admin.util.FilterUdiUtils;
import com.glxp.udi.admin.util.IdUtil;
import com.glxp.udi.admin.vo.StackCodeVo;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -83,13 +85,12 @@ public class StackCodeService {
* @param addStackCodeRequest
* @return
*/
public StackCode addCode(AddStackCodeRequest addStackCodeRequest) {
public StackCodeResponse addCode(AddStackCodeRequest addStackCodeRequest) {
StackCode stackCode = new StackCode();
stackCode.setCode(addStackCodeRequest.getCode());
if (StrUtil.isBlank(addStackCodeRequest.getOrderId())) {
//垛号为空,此条码为这个垛的第一个条码数据,先生垛号和垛数据,再添加条码
String stackId = idUtil.getStackId(addStackCodeRequest.getCustomerId());
stackCode.setOrderIdFk(stackId);
//创建垛数据
StackOrder stackOrder = new StackOrder();
//垛码
@ -98,6 +99,7 @@ public class StackCodeService {
stackOrder.setExportStatus(0);
stackOrder.setCustomerId(addStackCodeRequest.getCustomerId());
stackOrderDao.insert(stackOrder);
stackCode.setOrderIdFk(String.valueOf(stackOrder.getId()));
} else {
stackCode.setOrderIdFk(addStackCodeRequest.getOrderId());
}
@ -105,7 +107,11 @@ public class StackCodeService {
BeanUtil.copyProperties(udi, stackCode);
int id = stackCodeDao.insert(stackCode);
stackCode.setId(id);
return stackCode;
StackCodeResponse response = new StackCodeResponse();
BeanUtil.copyProperties(stackCode, response);
response.setStackId(stackOrderDao.selectOrderIdById(Integer.valueOf(stackCode.getOrderIdFk())));
return response;
}
/**
@ -123,4 +129,16 @@ public class StackCodeService {
}
return false;
}
/**
*
*
* @param orderId
* @param customerId
* @return
*/
public List<StackCodeVo> getExportData(String orderId) {
return stackCodeDao.getExportData(orderId);
}
}

@ -17,15 +17,11 @@ import com.glxp.udi.admin.entity.product.StackOrder;
import com.glxp.udi.admin.entity.udid.UdiEntity;
import com.glxp.udi.admin.req.product.StackOrderFilterRequest;
import com.glxp.udi.admin.req.product.StackUploadRequest;
import com.glxp.udi.admin.service.auth.CustomerService;
import com.glxp.udi.admin.util.FilterUdiUtils;
import com.glxp.udi.admin.util.IdUtil;
import com.glxp.udi.admin.vo.StackCodeVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.TransactionIsolationLevel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -51,10 +47,8 @@ public class StackOrderService {
private StackCodeDao stackCodeDao;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Resource
private CustomerService customerService;
private ExecutorService executorService = ThreadUtil.newExecutor(8);
private final ExecutorService executorService = ThreadUtil.newExecutor(8);
public IPage<StackOrder> filterList(StackOrderFilterRequest stackOrderFilterRequest) {
@ -72,26 +66,7 @@ public class StackOrderService {
public void updateOrder(StackUploadRequest stackUploadRequest) {
//更新垛数据
stackOrderDao.updateById(stackUploadRequest.getStackOrderEntity());
//更新码详情
if (CollUtil.isNotEmpty(stackUploadRequest.getStackCodeEntityList())) {
stackUploadRequest.getStackCodeEntityList().forEach(stackCode -> {
stackCode.setOrderIdFk(stackUploadRequest.getStackOrderEntity().getOrderId());
});
SqlSession batchSession = sqlSessionFactory.openSession(ExecutorType.BATCH, TransactionIsolationLevel.READ_COMMITTED);
StackCodeDao mapper = batchSession.getMapper(StackCodeDao.class);
List<StackCode> stackCodeEntityList = stackUploadRequest.getStackCodeEntityList();
for (StackCode stackCode : stackCodeEntityList) {
if (null != stackCode.getId()) {
mapper.updateById(stackCode);
} else {
mapper.insert(stackCode);
}
}
batchSession.commit();
batchSession.close();
}
}
public boolean isExit(String orderId) {
@ -105,7 +80,7 @@ public class StackOrderService {
stackOrderEntity.setCreateTime(new Date());
}
stackOrderDao.insert(stackOrderEntity);
return stackId;
return String.valueOf(stackOrderEntity.getId());
}
public void deleteById(Integer id) {
@ -114,7 +89,7 @@ public class StackOrderService {
//删除垛数据
stackOrderDao.deleteById(id);
//删除关联的条码数据
stackCodeDao.deleteByOrderId(orderId);
stackCodeDao.deleteByOrderId(String.valueOf(id));
}
/**
@ -151,7 +126,7 @@ public class StackOrderService {
for (int i = 1; i <= batchNum; i++) {
int start = (i - 1) * 1000;
int end = i * 1000;
int end = i == 1 ? (codeList.size() - 1) : i * 1000;
List<String> codePage = codeList.subList(start, end);
QueryWrapper<StackCode> wrapper = new QueryWrapper<>();
@ -208,7 +183,7 @@ public class StackOrderService {
//插入垛数据
stackOrderDao.insert(stackOrder);
List<StackCode> data = stacks.get(serialNum);
data.forEach(stackCode -> stackCode.setOrderIdFk(stackId));
data.forEach(stackCode -> stackCode.setOrderIdFk(String.valueOf(stackOrder.getId())));
//按照指定长度切分集合,批量插入
List<List<StackCode>> listList = ListUtil.split(data, 5000);
@ -221,4 +196,13 @@ public class StackOrderService {
FileUtil.del(filePath);
}
/**
*
*
* @param exportStatus
* @param id
*/
public void updateExportStatus(Integer exportStatus, Integer id) {
stackOrderDao.updateExportStatus(exportStatus, id);
}
}

@ -22,15 +22,21 @@
<insert id="batchInsert">
insert into stack_code (code, orderIdFk, batchNo, produceDate, expireDate, serialNo, nameCode) values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.code},
(#{item.code},
#{item.orderIdFk},
#{item.batchNo},
#{item.produceDate},
#{item.expireDate},
#{item.serialNo},
#{item.nameCode}
)
#{item.nameCode})
</foreach>
</insert>
<select id="getExportData" resultType="com.glxp.udi.admin.vo.StackCodeVo">
select code,
stack_order.orderId
from stack_code
left join stack_order on stack_order.id = stack_code.orderIdFk
where orderIdFk = #{orderId}
</select>
</mapper>

@ -6,4 +6,8 @@
from stack_order
where id = #{id}
</select>
<update id="updateExportStatus">
update stack_order set exportStatus = #{exportStatus} where id = #{id}
</update>
</mapper>
Loading…
Cancel
Save