openerp/jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialController.java

832 lines
38 KiB
Java
Raw Normal View History

2021-04-07 23:53:57 +08:00
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
2025-02-23 14:49:34 +08:00
import com.jsh.erp.base.BaseController;
import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.datasource.entities.Material;
import com.jsh.erp.datasource.entities.MaterialExtend;
2022-05-03 11:11:03 +08:00
import com.jsh.erp.datasource.entities.MaterialVo4Unit;
import com.jsh.erp.datasource.entities.Unit;
2025-02-24 23:08:06 +08:00
import com.jsh.erp.service.DepotService;
import com.jsh.erp.service.DepotItemService;
import com.jsh.erp.service.MaterialService;
import com.jsh.erp.service.RoleService;
import com.jsh.erp.service.SystemConfigService;
import com.jsh.erp.service.UnitService;
import com.jsh.erp.service.UserService;
2025-02-23 14:49:34 +08:00
import com.jsh.erp.utils.*;
2021-11-08 23:14:21 +08:00
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
2021-04-07 23:53:57 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
2021-04-07 23:53:57 +08:00
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
2022-05-03 11:11:03 +08:00
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
2021-04-07 23:53:57 +08:00
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
2025-02-23 14:49:34 +08:00
import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
2021-04-07 23:53:57 +08:00
/**
* @author ji|sheng|hua jshERP
*/
@RestController
@RequestMapping(value = "/material")
2021-11-08 23:14:21 +08:00
@Api(tags = {"商品管理"})
2025-02-23 14:49:34 +08:00
public class MaterialController extends BaseController {
2021-04-07 23:53:57 +08:00
private Logger logger = LoggerFactory.getLogger(MaterialController.class);
@Resource
private MaterialService materialService;
@Resource
private DepotItemService depotItemService;
@Resource
private SystemConfigService systemConfigService;
@Resource
private UnitService unitService;
@Resource
private DepotService depotService;
@Resource
private RoleService roleService;
@Resource
private UserService userService;
@Value(value="${file.uploadType}")
private Long fileUploadType;
2025-02-23 14:49:34 +08:00
@GetMapping(value = "/info")
@ApiOperation(value = "根据id获取信息")
public String getList(@RequestParam("id") Long id,
HttpServletRequest request) throws Exception {
Material material = materialService.getMaterial(id);
Map<String, Object> objectMap = new HashMap<>();
if(material != null) {
objectMap.put("info", material);
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
@GetMapping(value = "/list")
@ApiOperation(value = "获取信息列表")
public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
HttpServletRequest request)throws Exception {
String categoryId = StringUtil.getInfo(search, "categoryId");
String materialParam = StringUtil.getInfo(search, "materialParam");
String standard = StringUtil.getInfo(search, "standard");
String model = StringUtil.getInfo(search, "model");
String color = StringUtil.getInfo(search, "color");
String brand = StringUtil.getInfo(search, "brand");
String mfrs = StringUtil.getInfo(search, "mfrs");
String otherField1 = StringUtil.getInfo(search, "otherField1");
String otherField2 = StringUtil.getInfo(search, "otherField2");
String otherField3 = StringUtil.getInfo(search, "otherField3");
2025-02-23 14:49:34 +08:00
String weight = StringUtil.getInfo(search, "weight");
String expiryNum = StringUtil.getInfo(search, "expiryNum");
String enableSerialNumber = StringUtil.getInfo(search, "enableSerialNumber");
String enableBatchNumber = StringUtil.getInfo(search, "enableBatchNumber");
String position = StringUtil.getInfo(search, "position");
String enabled = StringUtil.getInfo(search, "enabled");
String remark = StringUtil.getInfo(search, "remark");
String mpList = StringUtil.getInfo(search, "mpList");
List<MaterialVo4Unit> list = materialService.select(materialParam, standard, model, color, brand, mfrs, otherField1, otherField2,
otherField3, weight, expiryNum, enableSerialNumber, enableBatchNumber, position, enabled, remark, categoryId, mpList);
2025-02-23 14:49:34 +08:00
return getDataTable(list);
}
@PostMapping(value = "/add")
@ApiOperation(value = "新增")
public String addResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int insert = materialService.insertMaterial(obj, request);
return returnStr(objectMap, insert);
}
@PutMapping(value = "/update")
@ApiOperation(value = "修改")
public String updateResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int update = materialService.updateMaterial(obj, request);
return returnStr(objectMap, update);
}
@DeleteMapping(value = "/delete")
@ApiOperation(value = "删除")
public String deleteResource(@RequestParam("id") Long id, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int delete = materialService.deleteMaterial(id, request);
return returnStr(objectMap, delete);
}
@DeleteMapping(value = "/deleteBatch")
@ApiOperation(value = "批量删除")
public String batchDeleteResource(@RequestParam("ids") String ids, HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int delete = materialService.batchDeleteMaterial(ids, request);
return returnStr(objectMap, delete);
}
@GetMapping(value = "/checkIsNameExist")
@ApiOperation(value = "检查名称是否存在")
public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int exist = materialService.checkIsNameExist(id, name);
if(exist > 0) {
objectMap.put("status", true);
} else {
objectMap.put("status", false);
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
2021-11-08 23:14:21 +08:00
/**
* 检查商品是否存在
* @param id
* @param name
* @param model
* @param color
* @param standard
* @param mfrs
* @param otherField1
* @param otherField2
* @param otherField3
* @param unit
* @param unitId
* @param request
* @return
* @throws Exception
*/
2021-04-07 23:53:57 +08:00
@GetMapping(value = "/checkIsExist")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "检查商品是否存在")
2021-04-07 23:53:57 +08:00
public String checkIsExist(@RequestParam("id") Long id, @RequestParam("name") String name,
@RequestParam("model") String model, @RequestParam("color") String color,
@RequestParam("standard") String standard, @RequestParam("mfrs") String mfrs,
@RequestParam("otherField1") String otherField1, @RequestParam("otherField2") String otherField2,
@RequestParam("otherField3") String otherField3, @RequestParam("unit") String unit,@RequestParam("unitId") Long unitId,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<String, Object>();
2021-06-20 23:53:58 +08:00
int exist = materialService.checkIsExist(id, name, StringUtil.toNull(model), StringUtil.toNull(color),
StringUtil.toNull(standard), StringUtil.toNull(mfrs), StringUtil.toNull(otherField1),
StringUtil.toNull(otherField2), StringUtil.toNull(otherField3), StringUtil.toNull(unit), unitId);
2021-04-07 23:53:57 +08:00
if(exist > 0) {
objectMap.put("status", true);
} else {
objectMap.put("status", false);
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
}
/**
* 批量设置状态-启用或者禁用
* @param jsonObject
* @param request
* @return
* @throws Exception
*/
@PostMapping(value = "/batchSetStatus")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "批量设置状态-启用或者禁用")
2021-04-07 23:53:57 +08:00
public String batchSetStatus(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
Boolean status = jsonObject.getBoolean("status");
String ids = jsonObject.getString("ids");
Map<String, Object> objectMap = new HashMap<>();
int res = materialService.batchSetStatus(status, ids);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 根据id来查询商品名称
* @param id
* @param request
* @return
*/
@GetMapping(value = "/findById")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "根据id来查询商品名称")
2021-04-07 23:53:57 +08:00
public BaseResponseInfo findById(@RequestParam("id") Long id, HttpServletRequest request) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
List<MaterialVo4Unit> list = materialService.findById(id);
res.code = 200;
res.data = list;
} catch(Exception e){
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 根据meId来查询商品名称
* @param meId
* @param request
* @return
*/
@GetMapping(value = "/findByIdWithBarCode")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "根据meId来查询商品名称")
2021-04-07 23:53:57 +08:00
public BaseResponseInfo findByIdWithBarCode(@RequestParam("meId") Long meId,
@RequestParam("mpList") String mpList,
HttpServletRequest request) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
String[] mpArr = mpList.split(",");
MaterialVo4Unit mu = new MaterialVo4Unit();
List<MaterialVo4Unit> list = materialService.findByIdWithBarCode(meId);
if(list!=null && list.size()>0) {
mu = list.get(0);
2022-05-03 11:11:03 +08:00
mu.setMaterialOther(materialService.getMaterialOtherByParam(mpArr, mu));
2021-04-07 23:53:57 +08:00
}
res.code = 200;
res.data = mu;
} catch(Exception e){
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 根据关键词查找商品信息-条码名称规格型号
* @param q
* @param request
* @return
*/
@GetMapping(value = "/getMaterialByParam")
@ApiOperation(value = "根据关键词查找商品信息")
public BaseResponseInfo getMaterialByParam(@RequestParam("q") String q,
HttpServletRequest request) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
JSONArray arr = materialService.getMaterialByParam(q);
res.code = 200;
res.data = arr;
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
2021-04-07 23:53:57 +08:00
/**
* 查找商品信息-下拉框
* @param mpList
* @param request
* @return
*/
@GetMapping(value = "/findBySelect")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "查找商品信息")
2021-04-07 23:53:57 +08:00
public JSONObject findBySelect(@RequestParam(value = "categoryId", required = false) Long categoryId,
@RequestParam(value = "q", required = false) String q,
@RequestParam(value = "standardOrModel", required = false) String standardOrModel,
2023-02-07 23:30:33 +08:00
@RequestParam(value = "mpList", required = false) String mpList,
2021-04-07 23:53:57 +08:00
@RequestParam(value = "depotId", required = false) Long depotId,
@RequestParam(value = "color", required = false) String color,
@RequestParam(value = "brand", required = false) String brand,
@RequestParam(value = "mfrs", required = false) String mfrs,
@RequestParam(value = "otherField1", required = false) String otherField1,
@RequestParam(value = "otherField2", required = false) String otherField2,
@RequestParam(value = "otherField3", required = false) String otherField3,
@RequestParam(value = "enableSerialNumber", required = false) String enableSerialNumber,
@RequestParam(value = "enableBatchNumber", required = false) String enableBatchNumber,
2021-04-07 23:53:57 +08:00
@RequestParam("page") Integer currentPage,
@RequestParam("rows") Integer pageSize,
HttpServletRequest request) throws Exception{
JSONObject object = new JSONObject();
try {
2023-02-07 23:30:33 +08:00
String[] mpArr = new String[]{};
if(StringUtil.isNotEmpty(mpList)){
mpArr= mpList.split(",");
}
List<MaterialVo4Unit> dataList = materialService.findBySelectWithBarCode(categoryId, q, StringUtil.toNull(standardOrModel),
StringUtil.toNull(color), StringUtil.toNull(brand), StringUtil.toNull(mfrs), StringUtil.toNull(otherField1), StringUtil.toNull(otherField2), StringUtil.toNull(otherField3),
enableSerialNumber, enableBatchNumber, (currentPage-1)*pageSize, pageSize);
int total = materialService.findBySelectWithBarCodeCount(categoryId, q, StringUtil.toNull(standardOrModel),
StringUtil.toNull(color), StringUtil.toNull(brand), StringUtil.toNull(mfrs), StringUtil.toNull(otherField1), StringUtil.toNull(otherField2), StringUtil.toNull(otherField3),
enableSerialNumber, enableBatchNumber);
2021-04-07 23:53:57 +08:00
object.put("total", total);
JSONArray dataArray = new JSONArray();
//存放数据json数组
if (null != dataList) {
for (MaterialVo4Unit material : dataList) {
JSONObject item = new JSONObject();
item.put("id", material.getMeId()); //商品扩展表的id
String ratioStr = ""; //比例
Unit unit = new Unit();
if (material.getUnitId() == null) {
2021-12-01 00:58:54 +08:00
ratioStr = "";
2021-04-07 23:53:57 +08:00
} else {
unit = unitService.getUnit(material.getUnitId());
//拼接副单位的比例
String commodityUnit = material.getCommodityUnit();
if(commodityUnit.equals(unit.getBasicUnit())) {
ratioStr = "[基本]";
}
if(commodityUnit.equals(unit.getOtherUnit()) && unit.getRatio()!=null) {
ratioStr = "[" + unit.getRatio().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
}
if(commodityUnit.equals(unit.getOtherUnitTwo()) && unit.getRatioTwo()!=null) {
ratioStr = "[" + unit.getRatioTwo().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
}
if(commodityUnit.equals(unit.getOtherUnitThree()) && unit.getRatioThree()!=null) {
ratioStr = "[" + unit.getRatioThree().stripTrailingZeros().toPlainString() + unit.getBasicUnit() + "]";
}
2021-04-07 23:53:57 +08:00
}
item.put("mBarCode", material.getmBarCode());
item.put("name", material.getName());
item.put("mnemonic", material.getMnemonic());
item.put("categoryName", material.getCategoryName());
item.put("standard", material.getStandard());
item.put("model", material.getModel());
2021-10-11 23:53:31 +08:00
item.put("color", material.getColor());
item.put("brand", material.getBrand());
item.put("mfrs", material.getMfrs());
2021-12-01 00:58:54 +08:00
item.put("unit", material.getCommodityUnit() + ratioStr);
2021-07-28 00:54:30 +08:00
item.put("sku", material.getSku());
item.put("enableSerialNumber", material.getEnableSerialNumber());
item.put("enableBatchNumber", material.getEnableBatchNumber());
BigDecimal stock;
2021-09-22 00:18:42 +08:00
if(StringUtil.isNotEmpty(material.getSku())){
stock = depotItemService.getSkuStockByParam(depotId,material.getMeId(),null,null);
} else {
stock = depotItemService.getCurrentStockByParam(depotId, material.getId());
if (material.getUnitId()!=null){
2021-12-01 00:58:54 +08:00
String commodityUnit = material.getCommodityUnit();
stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
}
2021-04-07 23:53:57 +08:00
}
2021-07-28 00:54:30 +08:00
item.put("stock", stock);
2022-05-03 11:11:03 +08:00
item.put("expand", materialService.getMaterialOtherByParam(mpArr, material));
item.put("otherField1", material.getOtherField1());
item.put("otherField2", material.getOtherField2());
item.put("otherField3", material.getOtherField3());
item.put("imgName", material.getImgName());
if(fileUploadType == 2) {
item.put("imgSmall", "small");
item.put("imgLarge", "large");
} else {
item.put("imgSmall", "");
item.put("imgLarge", "");
}
2021-04-07 23:53:57 +08:00
dataArray.add(item);
}
}
object.put("rows", dataArray);
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
return object;
}
/**
* 根据商品id查找商品信息
* @param meId
* @param request
* @return
* @throws Exception
*/
@GetMapping(value = "/getMaterialByMeId")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "根据商品id查找商品信息")
2021-04-07 23:53:57 +08:00
public JSONObject getMaterialByMeId(@RequestParam(value = "meId", required = false) Long meId,
@RequestParam("mpList") String mpList,
HttpServletRequest request) throws Exception{
JSONObject item = new JSONObject();
try {
String[] mpArr = mpList.split(",");
List<MaterialVo4Unit> materialList = materialService.getMaterialByMeId(meId);
if(materialList!=null && materialList.size()!=1) {
return item;
} else if(materialList.size() == 1) {
MaterialVo4Unit material = materialList.get(0);
item.put("Id", material.getMeId()); //商品扩展表的id
String ratio; //比例
if (material.getUnitId() == null || material.getUnitId().equals("")) {
ratio = "";
} else {
ratio = material.getUnitName();
ratio = ratio.substring(ratio.indexOf("("));
}
//名称/型号/扩展信息/包装
String MaterialName = "";
MaterialName = MaterialName + material.getmBarCode() + "_" + material.getName()
+ ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
2022-05-03 11:11:03 +08:00
String expand = materialService.getMaterialOtherByParam(mpArr, material); //扩展信息
2021-04-07 23:53:57 +08:00
MaterialName = MaterialName + expand + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
item.put("name", material.getName());
item.put("expand", expand);
item.put("model", material.getModel());
item.put("standard", material.getStandard());
item.put("unit", material.getUnit() + ratio);
}
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
return item;
}
/**
* 生成excel表格
* @param categoryId
* @param materialParam
* @param color
* @param weight
* @param expiryNum
* @param enabled
* @param enableSerialNumber
* @param enableBatchNumber
* @param remark
* @param mpList
2021-04-07 23:53:57 +08:00
* @param request
* @param response
*/
@GetMapping(value = "/exportExcel")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "生成excel表格")
2022-05-03 17:01:48 +08:00
public void exportExcel(@RequestParam(value = "categoryId", required = false) String categoryId,
@RequestParam(value = "materialParam", required = false) String materialParam,
2022-05-03 17:01:48 +08:00
@RequestParam(value = "color", required = false) String color,
@RequestParam(value = "materialOther", required = false) String materialOther,
2022-05-03 17:01:48 +08:00
@RequestParam(value = "weight", required = false) String weight,
@RequestParam(value = "expiryNum", required = false) String expiryNum,
@RequestParam(value = "enabled", required = false) String enabled,
2022-05-03 17:01:48 +08:00
@RequestParam(value = "enableSerialNumber", required = false) String enableSerialNumber,
@RequestParam(value = "enableBatchNumber", required = false) String enableBatchNumber,
@RequestParam(value = "remark", required = false) String remark,
@RequestParam(value = "mpList", required = false) String mpList,
2021-04-07 23:53:57 +08:00
HttpServletRequest request, HttpServletResponse response) {
try {
materialService.exportExcel(StringUtil.toNull(categoryId), StringUtil.toNull(materialParam), StringUtil.toNull(color),
StringUtil.toNull(materialOther), StringUtil.toNull(weight),
2023-04-18 23:43:10 +08:00
StringUtil.toNull(expiryNum), StringUtil.toNull(enabled), StringUtil.toNull(enableSerialNumber),
StringUtil.toNull(enableBatchNumber), StringUtil.toNull(remark), mpList, response);
2021-04-07 23:53:57 +08:00
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
}
/**
* excel表格导入产品含初始库存
* @param file
* @param request
* @param response
* @return
*/
@PostMapping(value = "/importExcel")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "excel表格导入产品")
2021-04-07 23:53:57 +08:00
public BaseResponseInfo importExcel(MultipartFile file,
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseResponseInfo res = new BaseResponseInfo();
try {
2022-05-03 11:11:03 +08:00
res = materialService.importExcel(file, request);
2021-04-07 23:53:57 +08:00
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
return res;
}
2021-11-08 23:14:21 +08:00
/**
* 获取商品序列号
* @param q
* @param currentPage
* @param pageSize
* @param request
* @param response
* @return
* @throws Exception
*/
2021-04-07 23:53:57 +08:00
@GetMapping(value = "/getMaterialEnableSerialNumberList")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "获取商品序列号")
2021-04-07 23:53:57 +08:00
public JSONObject getMaterialEnableSerialNumberList(
@RequestParam(value = "q", required = false) String q,
@RequestParam("page") Integer currentPage,
@RequestParam("rows") Integer pageSize,
HttpServletRequest request,
HttpServletResponse response)throws Exception {
JSONObject object= new JSONObject();
try {
List<MaterialVo4Unit> list = materialService.getMaterialEnableSerialNumberList(q, (currentPage-1)*pageSize, pageSize);
Long count = materialService.getMaterialEnableSerialNumberCount(q);
object.put("rows", list);
object.put("total", count);
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
return object;
}
2021-11-08 23:14:21 +08:00
/**
* 获取最大条码
* @return
* @throws Exception
*/
2021-04-07 23:53:57 +08:00
@GetMapping(value = "/getMaxBarCode")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "获取最大条码")
2021-04-07 23:53:57 +08:00
public BaseResponseInfo getMaxBarCode() throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
String barCode = materialService.getMaxBarCode();
map.put("barCode", barCode);
res.code = 200;
res.data = map;
return res;
}
/**
* 商品名称模糊匹配
* @return
* @throws Exception
*/
@GetMapping(value = "/getMaterialNameList")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "商品名称模糊匹配")
2021-04-07 23:53:57 +08:00
public JSONArray getMaterialNameList() throws Exception {
JSONArray arr = new JSONArray();
try {
List<String> list = materialService.getMaterialNameList();
for (String s : list) {
JSONObject item = new JSONObject();
item.put("value", s);
item.put("text", s);
arr.add(item);
}
} catch (Exception e) {
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
}
return arr;
}
/**
* 根据条码查询商品信息
* @return
* @throws Exception
*/
@GetMapping(value = "/getMaterialByBarCode")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "根据条码查询商品信息")
2021-04-07 23:53:57 +08:00
public BaseResponseInfo getMaterialByBarCode(@RequestParam("barCode") String barCode,
@RequestParam(value = "organId", required = false) Long organId,
@RequestParam(value = "depotId", required = false) Long depotId,
2021-04-07 23:53:57 +08:00
@RequestParam("mpList") String mpList,
2021-06-01 23:33:00 +08:00
@RequestParam(required = false, value = "prefixNo") String prefixNo,
2021-04-07 23:53:57 +08:00
HttpServletRequest request) throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
try {
Long userId = userService.getUserId(request);
String priceLimit = userService.getRoleTypeByUserId(userId).getPriceLimit();
2021-04-07 23:53:57 +08:00
String[] mpArr = mpList.split(",");
//支持序列号查询,先根据序列号查询条码,如果查不到就直接查条码
MaterialExtend materialExtend = materialService.getMaterialExtendBySerialNumber(barCode);
if(materialExtend!=null && StringUtil.isNotEmpty(materialExtend.getBarCode())) {
barCode = materialExtend.getBarCode();
}
2021-04-07 23:53:57 +08:00
List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode);
if(list!=null && list.size()>0) {
for(MaterialVo4Unit mvo: list) {
2022-05-03 11:11:03 +08:00
mvo.setMaterialOther(materialService.getMaterialOtherByParam(mpArr, mvo));
if ("LSCK".equals(prefixNo) || "LSTH".equals(prefixNo)) {
//零售价
mvo.setBillPrice(mvo.getCommodityDecimal());
} else if ("CGDD".equals(prefixNo) || "CGRK".equals(prefixNo) || "CGTH".equals(prefixNo)) {
//采购价
mvo.setBillPrice(mvo.getPurchaseDecimal());
} else if("QTRK".equals(prefixNo) || "DBCK".equals(prefixNo) || "ZZD".equals(prefixNo) || "CXD".equals(prefixNo)
|| "PDLR".equals(prefixNo) || "PDFP".equals(prefixNo)) {
//采购价-给录入界面按权限屏蔽
mvo.setBillPrice(roleService.parseBillPriceByLimit(mvo.getPurchaseDecimal(), "buy", priceLimit, request));
} if ("XSDD".equals(prefixNo) || "XSCK".equals(prefixNo) || "XSTH".equals(prefixNo) || "QTCK".equals(prefixNo)) {
//销售价
if(organId == null) {
mvo.setBillPrice(mvo.getWholesaleDecimal());
} else {
//查询最后一单的销售价,实现不同的客户不同的销售价
BigDecimal lastUnitPrice = depotItemService.getLastUnitPriceByParam(organId, mvo.getMeId(), prefixNo);
mvo.setBillPrice(lastUnitPrice!=null? lastUnitPrice : mvo.getWholesaleDecimal());
}
//销售价-给录入界面按权限屏蔽价格
if("QTCK".equals(prefixNo)) {
mvo.setBillPrice(roleService.parseBillPriceByLimit(mvo.getWholesaleDecimal(), "sale", priceLimit, request));
}
2021-04-07 23:53:57 +08:00
}
//仓库id
if (depotId == null) {
JSONArray depotArr = depotService.findDepotByCurrentUser();
for (Object obj : depotArr) {
JSONObject depotObj = JSONObject.parseObject(obj.toString());
if (depotObj.get("isDefault") != null) {
Boolean isDefault = depotObj.getBoolean("isDefault");
if (isDefault) {
Long id = depotObj.getLong("id");
if (!"CGDD".equals(prefixNo) && !"XSDD".equals(prefixNo)) {
//除订单之外的单据才有仓库
mvo.setDepotId(id);
}
getStockByMaterialInfo(mvo);
}
}
}
} else {
mvo.setDepotId(depotId);
getStockByMaterialInfo(mvo);
2021-04-07 23:53:57 +08:00
}
}
}
res.code = 200;
res.data = list;
2021-04-07 23:53:57 +08:00
} catch(Exception e){
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-04-07 23:53:57 +08:00
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
2021-06-20 22:34:04 +08:00
/**
* 根据商品信息获取库存进行赋值
* @param mvo
* @throws Exception
*/
private void getStockByMaterialInfo(MaterialVo4Unit mvo) throws Exception {
BigDecimal stock;
if (StringUtil.isNotEmpty(mvo.getSku())) {
stock = depotItemService.getSkuStockByParam(mvo.getDepotId(), mvo.getMeId(), null, null);
} else {
stock = depotItemService.getCurrentStockByParam(mvo.getDepotId(), mvo.getId());
if (mvo.getUnitId() != null) {
Unit unit = unitService.getUnit(mvo.getUnitId());
2021-12-01 00:58:54 +08:00
String commodityUnit = mvo.getCommodityUnit();
stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
}
}
mvo.setStock(stock);
}
2021-06-20 22:34:04 +08:00
/**
* 商品库存查询
* @param currentPage
* @param pageSize
2021-11-25 01:14:00 +08:00
* @param depotIds
2021-06-20 22:34:04 +08:00
* @param categoryId
* @param materialParam
* @param zeroStock
2021-10-17 22:18:14 +08:00
* @param column
* @param order
2021-06-20 22:34:04 +08:00
* @param request
* @return
* @throws Exception
*/
@GetMapping(value = "/getListWithStock")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "商品库存查询")
2021-06-20 22:34:04 +08:00
public BaseResponseInfo getListWithStock(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
2021-11-25 01:14:00 +08:00
@RequestParam(value = "depotIds", required = false) String depotIds,
@RequestParam(value = "categoryId", required = false) Long categoryId,
@RequestParam(value = "position", required = false) String position,
2021-06-20 22:34:04 +08:00
@RequestParam("materialParam") String materialParam,
2021-10-24 22:03:03 +08:00
@RequestParam("zeroStock") Integer zeroStock,
@RequestParam(value = "column", required = false, defaultValue = "createTime") String column,
@RequestParam(value = "order", required = false, defaultValue = "desc") String order,
2021-06-20 22:34:04 +08:00
HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<>();
try {
List<Long> idList = new ArrayList<>();
2021-11-25 01:14:00 +08:00
List<Long> depotList = new ArrayList<>();
2021-06-20 22:34:04 +08:00
if(categoryId != null){
idList = materialService.getListByParentId(categoryId);
}
2021-11-25 01:14:00 +08:00
if(StringUtil.isNotEmpty(depotIds)) {
depotList = StringUtil.strToLongList(depotIds);
} else {
//未选择仓库时默认为当前用户有权限的仓库
JSONArray depotArr = depotService.findDepotByCurrentUser();
for(Object obj: depotArr) {
JSONObject object = JSONObject.parseObject(obj.toString());
depotList.add(object.getLong("id"));
}
}
Boolean moveAvgPriceFlag = systemConfigService.getMoveAvgPriceFlag();
List<MaterialVo4Unit> dataList = materialService.getListWithStock(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam),
moveAvgPriceFlag, zeroStock, StringUtil.safeSqlParse(column), StringUtil.safeSqlParse(order), (currentPage-1)*pageSize, pageSize);
int total = materialService.getListWithStockCount(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam), zeroStock);
MaterialVo4Unit materialVo4Unit= materialService.getTotalStockAndPrice(depotList, idList, StringUtil.toNull(position), StringUtil.toNull(materialParam));
2021-06-20 22:34:04 +08:00
map.put("total", total);
map.put("currentStock", materialVo4Unit.getCurrentStock()!=null?materialVo4Unit.getCurrentStock():BigDecimal.ZERO);
if(moveAvgPriceFlag) {
map.put("currentStockPrice", materialVo4Unit.getCurrentStockMovePrice()!=null?materialVo4Unit.getCurrentStockMovePrice():BigDecimal.ZERO);
} else {
map.put("currentStockPrice", materialVo4Unit.getCurrentStockPrice()!=null?materialVo4Unit.getCurrentStockPrice():BigDecimal.ZERO);
}
map.put("currentWeight", materialVo4Unit.getCurrentWeight()!=null?materialVo4Unit.getCurrentWeight():BigDecimal.ZERO);
2021-06-20 22:34:04 +08:00
map.put("rows", dataList);
res.code = 200;
res.data = map;
} catch(Exception e){
2024-05-28 00:49:48 +08:00
logger.error(e.getMessage(), e);
2021-06-20 22:34:04 +08:00
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
2021-10-24 22:03:03 +08:00
/**
* 批量设置商品当前的实时库存按每个仓库
* @param jsonObject
* @param request
* @return
* @throws Exception
*/
@PostMapping(value = "/batchSetMaterialCurrentStock")
2021-11-08 23:14:21 +08:00
@ApiOperation(value = "批量设置商品当前的实时库存(按每个仓库)")
2021-10-24 22:03:03 +08:00
public String batchSetMaterialCurrentStock(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
String ids = jsonObject.getString("ids");
Map<String, Object> objectMap = new HashMap<>();
int res = materialService.batchSetMaterialCurrentStock(ids);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 批量设置商品当前的成本价
* @param jsonObject
* @param request
* @return
* @throws Exception
*/
@PostMapping(value = "/batchSetMaterialCurrentUnitPrice")
@ApiOperation(value = "批量设置商品当前的成本价")
public String batchSetMaterialCurrentUnitPrice(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
String ids = jsonObject.getString("ids");
Map<String, Object> objectMap = new HashMap<>();
int res = materialService.batchSetMaterialCurrentUnitPrice(ids);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 批量更新商品信息
* @param jsonObject
* @param request
* @return
* @throws Exception
*/
@PostMapping(value = "/batchUpdate")
@ApiOperation(value = "批量更新商品信息")
public String batchUpdate(@RequestBody JSONObject jsonObject,
HttpServletRequest request)throws Exception {
Map<String, Object> objectMap = new HashMap<>();
int res = materialService.batchUpdate(jsonObject);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
2024-11-14 00:01:06 +08:00
/**
* 转换名称为拼音
* @param jsonObject
*/
@PostMapping(value = "/changeNameToPinYin")
@ApiOperation(value = "转换名称为拼音")
public BaseResponseInfo changeNameToPinYin(@RequestBody JSONObject jsonObject)throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
try {
String name = jsonObject.getString("name");
res.code = 200;
res.data = PinYinUtil.getFirstLettersLo(name);
} catch(Exception e){
logger.error(e.getMessage(), e);
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
}