Commit 0ea74abd by shiwenbo

增加库存纠正接口和库存日志查询接口

parent f9037a55
......@@ -3,4 +3,6 @@ package com.xyst.dinas.sales.constant;
public interface InventoryConstant {
public static String INVENTORY_ENTITY = "com.xyst.dinas.sales.datamodel.Inventory";
public static String LOG_ENTITY = "com.beecode.bap.log.datamodel.Log";
}
......@@ -12,4 +12,8 @@ public interface InventoryDao {
void update(KObject kobj);
void save(KObject kobj);
KObject getItemByStationIdAndDinasTypeId(UUID stationId, UUID dinasTypeId);
List<KObject> queryLog(List<String> businessObjectId);
}
package com.xyst.dinas.sales.entity;
public class InventoryLog {
/*
* 纠正时间
*/
private String time;
/**
* 操作人
*/
private String operator;
/**
* 日志内容
*/
private String content;
public InventoryLog() {
}
public InventoryLog(String time, String operator, String content) {
this.time = time;
this.operator = operator;
this.content = content;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
......@@ -47,4 +47,30 @@ public class InventoryDaoImpl implements InventoryDao {
template.save(kobj);
}
@Override
public KObject getItemByStationIdAndDinasTypeId(UUID stationId, UUID dinasTypeId) {
return (KObject)template.execute(new HibernateCallback<KObject>() {
@Override
public KObject doInHibernate(Session session) throws HibernateException {
Query<KObject> query = session.createQuery("from " + InventoryConstant.INVENTORY_ENTITY + " where (discard is null or discard = 0) and station.id =:stationId and dinasType.id =:dinasTypeId", KObject.class);
query.setParameter("stationId", stationId);
query.setParameter("dinasTypeId", dinasTypeId);
return query.getSingleResult();
}
});
}
@Override
public List<KObject> queryLog(List<String> businessObjectId) {
return (List<KObject>)template.execute(new HibernateCallback<List<KObject>>() {
@Override
public List<KObject> doInHibernate(Session session) throws HibernateException {
Query<KObject> query = session.createQuery("from " + InventoryConstant.LOG_ENTITY + " where module = :module and businessObjectId in (:businessObjectId) order by time desc", KObject.class);
query.setParameter("module", InventoryConstant.INVENTORY_ENTITY);
query.setParameter("businessObjectId", businessObjectId);
return query.getResultList();
}
});
}
}
package com.xyst.dinas.sales.internal.service;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import com.beecode.amino.common.ValueConvertException;
import com.beecode.amino.core.Amino;
import com.beecode.bap.log.service.LogService;
import com.beecode.bap.staff.BapContext;
import com.beecode.bap.staff.service.StaffService;
import com.beecode.bcp.type.AttributeNotFoundException;
import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
......@@ -19,6 +27,7 @@ import com.xyst.dinas.biz.service.DinasTypeService;
import com.xyst.dinas.biz.service.StationService;
import com.xyst.dinas.sales.constant.InventoryConstant;
import com.xyst.dinas.sales.dao.InventoryDao;
import com.xyst.dinas.sales.entity.InventoryLog;
import com.xyst.dinas.sales.entity.StationDinasTypeRelation;
import com.xyst.dinas.sales.service.InventoryService;
......@@ -34,8 +43,17 @@ public class InventoryServiceImpl implements InventoryService {
public DinasOrganizationService dinasOrganizationService;
@Autowired
public LogService logService;
@Autowired
public StaffService staffService;
@Autowired
public InventoryDao inventoryDao;
@Autowired
public BapContext bapContext;
@Override
@Transactional
public List<StationDinasTypeRelation> getInventoryByRegionalCompany(UUID regionalCompany) {
......@@ -58,18 +76,55 @@ public class InventoryServiceImpl implements InventoryService {
@SuppressWarnings("unchecked")
@Override
@Transactional
public ResponseObj<String> modifyInventory(String body) {
JSONObject param = new JSONObject(body);
public ResponseObj<String> modifyInventory(String body, boolean isLog) {
JSONObject params = new JSONObject(body);
JSONArray datas = params.getJSONArray("datas");
for(int j = 0; j < datas.length(); j++) {
JSONObject param = datas.getJSONObject(j);
String regionalCompany = param.getString("regionalCompany");
if(null != regionalCompany) {
updateInventoryBaseInfo(UUID.fromString(regionalCompany));
//TODO:根据body数据赋值修正后的库存量
return ResponseObj.success("库存更新成功");
} else {
return ResponseObj.error("库存更新失败:区域公司不能为空");
//根据body数据赋值修正后的库存量
JSONArray data = param.getJSONArray("data");
for(int i = 0; i < data.length(); i++) {
JSONObject item = data.getJSONObject(i);
String stationId = item.getString("stationId");
String stationName = item.getString("stationName");
String dinasTypeId = item.getString("dinasTypeId");
String dinasTypeName = item.getString("dinasTypeName");
double amount = item.getDouble("amount");
KObject kobj = inventoryDao.getItemByStationIdAndDinasTypeId(UUID.fromString(stationId), UUID.fromString(dinasTypeId));
double oldAmount = kobj.getDouble("amount");
kobj.set("amount", amount);
inventoryDao.update(kobj);
if(isLog) {
try {
KObject log = Amino.getApplicationMetadataContext().getBean(InventoryConstant.LOG_ENTITY, KClass.class).newInstance();
log.set("id", UUID.randomUUID());
log.set("module", InventoryConstant.INVENTORY_ENTITY);
log.set("businessObjectId", kobj.getUuid("id").toString());
log.set("logContent", stationName + "的" + dinasTypeName + "库存量由" + oldAmount + "变为" + amount);
log.set("time", new Date());
log.set("loglevel", "INFO");
log.set("staffId", bapContext.getCurrentStaff().getUuid("id"));
log.set("deptId", bapContext.getCurrentStaff().get("department").getUuid("id"));
logService.addLog(log);
} catch (AttributeNotFoundException e) {
e.printStackTrace();
} catch (ValueConvertException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
return ResponseObj.success("库存更新成功");
}
public void updateInventoryBaseInfo(UUID regionalCompany) {
List<StationDinasTypeRelation> relation = getStationAndDinasTypeRel(regionalCompany);
//根据最新的场站与砂石对应关系,更新库中的数据。添加新的砂石类型,废弃没用的砂石类型
......@@ -139,4 +194,25 @@ public class InventoryServiceImpl implements InventoryService {
}
return relation;
}
@Override
public List<InventoryLog> queryLog(UUID regionalCompany) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<InventoryLog> result = new ArrayList<InventoryLog>();
List<KObject> inventory = inventoryDao.listAllByRegionalCompany(regionalCompany, false);
List<String> businessObjectId = new ArrayList<String>();
for(KObject i : inventory) {
businessObjectId.add(i.getUuid("id").toString());
}
List<KObject> logList = inventoryDao.queryLog(businessObjectId);
for(KObject log : logList) {
KObject operator = staffService.getById(log.getUuid("staffId"));
InventoryLog item = new InventoryLog();
item.setTime(format.format(log.getDate("time")));
item.setOperator(operator.getString("name"));
item.setContent(log.getString("logContent"));
result.add(item);
}
return result;
}
}
......@@ -4,11 +4,13 @@ import java.util.List;
import java.util.UUID;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.sales.entity.InventoryLog;
import com.xyst.dinas.sales.entity.StationDinasTypeRelation;
public interface InventoryService {
public List<StationDinasTypeRelation> getInventoryByRegionalCompany(UUID regionalCompany);
public ResponseObj<String> modifyInventory(String body);
public ResponseObj<String> modifyInventory(String body, boolean isLog);
public List<InventoryLog> queryLog(UUID regionalCompany);
}
......@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.beecode.xlib.runtime.Assert;
import com.xyst.dinas.sales.entity.InventoryLog;
import com.xyst.dinas.sales.entity.StationDinasTypeRelation;
import com.xyst.dinas.sales.service.InventoryService;
......@@ -35,7 +36,16 @@ public class InventoryController {
@ResponseBody
@RequestMapping(value = "/inventory/modify", method = RequestMethod.POST)
public Object modify(@RequestBody String body) {
ResponseObj<String> result = inventoryService.modifyInventory(body);
ResponseObj<String> result = inventoryService.modifyInventory(body, true);
return result;
}
//查询库存纠正日志
@ResponseBody
@RequestMapping(value = "/inventory/queryLog", method = RequestMethod.GET)
public Object queryLog(@RequestParam("regionalCompany") String regionalCompany) {
Assert.notNull(regionalCompany, "The regionalCompany must not be null");
List<InventoryLog> data = inventoryService.queryLog(UUID.fromString(regionalCompany));
return ResponseObj.success("库存纠正日志查询成功", data);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment