rev:新增原材料需求功能

This commit is contained in:
zhouz
2023-06-29 18:35:44 +08:00
parent 831acb3051
commit 7b360a1743
16 changed files with 1741 additions and 25 deletions

View File

@@ -1,7 +1,9 @@
package org.nl.common.domain;
import java.io.IOException;
@FunctionalInterface
public
interface LockProcess {
void process();
void process() throws IOException;
}

View File

@@ -1,22 +1,28 @@
package org.nl.wms.pcs_manage.controller.purchase;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.ApiOperation;
import org.nl.common.TableDataInfo;
import org.nl.common.anno.Log;
import org.nl.common.domain.query.PageQuery;
import org.nl.wms.masterdata_manage.storage.service.storage.dao.StIvtStructattr;
import org.nl.common.utils.RedissonUtils;
import org.nl.common.utils.SecurityUtils;
import org.nl.wms.pcs_manage.PCSEnum;
import org.nl.wms.pcs_manage.service.purchase.IPcsIfPurchaseorderService;
import org.nl.wms.pcs_manage.service.purchase.dao.PcsIfPurchaseorder;
import org.nl.wms.pcs_manage.service.purchase.dto.PurchaseOrderQuery;
import org.nl.wms.storage_manage.rawmanage.service.iostorInv.dto.YlIostorInvQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* <p>
@@ -36,8 +42,79 @@ public class PcsIfPurchaseorderController {
@GetMapping(value = "/forRawIn")
@Log("查询需入库的原料需求")
@ApiOperation("查询需入库的原料需求")
public ResponseEntity<Object> queryRawIn(PurchaseOrderQuery query, PageQuery page){
return new ResponseEntity<>(purchaseorderService.queryRawIn(query,page),HttpStatus.OK);
public ResponseEntity<Object> queryRawIn(PurchaseOrderQuery query, PageQuery page) {
return new ResponseEntity<>(purchaseorderService.queryRawIn(query, page), HttpStatus.OK);
}
@GetMapping
@Log("原料需求分页查询")
@ApiOperation("原料需求分页查询")
public ResponseEntity<Object> pageQuery(PurchaseOrderQuery query, PageQuery page) {
return new ResponseEntity<>(purchaseorderService.pageQuery(query, page), HttpStatus.OK);
}
@PostMapping
@Log("新增原料需求")
@ApiOperation("新增原料需求")
public ResponseEntity<Object> create(@RequestBody JSONObject whereJson) {
purchaseorderService.create(whereJson);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/update")
@Log("修改原料需求")
@ApiOperation("修改原料需求")
public ResponseEntity<Object> update(@RequestBody JSONObject whereJson) {
purchaseorderService.update(whereJson);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/commit")
@Log("提交原料需求")
@ApiOperation("提交原料需求")
public ResponseEntity<Object> commit(@RequestBody List<PcsIfPurchaseorder> list) {
list.forEach(order -> {
order.setStatus(PCSEnum.BILL_STATUS.code("提交"));
order.setAudit_id(SecurityUtils.getCurrentUserId());
order.setAudit_name(SecurityUtils.getCurrentNickName());
order.setAudit_time(DateUtil.now());
purchaseorderService.updateById(order);
});
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/getDtl")
@Log("获取原料需求明细")
@ApiOperation("获取原料需求明细")
public ResponseEntity<Object> getDtl(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(purchaseorderService.getDtl(whereJson), HttpStatus.OK);
}
@PostMapping("/delete")
@Log("删除原料需求")
@ApiOperation("删除原料需求")
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
for (Long id : ids) {
purchaseorderService.update(new UpdateWrapper<PcsIfPurchaseorder>().eq("id", id).set("is_delete", true));
}
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
public void download(PurchaseOrderQuery query, HttpServletResponse response) throws IOException {
purchaseorderService.download(query, response);
}
@PostMapping("/excelImport")
@Log("excel导入")
@ApiOperation("excel导入")
public ResponseEntity<Object> excelImport(@RequestParam("file") MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
RedissonUtils.lock(() -> {
purchaseorderService.excelImport(file, request, response);
}, "原料需求导入", null);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -6,6 +6,12 @@ import org.nl.common.domain.query.PageQuery;
import org.nl.wms.pcs_manage.service.purchase.dao.PcsIfPurchaseorder;
import org.nl.wms.pcs_manage.service.purchase.dto.PurchaseOrderQuery;
import org.nl.wms.storage_manage.rawmanage.service.iostorInv.dto.YlIostorInvQuery;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
* <p>
@@ -25,6 +31,8 @@ public interface IPcsIfPurchaseorderService extends IService<PcsIfPurchaseorder>
*/
Object queryRawIn(PurchaseOrderQuery query, PageQuery page);
Object pageQuery(PurchaseOrderQuery query, PageQuery page);
/**
* 修改原料需求表的入库数量并修改状态
*
@@ -32,4 +40,15 @@ public interface IPcsIfPurchaseorderService extends IService<PcsIfPurchaseorder>
*/
void updatePurchaseNum(JSONObject jo);
List<PcsIfPurchaseorder> getDtl(JSONObject jo);
void create(JSONObject form);
void download(PurchaseOrderQuery query, HttpServletResponse response) throws IOException;
void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException;
void update(JSONObject form);
}

View File

@@ -94,7 +94,12 @@ public class PcsIfPurchaseorder implements Serializable {
/**
* 状态
*/
private String STATUS;
private String status;
/**
* 生成方式
*/
private String create_mode;
/**
* 创建人
@@ -126,6 +131,21 @@ public class PcsIfPurchaseorder implements Serializable {
*/
private String audit_name;
/**
* 采购人
*/
private String purchase_id;
/**
* 采购人时间
*/
private String purchase_time;
/**
* 采购人姓名
*/
private String purchase_name;
/**
* 确认人
*/
@@ -151,6 +171,11 @@ public class PcsIfPurchaseorder implements Serializable {
*/
private Boolean is_delete;
/**
* 部门ID
*/
private String material_code;
/**
* 部门ID
*/

View File

@@ -21,4 +21,5 @@ import java.util.Map;
public interface PcsIfPurchaseorderMapper extends BaseMapper<PcsIfPurchaseorder> {
List<Map> getMstDetail(@Param("query") PurchaseOrderQuery query, @Param(value = "pageQuery") PageQuery pageQuery);
List<Map> queryAll(@Param("query") PurchaseOrderQuery query, @Param(value = "pageQuery") PageQuery pageQuery);
}

View File

@@ -29,4 +29,37 @@
</if>
</where>
</select>
<select id="queryAll" resultType="java.util.Map">
SELECT
po.*,
mb.material_code,
mb.material_name,
class.class_name
FROM
pcs_if_purchaseorder po
LEFT JOIN md_me_materialbase mb ON mb.material_id = po.material_id
LEFT JOIN md_pb_classstandard class ON class.class_id = mb.material_type_id
<where>
po.is_delete = '0'
<if test="query.status == '0'.toString()">
and po.status = '10'
</if>
<if test="query.status == '1'.toString()">
and po.status > '10'
</if>
<if test="query.start_time != null">
and po.ask_time >= #{query.start_time}
</if>
<if test="query.end_time != null">
and #{query.end_time} >= po.ask_time
</if>
<if test="query.bill_code != null and query.bill_code != ''">
and mst.bill_code = #{query.bill_code}
</if>
<if test="query.material_search != null and query.material_search != ''">
and (mb.material_code = #{query.material_search} OR mb.material_name = #{query.material_search})
</if>
</where>
</select>
</mapper>

View File

@@ -16,16 +16,12 @@ public class PurchaseOrderQuery extends BaseQuery<PcsIfPurchaseorder> {
private String bill_code;
private String status;
private String material_search;
private Boolean is_delete = false;
@Override
public void paramMapping() {
super.doP.put("bill_code", QParam.builder().k(new String[]{"bill_code"}).type(QueryTEnum.LK).build());
super.doP.put("material_search", QParam.builder().k(new String[]{"material_search"}).type(QueryTEnum.LK).build());
}
private String create_mode;
private String workshop_id;
}

View File

@@ -1,8 +1,13 @@
package org.nl.wms.pcs_manage.service.purchase.impl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -10,19 +15,27 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.nl.common.TableDataInfo;
import org.nl.common.domain.query.PageQuery;
import org.nl.common.utils.IdUtil;
import org.nl.common.utils.SecurityUtils;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil;
import org.nl.modules.tools.service.dto.LocalStorageDto;
import org.nl.wms.pcs_manage.PCSEnum;
import org.nl.wms.pcs_manage.service.purchase.IPcsIfPurchaseorderService;
import org.nl.wms.pcs_manage.service.purchase.dao.PcsIfPurchaseorder;
import org.nl.wms.pcs_manage.service.purchase.dao.mapper.PcsIfPurchaseorderMapper;
import org.nl.wms.pcs_manage.service.purchase.dto.PurchaseOrderQuery;
import org.nl.wms.storage_manage.CHECKEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* <p>
@@ -48,6 +61,79 @@ public class PcsIfPurchaseorderServiceImpl extends ServiceImpl<PcsIfPurchaseorde
return build;
}
@Override
public Object pageQuery(PurchaseOrderQuery query, PageQuery pageQuery) {
Page<Object> page = PageHelper.startPage(pageQuery.getPage() + 1, pageQuery.getSize());
List<Map> mst_detail = purchaseorderMapper.queryAll(query, pageQuery);
TableDataInfo<Map> build = TableDataInfo.build(mst_detail);
build.setTotalElements(page.getTotal());
return build;
}
@Override
public List<PcsIfPurchaseorder> getDtl(JSONObject jo) {
String material_id = jo.getString("material_id");
return this.list(new QueryWrapper<PcsIfPurchaseorder>().eq("material_id", material_id).eq("status", PCSEnum.BILL_STATUS.code("生成")).eq("is_delete", false));
}
@Override
public void update(JSONObject form) {
JSONArray rows = form.getJSONArray("tableData");
for (int i = 0; i < rows.size(); i++) {
JSONObject row = rows.getJSONObject(i);
PcsIfPurchaseorder purchase = row.toJavaObject(PcsIfPurchaseorder.class);
this.updateById(purchase);
}
}
@Override
public void download(PurchaseOrderQuery query, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
List<Map> mst_detail = purchaseorderMapper.queryAll(query, null);
for (Map dtl : mst_detail) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("id(不可修改)", dtl.get("id"));
map.put("车间", dtl.get("workshop_id"));
map.put("物料编码", dtl.get("material_code"));
map.put("物料名称", dtl.get("material_name"));
map.put("数量", dtl.get("qty"));
map.put("单位", dtl.get("qty_unit_name"));
map.put("要求到料日期", dtl.get("ask_time"));
map.put("订单编号", dtl.get("po_code"));
map.put("确认到料日期", dtl.get("agree_time"));
map.put("入库数量", dtl.get("instor_qty"));
map.put("状态", dtl.get("status"));
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
@Override
public void create(JSONObject form) {
JSONArray rows = form.getJSONArray("tableData");
for (int i = 0; i < rows.size(); i++) {
JSONObject row = rows.getJSONObject(i);
PcsIfPurchaseorder order = new PcsIfPurchaseorder();
order.setId(IdUtil.getStringId());
order.setWorkshop_id(form.getString("workshop_id"));
order.setMaterial_id(form.getString("material_id"));
order.setMaterial_code(form.getString("material_code"));
order.setQty(row.getBigDecimal("qty"));
order.setStatus(PCSEnum.BILL_STATUS.code("生成"));
order.setQty_unit_id(form.getString("qty_unit_id"));
order.setQty_unit_name(form.getString("qty_unit_name"));
order.setAsk_time(row.getString("ask_time"));
order.setCreate_mode(CHECKEnum.CREATE_MODE.code("PC产生"));
order.setCreate_id(SecurityUtils.getCurrentUserId());
order.setCreate_name(SecurityUtils.getCurrentNickName());
order.setCreate_time(DateUtil.now());
order.setIs_delete(false);
order.setSyscompanyid("111");
order.setSysdeptid("111");
this.save(order);
}
}
@Override
public void updatePurchaseNum(JSONObject jo) {
String po_code = jo.getString("po_code");
@@ -60,20 +146,55 @@ public class PcsIfPurchaseorderServiceImpl extends ServiceImpl<PcsIfPurchaseorde
}
PcsIfPurchaseorder purchaseorder = this.getOne(new QueryWrapper<PcsIfPurchaseorder>().eq("po_code", po_code));
if (purchaseorder.getSTATUS().equals(PCSEnum.BILL_STATUS.code("完成"))) {
if (purchaseorder.getStatus().equals(PCSEnum.BILL_STATUS.code("完成"))) {
throw new BadRequestException("当前单据状态已经完成,无法进行入库数修改!");
}
BigDecimal new_instor_qty = NumberUtil.add(instor_qty, purchaseorder.getInstor_qty(), 3);
purchaseorder.setQty(new_instor_qty);
if (purchaseorder.getTotal_qty().compareTo(new_instor_qty) <= 0) {
purchaseorder.setSTATUS(PCSEnum.BILL_STATUS.code("完成"));
purchaseorder.setStatus(PCSEnum.BILL_STATUS.code("完成"));
purchaseorder.setConfirm_id(SecurityUtils.getCurrentUserId());
purchaseorder.setConfirm_name(SecurityUtils.getCurrentNickName());
purchaseorder.setConfirm_time(DateUtil.now());
} else {
purchaseorder.setSTATUS(PCSEnum.BILL_STATUS.code("到货中"));
purchaseorder.setStatus(PCSEnum.BILL_STATUS.code("到货中"));
}
this.updateById(purchaseorder);
}
@Override
public void excelImport(MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
InputStream inputStream = file.getInputStream();
ExcelReader excelReader = ExcelUtil.getReader(inputStream);
List<List<Object>> read = excelReader.read();
for (int i = 1; i < read.size(); i++) {
List<Object> list = read.get(i);
if (ObjectUtil.isEmpty(list)) {
continue;
}
String id = (String) list.get(0);
String po_code = (String) list.get(7);
String agree_time = ((DateTime) list.get(8)).toString("YYYY-MM-dd");
String status = (String) list.get(10);
PcsIfPurchaseorder order = this.getOne(new QueryWrapper<PcsIfPurchaseorder>().eq("id", id));
if (ObjectUtil.isEmpty(order)) {
throw new BadRequestException("未查询到第" + (i + 1) + "行的原料需求!");
}
try {
if (status.equals(PCSEnum.BILL_STATUS.code("提交"))) {
order.setPo_code(po_code);
order.setAgree_time(agree_time);
order.setStatus(PCSEnum.BILL_STATUS.code("确认采购"));
order.setPurchase_id("0");
order.setPurchase_name("EXCEL导入");
order.setPurchase_time(DateUtil.now());
this.updateById(order);
}
} catch (Exception exception) {
throw new BadRequestException("" + (i + 1) + "行输入的数据有误!");
}
}
}
}