优化商品模块
This commit is contained in:
@@ -12,6 +12,7 @@ import com.jsh.erp.datasource.entities.Depot;
|
||||
import com.jsh.erp.datasource.entities.DepotEx;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.depot.DepotService;
|
||||
import com.jsh.erp.service.material.MaterialService;
|
||||
import com.jsh.erp.service.systemConfig.SystemConfigService;
|
||||
import com.jsh.erp.service.userBusiness.UserBusinessService;
|
||||
import com.jsh.erp.utils.*;
|
||||
@@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
|
||||
@@ -44,6 +46,9 @@ public class DepotController {
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Resource
|
||||
private MaterialService materialService;
|
||||
|
||||
@GetMapping(value = "/getAllList")
|
||||
public BaseResponseInfo getAllList(HttpServletRequest request) throws Exception{
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
@@ -232,4 +237,33 @@ public class DepotController {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getAllListWithStock")
|
||||
public BaseResponseInfo getAllList(@RequestParam("mId") Long mId,
|
||||
HttpServletRequest request) {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
List<Depot> list = depotService.getAllList();
|
||||
List<DepotEx> depotList = new ArrayList<DepotEx>();
|
||||
for(Depot depot: list) {
|
||||
DepotEx de = new DepotEx();
|
||||
if(mId!=0) {
|
||||
BigDecimal stock = materialService.getInitStock(mId, depot.getId());
|
||||
de.setStock(stock);
|
||||
} else {
|
||||
de.setStock(BigDecimal.ZERO);
|
||||
}
|
||||
de.setId(depot.getId());
|
||||
de.setName(depot.getName());
|
||||
depotList.add(de);
|
||||
}
|
||||
res.code = 200;
|
||||
res.data = depotList;
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
res.code = 500;
|
||||
res.data = "获取数据失败";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class MaterialController {
|
||||
}
|
||||
|
||||
/**
|
||||
* excel表格导入
|
||||
* excel表格导入产品(含初始库存)
|
||||
* @param materialFile
|
||||
* @param request
|
||||
* @param response
|
||||
@@ -257,30 +257,7 @@ public class MaterialController {
|
||||
info.code = 400;
|
||||
info.data = data;
|
||||
}
|
||||
//每行中数据顺序 "品名","类型","型号","安全存量","单位","零售价","最低售价","预计采购价","批发价","备注","状态"
|
||||
List<Material> mList = new ArrayList<Material>();
|
||||
for (int i = 1; i < src.getRows(); i++) {
|
||||
Material m = new Material();
|
||||
m.setName(ExcelUtils.getContent(src, i, 0));
|
||||
m.setCategoryid(1L); //根目录
|
||||
m.setModel(ExcelUtils.getContent(src, i, 2));
|
||||
String safetyStock = ExcelUtils.getContent(src, i, 3);
|
||||
m.setSafetystock(parseBigDecimalEx(safetyStock));
|
||||
m.setUnit(ExcelUtils.getContent(src, i, 4));
|
||||
String retailprice = ExcelUtils.getContent(src, i, 5);
|
||||
m.setRetailprice(parseBigDecimalEx(retailprice));
|
||||
String lowPrice = ExcelUtils.getContent(src, i, 6);
|
||||
m.setLowprice(parseBigDecimalEx(lowPrice));
|
||||
String presetpriceone = ExcelUtils.getContent(src, i, 7);
|
||||
m.setPresetpriceone(parseBigDecimalEx(presetpriceone));
|
||||
String presetpricetwo = ExcelUtils.getContent(src, i, 8);
|
||||
m.setPresetpricetwo(parseBigDecimalEx(presetpricetwo));
|
||||
m.setRemark(ExcelUtils.getContent(src, i, 9));
|
||||
String enabled = ExcelUtils.getContent(src, i, 10);
|
||||
m.setEnabled(enabled.equals("启用")? true: false);
|
||||
mList.add(m);
|
||||
}
|
||||
info = materialService.importExcel(mList);
|
||||
info = materialService.importExcel(src);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
message = "导入失败";
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Description
|
||||
*
|
||||
@@ -10,6 +12,8 @@ public class DepotEx extends Depot{
|
||||
//负责人名字
|
||||
private String principalName;
|
||||
|
||||
private BigDecimal stock;
|
||||
|
||||
public String getPrincipalName() {
|
||||
return principalName;
|
||||
}
|
||||
@@ -17,4 +21,12 @@ public class DepotEx extends Depot{
|
||||
public void setPrincipalName(String principalName) {
|
||||
this.principalName = principalName;
|
||||
}
|
||||
|
||||
public BigDecimal getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public void setStock(BigDecimal stock) {
|
||||
this.stock = stock;
|
||||
}
|
||||
}
|
||||
|
||||
197
src/main/java/com/jsh/erp/datasource/entities/MaterialStock.java
Normal file
197
src/main/java/com/jsh/erp/datasource/entities/MaterialStock.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class MaterialStock {
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.material_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private Long materialId;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.depot_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private Long depotId;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.number
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private BigDecimal number;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.tenant_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column jsh_material_stock.delete_fag
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
private String deleteFag;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.id
|
||||
*
|
||||
* @return the value of jsh_material_stock.id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.id
|
||||
*
|
||||
* @param id the value for jsh_material_stock.id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.material_id
|
||||
*
|
||||
* @return the value of jsh_material_stock.material_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Long getMaterialId() {
|
||||
return materialId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.material_id
|
||||
*
|
||||
* @param materialId the value for jsh_material_stock.material_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setMaterialId(Long materialId) {
|
||||
this.materialId = materialId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.depot_id
|
||||
*
|
||||
* @return the value of jsh_material_stock.depot_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Long getDepotId() {
|
||||
return depotId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.depot_id
|
||||
*
|
||||
* @param depotId the value for jsh_material_stock.depot_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setDepotId(Long depotId) {
|
||||
this.depotId = depotId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.number
|
||||
*
|
||||
* @return the value of jsh_material_stock.number
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public BigDecimal getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.number
|
||||
*
|
||||
* @param number the value for jsh_material_stock.number
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setNumber(BigDecimal number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.tenant_id
|
||||
*
|
||||
* @return the value of jsh_material_stock.tenant_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Long getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.tenant_id
|
||||
*
|
||||
* @param tenantId the value for jsh_material_stock.tenant_id
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setTenantId(Long tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column jsh_material_stock.delete_fag
|
||||
*
|
||||
* @return the value of jsh_material_stock.delete_fag
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public String getDeleteFag() {
|
||||
return deleteFag;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column jsh_material_stock.delete_fag
|
||||
*
|
||||
* @param deleteFag the value for jsh_material_stock.delete_fag
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setDeleteFag(String deleteFag) {
|
||||
this.deleteFag = deleteFag == null ? null : deleteFag.trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,673 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MaterialStockExample {
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
protected String orderByClause;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
protected boolean distinct;
|
||||
|
||||
/**
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public MaterialStockExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setOrderByClause(String orderByClause) {
|
||||
this.orderByClause = orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public String getOrderByClause() {
|
||||
return orderByClause;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void setDistinct(boolean distinct) {
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public boolean isDistinct() {
|
||||
return distinct;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public List<Criteria> getOredCriteria() {
|
||||
return oredCriteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void or(Criteria criteria) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Criteria or() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
oredCriteria.add(criteria);
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public Criteria createCriteria() {
|
||||
Criteria criteria = createCriteriaInternal();
|
||||
if (oredCriteria.size() == 0) {
|
||||
oredCriteria.add(criteria);
|
||||
}
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
protected Criteria createCriteriaInternal() {
|
||||
Criteria criteria = new Criteria();
|
||||
return criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public void clear() {
|
||||
oredCriteria.clear();
|
||||
orderByClause = null;
|
||||
distinct = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
protected abstract static class GeneratedCriteria {
|
||||
protected List<Criterion> criteria;
|
||||
|
||||
protected GeneratedCriteria() {
|
||||
super();
|
||||
criteria = new ArrayList<Criterion>();
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return criteria.size() > 0;
|
||||
}
|
||||
|
||||
public List<Criterion> getAllCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
public List<Criterion> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition) {
|
||||
if (condition == null) {
|
||||
throw new RuntimeException("Value for condition cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value, String property) {
|
||||
if (value == null) {
|
||||
throw new RuntimeException("Value for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value));
|
||||
}
|
||||
|
||||
protected void addCriterion(String condition, Object value1, Object value2, String property) {
|
||||
if (value1 == null || value2 == null) {
|
||||
throw new RuntimeException("Between values for " + property + " cannot be null");
|
||||
}
|
||||
criteria.add(new Criterion(condition, value1, value2));
|
||||
}
|
||||
|
||||
public Criteria andIdIsNull() {
|
||||
addCriterion("id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIsNotNull() {
|
||||
addCriterion("id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdEqualTo(Long value) {
|
||||
addCriterion("id =", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotEqualTo(Long value) {
|
||||
addCriterion("id <>", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThan(Long value) {
|
||||
addCriterion("id >", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("id >=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThan(Long value) {
|
||||
addCriterion("id <", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("id <=", value, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdIn(List<Long> values) {
|
||||
addCriterion("id in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotIn(List<Long> values) {
|
||||
addCriterion("id not in", values, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdBetween(Long value1, Long value2) {
|
||||
addCriterion("id between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("id not between", value1, value2, "id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdIsNull() {
|
||||
addCriterion("material_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdIsNotNull() {
|
||||
addCriterion("material_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdEqualTo(Long value) {
|
||||
addCriterion("material_id =", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdNotEqualTo(Long value) {
|
||||
addCriterion("material_id <>", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdGreaterThan(Long value) {
|
||||
addCriterion("material_id >", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("material_id >=", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdLessThan(Long value) {
|
||||
addCriterion("material_id <", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("material_id <=", value, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdIn(List<Long> values) {
|
||||
addCriterion("material_id in", values, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdNotIn(List<Long> values) {
|
||||
addCriterion("material_id not in", values, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdBetween(Long value1, Long value2) {
|
||||
addCriterion("material_id between", value1, value2, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andMaterialIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("material_id not between", value1, value2, "materialId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdIsNull() {
|
||||
addCriterion("depot_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdIsNotNull() {
|
||||
addCriterion("depot_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdEqualTo(Long value) {
|
||||
addCriterion("depot_id =", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdNotEqualTo(Long value) {
|
||||
addCriterion("depot_id <>", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdGreaterThan(Long value) {
|
||||
addCriterion("depot_id >", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("depot_id >=", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdLessThan(Long value) {
|
||||
addCriterion("depot_id <", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("depot_id <=", value, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdIn(List<Long> values) {
|
||||
addCriterion("depot_id in", values, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdNotIn(List<Long> values) {
|
||||
addCriterion("depot_id not in", values, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdBetween(Long value1, Long value2) {
|
||||
addCriterion("depot_id between", value1, value2, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDepotIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("depot_id not between", value1, value2, "depotId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberIsNull() {
|
||||
addCriterion("number is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberIsNotNull() {
|
||||
addCriterion("number is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberEqualTo(BigDecimal value) {
|
||||
addCriterion("number =", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberNotEqualTo(BigDecimal value) {
|
||||
addCriterion("number <>", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberGreaterThan(BigDecimal value) {
|
||||
addCriterion("number >", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberGreaterThanOrEqualTo(BigDecimal value) {
|
||||
addCriterion("number >=", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberLessThan(BigDecimal value) {
|
||||
addCriterion("number <", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberLessThanOrEqualTo(BigDecimal value) {
|
||||
addCriterion("number <=", value, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberIn(List<BigDecimal> values) {
|
||||
addCriterion("number in", values, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberNotIn(List<BigDecimal> values) {
|
||||
addCriterion("number not in", values, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberBetween(BigDecimal value1, BigDecimal value2) {
|
||||
addCriterion("number between", value1, value2, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andNumberNotBetween(BigDecimal value1, BigDecimal value2) {
|
||||
addCriterion("number not between", value1, value2, "number");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdIsNull() {
|
||||
addCriterion("tenant_id is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdIsNotNull() {
|
||||
addCriterion("tenant_id is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdEqualTo(Long value) {
|
||||
addCriterion("tenant_id =", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdNotEqualTo(Long value) {
|
||||
addCriterion("tenant_id <>", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdGreaterThan(Long value) {
|
||||
addCriterion("tenant_id >", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdGreaterThanOrEqualTo(Long value) {
|
||||
addCriterion("tenant_id >=", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdLessThan(Long value) {
|
||||
addCriterion("tenant_id <", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdLessThanOrEqualTo(Long value) {
|
||||
addCriterion("tenant_id <=", value, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdIn(List<Long> values) {
|
||||
addCriterion("tenant_id in", values, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdNotIn(List<Long> values) {
|
||||
addCriterion("tenant_id not in", values, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdBetween(Long value1, Long value2) {
|
||||
addCriterion("tenant_id between", value1, value2, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andTenantIdNotBetween(Long value1, Long value2) {
|
||||
addCriterion("tenant_id not between", value1, value2, "tenantId");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagIsNull() {
|
||||
addCriterion("delete_fag is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagIsNotNull() {
|
||||
addCriterion("delete_fag is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagEqualTo(String value) {
|
||||
addCriterion("delete_fag =", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagNotEqualTo(String value) {
|
||||
addCriterion("delete_fag <>", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagGreaterThan(String value) {
|
||||
addCriterion("delete_fag >", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("delete_fag >=", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagLessThan(String value) {
|
||||
addCriterion("delete_fag <", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagLessThanOrEqualTo(String value) {
|
||||
addCriterion("delete_fag <=", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagLike(String value) {
|
||||
addCriterion("delete_fag like", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagNotLike(String value) {
|
||||
addCriterion("delete_fag not like", value, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagIn(List<String> values) {
|
||||
addCriterion("delete_fag in", values, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagNotIn(List<String> values) {
|
||||
addCriterion("delete_fag not in", values, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagBetween(String value1, String value2) {
|
||||
addCriterion("delete_fag between", value1, value2, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andDeleteFagNotBetween(String value1, String value2) {
|
||||
addCriterion("delete_fag not between", value1, value2, "deleteFag");
|
||||
return (Criteria) this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated do_not_delete_during_merge
|
||||
*/
|
||||
public static class Criteria extends GeneratedCriteria {
|
||||
|
||||
protected Criteria() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class was generated by MyBatis Generator.
|
||||
* This class corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
public static class Criterion {
|
||||
private String condition;
|
||||
|
||||
private Object value;
|
||||
|
||||
private Object secondValue;
|
||||
|
||||
private boolean noValue;
|
||||
|
||||
private boolean singleValue;
|
||||
|
||||
private boolean betweenValue;
|
||||
|
||||
private boolean listValue;
|
||||
|
||||
private String typeHandler;
|
||||
|
||||
public String getCondition() {
|
||||
return condition;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Object getSecondValue() {
|
||||
return secondValue;
|
||||
}
|
||||
|
||||
public boolean isNoValue() {
|
||||
return noValue;
|
||||
}
|
||||
|
||||
public boolean isSingleValue() {
|
||||
return singleValue;
|
||||
}
|
||||
|
||||
public boolean isBetweenValue() {
|
||||
return betweenValue;
|
||||
}
|
||||
|
||||
public boolean isListValue() {
|
||||
return listValue;
|
||||
}
|
||||
|
||||
public String getTypeHandler() {
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
protected Criterion(String condition) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.typeHandler = null;
|
||||
this.noValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.typeHandler = typeHandler;
|
||||
if (value instanceof List<?>) {
|
||||
this.listValue = true;
|
||||
} else {
|
||||
this.singleValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value) {
|
||||
this(condition, value, null);
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
|
||||
super();
|
||||
this.condition = condition;
|
||||
this.value = value;
|
||||
this.secondValue = secondValue;
|
||||
this.typeHandler = typeHandler;
|
||||
this.betweenValue = true;
|
||||
}
|
||||
|
||||
protected Criterion(String condition, Object value, Object secondValue) {
|
||||
this(condition, value, secondValue, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.jsh.erp.datasource.entities;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
public class MaterialWithInitStock extends Material {
|
||||
|
||||
private Map<Long, BigDecimal> stockMap;
|
||||
|
||||
public Map<Long, BigDecimal> getStockMap() {
|
||||
return stockMap;
|
||||
}
|
||||
|
||||
public void setStockMap(Map<Long, BigDecimal> stockMap) {
|
||||
this.stockMap = stockMap;
|
||||
}
|
||||
}
|
||||
@@ -59,4 +59,6 @@ public interface MaterialMapperEx {
|
||||
List<Material> getMaterialListByCategoryIds(@Param("categoryIds") String[] categoryIds);
|
||||
|
||||
List<Material> getMaterialListByUnitIds(@Param("unitIds") String[] unitIds);
|
||||
|
||||
int insertSelectiveEx(Material record);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.jsh.erp.datasource.mappers;
|
||||
|
||||
import com.jsh.erp.datasource.entities.MaterialStock;
|
||||
import com.jsh.erp.datasource.entities.MaterialStockExample;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface MaterialStockMapper {
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int countByExample(MaterialStockExample example);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int deleteByExample(MaterialStockExample example);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int deleteByPrimaryKey(Long id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int insert(MaterialStock record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int insertSelective(MaterialStock record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
List<MaterialStock> selectByExample(MaterialStockExample example);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
MaterialStock selectByPrimaryKey(Long id);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int updateByExampleSelective(@Param("record") MaterialStock record, @Param("example") MaterialStockExample example);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int updateByExample(@Param("record") MaterialStock record, @Param("example") MaterialStockExample example);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int updateByPrimaryKeySelective(MaterialStock record);
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method corresponds to the database table jsh_material_stock
|
||||
*
|
||||
* @mbggenerated
|
||||
*/
|
||||
int updateByPrimaryKey(MaterialStock record);
|
||||
}
|
||||
@@ -292,4 +292,19 @@ public class DepotService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称获取id
|
||||
* @param name
|
||||
*/
|
||||
public Long getIdByName(String name){
|
||||
Long id = 0L;
|
||||
DepotExample example = new DepotExample();
|
||||
example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
List<Depot> list = depotMapper.selectByExample(example);
|
||||
if(list!=null && list.size()>0) {
|
||||
id = list.get(0).getId();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,10 +663,12 @@ public class DepotItemService {
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getStockByParam(Long depotId, Long mId, String beginTime, String endTime, Long tenantId){
|
||||
//初始库存
|
||||
BigDecimal initStock = materialService.getInitStockByMid(depotId, mId);
|
||||
DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParam(depotId, mId, beginTime, endTime, tenantId);
|
||||
BigDecimal intNum = stockObj.getInNum();
|
||||
BigDecimal outNum = stockObj.getOutNum();
|
||||
return intNum.subtract(outNum);
|
||||
return initStock.add(intNum).subtract(outNum);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.jsh.erp.service.material;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
@@ -8,13 +10,19 @@ import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.datasource.mappers.DepotItemMapperEx;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapper;
|
||||
import com.jsh.erp.datasource.mappers.MaterialMapperEx;
|
||||
import com.jsh.erp.datasource.mappers.MaterialStockMapper;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.exception.JshException;
|
||||
import com.jsh.erp.service.depot.DepotService;
|
||||
import com.jsh.erp.service.depotItem.DepotItemService;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
import com.jsh.erp.service.materialCategory.MaterialCategoryService;
|
||||
import com.jsh.erp.service.unit.UnitService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
import com.jsh.erp.utils.ExcelUtils;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import jxl.Sheet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -24,6 +32,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@@ -42,6 +51,14 @@ public class MaterialService {
|
||||
private DepotItemMapperEx depotItemMapperEx;
|
||||
@Resource
|
||||
private DepotItemService depotItemService;
|
||||
@Resource
|
||||
private MaterialCategoryService materialCategoryService;
|
||||
@Resource
|
||||
private UnitService unitService;
|
||||
@Resource
|
||||
private MaterialStockMapper materialStockMapper;
|
||||
@Resource
|
||||
private DepotService depotService;
|
||||
|
||||
public Material getMaterial(long id)throws Exception {
|
||||
Material result=null;
|
||||
@@ -125,6 +142,22 @@ public class MaterialService {
|
||||
int result =0;
|
||||
try{
|
||||
result= materialMapper.insertSelective(material);
|
||||
JSONObject mObj = JSON.parseObject(beanJson);
|
||||
Long mId = material.getId();
|
||||
if(mObj.get("stock")!=null) {
|
||||
String stockStr = mObj.getString("stock");
|
||||
JSONArray stockArr = JSONArray.parseArray(stockStr);
|
||||
for(Object object: stockArr) {
|
||||
JSONObject jsonObj = (JSONObject)object;
|
||||
if(jsonObj.get("depotId")!=null && jsonObj.get("number")!=null) {
|
||||
String number = jsonObj.getString("number");
|
||||
Long depotId = jsonObj.getLong("depotId");
|
||||
if(number!=null && Double.valueOf(number)>0) {
|
||||
insertStockByMaterialAndDepot(depotId, mId, parseBigDecimalEx(number));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logService.insertLog("商品", BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
|
||||
}catch(Exception e){
|
||||
JshException.writeFail(logger, e);
|
||||
@@ -145,6 +178,25 @@ public class MaterialService {
|
||||
} else {
|
||||
materialMapperEx.updateUnitIdNullByPrimaryKey(id); //将多单位置空
|
||||
}
|
||||
JSONObject mObj = JSON.parseObject(beanJson);
|
||||
if(mObj.get("stock")!=null) {
|
||||
String stockStr = mObj.getString("stock");
|
||||
JSONArray stockArr = JSONArray.parseArray(stockStr);
|
||||
for (Object object : stockArr) {
|
||||
JSONObject jsonObj = (JSONObject) object;
|
||||
if (jsonObj.get("depotId") != null && jsonObj.get("number") != null) {
|
||||
String number = jsonObj.getString("number");
|
||||
Long depotId = jsonObj.getLong("depotId");
|
||||
//先清除再插入
|
||||
MaterialStockExample example = new MaterialStockExample();
|
||||
example.createCriteria().andMaterialIdEqualTo(id).andDepotIdEqualTo(depotId);
|
||||
materialStockMapper.deleteByExample(example);
|
||||
if (number != null && Double.valueOf(number) > 0) {
|
||||
insertStockByMaterialAndDepot(depotId, id, parseBigDecimalEx(number));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logService.insertLog("商品",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(id).toString(), request);
|
||||
}catch(Exception e){
|
||||
@@ -296,21 +348,127 @@ public class MaterialService {
|
||||
}
|
||||
return resList;
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public BaseResponseInfo importExcel(List<Material> mList) throws Exception {
|
||||
public BaseResponseInfo importExcel(Sheet src) throws Exception {
|
||||
List<Depot> depotList= depotService.getDepot();
|
||||
int depotCount = depotList.size();
|
||||
List<MaterialWithInitStock> mList = new ArrayList<MaterialWithInitStock>();
|
||||
for (int i = 2; i < src.getRows(); i++) {
|
||||
String name = ExcelUtils.getContent(src, i, 0); //名称
|
||||
String model = ExcelUtils.getContent(src, i, 1); //型号
|
||||
String categoryName = ExcelUtils.getContent(src, i, 2); //类型
|
||||
String safetyStock = ExcelUtils.getContent(src, i, 3); //安全存量
|
||||
String color = ExcelUtils.getContent(src, i, 4); //颜色
|
||||
String unit = ExcelUtils.getContent(src, i, 5); //单位
|
||||
//校验名称、型号、单位是否为空
|
||||
if(StringUtil.isNotEmpty(name) && StringUtil.isNotEmpty(model) && StringUtil.isNotEmpty(unit)) {
|
||||
MaterialWithInitStock m = new MaterialWithInitStock();
|
||||
m.setName(name);
|
||||
m.setModel(model);
|
||||
Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
|
||||
m.setCategoryid(categoryId);
|
||||
m.setSafetystock(parseBigDecimalEx(safetyStock));
|
||||
m.setColor(color);
|
||||
String manyUnit = ExcelUtils.getContent(src, i, 6); //多单位
|
||||
String ratio = ExcelUtils.getContent(src, i, 7); //比例
|
||||
String retailPrice = ExcelUtils.getContent(src, i, 8); //零售价
|
||||
String lowPrice = ExcelUtils.getContent(src, i, 9); //最低售价
|
||||
String presetpriceone = ExcelUtils.getContent(src, i, 10); //预计采购价
|
||||
String presetpricetwo = ExcelUtils.getContent(src, i, 11); //销售价
|
||||
if(StringUtil.isNotEmpty(manyUnit.trim())){ //多单位
|
||||
String manyUnitAll = unit + "," + manyUnit + "(1:" + ratio + ")";
|
||||
Long unitId = unitService.getUnitIdByName(manyUnitAll);
|
||||
m.setUnitid(unitId);
|
||||
m.setFirstoutunit(unit); //首选出库单位
|
||||
m.setFirstinunit(manyUnit); //首选入库单位
|
||||
JSONArray arr = new JSONArray();
|
||||
JSONObject basicObj = new JSONObject();
|
||||
basicObj.put("Unit", unit);
|
||||
basicObj.put("RetailPrice", retailPrice);
|
||||
basicObj.put("LowPrice", lowPrice);
|
||||
basicObj.put("PresetPriceOne", presetpriceone);
|
||||
basicObj.put("PresetPriceTwo", presetpricetwo);
|
||||
JSONObject basicObjEx = new JSONObject();
|
||||
basicObjEx.put("basic", basicObj);
|
||||
JSONObject otherObj = new JSONObject();
|
||||
otherObj.put("Unit", manyUnit);
|
||||
otherObj.put("RetailPrice", parsePrice(retailPrice,ratio));
|
||||
otherObj.put("LowPrice", parsePrice(lowPrice,ratio));
|
||||
otherObj.put("PresetPriceOne", parsePrice(presetpriceone,ratio));
|
||||
otherObj.put("PresetPriceTwo", parsePrice(presetpricetwo,ratio));
|
||||
JSONObject otherObjEx = new JSONObject();
|
||||
otherObjEx.put("other", otherObj);
|
||||
arr.add(basicObjEx);
|
||||
arr.add(otherObjEx);
|
||||
m.setPricestrategy(arr.toJSONString());
|
||||
} else {
|
||||
m.setUnit(unit);
|
||||
m.setRetailprice(parseBigDecimalEx(retailPrice));
|
||||
m.setLowprice(parseBigDecimalEx(lowPrice));
|
||||
m.setPresetpriceone(parseBigDecimalEx(presetpriceone));
|
||||
m.setPresetpricetwo(parseBigDecimalEx(presetpricetwo));
|
||||
}
|
||||
String enabled = ExcelUtils.getContent(src, i, 12); //状态
|
||||
m.setEnabled(enabled.equals("1")? true: false);
|
||||
//缓存各个仓库的库存信息
|
||||
Map<Long, BigDecimal> stockMap = new HashMap<Long, BigDecimal>();
|
||||
for(int j=1; j<=depotCount;j++) {
|
||||
int col = 12+j;
|
||||
if(col <= src.getColumns()){
|
||||
String depotName = ExcelUtils.getContent(src, 1, col); //获取仓库名称
|
||||
Long depotId = depotService.getIdByName(depotName);
|
||||
if(depotId!=0L){
|
||||
String stockStr = ExcelUtils.getContent(src, i, col);
|
||||
if(StringUtil.isNotEmpty(stockStr)) {
|
||||
stockMap.put(depotId, parseBigDecimalEx(stockStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m.setStockMap(stockMap);
|
||||
mList.add(m);
|
||||
}
|
||||
}
|
||||
logService.insertLog("商品",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
BaseResponseInfo info = new BaseResponseInfo();
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
try {
|
||||
for(Material m: mList) {
|
||||
materialMapper.insertSelective(m);
|
||||
Long mId = 0L;
|
||||
for(MaterialWithInitStock m: mList) {
|
||||
//判断该商品是否存在,如果不存在就新增,如果存在就更新
|
||||
List<Material> materials = getMaterialListByParam(m.getName(),m.getModel(),m.getColor(),m.getStandard(),
|
||||
m.getMfrs(),m.getUnit(),m.getUnitid());
|
||||
if(materials.size()<=0) {
|
||||
materialMapperEx.insertSelectiveEx(m);
|
||||
mId = m.getId();
|
||||
} else {
|
||||
mId = materials.get(0).getId();
|
||||
String materialJson = JSON.toJSONString(m);
|
||||
Material material = JSONObject.parseObject(materialJson, Material.class);
|
||||
material.setId(mId);
|
||||
materialMapper.updateByPrimaryKeySelective(material);
|
||||
}
|
||||
//给商品初始化库存
|
||||
Map<Long, BigDecimal> stockMap = m.getStockMap();
|
||||
Long depotId = null;
|
||||
for(Depot depot: depotList){
|
||||
BigDecimal stock = stockMap.get(depot.getId());
|
||||
//先清除再插入
|
||||
MaterialStockExample example = new MaterialStockExample();
|
||||
example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(depot.getId());
|
||||
materialStockMapper.deleteByExample(example);
|
||||
if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
|
||||
depotId = depot.getId();
|
||||
insertStockByMaterialAndDepot(depotId, mId, stock);
|
||||
}
|
||||
}
|
||||
}
|
||||
info.code = 200;
|
||||
data.put("message", "成功");
|
||||
} catch (Exception e) {
|
||||
JshException.writeFail(logger, e);
|
||||
e.printStackTrace();
|
||||
info.code = 500;
|
||||
data.put("message", e.getMessage());
|
||||
@@ -319,6 +477,57 @@ public class MaterialService {
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件返回产品列表
|
||||
* @param name
|
||||
* @param model
|
||||
* @param color
|
||||
* @param standard
|
||||
* @param mfrs
|
||||
* @param unit
|
||||
* @param unitId
|
||||
* @return
|
||||
*/
|
||||
private List<Material> getMaterialListByParam(String name, String model, String color,
|
||||
String standard, String mfrs, String unit, Long unitId) {
|
||||
MaterialExample example = new MaterialExample();
|
||||
MaterialExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andNameEqualTo(name).andModelEqualTo(model);
|
||||
if (StringUtil.isNotEmpty(color)) {
|
||||
criteria.andColorEqualTo(color);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(standard)) {
|
||||
criteria.andStandardEqualTo(standard);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(mfrs)) {
|
||||
criteria.andMfrsEqualTo(mfrs);
|
||||
}
|
||||
if (StringUtil.isNotEmpty(unit)) {
|
||||
criteria.andUnitEqualTo(unit);
|
||||
}
|
||||
if (unitId !=null) {
|
||||
criteria.andUnitidEqualTo(unitId);
|
||||
}
|
||||
criteria.andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
List<Material> list = materialMapper.selectByExample(example);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入初始库存
|
||||
* @param depotId
|
||||
* @param mId
|
||||
* @param stock
|
||||
*/
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public void insertStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock){
|
||||
MaterialStock materialStock = new MaterialStock();
|
||||
materialStock.setDepotId(depotId);
|
||||
materialStock.setMaterialId(mId);
|
||||
materialStock.setNumber(stock);
|
||||
materialStockMapper.insertSelective(materialStock); //存入初始库存
|
||||
}
|
||||
|
||||
public List<Material> getMaterialEnableSerialNumberList(Map<String, Object> parameterMap)throws Exception {
|
||||
List<Material> list =null;
|
||||
try{
|
||||
@@ -387,4 +596,66 @@ public class MaterialService {
|
||||
return deleteTotal;
|
||||
|
||||
}
|
||||
|
||||
public BigDecimal parseBigDecimalEx(String str) throws Exception{
|
||||
if(!StringUtil.isEmpty(str)) {
|
||||
return new BigDecimal(str);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public BigDecimal parsePrice(String price, String ratio) throws Exception{
|
||||
if(StringUtil.isEmpty(price) || StringUtil.isEmpty(ratio)) {
|
||||
return BigDecimal.ZERO;
|
||||
} else {
|
||||
BigDecimal pr=new BigDecimal(price);
|
||||
BigDecimal r=new BigDecimal(ratio);
|
||||
return pr.multiply(r);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品和仓库获取初始库存
|
||||
* @param materialId
|
||||
* @param depotId
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getInitStock(Long materialId, Long depotId) {
|
||||
BigDecimal stock = BigDecimal.ZERO;
|
||||
MaterialStockExample example = new MaterialStockExample();
|
||||
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
|
||||
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
List<MaterialStock> list = materialStockMapper.selectByExample(example);
|
||||
if(list!=null && list.size()>0) {
|
||||
stock = list.get(0).getNumber();
|
||||
}
|
||||
return stock;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品获取初始库存
|
||||
* @param materialId
|
||||
* @return
|
||||
*/
|
||||
public BigDecimal getInitStockByMid(Long depotId, Long materialId) {
|
||||
BigDecimal stock = BigDecimal.ZERO;
|
||||
MaterialStockExample example = new MaterialStockExample();
|
||||
if(depotId!=null) {
|
||||
example.createCriteria().andMaterialIdEqualTo(materialId).andDepotIdEqualTo(depotId)
|
||||
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
} else {
|
||||
example.createCriteria().andMaterialIdEqualTo(materialId)
|
||||
.andDeleteFagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
}
|
||||
List<MaterialStock> list = materialStockMapper.selectByExample(example);
|
||||
if(list!=null && list.size()>0) {
|
||||
for(MaterialStock ms: list) {
|
||||
if(ms!=null) {
|
||||
stock = stock.add(ms.getNumber());
|
||||
}
|
||||
}
|
||||
}
|
||||
return stock;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,4 +388,19 @@ public class MaterialCategoryService {
|
||||
deleteTotal= batchDeleteMaterialCategoryByIds(ids);
|
||||
return deleteTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称获取类型
|
||||
* @param name
|
||||
*/
|
||||
public Long getCategoryIdByName(String name){
|
||||
Long categoryId = 0l;
|
||||
MaterialCategoryExample example = new MaterialCategoryExample();
|
||||
example.createCriteria().andNameEqualTo(name).andStatusNotEqualTo(BusinessConstants.DELETE_TYPE_FORCE);
|
||||
List<MaterialCategory> list = materialCategoryMapper.selectByExample(example);
|
||||
if(list!=null && list.size()>0) {
|
||||
categoryId = list.get(0).getId();
|
||||
}
|
||||
return categoryId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,4 +208,19 @@ public class UnitService {
|
||||
deleteTotal= batchDeleteUnitByIds(ids);
|
||||
return deleteTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称获取类型
|
||||
* @param name
|
||||
*/
|
||||
public Long getUnitIdByName(String name){
|
||||
Long unitId = 0l;
|
||||
UnitExample example = new UnitExample();
|
||||
example.createCriteria().andUnameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
|
||||
List<Unit> list = unitMapper.selectByExample(example);
|
||||
if(list!=null && list.size()>0) {
|
||||
unitId = list.get(0).getId();
|
||||
}
|
||||
return unitId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user