Commit 9d95b93c by zhangtw

导入

parent d0f62691
package com.scpyun.platform.jilinsscgsdp.service.impl; package com.scpyun.platform.jilinsscgsdp.service.impl;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.scpyun.base.bean.Page; import com.scpyun.base.bean.Page;
import com.scpyun.base.core.annotation.Api; import com.scpyun.base.core.annotation.Api;
import com.scpyun.base.core.annotation.ApiOperation; import com.scpyun.base.core.annotation.ApiOperation;
import com.scpyun.base.core.exception.CustomException; import com.scpyun.base.core.exception.CustomException;
import com.scpyun.base.db.service.CommonService; import com.scpyun.base.db.service.CommonService;
import com.scpyun.platform.jilinsscgsdp.utils.InboundFileListener;
import com.scpyun.platform.jilinsscgsdp.utils.MaterialFileListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
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.web.multipart.MultipartFile;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
...@@ -293,6 +305,39 @@ public class KeyDmInboundServiceImpl { ...@@ -293,6 +305,39 @@ public class KeyDmInboundServiceImpl {
return ret; return ret;
} }
@ApiOperation(value = "导入入库单", desc = "解析 Excel 导入入库信息")
public Map<String, Object> importInbound(Map<String, Object> map, MultipartFile file) {
Map<String, Object> result = new HashMap<>();
try {
InboundFileListener listener = new InboundFileListener(commonService, namespace, map);
EasyExcel.read(file.getInputStream(), com.scpyun.platform.jilinsscgsdp.bean.entity.InboundImp.class, listener).sheet().headRowNumber(1).doRead();
result = listener.getResult();
} catch (IOException e) {
throw new CustomException("导入失败");
}
return result;
}
@ApiOperation(value = "导入模板下载", desc = "下载入库导入模板")
public void templateDownload(Map<String, Object> map, HttpServletResponse response) {
response.setContentType("application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
try {
String fileName = URLEncoder.encode("入库导入模板", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
response.setHeader("filename", fileName + ".xlsx");
response.setHeader("Access-Control-Expose-Headers", "filename,Content-Disposition");
String tpl = "keyInboundImp.xlsx";
Resource resource = new ClassPathResource(tpl);
InputStream is = resource.getInputStream();
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(is).excelType(ExcelTypeEnum.XLSX).build();
excelWriter.finish();
} catch (Exception e) {
throw new CustomException("模板下载失败");
}
}
} }
...@@ -185,6 +185,143 @@ ...@@ -185,6 +185,143 @@
left join jl_key_dm_borrow_application as ba on bad.application_id = ba.id left join jl_key_dm_borrow_application as ba on bad.application_id = ba.id
where ba.id = #{id} where ba.id = #{id}
</select> </select>
<!-- 将物料code为键做成字典-->
<select id="getMaterialMap" resultType="map">
select *
from jl_key_dm_material
where is_used = 1
</select>
<insert id="batchInsertInboundMasters" parameterType="map">
INSERT INTO jl_key_dm_inbound_record (
id,
inbound_no,
batch_no,
inbound_type,
inbound_status,
inbound_date,
is_used,
storage_location,
remark,
create_by,
create_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.id},
#{item.inbound_no},
#{item.batch_no},
#{item.inbound_type},
#{item.inbound_status},
#{item.inbound_date},
#{item.is_used},
#{item.storage_location},
#{item.remark},
#{item.create_by},
#{item.create_time}
)
</foreach>
</insert>
<insert id="batchInsertInboundDetails" parameterType="map">
INSERT INTO jl_key_dm_inbound_detail (
id,
inbound_id,
material_id,
inbound_type,
inbound_quantity,
unit_price,
total_amount,
production_date,
expiry_date,
is_used,
create_by,
create_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.id},
#{item.inbound_id},
#{item.material_id},
#{item.inbound_type},
#{item.inbound_quantity},
#{item.unit_price},
#{item.total_amount},
#{item.production_date},
#{item.expiry_date},
#{item.is_used},
#{item.create_by},
#{item.create_time}
)
</foreach>
</insert>
<update id="batchUpdateMaterialStock" parameterType="map">
UPDATE jl_key_dm_inventory
SET total_quantity = total_quantity + CASE id
<foreach collection="list" item="item">
WHEN #{item.material_id} THEN #{item.quantity}
</foreach>
ELSE 0
END,
update_time = NOW()
WHERE id IN
<foreach collection="list" item="item" open="(" separator="," close=")">
#{item.material_id}
</foreach>
</update>
<insert id="insertInboundMaster" parameterType="map">
INSERT INTO jl_key_dm_inbound_record (
id,
inbound_no,
batch_no,
inbound_type,
inbound_status,
inbound_date,
is_used,
storage_location,
remark,
create_by,
create_time
) VALUES (
#{id},
#{inbound_no},
#{batch_no},
#{inbound_type},
#{inbound_status},
#{inbound_date},
#{is_used},
#{storage_location},
#{remark},
#{create_by},
#{create_time}
)
</insert>
<insert id="insertInboundDetail" parameterType="map">
INSERT INTO jl_key_dm_inbound_detail (
id,
inbound_id,
material_id,
inbound_type,
inbound_quantity,
unit_price,
total_amount,
production_date,
expiry_date,
create_by,
create_time
) VALUES (
#{id},
#{inbound_id},
#{material_id},
#{inbound_type},
#{inbound_quantity},
#{unit_price},
#{total_amount},
#{production_date},
#{expiry_date},
#{create_by},
#{create_time}
)
</insert>
</mapper> </mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论