Commit 9f230674 by shiwenbo

增加库存后端模型和接口

parent d8146621
......@@ -6,15 +6,34 @@ import com.xyst.dinas.sales.dao.SalesPlanDao;
import com.xyst.dinas.sales.internal.service.SalesPlanServiceImpl;
import com.xyst.dinas.sales.service.SalesPlanService;
import com.xyst.dinas.sales.task.SalesPlanAutoCreateTaskRegister;
import com.xyst.dinas.sales.dao.InventoryDao;
import com.xyst.dinas.sales.dao.NeedPlanDao;
import com.xyst.dinas.sales.internal.dao.InventoryDaoImpl;
import com.xyst.dinas.sales.internal.dao.NeedPlanDaoImpl;
import com.xyst.dinas.sales.internal.service.InventoryServiceImpl;
import com.xyst.dinas.sales.internal.service.NeedPlanServiceImpl;
import com.xyst.dinas.sales.service.InventoryService;
import com.xyst.dinas.sales.service.NeedPlanService;
import com.xyst.dinas.sales.web.InventoryController;
import com.xyst.dinas.sales.web.NeedPlanController;
import com.xyst.dinas.sales.web.SalesPlanController;
public class SalesConfiguration {
@Bean
public InventoryController inventoryController() {
return new InventoryController();
}
@Bean
public InventoryService inventoryService() {
return new InventoryServiceImpl();
}
@Bean
public InventoryDao inventoryDao() {
return new InventoryDaoImpl();
}
@Bean
public SalesPlanController salesPlanController() {
......
package com.xyst.dinas.sales.constant;
public interface InventoryConstant {
public static String INVENTORY_ENTITY = "com.xyst.dinas.sales.datamodel.Inventory";
}
package com.xyst.dinas.sales.dao;
import java.util.List;
import java.util.UUID;
import com.beecode.bcp.type.KObject;
public interface InventoryDao {
List<KObject> listAllByRegionalCompany(UUID regionalCompany, boolean includeDiscard);
void update(KObject kobj);
void save(KObject kobj);
}
package com.xyst.dinas.sales.entity;
import java.util.UUID;
public class StationDinasTypeRelation {
/*
* 场站id
*/
private UUID stationId;
/*
* 砂石类型id
*/
private UUID dinasTypeId;
/*
* 砂石单价
*/
private double price;
public StationDinasTypeRelation(UUID stationId, UUID dinasTypeId, double price) {
this.stationId = stationId;
this.dinasTypeId = dinasTypeId;
this.price = price;
}
public UUID getStationId() {
return stationId;
}
public UUID getDinasTypeId() {
return dinasTypeId;
}
public double getPrice() {
return price;
}
}
package com.xyst.dinas.sales.internal.dao;
import java.util.List;
import java.util.UUID;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.HibernateOperations;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.sales.constant.InventoryConstant;
import com.xyst.dinas.sales.dao.InventoryDao;
public class InventoryDaoImpl implements InventoryDao {
@Autowired
private HibernateOperations template;
@Override
public List<KObject> listAllByRegionalCompany(UUID regionalCompany, boolean includeDiscard) {
return (List<KObject>)template.execute(new HibernateCallback<List<KObject>>() {
@Override
public List<KObject> doInHibernate(Session session) throws HibernateException {
if(includeDiscard) {
Query<KObject> query = session.createQuery("from " + InventoryConstant.INVENTORY_ENTITY + " where regionalCompany.id =:regionalCompany", KObject.class);
query.setParameter("regionalCompany", regionalCompany);
return query.getResultList();
} else {
Query<KObject> query = session.createQuery("from " + InventoryConstant.INVENTORY_ENTITY + " where (discard is null or discard = 0) and regionalCompany.id =:regionalCompany", KObject.class);
query.setParameter("regionalCompany", regionalCompany);
return query.getResultList();
}
}
});
}
@Override
public void update(KObject kobj) {
template.update(kobj);
}
@Override
public void save(KObject kobj) {
template.save(kobj);
}
}
package com.xyst.dinas.sales.internal.service;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.transaction.Transactional;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import com.beecode.amino.core.Amino;
import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.xyst.dinas.biz.service.DinasOrganizationService;
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.StationDinasTypeRelation;
import com.xyst.dinas.sales.service.InventoryService;
public class InventoryServiceImpl implements InventoryService {
@Autowired
public StationService stationService;
@Autowired
public DinasTypeService dinasTypeService;
@Autowired
public DinasOrganizationService dinasOrganizationService;
@Autowired
public InventoryDao inventoryDao;
@Override
@Transactional
public List<KObject> getInventoryByRegionalCompany(UUID regionalCompany) {
updateInventoryBaseInfo(regionalCompany);
List<KObject> inventory = inventoryDao.listAllByRegionalCompany(regionalCompany, false);
return inventory;
}
@SuppressWarnings("unchecked")
@Override
@Transactional
public ResponseObj<String> modifyInventory(String body) {
JSONObject param = new JSONObject(body);
String regionalCompany = param.getString("regionalCompany");
if(null != regionalCompany) {
updateInventoryBaseInfo(UUID.fromString(regionalCompany));
//TODO:根据body数据赋值修正后的库存量
return ResponseObj.success("库存更新成功");
} else {
return ResponseObj.error("库存更新失败:区域公司不能为空");
}
}
public void updateInventoryBaseInfo(UUID regionalCompany) {
List<StationDinasTypeRelation> relation = getStationAndDinasTypeRel(regionalCompany);
//根据最新的场站与砂石对应关系,更新库中的数据。添加新的砂石类型,废弃没用的砂石类型
List<KObject> inventory = inventoryDao.listAllByRegionalCompany(regionalCompany, true);
for(StationDinasTypeRelation r : relation) {
UUID stationId = r.getStationId();
UUID dinasTypeId = r.getDinasTypeId();
double price = r.getPrice();
boolean findFlag = false;
for(KObject i : inventory) {
if(i.get("station").getUuid("id").equals(stationId) && i.get("dinasType").getUuid("id").equals(dinasTypeId)) {
findFlag = true;
i.set("price", price); //赋值最新砂价
i.set("discard", false); //赋值未废弃
inventoryDao.update(i);
break;
}
}
//未找到,则新增
if(!findFlag) {
KObject item = Amino.getApplicationMetadataContext().getBean(InventoryConstant.INVENTORY_ENTITY, KClass.class).newInstance();
item.set("regionalCompany", dinasOrganizationService.load(regionalCompany));
item.set("station", stationService.getById(stationId));
item.set("dinasType", dinasTypeService.getById(dinasTypeId));
item.set("amount", 0);
item.set("price", price);
inventoryDao.save(item);
}
}
//处理那些已经不再销售的砂石
for(KObject i : inventory) {
UUID stationId = i.get("station").getUuid("id");
UUID dinasTypeId = i.get("dinasType").getUuid("id");
boolean findFlag = false;
for(StationDinasTypeRelation r : relation) {
if(r.getStationId().equals(stationId) && r.getDinasTypeId().equals(dinasTypeId)) {
findFlag = true;
break;
}
}
if(!findFlag) {
i.set("amount", 0); //库存量置空
i.set("price", 0); //砂价置空
i.set("discard", true); //转为废弃
inventoryDao.update(i);
}
}
}
//查询最新的场站与砂石类型对应关系
public List<StationDinasTypeRelation> getStationAndDinasTypeRel(UUID regionalCompany) {
List<StationDinasTypeRelation> relation = new ArrayList<StationDinasTypeRelation>();
List<KObject> stationList;
try {
stationList = stationService.listStationInfoByRegionalCompany(regionalCompany);
for(KObject station : stationList) {
List<KObject> dinasTypeList = dinasTypeService.getByStation(station.getUuid("id"));
//TODO:带出今日砂价
for(KObject dinasType : dinasTypeList) {
StationDinasTypeRelation item = new StationDinasTypeRelation(station.getUuid("id"), dinasType.getUuid("id"), 0);
relation.add(item);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return relation;
}
}
package com.xyst.dinas.sales.service;
import java.util.List;
import java.util.UUID;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
public interface InventoryService {
public List<KObject> getInventoryByRegionalCompany(UUID regionalCompany);
public ResponseObj<String> modifyInventory(String body);
}
package com.xyst.dinas.sales.web;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.beecode.xlib.runtime.Assert;
import com.xyst.dinas.sales.service.InventoryService;
@RestController
public class InventoryController {
@Autowired
public InventoryService inventoryService;
//查询库存量
@ResponseBody
@RequestMapping(value = "/inventory/query", method = RequestMethod.GET)
public Object query(@RequestParam("regionalCompany") String regionalCompany) {
Assert.notNull(regionalCompany, "The regionalCompany must not be null");
List<KObject> data = inventoryService.getInventoryByRegionalCompany(UUID.fromString(regionalCompany));
return ResponseObj.success("库存查询成功", data);
}
//修改库存量
@ResponseBody
@RequestMapping(value = "/inventory/modify", method = RequestMethod.POST)
public Object modify(@RequestBody String body) {
ResponseObj<String> result = inventoryService.modifyInventory(body);
return result;
}
}
<model>
<header>
<type>bcp.type.DataModel</type>
<package>com.xyst.dinas.sales.datamodel</package>
<title>库存</title>
<name>Inventory</name>
<tags></tags>
<description>库存</description>
<templateName>mk.ide.ui.editor.data.model.template.bill</templateName>
<tablePrefix>xyst_dinas_sales_</tablePrefix>
</header>
<content>
<dataModel id='4d1e55e3-fb56-4020-878c-c74fe7fa12f2' multiVersion='' domainInherit='undefined' tableName='xyst_dinas_sales_inventory'>
<parent>com.beecode.bap.biztrait.datamodel.BasicBillRequirement</parent>
<parent>com.beecode.inz.common.datamodel.BaseInfo</parent>
<attribute id='12a14135-5cee-4563-8efb-b089b3d77a99' name='regionalCompany' columnName='regional_company' title='区域公司' type='com.xyst.dinas.biz.datamodel.Organization' default='' precision='' isArray='false'>
<annotation id='527cba7b-1eef-4497-abde-20591745cb3b' attributeId='967e6993-1c60-4bdc-94f2-d3884456e306' name='length' value='undefined'>
</annotation>
<annotation id='99562290-b829-4b40-b3ed-8a39d941b1c6' attributeId='62f868c8-e8a7-48e9-b53e-b5ce244f9702' name='mappingType' value='many-to-one'>
</annotation>
</attribute>
<attribute id='d10220a7-89cd-4671-9b48-c13b51672859' name='station' columnName='station' title='场站' type='com.xyst.dinas.biz.datamodel.Station' default='' precision='' isArray='false'>
<annotation id='d9222f6b-f0ad-4597-92c4-4f35740d0ca7' attributeId='e4203856-cfc8-4a88-80c7-d92a82c47310' name='length' value='undefined'></annotation>
<annotation id='c7cbe49c-85ca-4864-b4f1-d3127ab7f058' attributeId='6bd559ee-1b66-4ac7-a706-14643629e9b2' name='mappingType' value='many-to-one'></annotation>
</attribute>
<attribute id='8f779083-c728-490e-a459-8916298b1590' name='dinasType' columnName='dinas_type' title='砂石类型' type='com.xyst.dinas.biz.datamodel.DinasType' default='' precision='' isArray='false'>
<annotation id='8edb047a-b327-4ba7-9b73-3e4f1bc68c65' attributeId='428a37e2-29f0-4509-9aa1-166f6d0d1e38' name='length' value='undefined'>
</annotation>
<annotation id='5af90fef-5a6a-4015-910a-5b07e0f67ef2' attributeId='364e9851-e1b5-466f-a526-fb6fbfe35898' name='mappingType' value='many-to-one'>
</annotation>
</attribute>
<attribute id='e6047347-2d63-49f4-b4bd-24f354457d17' name='amount' columnName='amount' title='库存量' type='fixnum' default='' precision='' isArray='false'>
<annotation id='8901a903-1817-4353-abd6-2920476b69fa' attributeId='774e6bb7-227d-4fb6-b836-af22c1dae5bb' name='length' value='undefined'>
</annotation>
</attribute>
<attribute id='415b40cc-1cdc-4483-91a6-bba4a949e2d4' name='price' columnName='price' title='单价' type='fixnum' default='' precision='' isArray='false'>
<annotation id='a77dfabd-70f7-4bba-a707-2796232933cc' attributeId='307f585e-2665-423e-89b3-409d6ba6e349' name='length' value='100'>
</annotation>
<annotation id='13dc278b-c705-492c-b2cc-42e985f4c49e' attributeId='955c2da2-f35a-4f19-a4e5-cd2dae289e87' name='precision' value='12'>
</annotation>
<annotation id='46b02079-0159-4429-aebe-35f11d4c47ea' attributeId='91da4a43-ce42-42a8-8139-82e20c81ce09' name='scale' value='2'>
</annotation>
</attribute>
<hibernate>/xyst.dinas.sales/src/main/resources/config/Inventory.hbm.xml</hibernate>
</dataModel>
</content>
</model>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.beecode.cn/schema/amino-metadata" xmlns:m="http://www.beecode.cn/schema/bcp-type">
<specification>1.0</specification>
<id>4d1e55e3-fb56-4020-878c-c74fe7fa12f2</id>
<name>com.xyst.dinas.sales.datamodel.Inventory</name>
<title>库存</title>
<description>库存</description>
<define>bcp.type.Class</define>
<define-version>1.0</define-version>
<dependency>com.xyst.dinas.biz.datamodel.Organization</dependency>
<dependency>com.beecode.inz.common.datamodel.BaseInfo</dependency>
<dependency>com.xyst.dinas.biz.datamodel.Station</dependency>
<dependency>com.xyst.dinas.biz.datamodel.DinasType</dependency>
<dependency>bcp.type.constraint.Numeric</dependency>
<dependency>com.beecode.bap.biztrait.datamodel.BasicBillRequirement</dependency>
<content>
<m:class>
<m:parents>
<m:parent>com.beecode.bap.biztrait.datamodel.BasicBillRequirement</m:parent>
<m:parent>com.beecode.inz.common.datamodel.BaseInfo</m:parent>
</m:parents>
<m:attributes>
<m:attribute>
<m:annotations/>
<m:id>12a14135-5cee-4563-8efb-b089b3d77a99</m:id>
<m:name>regionalCompany</m:name>
<m:title>区域公司</m:title>
<m:type>com.xyst.dinas.biz.datamodel.Organization</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations/>
<m:id>d10220a7-89cd-4671-9b48-c13b51672859</m:id>
<m:name>station</m:name>
<m:title>场站</m:title>
<m:type>com.xyst.dinas.biz.datamodel.Station</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations/>
<m:id>8f779083-c728-490e-a459-8916298b1590</m:id>
<m:name>dinasType</m:name>
<m:title>砂石类型</m:title>
<m:type>com.xyst.dinas.biz.datamodel.DinasType</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations>
<m:annotation>
<m:type>bcp.type.constraint.Numeric</m:type>
<m:properties>
<m:property>
<m:key>precision</m:key>
<m:value>0</m:value>
</m:property>
<m:property>
<m:key>scale</m:key>
<m:value>0</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>e6047347-2d63-49f4-b4bd-24f354457d17</m:id>
<m:name>amount</m:name>
<m:title>库存量</m:title>
<m:type>fixnum</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
<m:attribute>
<m:annotations>
<m:annotation>
<m:type>bcp.type.constraint.Numeric</m:type>
<m:properties>
<m:property>
<m:key>precision</m:key>
<m:value>12</m:value>
</m:property>
<m:property>
<m:key>scale</m:key>
<m:value>2</m:value>
</m:property>
</m:properties>
</m:annotation>
</m:annotations>
<m:id>415b40cc-1cdc-4483-91a6-bba4a949e2d4</m:id>
<m:name>price</m:name>
<m:title>单价</m:title>
<m:type>fixnum</m:type>
<m:description></m:description>
<m:default></m:default>
</m:attribute>
</m:attributes>
</m:class>
</content>
</metadata>
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping
http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd">
<class entity-name="com.xyst.dinas.sales.datamodel.Inventory" table="xyst_dinas_sales_inventory" optimistic-lock="version">
<tuplizer entity-mode="dynamic-map" class="com.beecode.bcp.store.hibernate.KObjectEntityTuplizer"/>
<id name="id" type="uuid-binary" column="id" length="16">
<generator class="assigned" />
</id>
<version name="version" type="int" column="version"/>
<property name="createTime" type="timestamp" not-null="false">
<column name="create_time"></column>
</property>
<many-to-one name="creator" entity-name="com.beecode.bap.staff.datamodel.Staff" fetch="select">
<column name="creator_id" not-null="false"/>
</many-to-one>
<property name="modifyTime" type="timestamp" not-null="false">
<column name="modify_time"></column>
</property>
<many-to-one name="modifier" entity-name="com.beecode.bap.staff.datamodel.Staff" fetch="select">
<column name="modifier_id" not-null="false"/>
</many-to-one>
<property name="discard" type="boolean" not-null="false">
<column name="discard"></column>
</property>
<many-to-one name="regionalCompany" entity-name="com.xyst.dinas.biz.datamodel.Organization" fetch="select">
<column name="regional_company" not-null="false"></column>
</many-to-one>
<many-to-one name="station" entity-name="com.xyst.dinas.biz.datamodel.Station" fetch="select">
<column name="station" not-null="false"/>
</many-to-one>
<many-to-one name="dinasType" entity-name="com.xyst.dinas.biz.datamodel.DinasType" fetch="select">
<column name="dinas_type" not-null="false"></column>
</many-to-one>
<property name="amount" type="big_decimal" not-null="false">
<column name="amount" precision="12" scale="4"></column>
</property>
<property name="price" type="big_decimal" not-null="false">
<column name="price" precision="12" scale="2"></column>
</property>
</class>
</hibernate-mapping>
\ No newline at end of file
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