Commit 7a436d1c authored by 季圣华's avatar 季圣华
Browse files

!14 格式化代码,看着有点别扭

Merge pull request !14 from SmkfGao/master
parents 8f304964 6bc92ec9
......@@ -19,45 +19,46 @@ import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* 单据明细管理
* @author jishenghua qq:752718920
*/
*/
@SuppressWarnings("serial")
public class DepotItemAction extends BaseAction<DepotItemModel>
{
private MaterialIService materialService;
private DepotItemIService depotItemService;
private DepotItemModel model = new DepotItemModel();
public class DepotItemAction extends BaseAction<DepotItemModel> {
/**
* action返回excel结果
*/
public static final String EXCEL = "excel";
private MaterialIService materialService;
private DepotItemIService depotItemService;
private DepotItemModel model = new DepotItemModel();
/**
* 保存明细
*
* @return
*/
public void saveDetials() {
Log.infoFileSync("==================开始调用保存仓管通明细信息方法saveDetials()===================");
Boolean flag = false;
try {
Long headerId=model.getHeaderId();
String inserted=model.getInserted();
String deleted=model.getDeleted();
String updated=model.getUpdated();
Long headerId = model.getHeaderId();
String inserted = model.getInserted();
String deleted = model.getDeleted();
String updated = model.getUpdated();
//转为json
JSONArray insertedJson = JSONArray.fromObject(inserted);
JSONArray deletedJson = JSONArray.fromObject(deleted);
JSONArray updatedJson = JSONArray.fromObject(updated);
if(null != insertedJson) {
for(int i = 0;i < insertedJson.size(); i++) {
if (null != insertedJson) {
for (int i = 0; i < insertedJson.size(); i++) {
DepotItem depotItem = new DepotItem();
JSONObject tempInsertedJson = JSONObject.fromObject(insertedJson.get(i));
depotItem.setHeaderId(new DepotHead(headerId));
depotItem.setMaterialId(new Material(tempInsertedJson.getLong("MaterialId")));
depotItem.setMUnit(tempInsertedJson.getString("Unit"));
if(!StringUtils.isEmpty(tempInsertedJson.get("OperNumber").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("OperNumber").toString())) {
depotItem.setOperNumber(tempInsertedJson.getDouble("OperNumber"));
try {
String Unit = tempInsertedJson.get("Unit").toString();
......@@ -65,74 +66,83 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
Long mId = Long.parseLong(tempInsertedJson.get("MaterialId").toString());
//以下进行单位换算
String UnitName = findUnitName(mId); //查询计量单位名称
if(!UnitName.equals("")) {
if (!UnitName.equals("")) {
String UnitList = UnitName.substring(0, UnitName.indexOf("("));
String RatioList = UnitName.substring(UnitName.indexOf("("));
String basicUnit = UnitList.substring(0, UnitList.indexOf(",")); //基本单位
String otherUnit = UnitList.substring(UnitList.indexOf(",")+1); //副单位
Integer ratio = Integer.parseInt(RatioList.substring(RatioList.indexOf(":") + 1).replace(")","")); //比例
if(Unit.equals(basicUnit)){ //如果等于基础单位
String otherUnit = UnitList.substring(UnitList.indexOf(",") + 1); //副单位
Integer ratio = Integer.parseInt(RatioList.substring(RatioList.indexOf(":") + 1).replace(")", "")); //比例
if (Unit.equals(basicUnit)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (Unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber * ratio); //数量乘以比例
}
else if(Unit.equals(otherUnit)){ //如果等于副单位
depotItem.setBasicNumber(oNumber*ratio); //数量乘以比例
}
}
else {
} else {
depotItem.setBasicNumber(oNumber); //其他情况
}
}
catch(Exception e){
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
}
if(!StringUtils.isEmpty(tempInsertedJson.get("UnitPrice").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("UnitPrice").toString())) {
depotItem.setUnitPrice(tempInsertedJson.getDouble("UnitPrice"));
}
if(!StringUtils.isEmpty(tempInsertedJson.get("TaxUnitPrice").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxUnitPrice").toString())) {
depotItem.setTaxUnitPrice(tempInsertedJson.getDouble("TaxUnitPrice"));
}
if(!StringUtils.isEmpty(tempInsertedJson.get("AllPrice").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("AllPrice").toString())) {
depotItem.setAllPrice(tempInsertedJson.getDouble("AllPrice"));
}
depotItem.setRemark(tempInsertedJson.getString("Remark"));
if(tempInsertedJson.get("DepotId")!=null && !StringUtils.isEmpty(tempInsertedJson.get("DepotId").toString())){
if (tempInsertedJson.get("DepotId") != null && !StringUtils.isEmpty(tempInsertedJson.get("DepotId").toString())) {
depotItem.setDepotId(new Depot(tempInsertedJson.getLong("DepotId")));
}
if(tempInsertedJson.get("AnotherDepotId")!=null && !StringUtils.isEmpty(tempInsertedJson.get("AnotherDepotId").toString())){
if (tempInsertedJson.get("AnotherDepotId") != null && !StringUtils.isEmpty(tempInsertedJson.get("AnotherDepotId").toString())) {
depotItem.setAnotherDepotId(new Depot(tempInsertedJson.getLong("AnotherDepotId")));
}
if(!StringUtils.isEmpty(tempInsertedJson.get("TaxRate").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxRate").toString())) {
depotItem.setTaxRate(tempInsertedJson.getDouble("TaxRate"));
}
if(!StringUtils.isEmpty(tempInsertedJson.get("TaxMoney").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxMoney").toString())) {
depotItem.setTaxMoney(tempInsertedJson.getDouble("TaxMoney"));
}
if(!StringUtils.isEmpty(tempInsertedJson.get("TaxLastMoney").toString())){
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxLastMoney").toString())) {
depotItem.setTaxLastMoney(tempInsertedJson.getDouble("TaxLastMoney"));
}
if(tempInsertedJson.get("OtherField1")!=null){depotItem.setOtherField1(tempInsertedJson.getString("OtherField1"));}
if(tempInsertedJson.get("OtherField2")!=null){depotItem.setOtherField2(tempInsertedJson.getString("OtherField2"));}
if(tempInsertedJson.get("OtherField3")!=null){depotItem.setOtherField3(tempInsertedJson.getString("OtherField3"));}
if(tempInsertedJson.get("OtherField4")!=null){depotItem.setOtherField4(tempInsertedJson.getString("OtherField4"));}
if(tempInsertedJson.get("OtherField5")!=null){depotItem.setOtherField5(tempInsertedJson.getString("OtherField5"));}
if(tempInsertedJson.get("MType")!=null){depotItem.setMType(tempInsertedJson.getString("MType"));}
if (tempInsertedJson.get("OtherField1") != null) {
depotItem.setOtherField1(tempInsertedJson.getString("OtherField1"));
}
if (tempInsertedJson.get("OtherField2") != null) {
depotItem.setOtherField2(tempInsertedJson.getString("OtherField2"));
}
if (tempInsertedJson.get("OtherField3") != null) {
depotItem.setOtherField3(tempInsertedJson.getString("OtherField3"));
}
if (tempInsertedJson.get("OtherField4") != null) {
depotItem.setOtherField4(tempInsertedJson.getString("OtherField4"));
}
if (tempInsertedJson.get("OtherField5") != null) {
depotItem.setOtherField5(tempInsertedJson.getString("OtherField5"));
}
if (tempInsertedJson.get("MType") != null) {
depotItem.setMType(tempInsertedJson.getString("MType"));
}
depotItemService.create(depotItem);
}
}
if(null != deletedJson) {
for(int i = 0;i < deletedJson.size(); i++) {
if (null != deletedJson) {
for (int i = 0; i < deletedJson.size(); i++) {
JSONObject tempDeletedJson = JSONObject.fromObject(deletedJson.get(i));
depotItemService.delete(tempDeletedJson.getLong("Id"));
}
}
if(null != updatedJson) {
for(int i = 0;i < updatedJson.size(); i++) {
if (null != updatedJson) {
for (int i = 0; i < updatedJson.size(); i++) {
JSONObject tempUpdatedJson = JSONObject.fromObject(updatedJson.get(i));
DepotItem depotItem = depotItemService.get(tempUpdatedJson.getLong("Id"));
depotItem.setMaterialId(new Material(tempUpdatedJson.getLong("MaterialId")));
depotItem.setMUnit(tempUpdatedJson.getString("Unit"));
if(!StringUtils.isEmpty(tempUpdatedJson.get("OperNumber").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("OperNumber").toString())) {
depotItem.setOperNumber(tempUpdatedJson.getDouble("OperNumber"));
try {
String Unit = tempUpdatedJson.get("Unit").toString();
......@@ -140,50 +150,47 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
Long mId = Long.parseLong(tempUpdatedJson.get("MaterialId").toString());
//以下进行单位换算
String UnitName = findUnitName(mId); //查询计量单位名称
if(!UnitName.equals("")) {
if (!UnitName.equals("")) {
String UnitList = UnitName.substring(0, UnitName.indexOf("("));
String RatioList = UnitName.substring(UnitName.indexOf("("));
String basicUnit = UnitList.substring(0, UnitList.indexOf(",")); //基本单位
String otherUnit = UnitList.substring(UnitList.indexOf(",")+1); //副单位
Integer ratio = Integer.parseInt(RatioList.substring(RatioList.indexOf(":") + 1).replace(")","")); //比例
if(Unit.equals(basicUnit)){ //如果等于基础单位
String otherUnit = UnitList.substring(UnitList.indexOf(",") + 1); //副单位
Integer ratio = Integer.parseInt(RatioList.substring(RatioList.indexOf(":") + 1).replace(")", "")); //比例
if (Unit.equals(basicUnit)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (Unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber * ratio); //数量乘以比例
}
else if(Unit.equals(otherUnit)){ //如果等于副单位
depotItem.setBasicNumber(oNumber*ratio); //数量乘以比例
}
}
else {
} else {
depotItem.setBasicNumber(oNumber); //其他情况
}
}
catch(Exception e){
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("UnitPrice").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("UnitPrice").toString())) {
depotItem.setUnitPrice(tempUpdatedJson.getDouble("UnitPrice"));
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("TaxUnitPrice").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxUnitPrice").toString())) {
depotItem.setTaxUnitPrice(tempUpdatedJson.getDouble("TaxUnitPrice"));
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("AllPrice").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("AllPrice").toString())) {
depotItem.setAllPrice(tempUpdatedJson.getDouble("AllPrice"));
}
depotItem.setRemark(tempUpdatedJson.getString("Remark"));
if(tempUpdatedJson.get("DepotId")!=null && !StringUtils.isEmpty(tempUpdatedJson.get("DepotId").toString())){
if (tempUpdatedJson.get("DepotId") != null && !StringUtils.isEmpty(tempUpdatedJson.get("DepotId").toString())) {
depotItem.setDepotId(new Depot(tempUpdatedJson.getLong("DepotId")));
}
if(tempUpdatedJson.get("AnotherDepotId")!=null && !StringUtils.isEmpty(tempUpdatedJson.get("AnotherDepotId").toString())){
if (tempUpdatedJson.get("AnotherDepotId") != null && !StringUtils.isEmpty(tempUpdatedJson.get("AnotherDepotId").toString())) {
depotItem.setAnotherDepotId(new Depot(tempUpdatedJson.getLong("AnotherDepotId")));
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("TaxRate").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxRate").toString())) {
depotItem.setTaxRate(tempUpdatedJson.getDouble("TaxRate"));
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("TaxMoney").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxMoney").toString())) {
depotItem.setTaxMoney(tempUpdatedJson.getDouble("TaxMoney"));
}
if(!StringUtils.isEmpty(tempUpdatedJson.get("TaxLastMoney").toString())){
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxLastMoney").toString())) {
depotItem.setTaxLastMoney(tempUpdatedJson.getDouble("TaxLastMoney"));
}
depotItem.setOtherField1(tempUpdatedJson.getString("OtherField1"));
......@@ -201,48 +208,45 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>保存仓管通明细信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally {
} finally {
try {
toClient(flag.toString());
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>保存仓管通明细信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "保存仓管通明细", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "保存仓管通明细对应主表编号为 "+ model.getHeaderId() + " " + tipMsg + "!", "保存仓管通明细" + tipMsg));
, tipType, "保存仓管通明细对应主表编号为 " + model.getHeaderId() + " " + tipMsg + "!", "保存仓管通明细" + tipMsg));
Log.infoFileSync("==================结束调用保存仓管通明细方法saveDetials()===================");
}
/**
* 查询计量单位信息
*
* @return
*/
public String findUnitName(Long mId){
String unitName ="";
public String findUnitName(Long mId) {
String unitName = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try {
materialService.findUnitName(pageUtil, mId);
unitName = pageUtil.getPageList().toString();
if(unitName!=null){
unitName = unitName.substring(1,unitName.length()-1);
if(unitName.equals("null")){
if (unitName != null) {
unitName = unitName.substring(1, unitName.length() - 1);
if (unitName.equals("null")) {
unitName = "";
}
}
}
catch (JshException e) {
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -252,6 +256,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 查找明细信息
*
* @return
*/
public void findBy() {
......@@ -268,23 +273,22 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList) {
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
String ratio; //比例
if(depotItem.getMaterialId().getUnitId() == null || depotItem.getMaterialId().getUnitId().equals("")){
if (depotItem.getMaterialId().getUnitId() == null || depotItem.getMaterialId().getUnitId().equals("")) {
ratio = "";
}
else {
} else {
ratio = depotItem.getMaterialId().getUnitId().getUName();
ratio = ratio.substring(ratio.indexOf("("));
}
//品名/型号/扩展信息/包装
String MaterialName = depotItem.getMaterialId().getName() + ((depotItem.getMaterialId().getModel() == null || depotItem.getMaterialId().getModel().equals(""))?"":"("+depotItem.getMaterialId().getModel() + ")");
String MaterialName = depotItem.getMaterialId().getName() + ((depotItem.getMaterialId().getModel() == null || depotItem.getMaterialId().getModel().equals("")) ? "" : "(" + depotItem.getMaterialId().getModel() + ")");
String materialOther = getOtherInfo(mpArr, depotItem);
MaterialName = MaterialName + materialOther + ((depotItem.getMaterialId().getUnit() == null || depotItem.getMaterialId().getUnit().equals(""))?"":"("+depotItem.getMaterialId().getUnit() + ")") + ratio;
MaterialName = MaterialName + materialOther + ((depotItem.getMaterialId().getUnit() == null || depotItem.getMaterialId().getUnit().equals("")) ? "" : "(" + depotItem.getMaterialId().getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
item.put("Unit", depotItem.getMUnit());
item.put("OperNumber", depotItem.getOperNumber());
......@@ -294,10 +298,10 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
item.put("AllPrice", depotItem.getAllPrice());
item.put("Remark", depotItem.getRemark());
item.put("Img", depotItem.getImg());
item.put("DepotId", depotItem.getDepotId()==null?"":depotItem.getDepotId().getId());
item.put("DepotName", depotItem.getDepotId()==null?"":depotItem.getDepotId().getName());
item.put("AnotherDepotId", depotItem.getAnotherDepotId()==null?"":depotItem.getAnotherDepotId().getId());
item.put("AnotherDepotName", depotItem.getAnotherDepotId()==null?"":depotItem.getAnotherDepotId().getName());
item.put("DepotId", depotItem.getDepotId() == null ? "" : depotItem.getDepotId().getId());
item.put("DepotName", depotItem.getDepotId() == null ? "" : depotItem.getDepotId().getName());
item.put("AnotherDepotId", depotItem.getAnotherDepotId() == null ? "" : depotItem.getAnotherDepotId().getId());
item.put("AnotherDepotName", depotItem.getAnotherDepotId() == null ? "" : depotItem.getAnotherDepotId().getName());
item.put("TaxRate", depotItem.getTaxRate());
item.put("TaxMoney", depotItem.getTaxMoney());
item.put("TaxLastMoney", depotItem.getTaxLastMoney());
......@@ -314,17 +318,16 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找仓管通信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询仓管通信息结果异常", e);
}
}
/**
* 查找所有的明细
*
* @return
*/
public void findByAll() {
......@@ -342,17 +345,17 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList) {
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer prevSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true);
Integer InSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Integer OutSum = sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Double prevPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumPrice("出库",pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Double OutPrice = sumPrice("出库",pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Integer prevSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Integer InSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Integer OutSum = sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double prevPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double OutPrice = sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
......@@ -361,8 +364,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
item.put("MaterialColor", depotItem.getMaterialId().getColor());
item.put("MaterialUnit", depotItem.getMaterialId().getUnit());
Double unitPrice = 0.0;
if(prevSum + InSum - OutSum != 0.0){
unitPrice = (prevPrice + InPrice - OutPrice)/(prevSum + InSum - OutSum);
if (prevSum + InSum - OutSum != 0.0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);
}
item.put("UnitPrice", unitPrice);
item.put("prevSum", prevSum);
......@@ -376,19 +379,16 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 根据商品id和仓库id查询库存数量
*
* @return
*/
public void findStockNumById() {
......@@ -404,13 +404,13 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList) {
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer prevSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true);
Integer InSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Integer OutSum = sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
Integer prevSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Integer InSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Integer OutSum = sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("thisSum", prevSum + InSum - OutSum);
......@@ -420,19 +420,16 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 只根据商品id查询库存数量
*
* @return
*/
public void findStockNumByMaterialId() {
......@@ -447,12 +444,12 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList) {
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer InSum = sumNumberByMaterialId("入库", depotItem.getMaterialId().getId());
Integer OutSum = sumNumberByMaterialId("出库", depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("thisSum", InSum - OutSum);
......@@ -462,19 +459,16 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 只根据商品id查询单据列表
*
* @return
*/
public void findDetailByTypeAndMaterialId() {
......@@ -489,8 +483,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(dataList!=null){
for(Integer i=0; i<dataList.size(); i++){
if (dataList != null) {
for (Integer i = 0; i < dataList.size(); i++) {
JSONObject item = new JSONObject();
Object dl = dataList.get(i); //获取对象
Object[] arr = (Object[]) dl; //转为数组
......@@ -504,17 +498,16 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
catch (JshException e) {
} catch (JshException e) {
e.printStackTrace();
}
}
/**
* 查找礼品卡信息
*
* @return
*/
public void findGiftByAll() {
......@@ -532,13 +525,13 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList){
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer InSum = sumNumberGift("礼品充值", pid, depotItem.getMaterialId().getId(), "in");
Integer OutSum = sumNumberGift("礼品销售", pid, depotItem.getMaterialId().getId(), "out");
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
......@@ -553,23 +546,20 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 进货统计
*
* @return
*/
public void buyIn()
{
try
{
public void buyIn() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
......@@ -582,17 +572,15 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(DepotItem depotItem:dataList)
{
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer InSum = sumNumberBuyOrSale("入库","采购",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer OutSum = sumNumberBuyOrSale("出库","采购退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Double InSumPrice = sumPriceBuyOrSale("入库","采购",depotItem.getMaterialId().getId(),model.getMonthTime());
Double OutSumPrice = sumPriceBuyOrSale("出库","采购退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer InSum = sumNumberBuyOrSale("入库", "采购", depotItem.getMaterialId().getId(), model.getMonthTime());
Integer OutSum = sumNumberBuyOrSale("出库", "采购退货", depotItem.getMaterialId().getId(), model.getMonthTime());
Double InSumPrice = sumPriceBuyOrSale("入库", "采购", depotItem.getMaterialId().getId(), model.getMonthTime());
Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", depotItem.getMaterialId().getId(), model.getMonthTime());
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
......@@ -610,24 +598,20 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 销售统计
*
* @return
*/
public void saleOut()
{
try
{
public void saleOut() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
......@@ -640,21 +624,19 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(DepotItem depotItem:dataList)
{
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer OutSumRetail = sumNumberBuyOrSale("出库","零售",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer OutSum = sumNumberBuyOrSale("出库","销售",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer InSumRetail = sumNumberBuyOrSale("入库","零售退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer InSum = sumNumberBuyOrSale("入库","销售退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Double OutSumRetailPrice = sumPriceBuyOrSale("出库","零售",depotItem.getMaterialId().getId(),model.getMonthTime());
Double OutSumPrice = sumPriceBuyOrSale("出库","销售",depotItem.getMaterialId().getId(),model.getMonthTime());
Double InSumRetailPrice = sumPriceBuyOrSale("入库","零售退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Double InSumPrice = sumPriceBuyOrSale("入库","销售退货",depotItem.getMaterialId().getId(),model.getMonthTime());
Integer OutSumRetail = sumNumberBuyOrSale("出库", "零售", depotItem.getMaterialId().getId(), model.getMonthTime());
Integer OutSum = sumNumberBuyOrSale("出库", "销售", depotItem.getMaterialId().getId(), model.getMonthTime());
Integer InSumRetail = sumNumberBuyOrSale("入库", "零售退货", depotItem.getMaterialId().getId(), model.getMonthTime());
Integer InSum = sumNumberBuyOrSale("入库", "销售退货", depotItem.getMaterialId().getId(), model.getMonthTime());
Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", depotItem.getMaterialId().getId(), model.getMonthTime());
Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", depotItem.getMaterialId().getId(), model.getMonthTime());
Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", depotItem.getMaterialId().getId(), model.getMonthTime());
Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", depotItem.getMaterialId().getId(), model.getMonthTime());
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
......@@ -672,24 +654,20 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 统计总计金额
*
* @return
*/
public void totalCountMoney()
{
try
{
public void totalCountMoney() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
......@@ -700,32 +678,27 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
JSONObject outer = new JSONObject();
Integer pid = model.getProjectId();
Double thisAllPrice = 0.0;
if(null != dataList)
{
for(DepotItem depotItem:dataList)
{
Double prevPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumPrice("出库",pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Double OutPrice = sumPrice("出库",pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
if (null != dataList) {
for (DepotItem depotItem : dataList) {
Double prevPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double OutPrice = sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice);
}
}
outer.put("totalCount", thisAllPrice);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 导出excel表格
*
* @return
*/
@SuppressWarnings("unchecked")
......@@ -742,21 +715,21 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(DepotItem depotItem:dataList) {
if (null != dataList) {
for (DepotItem depotItem : dataList) {
JSONObject item = new JSONObject();
Integer prevSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true);
Integer InSum = sumNumber("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Integer OutSum = sumNumber("出库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Double prevPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),true) - sumPrice("出库", pid,depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库",pid,depotItem.getMaterialId().getId(),model.getMonthTime(),false);
Double OutPrice = sumPrice("出库",pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Integer prevSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Integer InSum = sumNumber("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Integer OutSum = sumNumber("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double prevPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true) - sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), true);
Double InPrice = sumPrice("入库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double OutPrice = sumPrice("出库", pid, depotItem.getMaterialId().getId(), model.getMonthTime(), false);
Double unitPrice = 0.0;
if(prevSum + InSum - OutSum != 0) {
unitPrice = (prevPrice + InPrice - OutPrice)/(prevSum + InSum - OutSum);
if (prevSum + InSum - OutSum != 0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);
}
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId()==null?"":depotItem.getMaterialId().getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("MaterialStandard", depotItem.getMaterialId().getStandard());
......@@ -772,11 +745,10 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
}
}
String isCurrentPage = "allPage";
model.setFileName(Tools.changeUnicode("report.xls",model.getBrowserType()));
model.setExcelStream(depotItemService.exmportExcel(isCurrentPage,dataArray));
}
catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>调用导出信息action方法exportExcel异常",e);
model.setFileName(Tools.changeUnicode("report.xls", model.getBrowserType()));
model.setExcelStream(depotItemService.exmportExcel(isCurrentPage, dataArray));
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>调用导出信息action方法exportExcel异常", e);
model.getShowModel().setMsgTip("export excel exception");
}
Log.infoFileSync("===================调用导出信息action方法exportExcel结束==================");
......@@ -785,6 +757,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 数量合计
*
* @param type
* @param MId
* @param MonthTime
......@@ -792,7 +765,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
* @return
*/
@SuppressWarnings("unchecked")
public Integer sumNumber(String type,Integer ProjectId,Long MId,String MonthTime, Boolean isPrev) {
public Integer sumNumber(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Integer sumNumber = 0;
String allNumber = "";
PageUtil pageUtil = new PageUtil();
......@@ -801,8 +774,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
try {
depotItemService.findByType(pageUtil, type, ProjectId, MId, MonthTime, isPrev);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1,allNumber.length()-1);
if(allNumber.equals("null")){
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
......@@ -816,12 +789,13 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 仅根据商品Id进行数量合计
*
* @param type
* @param MId
* @return
*/
@SuppressWarnings("unchecked")
public Integer sumNumberByMaterialId(String type,Long MId) {
public Integer sumNumberByMaterialId(String type, Long MId) {
Integer sumNumber = 0;
String allNumber = "";
PageUtil pageUtil = new PageUtil();
......@@ -830,8 +804,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
try {
depotItemService.findByTypeAndMaterialId(pageUtil, type, MId);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1,allNumber.length()-1);
if(allNumber.equals("null")){
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
......@@ -845,6 +819,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 数量合计-礼品卡
*
* @param type
* @param MId
* @param MonthTime
......@@ -852,17 +827,17 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
* @return
*/
@SuppressWarnings("unchecked")
public Integer sumNumberGift(String subType,Integer ProjectId,Long MId,String type) {
public Integer sumNumberGift(String subType, Integer ProjectId, Long MId, String type) {
Integer sumNumber = 0;
String allNumber = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try {
depotItemService.findGiftByType(pageUtil, subType, ProjectId, MId,type);
depotItemService.findGiftByType(pageUtil, subType, ProjectId, MId, type);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1,allNumber.length()-1);
if(allNumber.equals("null")){
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
......@@ -876,6 +851,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 价格合计
*
* @param type
* @param MId
* @param MonthTime
......@@ -883,7 +859,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
* @return
*/
@SuppressWarnings("unchecked")
public Double sumPrice(String type,Integer ProjectId,Long MId,String MonthTime, Boolean isPrev) {
public Double sumPrice(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Double sumPrice = 0.0;
String allPrice = "";
PageUtil pageUtil = new PageUtil();
......@@ -892,8 +868,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
try {
depotItemService.findPriceByType(pageUtil, type, ProjectId, MId, MonthTime, isPrev);
allPrice = pageUtil.getPageList().toString();
allPrice = allPrice.substring(1,allPrice.length()-1);
if(allPrice.equals("null")){
allPrice = allPrice.substring(1, allPrice.length() - 1);
if (allPrice.equals("null")) {
allPrice = "0";
}
allPrice = allPrice.replace(".0", "");
......@@ -906,7 +882,7 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
}
@SuppressWarnings("unchecked")
public Integer sumNumberBuyOrSale(String type,String subType,Long MId,String MonthTime) {
public Integer sumNumberBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Integer sumNumber = 0;
String allNumber = "";
String sumType = "Number";
......@@ -916,8 +892,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
try {
depotItemService.buyOrSale(pageUtil, type, subType, MId, MonthTime, sumType);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1,allNumber.length()-1);
if(allNumber.equals("null")){
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
......@@ -928,8 +904,9 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
sumNumber = Integer.parseInt(allNumber);
return sumNumber;
}
@SuppressWarnings("unchecked")
public Double sumPriceBuyOrSale(String type,String subType,Long MId,String MonthTime) {
public Double sumPriceBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Double sumPrice = 0.0;
String allPrice = "";
String sumType = "Price";
......@@ -939,8 +916,8 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
try {
depotItemService.buyOrSale(pageUtil, type, subType, MId, MonthTime, sumType);
allPrice = pageUtil.getPageList().toString();
allPrice = allPrice.substring(1,allPrice.length()-1);
if(allPrice.equals("null")){
allPrice = allPrice.substring(1, allPrice.length() - 1);
if (allPrice.equals("null")) {
allPrice = "0";
}
allPrice = allPrice.replace(".0", "");
......@@ -954,76 +931,76 @@ public class DepotItemAction extends BaseAction<DepotItemModel>
/**
* 获取扩展信息
*
* @return
*/
public String getOtherInfo(String[] mpArr, DepotItem depotItem){
public String getOtherInfo(String[] mpArr, DepotItem depotItem) {
String materialOther = "";
for(int i=0; i< mpArr.length; i++) {
if(mpArr[i].equals("颜色")) {
materialOther = materialOther + ((depotItem.getMaterialId().getColor() == null || depotItem.getMaterialId().getColor().equals(""))?"":"("+depotItem.getMaterialId().getColor() + ")");
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("颜色")) {
materialOther = materialOther + ((depotItem.getMaterialId().getColor() == null || depotItem.getMaterialId().getColor().equals("")) ? "" : "(" + depotItem.getMaterialId().getColor() + ")");
}
if(mpArr[i].equals("规格")) {
materialOther = materialOther + ((depotItem.getMaterialId().getStandard() == null || depotItem.getMaterialId().getStandard().equals(""))?"":"("+depotItem.getMaterialId().getStandard() + ")");
if (mpArr[i].equals("规格")) {
materialOther = materialOther + ((depotItem.getMaterialId().getStandard() == null || depotItem.getMaterialId().getStandard().equals("")) ? "" : "(" + depotItem.getMaterialId().getStandard() + ")");
}
if(mpArr[i].equals("制造商")) {
materialOther = materialOther + ((depotItem.getMaterialId().getMfrs() == null || depotItem.getMaterialId().getMfrs().equals(""))?"":"("+depotItem.getMaterialId().getMfrs() + ")");
if (mpArr[i].equals("制造商")) {
materialOther = materialOther + ((depotItem.getMaterialId().getMfrs() == null || depotItem.getMaterialId().getMfrs().equals("")) ? "" : "(" + depotItem.getMaterialId().getMfrs() + ")");
}
if(mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField1() == null || depotItem.getMaterialId().getOtherField1().equals(""))?"":"("+depotItem.getMaterialId().getOtherField1() + ")");
if (mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField1() == null || depotItem.getMaterialId().getOtherField1().equals("")) ? "" : "(" + depotItem.getMaterialId().getOtherField1() + ")");
}
if(mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField2() == null || depotItem.getMaterialId().getOtherField2().equals(""))?"":"("+depotItem.getMaterialId().getOtherField2() + ")");
if (mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField2() == null || depotItem.getMaterialId().getOtherField2().equals("")) ? "" : "(" + depotItem.getMaterialId().getOtherField2() + ")");
}
if(mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField3() == null || depotItem.getMaterialId().getOtherField3().equals(""))?"":"("+depotItem.getMaterialId().getOtherField3() + ")");
if (mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField3() == null || depotItem.getMaterialId().getOtherField3().equals("")) ? "" : "(" + depotItem.getMaterialId().getOtherField3() + ")");
}
}
return materialOther;
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getCondition()
{
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("HeaderId_n_eq", model.getHeaderId());
condition.put("Id_s_order","asc");
condition.put("Id_s_order", "asc");
return condition;
}
private Map<String,Object> getConditionALL()
{
private Map<String, Object> getConditionALL() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("HeaderId_s_in", model.getHeadIds());
condition.put("MaterialId_s_in", model.getMaterialIds());
condition.put("MaterialId_s_gb","aaa");
condition.put("MaterialId_s_gb", "aaa");
return condition;
}
private Map<String,Object> getConditionById() {
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("MaterialId_n_eq", model.getMaterialId());
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public DepotItemModel getModel()
{
public DepotItemModel getModel() {
return model;
}
public void setDepotItemService(DepotItemIService depotItemService)
{
public void setDepotItemService(DepotItemIService depotItemService) {
this.depotItemService = depotItemService;
}
......
package com.jsh.action.materials;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.Logdetails;
import com.jsh.model.po.Material;
import com.jsh.model.po.MaterialCategory;
import com.jsh.model.po.Unit;
import com.jsh.model.vo.materials.MaterialModel;
import com.jsh.service.materials.MaterialIService;
import com.jsh.util.JshException;
import com.jsh.util.MaterialConstants;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Timestamp;
......@@ -8,39 +24,25 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jsh.model.po.*;
import com.jsh.util.JshException;
import com.jsh.util.MaterialConstants;
import com.jsh.util.Tools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.vo.materials.MaterialModel;
import com.jsh.service.materials.MaterialIService;
import com.jsh.util.PageUtil;
/*
* 商品管理
* @author jishenghua qq:752718920
*/
*/
@SuppressWarnings("serial")
public class MaterialAction extends BaseAction<MaterialModel>
{
public class MaterialAction extends BaseAction<MaterialModel> {
public static final String EXCEL = "excel"; //action返回excel结果
private MaterialIService materialService;
private MaterialModel model = new MaterialModel();
public static final String EXCEL = "excel"; //action返回excel结果
/**
* 增加商品
*
* @return
*/
public void create()
{
public void create() {
Log.infoFileSync("==================开始调用增加商品信息方法create()===================");
Boolean flag = false;
try
{
try {
Material material = new Material();
material.setMaterialCategory(new MaterialCategory(model.getCategoryId()));
......@@ -56,10 +58,9 @@ public class MaterialAction extends BaseAction<MaterialModel>
material.setLowPrice(model.getLowPrice());
material.setPresetPriceOne(model.getPresetPriceOne());
material.setPresetPriceTwo(model.getPresetPriceTwo());
if(model.getUnitId()!=null){
if (model.getUnitId() != null) {
material.setUnitId(new Unit(model.getUnitId()));
}
else {
} else {
material.setUnitId(null);
}
material.setFirstOutUnit(model.getFirstOutUnit());
......@@ -77,47 +78,37 @@ public class MaterialAction extends BaseAction<MaterialModel>
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加商品信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加商品信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加商品名称为 "+ model.getName() + " " + tipMsg + "!", "增加商品" + tipMsg));
, tipType, "增加商品名称为 " + model.getName() + " " + tipMsg + "!", "增加商品" + tipMsg));
Log.infoFileSync("==================结束调用增加商品方法create()===================");
}
/**
* 删除商品
*
* @return
*/
public String delete()
{
public String delete() {
Log.infoFileSync("====================开始调用删除商品信息方法delete()================");
try
{
try {
materialService.delete(model.getMaterialID());
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getMaterialID() + " 的商品异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -125,20 +116,19 @@ public class MaterialAction extends BaseAction<MaterialModel>
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除商品ID为 "+ model.getMaterialID() + " " + tipMsg + "!", "删除商品" + tipMsg));
, tipType, "删除商品ID为 " + model.getMaterialID() + " " + tipMsg + "!", "删除商品" + tipMsg));
Log.infoFileSync("====================结束调用删除商品信息方法delete()================");
return SUCCESS;
}
/**
* 更新商品
*
* @return
*/
public void update()
{
public void update() {
Boolean flag = false;
try
{
try {
Material material = materialService.get(model.getMaterialID());
material.setMaterialCategory(new MaterialCategory(model.getCategoryId()));
......@@ -154,10 +144,9 @@ public class MaterialAction extends BaseAction<MaterialModel>
material.setLowPrice(model.getLowPrice());
material.setPresetPriceOne(model.getPresetPriceOne());
material.setPresetPriceTwo(model.getPresetPriceTwo());
if(model.getUnitId()!=null){
if (model.getUnitId() != null) {
material.setUnitId(new Unit(model.getUnitId()));
}
else {
} else {
material.setUnitId(null);
}
material.setFirstOutUnit(model.getFirstOutUnit());
......@@ -172,46 +161,36 @@ public class MaterialAction extends BaseAction<MaterialModel>
flag = true;
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品ID为 : " + model.getMaterialID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品ID为 "+ model.getMaterialID() + " " + tipMsg + "!", "更新商品" + tipMsg));
, tipType, "更新商品ID为 " + model.getMaterialID() + " " + tipMsg + "!", "更新商品" + tipMsg));
}
/**
* 批量删除指定ID商品
*
* @return
*/
public String batchDelete()
{
try
{
public String batchDelete() {
try {
materialService.batchDelete(model.getMaterialIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除商品ID为:" + model.getMaterialIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -219,26 +198,23 @@ public class MaterialAction extends BaseAction<MaterialModel>
logService.create(new Logdetails(getUser(), "批量删除商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除商品ID为 "+ model.getMaterialIDs() + " " + tipMsg + "!", "批量删除商品" + tipMsg));
, tipType, "批量删除商品ID为 " + model.getMaterialIDs() + " " + tipMsg + "!", "批量删除商品" + tipMsg));
return SUCCESS;
}
/**
* 批量设置状态-启用或者禁用
*
* @return
*/
public String batchSetEnable()
{
try
{
materialService.batchSetEnable(model.getEnabled(),model.getMaterialIDs());
public String batchSetEnable() {
try {
materialService.batchSetEnable(model.getEnabled(), model.getMaterialIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量修改状态,商品ID为:" + model.getMaterialIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -246,12 +222,13 @@ public class MaterialAction extends BaseAction<MaterialModel>
logService.create(new Logdetails(getUser(), "批量修改商品状态", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量修改状态,商品ID为 "+ model.getMaterialIDs() + " " + tipMsg + "!", "批量修改商品状态" + tipMsg));
, tipType, "批量修改状态,商品ID为 " + model.getMaterialIDs() + " " + tipMsg + "!", "批量修改商品状态" + tipMsg));
return SUCCESS;
}
/**
* 查找该商品是否存在
*
* @return
*/
public void checkIsExist() {
......@@ -263,41 +240,35 @@ public class MaterialAction extends BaseAction<MaterialModel>
pageUtil.setAdvSearch(getConditionCheckIsExist());
materialService.find(pageUtil);
List<Material> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0){
if (null != dataList && dataList.size() > 0) {
flag = true;
}
else{
} else {
flag = false;
}
//回写查询结果
toClient(flag.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 查找商品信息
*
* @return
*/
public void findBy()
{
try
{
public void findBy() {
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
Long lei=model.getCategoryId();
if(1==lei) //判断值还真不能用String类型的判断
Long lei = model.getCategoryId();
if (1 == lei) //判断值还真不能用String类型的判断
{
pageUtil.setAdvSearch(getCondition_all());
}
else if(1!=lei)
{
} else if (1 != lei) {
pageUtil.setAdvSearch(getCondition());
}
materialService.find(pageUtil);
......@@ -309,59 +280,57 @@ public class MaterialAction extends BaseAction<MaterialModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(Material material:dataList)
{
if (null != dataList) {
for (Material material : dataList) {
JSONObject item = new JSONObject();
item.put("Id", material.getId());
item.put("Name", material.getName());
item.put("CategoryId", material.getMaterialCategory().getId()); //类型Id
item.put("CategoryName", material.getMaterialCategory().getName()); //类型名称
item.put("Packing", material.getPacking()==null?"" : material.getPacking());
item.put("SafetyStock", material.getSafetyStock()==null?"" : material.getSafetyStock());
item.put("Model", material.getModel()==null?"" : material.getModel());
item.put("Packing", material.getPacking() == null ? "" : material.getPacking());
item.put("SafetyStock", material.getSafetyStock() == null ? "" : material.getSafetyStock());
item.put("Model", material.getModel() == null ? "" : material.getModel());
//扩展信息
String materialOther = "";
for(int i=0; i< mpArr.length; i++) {
if(mpArr[i].equals("颜色")) {
materialOther = materialOther + ((material.getColor() == null || material.getColor().equals(""))?"":"("+material.getColor() + ")");
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("颜色")) {
materialOther = materialOther + ((material.getColor() == null || material.getColor().equals("")) ? "" : "(" + material.getColor() + ")");
}
if(mpArr[i].equals("规格")) {
materialOther = materialOther + ((material.getStandard() == null || material.getStandard().equals(""))?"":"("+material.getStandard() + ")");
if (mpArr[i].equals("规格")) {
materialOther = materialOther + ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
}
if(mpArr[i].equals("制造商")) {
materialOther = materialOther + ((material.getMfrs() == null || material.getMfrs().equals(""))?"":"("+material.getMfrs() + ")");
if (mpArr[i].equals("制造商")) {
materialOther = materialOther + ((material.getMfrs() == null || material.getMfrs().equals("")) ? "" : "(" + material.getMfrs() + ")");
}
if(mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((material.getOtherField1() == null || material.getOtherField1().equals(""))?"":"("+material.getOtherField1() + ")");
if (mpArr[i].equals("自定义1")) {
materialOther = materialOther + ((material.getOtherField1() == null || material.getOtherField1().equals("")) ? "" : "(" + material.getOtherField1() + ")");
}
if(mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((material.getOtherField2() == null || material.getOtherField2().equals(""))?"":"("+material.getOtherField2() + ")");
if (mpArr[i].equals("自定义2")) {
materialOther = materialOther + ((material.getOtherField2() == null || material.getOtherField2().equals("")) ? "" : "(" + material.getOtherField2() + ")");
}
if(mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((material.getOtherField3() == null || material.getOtherField3().equals(""))?"":"("+material.getOtherField3() + ")");
if (mpArr[i].equals("自定义3")) {
materialOther = materialOther + ((material.getOtherField3() == null || material.getOtherField3().equals("")) ? "" : "(" + material.getOtherField3() + ")");
}
}
item.put("MaterialOther", materialOther);
item.put("Unit", material.getUnit()==null?"": material.getUnit());
item.put("Unit", material.getUnit() == null ? "" : material.getUnit());
item.put("RetailPrice", material.getRetailPrice());
item.put("LowPrice", material.getLowPrice());
item.put("PresetPriceOne", material.getPresetPriceOne()==null? "":material.getPresetPriceOne());
item.put("PresetPriceTwo", material.getPresetPriceTwo()==null? "":material.getPresetPriceTwo());
item.put("UnitId",material.getUnitId()==null? "": material.getUnitId().getId()); //计量单位Id
item.put("UnitName", material.getUnitId()==null? "": material.getUnitId().getUName()); //计量单位名称
item.put("PresetPriceOne", material.getPresetPriceOne() == null ? "" : material.getPresetPriceOne());
item.put("PresetPriceTwo", material.getPresetPriceTwo() == null ? "" : material.getPresetPriceTwo());
item.put("UnitId", material.getUnitId() == null ? "" : material.getUnitId().getId()); //计量单位Id
item.put("UnitName", material.getUnitId() == null ? "" : material.getUnitId().getUName()); //计量单位名称
item.put("FirstOutUnit", material.getFirstOutUnit());
item.put("FirstInUnit", material.getFirstInUnit());
item.put("PriceStrategy", material.getPriceStrategy());
item.put("Enabled", material.getEnabled());
item.put("Remark", material.getRemark());
item.put("Color", material.getColor()==null?"" : material.getColor());
item.put("Standard", material.getStandard()==null?"" : material.getStandard());
item.put("Mfrs", material.getMfrs()==null?"" : material.getMfrs());
item.put("OtherField1", material.getOtherField1()==null?"" : material.getOtherField1());
item.put("OtherField2", material.getOtherField2()==null?"" : material.getOtherField2());
item.put("OtherField3", material.getOtherField3()==null?"" : material.getOtherField3());
item.put("Color", material.getColor() == null ? "" : material.getColor());
item.put("Standard", material.getStandard() == null ? "" : material.getStandard());
item.put("Mfrs", material.getMfrs() == null ? "" : material.getMfrs());
item.put("OtherField1", material.getOtherField1() == null ? "" : material.getOtherField1());
item.put("OtherField2", material.getOtherField2() == null ? "" : material.getOtherField2());
item.put("OtherField3", material.getOtherField3() == null ? "" : material.getOtherField3());
item.put("op", 1);
dataArray.add(item);
}
......@@ -369,24 +338,20 @@ public class MaterialAction extends BaseAction<MaterialModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 根据id来查询商品名称
*
* @return
*/
public void findById() {
try
{
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setAdvSearch(getConditionById());
materialService.find(pageUtil);
......@@ -395,26 +360,24 @@ public class MaterialAction extends BaseAction<MaterialModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(Material material:dataList)
{
if (null != dataList) {
for (Material material : dataList) {
JSONObject item = new JSONObject();
item.put("Id", material.getId());
item.put("Name", material.getName());
item.put("Mfrs", material.getMfrs()==null?"" : material.getMfrs());
item.put("Packing", material.getPacking()==null?"" : material.getPacking());
item.put("SafetyStock", material.getSafetyStock()==null?"" : material.getSafetyStock());
item.put("Mfrs", material.getMfrs() == null ? "" : material.getMfrs());
item.put("Packing", material.getPacking() == null ? "" : material.getPacking());
item.put("SafetyStock", material.getSafetyStock() == null ? "" : material.getSafetyStock());
item.put("Model", material.getModel());
item.put("Standard", material.getStandard());
item.put("Color", material.getColor()==null?"": material.getColor());
item.put("Color", material.getColor() == null ? "" : material.getColor());
item.put("Unit", material.getUnit());
item.put("RetailPrice", material.getRetailPrice());
item.put("LowPrice", material.getLowPrice());
item.put("PresetPriceOne", material.getPresetPriceOne());
item.put("PresetPriceTwo", material.getPresetPriceTwo());
item.put("UnitId",material.getUnitId()==null? "": material.getUnitId().getId()); //计量单位Id
item.put("UnitName", material.getUnitId()==null? "": material.getUnitId().getUName()); //计量单位名称
item.put("UnitId", material.getUnitId() == null ? "" : material.getUnitId().getId()); //计量单位Id
item.put("UnitName", material.getUnitId() == null ? "" : material.getUnitId().getUName()); //计量单位名称
item.put("FirstOutUnit", material.getFirstOutUnit());
item.put("FirstInUnit", material.getFirstInUnit());
item.put("PriceStrategy", material.getPriceStrategy());
......@@ -426,19 +389,16 @@ public class MaterialAction extends BaseAction<MaterialModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 查找商品信息-下拉框
*
* @return
*/
public void findBySelect() {
......@@ -453,52 +413,49 @@ public class MaterialAction extends BaseAction<MaterialModel>
String[] mpArr = mpList.split(",");
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(Material material:dataList) {
if (null != dataList) {
for (Material material : dataList) {
JSONObject item = new JSONObject();
item.put("Id", material.getId());
String ratio; //比例
if(material.getUnitId() == null || material.getUnitId().equals("")){
if (material.getUnitId() == null || material.getUnitId().equals("")) {
ratio = "";
}
else {
} else {
ratio = material.getUnitId().getUName();
ratio = ratio.substring(ratio.indexOf("("));
}
//品名/型号/扩展信息/包装
String MaterialName = material.getName() + ((material.getModel() == null || material.getModel().equals(""))?"":"("+material.getModel() + ")");
for(int i=0; i< mpArr.length; i++) {
if(mpArr[i].equals("颜色")) {
MaterialName = MaterialName + ((material.getColor() == null || material.getColor().equals(""))?"":"("+material.getColor() + ")");
String MaterialName = material.getName() + ((material.getModel() == null || material.getModel().equals("")) ? "" : "(" + material.getModel() + ")");
for (int i = 0; i < mpArr.length; i++) {
if (mpArr[i].equals("颜色")) {
MaterialName = MaterialName + ((material.getColor() == null || material.getColor().equals("")) ? "" : "(" + material.getColor() + ")");
}
if(mpArr[i].equals("规格")) {
MaterialName = MaterialName + ((material.getStandard() == null || material.getStandard().equals(""))?"":"("+material.getStandard() + ")");
if (mpArr[i].equals("规格")) {
MaterialName = MaterialName + ((material.getStandard() == null || material.getStandard().equals("")) ? "" : "(" + material.getStandard() + ")");
}
if(mpArr[i].equals("制造商")) {
MaterialName = MaterialName + ((material.getMfrs() == null || material.getMfrs().equals(""))?"":"("+material.getMfrs() + ")");
if (mpArr[i].equals("制造商")) {
MaterialName = MaterialName + ((material.getMfrs() == null || material.getMfrs().equals("")) ? "" : "(" + material.getMfrs() + ")");
}
if(mpArr[i].equals("自定义1")) {
MaterialName = MaterialName + ((material.getOtherField1() == null || material.getOtherField1().equals(""))?"":"("+material.getOtherField1() + ")");
if (mpArr[i].equals("自定义1")) {
MaterialName = MaterialName + ((material.getOtherField1() == null || material.getOtherField1().equals("")) ? "" : "(" + material.getOtherField1() + ")");
}
if(mpArr[i].equals("自定义2")) {
MaterialName = MaterialName + ((material.getOtherField2() == null || material.getOtherField2().equals(""))?"":"("+material.getOtherField2() + ")");
if (mpArr[i].equals("自定义2")) {
MaterialName = MaterialName + ((material.getOtherField2() == null || material.getOtherField2().equals("")) ? "" : "(" + material.getOtherField2() + ")");
}
if(mpArr[i].equals("自定义3")) {
MaterialName = MaterialName + ((material.getOtherField3() == null || material.getOtherField3().equals(""))?"":"("+material.getOtherField3() + ")");
if (mpArr[i].equals("自定义3")) {
MaterialName = MaterialName + ((material.getOtherField3() == null || material.getOtherField3().equals("")) ? "" : "(" + material.getOtherField3() + ")");
}
}
MaterialName = MaterialName + ((material.getUnit() == null || material.getUnit().equals(""))?"":"("+material.getUnit() + ")") + ratio;
MaterialName = MaterialName + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
dataArray.add(item);
}
}
//回写查询结果
toClient(dataArray.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找供应商信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询供应商信息结果异常", e);
} catch (Exception e) {
e.printStackTrace();
......@@ -507,12 +464,11 @@ public class MaterialAction extends BaseAction<MaterialModel>
/**
* 查找商品信息-统计排序
*
* @return
*/
public void findByOrder()
{
try
{
public void findByOrder() {
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
......@@ -522,32 +478,27 @@ public class MaterialAction extends BaseAction<MaterialModel>
//存放数据json数组
JSONObject outer = new JSONObject();
String mId = "";
if(null != dataList)
{
for(Material material:dataList)
{
if (null != dataList) {
for (Material material : dataList) {
mId = mId + material.getId() + ",";
}
}
if(mId!="") {
if (mId != "") {
mId = mId.substring(0, mId.lastIndexOf(","));
}
outer.put("mIds", mId);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找供应商信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询供应商信息结果异常", e);
}
}
/**
* 导入excel表格-供应商
*
* @return
*/
@SuppressWarnings("unchecked")
......@@ -558,13 +509,11 @@ public class MaterialAction extends BaseAction<MaterialModel>
try {
InputStream in = materialService.importExcel(model.getMaterialFile());
if(null != in)
{
if (null != in) {
model.setFileName(Tools.getRandomChar() + Tools.getNow2(Calendar.getInstance().getTime()) + "_wrong.xls");
model.setExcelStream(in);
returnStr = MaterialConstants.BusinessForExcel.EXCEL;
}
else {
} else {
result = true;
try {
toClient(result.toString());
......@@ -575,9 +524,7 @@ public class MaterialAction extends BaseAction<MaterialModel>
returnStr = SUCCESS;
}
}
catch (JshException e)
{
} catch (JshException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>导入excel表格信息异常", e);
}
return returnStr;
......@@ -585,6 +532,7 @@ public class MaterialAction extends BaseAction<MaterialModel>
/**
* 导出excel表格
*
* @return
*/
@SuppressWarnings("unchecked")
......@@ -592,15 +540,14 @@ public class MaterialAction extends BaseAction<MaterialModel>
Log.infoFileSync("===================调用导出信息action方法exportExcel开始=======================");
try {
String sName = "pageUtilMaterial";
PageUtil<Material> pageUtil = (PageUtil<Material>)getSession().get(sName);
PageUtil<Material> pageUtil = (PageUtil<Material>) getSession().get(sName);
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
String isCurrentPage = "allPage";
model.setFileName(Tools.changeUnicode("goods" + System.currentTimeMillis() + ".xls", model.getBrowserType()));
model.setExcelStream(materialService.exmportExcel(isCurrentPage,pageUtil));
}
catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>调用导出信息action方法exportExcel异常",e);
model.setExcelStream(materialService.exmportExcel(isCurrentPage, pageUtil));
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>>>>调用导出信息action方法exportExcel异常", e);
model.getShowModel().setMsgTip("export excel exception");
}
Log.infoFileSync("===================调用导出信息action方法exportExcel结束==================");
......@@ -609,14 +556,14 @@ public class MaterialAction extends BaseAction<MaterialModel>
/**
* 拼接搜索条件(查全部)
*
* @return
*/
private Map<String,Object> getCondition_all()
{
private Map<String, Object> getCondition_all() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name_s_like", model.getName());
condition.put("Model_s_like", model.getModel());
condition.put("Color_s_like", model.getColor());
......@@ -626,13 +573,14 @@ public class MaterialAction extends BaseAction<MaterialModel>
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getCondition() {
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name_s_like", model.getName());
condition.put("Model_s_like", model.getModel());
condition.put("Color_s_like", model.getColor());
......@@ -641,9 +589,9 @@ public class MaterialAction extends BaseAction<MaterialModel>
return condition;
}
private Map<String,Object> getConditionCheckIsExist() {
Map<String,Object> condition = new HashMap<String,Object>();
if(model.getMaterialID()>0){
private Map<String, Object> getConditionCheckIsExist() {
Map<String, Object> condition = new HashMap<String, Object>();
if (model.getMaterialID() > 0) {
condition.put("ID_n_neq", model.getMaterialID());
}
condition.put("Name_s_eq", model.getName());
......@@ -654,10 +602,10 @@ public class MaterialAction extends BaseAction<MaterialModel>
condition.put("OtherField1_s_eq", model.getOtherField1());
condition.put("OtherField2_s_eq", model.getOtherField2());
condition.put("OtherField3_s_eq", model.getOtherField3());
if(model.getUnit()!=null){
if (model.getUnit() != null) {
condition.put("Unit_s_eq", model.getUnit());
}
if(model.getUnitId()!=null){
if (model.getUnitId() != null) {
condition.put("UnitId_n_eq", model.getUnitId());
}
return condition;
......@@ -665,55 +613,54 @@ public class MaterialAction extends BaseAction<MaterialModel>
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getConditionById()
{
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Id_n_eq", model.getMaterialID());
return condition;
}
/**
* 拼接搜索条件-下拉框
*
* @return
*/
private Map<String,Object> getCondition_Select()
{
private Map<String, Object> getCondition_Select() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
condition.put("enabled_s_eq",1);
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("enabled_s_eq", 1);
condition.put("Id_s_order", "asc");
return condition;
}
/**
* 拼接搜索条件-下拉框
*
* @return
*/
private Map<String,Object> getCondition_Order()
{
private Map<String, Object> getCondition_Order() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name,Model_s_order", "asc");
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public MaterialModel getModel()
{
public MaterialModel getModel() {
return model;
}
public void setMaterialService(MaterialIService materialService)
{
public void setMaterialService(MaterialIService materialService) {
this.materialService = materialService;
}
}
package com.jsh.action.materials;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.MaterialCategory;
import com.jsh.model.po.Logdetails;
import com.jsh.model.po.MaterialCategory;
import com.jsh.model.vo.materials.MaterialCategoryModel;
import com.jsh.service.materials.MaterialCategoryIService;
import com.jsh.util.PageUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* 商品类型管理
* @author jishenghua qq:752718920
*/
*/
@SuppressWarnings("serial")
public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
{
public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel> {
private MaterialCategoryIService materialCategoryService;
private MaterialCategoryModel model = new MaterialCategoryModel();
@SuppressWarnings({ "rawtypes", "unchecked" })
public String getBasicData()
{
Map<String,List> mapData = model.getShowModel().getMap();
@SuppressWarnings({"rawtypes", "unchecked"})
public String getBasicData() {
Map<String, List> mapData = model.getShowModel().getMap();
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try
{
Map<String,Object> condition = pageUtil.getAdvSearch();
try {
Map<String, Object> condition = pageUtil.getAdvSearch();
condition.put("ParentId_n_eq", model.getParentId());
condition.put("Id_n_neq", 1);
condition.put("Id_s_order", "asc");
materialCategoryService.find(pageUtil);
mapData.put("materialCategoryList", pageUtil.getPageList());
}
catch (Exception e)
{
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>查找商品类别信息异常", e);
model.getShowModel().setMsgTip("exceptoin");
}
......@@ -52,14 +49,13 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
/**
* 增加商品类别
*
* @return
*/
public void create()
{
public void create() {
Log.infoFileSync("==================开始调用增加商品类别信息方法create()===================");
Boolean flag = false;
try
{
try {
MaterialCategory materialCategory = new MaterialCategory();
materialCategory.setMaterialCategory(new MaterialCategory(model.getParentId()));
......@@ -72,47 +68,37 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加商品类别信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加商品类别信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加商品类别名称为 "+ model.getName() + " " + tipMsg + "!", "增加商品类别" + tipMsg));
, tipType, "增加商品类别名称为 " + model.getName() + " " + tipMsg + "!", "增加商品类别" + tipMsg));
Log.infoFileSync("==================结束调用增加商品类别方法create()===================");
}
/**
* 删除商品类别
*
* @return
*/
public String delete()
{
public String delete() {
Log.infoFileSync("====================开始调用删除商品类别信息方法delete()================");
try
{
try {
materialCategoryService.delete(model.getMaterialCategoryID());
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getMaterialCategoryID() + " 的商品类别异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -120,20 +106,19 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除商品类别ID为 "+ model.getMaterialCategoryID() + " " + tipMsg + "!", "删除商品类别" + tipMsg));
, tipType, "删除商品类别ID为 " + model.getMaterialCategoryID() + " " + tipMsg + "!", "删除商品类别" + tipMsg));
Log.infoFileSync("====================结束调用删除商品类别信息方法delete()================");
return SUCCESS;
}
/**
* 更新商品类别
*
* @return
*/
public void update()
{
public void update() {
Boolean flag = false;
try
{
try {
MaterialCategory materialCategory = materialCategoryService.get(model.getMaterialCategoryID());
materialCategory.setMaterialCategory(new MaterialCategory(model.getParentId()));
......@@ -144,46 +129,36 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
flag = true;
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品类别ID为 : " + model.getMaterialCategoryID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品类别回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品类别ID为 "+ model.getMaterialCategoryID() + " " + tipMsg + "!", "更新商品类别" + tipMsg));
, tipType, "更新商品类别ID为 " + model.getMaterialCategoryID() + " " + tipMsg + "!", "更新商品类别" + tipMsg));
}
/**
* 批量删除指定ID商品类别
*
* @return
*/
public String batchDelete()
{
try
{
public String batchDelete() {
try {
materialCategoryService.batchDelete(model.getMaterialCategoryIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除商品类别ID为:" + model.getMaterialCategoryIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -191,18 +166,17 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
logService.create(new Logdetails(getUser(), "批量删除商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除商品类别ID为 "+ model.getMaterialCategoryIDs() + " " + tipMsg + "!", "批量删除商品类别" + tipMsg));
, tipType, "批量删除商品类别ID为 " + model.getMaterialCategoryIDs() + " " + tipMsg + "!", "批量删除商品类别" + tipMsg));
return SUCCESS;
}
/**
* 查找商品类别信息
*
* @return
*/
public void findBy()
{
try
{
public void findBy() {
try {
PageUtil<MaterialCategory> pageUtil = new PageUtil<MaterialCategory>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
......@@ -218,10 +192,8 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(MaterialCategory materialCategory:dataList)
{
if (null != dataList) {
for (MaterialCategory materialCategory : dataList) {
JSONObject item = new JSONObject();
item.put("Id", materialCategory.getId());
item.put("ParentId", materialCategory.getMaterialCategory().getId());
......@@ -235,19 +207,16 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品类别信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品类别信息结果异常", e);
}
}
/**
* 根据id来查询商品名称
*
* @return
*/
public void findById() {
......@@ -257,35 +226,31 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
materialCategoryService.find(pageUtil);
List<MaterialCategory> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
if(null != dataList) {
for(MaterialCategory materialCategory : dataList) {
if (null != dataList) {
for (MaterialCategory materialCategory : dataList) {
outer.put("name", materialCategory.getName());
outer.put("parentId", materialCategory.getMaterialCategory().getId());
}
}
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品类别信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品类别信息结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getCondition()
{
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name_s_like", model.getName());
condition.put("ParentId_n_eq", model.getParentId());
condition.put("Id_n_neq", 1);
......@@ -295,25 +260,25 @@ public class MaterialCategoryAction extends BaseAction<MaterialCategoryModel>
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getConditionById(){
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Id_n_eq", model.getMaterialCategoryID());
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public MaterialCategoryModel getModel()
{
public MaterialCategoryModel getModel() {
return model;
}
public void setMaterialCategoryService(MaterialCategoryIService materialCategoryService)
{
public void setMaterialCategoryService(MaterialCategoryIService materialCategoryService) {
this.materialCategoryService = materialCategoryService;
}
}
......@@ -20,15 +20,15 @@ import java.util.Map;
/*
* 商品属性
* @author ji s h e n g hua qq:75 27 18 920
*/
*/
@SuppressWarnings("serial")
public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel>
{
public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel> {
private MaterialPropertyIService materialPropertyService;
private MaterialPropertyModel model = new MaterialPropertyModel();
/**
* 更新商品属性
*
* @return
*/
public void update() {
......@@ -44,28 +44,26 @@ public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel>
flag = true;
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品属性ID为 : " + model.getId() + "失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally {
} finally {
try {
toClient(flag.toString());
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品属性回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品属性", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品属性ID为 "+ model.getId() + " " + tipMsg + "!", "更新商品属性" + tipMsg));
, tipType, "更新商品属性ID为 " + model.getId() + " " + tipMsg + "!", "更新商品属性" + tipMsg));
}
/**
* 查找商品属性
*
* @return
*/
public void findBy() {
......@@ -81,8 +79,8 @@ public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(MaterialProperty materialProperty:dataList) {
if (null != dataList) {
for (MaterialProperty materialProperty : dataList) {
JSONObject item = new JSONObject();
item.put("id", materialProperty.getId());
item.put("nativeName", materialProperty.getNativeName());
......@@ -95,27 +93,23 @@ public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品属性异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品属性结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getCondition()
{
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("nativeName_s_like", model.getNativeName());
condition.put("sort_s_order", "asc");
return condition;
......@@ -126,6 +120,7 @@ public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel>
public MaterialPropertyModel getModel() {
return model;
}
public void setMaterialPropertyService(MaterialPropertyIService materialPropertyService) {
this.materialPropertyService = materialPropertyService;
}
......
package com.jsh.action.materials;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.Depot;
import com.jsh.model.po.Person;
import com.jsh.model.po.Logdetails;
import com.jsh.model.po.Person;
import com.jsh.model.vo.materials.PersonModel;
import com.jsh.service.materials.PersonIService;
import com.jsh.util.PageUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* 经手人管理
* @author jishenghua qq:752718920
*/
*/
@SuppressWarnings("serial")
public class PersonAction extends BaseAction<PersonModel>
{
public class PersonAction extends BaseAction<PersonModel> {
private PersonIService personService;
private PersonModel model = new PersonModel();
@SuppressWarnings({ "rawtypes", "unchecked" })
public String getBasicData()
{
Map<String,List> mapData = model.getShowModel().getMap();
@SuppressWarnings({"rawtypes", "unchecked"})
public String getBasicData() {
Map<String, List> mapData = model.getShowModel().getMap();
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try
{
Map<String,Object> condition = pageUtil.getAdvSearch();
try {
Map<String, Object> condition = pageUtil.getAdvSearch();
condition.put("Id_s_order", "asc");
personService.find(pageUtil);
mapData.put("personList", pageUtil.getPageList());
}
catch (Exception e)
{
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>查找系统基础数据信息异常", e);
model.getShowModel().setMsgTip("exceptoin");
}
return SUCCESS;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public String getPersonByType()
{
Map<String,List> mapData = model.getShowModel().getMap();
@SuppressWarnings({"rawtypes", "unchecked"})
public String getPersonByType() {
Map<String, List> mapData = model.getShowModel().getMap();
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try
{
Map<String,Object> condition = pageUtil.getAdvSearch();
try {
Map<String, Object> condition = pageUtil.getAdvSearch();
condition.put("Type_s_eq", model.getType());
condition.put("Id_s_order", "asc");
personService.find(pageUtil);
mapData.put("personList", pageUtil.getPageList());
}
catch (Exception e)
{
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>查找系统基础数据信息异常", e);
model.getShowModel().setMsgTip("exceptoin");
}
......@@ -73,6 +65,7 @@ public class PersonAction extends BaseAction<PersonModel>
/**
* 根据类型获取经手人信息 1-业务员,2-仓管员,3-财务员
*
* @return
*/
public void getPersonByNumType() {
......@@ -80,24 +73,22 @@ public class PersonAction extends BaseAction<PersonModel>
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
Map<String,Object> condition = pageUtil.getAdvSearch();
Map<String, Object> condition = pageUtil.getAdvSearch();
String type = "";
if(model.getType().equals("1")){
if (model.getType().equals("1")) {
type = "业务员";
}
else if(model.getType().equals("2")){
} else if (model.getType().equals("2")) {
type = "仓管员";
}
else if(model.getType().equals("3")){
} else if (model.getType().equals("3")) {
type = "财务员";
}
condition.put("Type_s_eq",type);
condition.put("Type_s_eq", type);
condition.put("Id_s_order", "asc");
personService.find(pageUtil);
List<Person> dataList = pageUtil.getPageList();
JSONArray dataArray = new JSONArray();
if(null != dataList) {
for(Person person:dataList){
if (null != dataList) {
for (Person person : dataList) {
JSONObject item = new JSONObject();
item.put("id", person.getId());
item.put("name", person.getName());
......@@ -106,17 +97,16 @@ public class PersonAction extends BaseAction<PersonModel>
}
//回写查询结果
toClient(dataArray.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 根据Id获取经手人信息
*
* @return
*/
public void getPersonByIds() {
......@@ -124,38 +114,35 @@ public class PersonAction extends BaseAction<PersonModel>
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
Map<String,Object> condition = pageUtil.getAdvSearch();
Map<String, Object> condition = pageUtil.getAdvSearch();
condition.put("Id_s_in", model.getPersonIDs());
condition.put("Id_s_order", "asc");
personService.find(pageUtil);
List<Person> dataList = pageUtil.getPageList();
StringBuffer sb = new StringBuffer();
if(null != dataList) {
for(Person person:dataList){
if (null != dataList) {
for (Person person : dataList) {
sb.append(person.getName() + " ");
}
}
//回写查询结果
toClient(sb.toString());
}
catch (DataAccessException e) {
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找信息异常", e);
}
catch (IOException e) {
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 增加经手人
*
* @return
*/
public void create()
{
public void create() {
Log.infoFileSync("==================开始调用增加经手人信息方法create()===================");
Boolean flag = false;
try
{
try {
Person person = new Person();
person.setType(model.getType());
......@@ -167,47 +154,37 @@ public class PersonAction extends BaseAction<PersonModel>
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加经手人信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加经手人信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加经手人名称为 "+ model.getName() + " " + tipMsg + "!", "增加经手人" + tipMsg));
, tipType, "增加经手人名称为 " + model.getName() + " " + tipMsg + "!", "增加经手人" + tipMsg));
Log.infoFileSync("==================结束调用增加经手人方法create()===================");
}
/**
* 删除经手人
*
* @return
*/
public String delete()
{
public String delete() {
Log.infoFileSync("====================开始调用删除经手人信息方法delete()================");
try
{
try {
personService.delete(model.getPersonID());
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getPersonID() + " 的经手人异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -215,20 +192,19 @@ public class PersonAction extends BaseAction<PersonModel>
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除经手人ID为 "+ model.getPersonID() + " " + tipMsg + "!", "删除经手人" + tipMsg));
, tipType, "删除经手人ID为 " + model.getPersonID() + " " + tipMsg + "!", "删除经手人" + tipMsg));
Log.infoFileSync("====================结束调用删除经手人信息方法delete()================");
return SUCCESS;
}
/**
* 更新经手人
*
* @return
*/
public void update()
{
public void update() {
Boolean flag = false;
try
{
try {
Person person = personService.get(model.getPersonID());
person.setType(model.getType());
......@@ -238,46 +214,36 @@ public class PersonAction extends BaseAction<PersonModel>
flag = true;
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改经手人ID为 : " + model.getPersonID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
}
finally
{
try
{
} finally {
try {
toClient(flag.toString());
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改经手人回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新经手人ID为 "+ model.getPersonID() + " " + tipMsg + "!", "更新经手人" + tipMsg));
, tipType, "更新经手人ID为 " + model.getPersonID() + " " + tipMsg + "!", "更新经手人" + tipMsg));
}
/**
* 批量删除指定ID经手人
*
* @return
*/
public String batchDelete()
{
try
{
public String batchDelete() {
try {
personService.batchDelete(model.getPersonIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除经手人ID为:" + model.getPersonIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
......@@ -285,18 +251,17 @@ public class PersonAction extends BaseAction<PersonModel>
logService.create(new Logdetails(getUser(), "批量删除经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除经手人ID为 "+ model.getPersonIDs() + " " + tipMsg + "!", "批量删除经手人" + tipMsg));
, tipType, "批量删除经手人ID为 " + model.getPersonIDs() + " " + tipMsg + "!", "批量删除经手人" + tipMsg));
return SUCCESS;
}
/**
* 查找经手人信息
*
* @return
*/
public void findBy()
{
try
{
public void findBy() {
try {
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
......@@ -308,10 +273,8 @@ public class PersonAction extends BaseAction<PersonModel>
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if(null != dataList)
{
for(Person person:dataList)
{
if (null != dataList) {
for (Person person : dataList) {
JSONObject item = new JSONObject();
item.put("Id", person.getId());
item.put("Type", person.getType());
......@@ -323,27 +286,23 @@ public class PersonAction extends BaseAction<PersonModel>
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
}
catch (DataAccessException e)
{
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找经手人信息异常", e);
}
catch (IOException e)
{
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询经手人信息结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String,Object> getCondition()
{
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name_s_like", model.getName());
condition.put("Type_s_eq", model.getType());
return condition;
......@@ -351,12 +310,11 @@ public class PersonAction extends BaseAction<PersonModel>
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public PersonModel getModel()
{
public PersonModel getModel() {
return model;
}
public void setPersonService(PersonIService personService)
{
public void setPersonService(PersonIService personService) {
this.personService = personService;
}
}
package com.jsh.base;
import java.io.IOException;
import java.util.Map;
import com.jsh.model.po.Basicuser;
import com.jsh.service.basic.LogIService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.ServletActionContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.jsh.model.po.Basicuser;
import com.jsh.service.basic.LogIService;
/**
* struts2工具类
*
* @author jishenghua qq752718920
* struts2 base action 一些常用方法获取
*/
@SuppressWarnings("serial")
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T>
{
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
public LogIService logService;
/**
......@@ -33,82 +32,82 @@ public abstract class BaseAction<T> extends ActionSupport implements ModelDriven
*/
public short tipType = 0;
public void setLogService(LogIService logService)
{
this.logService = logService;
}
/**
* 获取session
*
* @return
*/
public static Map<String,Object> getSession()
{
public static Map<String, Object> getSession() {
return ActionContext.getContext().getSession();
}
/**
* 获取request
*
* @return
*/
public static HttpServletRequest getRequest()
{
public static HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* 获取response
*
* @return response
*/
public static HttpServletResponse getResponse()
{
public static HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
public void setLogService(LogIService logService) {
this.logService = logService;
}
/**
* 添加错误信息
*
* @param anErrorMessage
*/
public void addActionError(String anErrorMessage)
{
public void addActionError(String anErrorMessage) {
super.addActionError(anErrorMessage);
}
/**
* 添加消息
*
* @param aMessage
*/
public void addActionMessage(String aMessage)
{
public void addActionMessage(String aMessage) {
clearErrorsAndMessages();
super.addActionMessage(aMessage);
}
/**
* 添加字段错误
*
* @param fieldName
* @param errorMessage
*/
public void addFieldError(String fieldName, String errorMessage)
{
public void addFieldError(String fieldName, String errorMessage) {
clearErrorsAndMessages();
super.addFieldError(fieldName, errorMessage);
}
/**
* 登录用户信息
*
* @return 登录用户对象
*/
public Basicuser getUser()
{
return (Basicuser)getSession().get("user");
public Basicuser getUser() {
return (Basicuser) getSession().get("user");
}
/**
* 回写客户端数据
*
* @throws IOException
*/
public void toClient(String jsonData) throws IOException
{
public void toClient(String jsonData) throws IOException {
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
response.getWriter().print(jsonData);
......
package com.jsh.base;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
import org.hibernate.Query;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
* 基础dao
*
* @author ji_sheng_hua qq:752718920
*/
public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T>
{
public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T> {
protected Class<T> entityClass;
public void setPoJoClass(Class<T> c)
{
public void setPoJoClass(Class<T> c) {
this.entityClass = c;
}
protected Class<T> getEntityClass()
{
protected Class<T> getEntityClass() {
return this.entityClass;
}
@Override
public Serializable create(T t) throws DataAccessException
{
public Serializable create(T t) throws DataAccessException {
return this.getHibernateTemplate().save(t);
}
@Override
public void delete(T t) throws DataAccessException
{
public void delete(T t) throws DataAccessException {
this.getHibernateTemplate().delete(t);
}
@Override
public T get(Long objID) throws DataAccessException
{
public T get(Long objID) throws DataAccessException {
return (T) this.getHibernateTemplate().get(getEntityClass(), objID);
}
@Override
public void update(T t) throws DataAccessException
{
public void update(T t) throws DataAccessException {
this.getHibernateTemplate().update(t);
}
@Override
public void batchDelete(String objIDs) throws DataAccessException
{
this.getHibernateTemplate().bulkUpdate("delete from " + getEntityClass().getName() + " where id in ("+ objIDs + ")");
public void batchDelete(String objIDs) throws DataAccessException {
this.getHibernateTemplate().bulkUpdate("delete from " + getEntityClass().getName() + " where id in (" + objIDs + ")");
}
@SuppressWarnings("unchecked")
@Override
public void find(PageUtil<T> pageUtil) throws DataAccessException
{
public void find(PageUtil<T> pageUtil) throws DataAccessException {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+
.createQuery(" from " + getEntityClass().getName() + " where 1=1 " +
SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
// 分页查询
int pageNo = pageUtil.getCurPage();
int pageSize = pageUtil.getPageSize();
if (0 != pageNo && 0 != pageSize)
{
if (0 != pageNo && 0 != pageSize) {
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
}
......@@ -94,10 +85,9 @@ public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T>
@SuppressWarnings("unchecked")
@Override
public List<T> find(Map<String, Object> conditon, int pageSize, int pageNo)throws DataAccessException
{
public List<T> find(Map<String, Object> conditon, int pageSize, int pageNo) throws DataAccessException {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon));
.createQuery(" from " + getEntityClass().getName() + " where 1=1 " + SearchConditionUtil.getCondition(conditon));
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
return query.list();
......@@ -105,10 +95,9 @@ public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T>
@SuppressWarnings("unchecked")
@Override
public List<T> find(String hql, int pageSize, int pageNo)throws DataAccessException
{
public List<T> find(String hql, int pageSize, int pageNo) throws DataAccessException {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ hql);
.createQuery(" from " + getEntityClass().getName() + " where 1=1 " + hql);
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
return query.list();
......@@ -116,25 +105,22 @@ public class BaseDAO<T> extends HibernateDaoSupport implements BaseIDAO<T>
@SuppressWarnings("unchecked")
@Override
public Integer countSum(Map<String, Object> conditon)throws DataAccessException
{
public Integer countSum(Map<String, Object> conditon) throws DataAccessException {
List<T> dataList = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon)).list();
return dataList ==null?0:dataList.size();
.createQuery(" from " + getEntityClass().getName() + " where 1=1 " + SearchConditionUtil.getCondition(conditon)).list();
return dataList == null ? 0 : dataList.size();
}
@SuppressWarnings("unchecked")
@Override
public Integer countSum(String hql) throws DataAccessException
{
public Integer countSum(String hql) throws DataAccessException {
List<T> dataList = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.createQuery(" from " + getEntityClass().getName() + " where 1=1 "+ hql).list();
return dataList ==null?0:dataList.size();
.createQuery(" from " + getEntityClass().getName() + " where 1=1 " + hql).list();
return dataList == null ? 0 : dataList.size();
}
@Override
public void save(T t) throws DataAccessException
{
public void save(T t) throws DataAccessException {
this.getHibernateTemplate().save(t);
}
}
package com.jsh.base;
import com.jsh.util.PageUtil;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import com.jsh.util.PageUtil;
/**
* 常用增删改查操作
* @author ji-sheng-hua qq752718920
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public interface BaseIDAO<T>
{
public interface BaseIDAO<T> {
/**
* 设置操作类对象
*
* @param paramClass
*/
void setPoJoClass(Class<T> paramClass);
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
Serializable create(T t)throws DataAccessException;
Serializable create(T t) throws DataAccessException;
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
void save(T t)throws DataAccessException;
void save(T t) throws DataAccessException;
/**
* 删除
*
* @param t 对象
* @throws DataAccessException
*/
void delete(T t)throws DataAccessException;
void delete(T t) throws DataAccessException;
/**
* 获取
*
* @param objID ID
* @return 对象
* @throws DataAccessException
*/
T get(Long objID)throws DataAccessException;
T get(Long objID) throws DataAccessException;
/**
* 修改信息
*
* @param t 要修改的对象
* @throws DataAccessException
*/
void update(T t)throws DataAccessException;
void update(T t) throws DataAccessException;
/**
* 批量删除信息
*
* @param 以逗号分割的ID
* @throws DataAccessException
*/
void batchDelete(String objIDs)throws DataAccessException;
void batchDelete(String objIDs) throws DataAccessException;
/**
* 查找列表
*
* @param pageUtil 分页工具类
* @throws DataAccessException
*/
void find(PageUtil<T> pageUtil)throws DataAccessException;
void find(PageUtil<T> pageUtil) throws DataAccessException;
/**
* 根据条件查询列表--没有分页信息
......@@ -88,37 +95,41 @@ public interface BaseIDAO<T>
/**
* 根据搜索条件查询--分页
*
* @param conditon 查询条件
* @param pageSize 每页个数
* @param pageNo 页码
* @return 查询列表数据
* @throws DataAccessException
*/
List<T> find(Map<String,Object> conditon,int pageSize,int pageNo)throws DataAccessException;
List<T> find(Map<String, Object> conditon, int pageSize, int pageNo) throws DataAccessException;
/**
* 根据hql查询--分页
*
* @param hql hibernate查询语句
* @param pageSize 每页个数
* @param pageNo 页码
* @return 查询列表数据
* @throws DataAccessException
*/
List<T> find(String hql,int pageSize,int pageNo)throws DataAccessException;
List<T> find(String hql, int pageSize, int pageNo) throws DataAccessException;
/**
* 查找符合条件的总数
*
* @param conditon
* @return
* @throws DataAccessException
*/
Integer countSum(Map<String,Object> conditon)throws DataAccessException;
Integer countSum(Map<String, Object> conditon) throws DataAccessException;
/**
* 查找符合条件的总数
*
* @param hql
* @return
* @throws DataAccessException
*/
Integer countSum(String hql)throws DataAccessException;
Integer countSum(String hql) throws DataAccessException;
}
package com.jsh.base;
import java.io.Serializable;
import com.jsh.util.PageUtil;
import org.springframework.dao.DataAccessException;
import com.jsh.util.PageUtil;
import java.io.Serializable;
/**
* 服务层底层接口
* @author ji-sheng-hua qq752718920
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public interface BaseIService<T>
{
public interface BaseIService<T> {
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
Serializable create(T t)throws DataAccessException;
Serializable create(T t) throws DataAccessException;
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
void save(T t)throws DataAccessException;
void save(T t) throws DataAccessException;
/**
* 删除
*
* @param t 对象
* @throws DataAccessException
*/
void delete(T t)throws DataAccessException;
void delete(T t) throws DataAccessException;
/**
* 删除
*
* @param id 对象ID
* @throws DataAccessException
*/
void delete(Long id)throws DataAccessException;
void delete(Long id) throws DataAccessException;
/**
* 获取
*
* @param objID ID
* @return 对象
* @throws DataAccessException
*/
T get(Long objID)throws DataAccessException;
T get(Long objID) throws DataAccessException;
/**
* 修改信息
*
* @param t 要修改的对象
* @throws DataAccessException
*/
void update(T t)throws DataAccessException;
void update(T t) throws DataAccessException;
/**
* 批量删除信息
*
* @param 以逗号分割的ID
* @throws DataAccessException
*/
void batchDelete(String objIDs)throws DataAccessException;
void batchDelete(String objIDs) throws DataAccessException;
/**
* 查找列表
*
* @param pageUtil 分页工具类
* @throws DataAccessException
*/
......@@ -71,6 +79,7 @@ public interface BaseIService<T>
/**
* 检查名称是否存在,页面唯一性效验使用
*
* @param filedName 效验的字段名称
* @param filedVale 校验值
* @param idFiled ID字段名称
......@@ -78,10 +87,11 @@ public interface BaseIService<T>
* @return true==存在 false==不存在
* @throws DataAccessException
*/
Boolean checkIsNameExist(String filedName,String filedVale,String idFiled,Long objectID) throws DataAccessException;
Boolean checkIsNameExist(String filedName, String filedVale, String idFiled, Long objectID) throws DataAccessException;
/**
* 检查UserBusiness是否存在,页面唯一性效验使用
*
* @param TypeName 类型名称
* @param TypeVale 类型值
* @param KeyIdName 关键id
......@@ -91,10 +101,11 @@ public interface BaseIService<T>
* @return true==存在 false==不存在
* @throws DataAccessException
*/
Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException;
Boolean checkIsUserBusinessExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue, String UBName, String UBValue) throws DataAccessException;
/**
* 检查UserBusiness是否存在,页面唯一性效验使用
*
* @param TypeName 类型名称
* @param TypeVale 类型值
* @param KeyIdName 关键id
......@@ -105,5 +116,4 @@ public interface BaseIService<T>
Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException;
}
package com.jsh.base;
import com.jsh.util.PageUtil;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import com.jsh.util.JshException;
import com.jsh.model.po.Basicuser;
import com.jsh.util.PageUtil;
/**
* 底层服务层
* @author ji-sheng-hua qq752718920
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public abstract class BaseService<T> implements BaseIService<T>
{
public abstract class BaseService<T> implements BaseIService<T> {
protected Class<T> entityClass;
/**
* Dao对象
*/
private BaseIDAO<T> baseDao;
protected Class<T> entityClass;
protected BaseIDAO<T> getBaseDao() {
return this.baseDao;
}
public void setBaseDao(BaseIDAO<T> baseDao)
{
public void setBaseDao(BaseIDAO<T> baseDao) {
this.baseDao = baseDao;
setPoJoClass(getEntityClass());
}
protected BaseIDAO<T> getBaseDao()
{
return this.baseDao;
}
private void setPoJoClass(Class<T> c)
{
private void setPoJoClass(Class<T> c) {
this.baseDao.setPoJoClass(c);
}
protected abstract Class<T> getEntityClass();
@Override
public Serializable create(T t) throws DataAccessException
{
public Serializable create(T t) throws DataAccessException {
return baseDao.create(t);
}
@Override
public void save(T t) throws DataAccessException
{
public void save(T t) throws DataAccessException {
baseDao.save(t);
}
@Override
public void delete(T t) throws DataAccessException
{
public void delete(T t) throws DataAccessException {
baseDao.delete(t);
}
@Override
public void delete(Long id) throws DataAccessException
{
public void delete(Long id) throws DataAccessException {
baseDao.batchDelete(id.toString());
}
@Override
public T get(Long objID) throws DataAccessException
{
public T get(Long objID) throws DataAccessException {
return baseDao.get(objID);
}
@Override
public void update(T t) throws DataAccessException
{
public void update(T t) throws DataAccessException {
baseDao.update(t);
}
@Override
public void batchDelete(String objIDs) throws DataAccessException
{
public void batchDelete(String objIDs) throws DataAccessException {
baseDao.batchDelete(objIDs);
}
@Override
public void find(PageUtil<T> pageUtil) throws DataAccessException
{
public void find(PageUtil<T> pageUtil) throws DataAccessException {
baseDao.find(pageUtil);
}
@Override
public Boolean checkIsNameExist(String filedName, String filedVale,String idFiled,Long objectID) throws DataAccessException
{
public Boolean checkIsNameExist(String filedName, String filedVale, String idFiled, Long objectID) throws DataAccessException {
PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put(filedName + "_s_eq", filedVale);
condition.put(idFiled + "_n_neq", objectID);
pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0)
if (null != dataList && dataList.size() > 0)
return true;
return false;
}
@Override
public Boolean checkIsUserBusinessExist(String TypeName,String TypeVale,String KeyIdName,String KeyIdValue,String UBName,String UBValue) throws DataAccessException
{
public Boolean checkIsUserBusinessExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue, String UBName, String UBValue) throws DataAccessException {
PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put(TypeName + "_s_eq", TypeVale);
condition.put(KeyIdName + "_s_eq", KeyIdValue);
condition.put(UBName + "_s_like", UBValue);
......@@ -118,23 +102,22 @@ public abstract class BaseService<T> implements BaseIService<T>
baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0)
if (null != dataList && dataList.size() > 0)
return true;
return false;
}
@Override
public Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException
{
public Boolean checkIsValueExist(String TypeName, String TypeVale, String KeyIdName, String KeyIdValue) throws DataAccessException {
PageUtil<T> pageUtil = new PageUtil<T>();
Map<String,Object> condition = new HashMap<String,Object>();
Map<String, Object> condition = new HashMap<String, Object>();
condition.put(TypeName + "_s_eq", TypeVale);
condition.put(KeyIdName + "_s_eq", KeyIdValue);
pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList();
if(null != dataList && dataList.size() > 0)
if (null != dataList && dataList.size() > 0)
return true;
return false;
}
......
......@@ -4,159 +4,150 @@ import org.apache.log4j.Logger;
/**
* 封装log4j日志信息,打印日志信息类
*
* @author ji/sheng/hua qq_7527.18920
* @since 2014-01-22
*/
public class Log
{
/**
* 根据异常信息获取调用类的信息
*/
private static final Exception ex = new Exception();
/**
* 获取Log4j实例
*/
private static final Logger log = Logger.getLogger("jsh");
public class Log {
/**
* Info级别日志前缀
*/
public static final String LOG_INFO_PREFIX = "==========";
/**
* error级别日志前缀
*/
public static final String LOG_ERROR_PREFIX = ">>>>>>>>>>";
/**
* debug级别日志前缀
*/
public static final String LOG_DEBUG_PREFIX = "-----------";
/**
* fatal级别日志前缀
*/
public static final String LOG_FATAL_PREFIX = "$$$$$$$$$$";
/**
* warn级别日志前缀
*/
public static final String LOG_WARN_PREFIX = "##########";
/**
* 根据异常信息获取调用类的信息
*/
private static final Exception ex = new Exception();
/**
* 获取Log4j实例
*/
private static final Logger log = Logger.getLogger("jsh");
/**
* 打印deug日期信息
*
* @param msg 日志信息
*/
public static void debugFileSync(Object msg)
{
public static void debugFileSync(Object msg) {
log.debug(getLogDetail(msg));
}
/**
* 打印debug异常信息
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void debugFileSync(Object msg, Throwable e)
{
public static void debugFileSync(Object msg, Throwable e) {
log.debug(getLogDetail(msg), e);
}
/**
* 打印info日志信息
*
* @param msg 日志信息
*/
public static void infoFileSync(Object msg)
{
public static void infoFileSync(Object msg) {
log.info(getLogDetail(msg));
}
/**
* 打印 info日志带异常信息
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void infoFileSync(Object msg, Throwable e)
{
public static void infoFileSync(Object msg, Throwable e) {
log.info(getLogDetail(msg), e);
}
/**
* 打印warn日期信息
*
* @param msg 日志信息
*/
public static void warnFileSync(Object msg)
{
public static void warnFileSync(Object msg) {
log.warn(getLogDetail(msg));
}
/**
* 打印warn日志信息带异常
*
* @param msg日志信息
* @param e 异常堆栈
*/
public static void warnFileSync(Object msg, Throwable e)
{
public static void warnFileSync(Object msg, Throwable e) {
log.warn(getLogDetail(msg), e);
}
/**
* 打印error日志信息
*
* @param msg 日志信息
*/
public static void errorFileSync(Object msg)
{
public static void errorFileSync(Object msg) {
log.error(getLogDetail(msg));
}
/**
* 打印error日志信息带异常
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void errorFileSync(Object msg, Throwable e)
{
public static void errorFileSync(Object msg, Throwable e) {
log.error(getLogDetail(msg), e);
}
/**
* 打印fatal日志信息
*
* @param msg 日志信息
*/
public static void fatalFileSync(Object msg)
{
public static void fatalFileSync(Object msg) {
log.fatal(getLogDetail(msg));
}
/**
* 打印fatal日志信息带异常
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void fatalFileSync(Object msg, Throwable e)
{
public static void fatalFileSync(Object msg, Throwable e) {
log.fatal(getLogDetail(msg), e);
}
/**
* 拼装日志详细信息
*
* @param message 要打印的日志信息
* @return 封装后的日志详细信息
*/
private static synchronized String getLogDetail(Object message)
{
private static synchronized String getLogDetail(Object message) {
String msg = "";
if (null != message)
msg = message.toString();
StringBuffer bf = new StringBuffer();
try
{
try {
ex.fillInStackTrace();
throw ex;
}
catch (Exception ex)
{
} catch (Exception ex) {
StackTraceElement[] trace = ex.getStackTrace();
//获取异常堆栈中的调用类信息
final int pos = 2;
......
......@@ -3,15 +3,14 @@ package com.jsh.dao.asset;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.Asset;
public class AssetDAO extends BaseDAO<Asset> implements AssetIDAO
{
public class AssetDAO extends BaseDAO<Asset> implements AssetIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Asset> getEntityClass()
{
public Class<Asset> getEntityClass() {
return Asset.class;
}
}
......@@ -3,7 +3,6 @@ package com.jsh.dao.asset;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.Asset;
public interface AssetIDAO extends BaseIDAO<Asset>
{
public interface AssetIDAO extends BaseIDAO<Asset> {
}
package com.jsh.dao.asset;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.jsh.util.JshException;
import com.jsh.model.po.Asset;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class ReportDAO extends HibernateDaoSupport implements ReportIDAO
{
public class ReportDAO extends HibernateDaoSupport implements ReportIDAO {
@SuppressWarnings("unchecked")
@Override
public void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws JshException
{
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(" + reportType +") as dataSum, " + reportName + " from Asset asset where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
public void find(PageUtil<Asset> pageUtil, String reportType, String reportName) throws JshException {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select count(" + reportType + ") as dataSum, " + reportName + " from Asset asset where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
......
package com.jsh.dao.asset;
import com.jsh.util.JshException;
import com.jsh.model.po.Asset;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
public interface ReportIDAO
{
public interface ReportIDAO {
/**
* 查找资产列表
*
* @param pageUtil 分页工具类
* @param reportType 报表统计字段
* @throws JshException
*/
void find(PageUtil<Asset> pageUtil,String reportType,String reportName) throws JshException;
void find(PageUtil<Asset> pageUtil, String reportType, String reportName) throws JshException;
}
......@@ -7,15 +7,14 @@ import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
import org.hibernate.Query;
public class AccountDAO extends BaseDAO<Account> implements AccountIDAO
{
public class AccountDAO extends BaseDAO<Account> implements AccountIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Account> getEntityClass()
{
public Class<Account> getEntityClass() {
return Account.class;
}
......@@ -25,15 +24,15 @@ public class AccountDAO extends BaseDAO<Account> implements AccountIDAO
//主表出入库涉及的账户
queryString.append("select dh.Number,concat(dh.SubType,dh.Type) as newType,s.supplier,dh.ChangeAmount,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
" from jsh_depothead dh inner join jsh_supplier s on dh.OrganId = s.id where 1=1 ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and dh.AccountId='"+ accountId +"' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and dh.AccountId='" + accountId + "' ");
}
//主表收入和支出涉及的账户
queryString.append("UNION ALL " +
"select ah.BillNo,ah.Type as newType,s.supplier,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
" from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id where 1=1 ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='"+ accountId +"' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='" + accountId + "' ");
}
//明细中涉及的账户(收款,付款,收预付款)
queryString.append("UNION ALL " +
......@@ -41,31 +40,31 @@ public class AccountDAO extends BaseDAO<Account> implements AccountIDAO
" from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id " +
" inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type in ('收款','付款','收预付款') ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='"+ accountId +"' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='" + accountId + "' ");
}
//主表中转出的账户
queryString.append("UNION ALL " +
"select ah.BillNo,ah.Type as newType, '' as sName,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
" from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type='转账' ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='"+ accountId +"' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='" + accountId + "' ");
}
//明细中被转入的账户
queryString.append("UNION ALL " +
"select ah.BillNo,ah.Type as newType, '' as sName,ai.EachAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
" from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type='转账' ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='"+ accountId +"' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='" + accountId + "' ");
}
//多账户的情况
queryString.append("UNION ALL " +
"select dh.Number,concat(dh.SubType,dh.Type) as newType,s.supplier,dh.ChangeAmount,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime,dh.AccountIdList,dh.AccountMoneyList" +
" from jsh_depothead dh inner join jsh_supplier s on dh.OrganId = s.id where 1=1 ");
if(accountId!=null && !accountId.equals("")) {
queryString.append(" and dh.AccountIdList like '%\""+ accountId +"\"%' ");
if (accountId != null && !accountId.equals("")) {
queryString.append(" and dh.AccountIdList like '%\"" + accountId + "\"%' ");
}
queryString.append(" ORDER BY oTime desc");
Query query;
......
......@@ -3,15 +3,14 @@ package com.jsh.dao.basic;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.App;
public class AppDAO extends BaseDAO<App> implements AppIDAO
{
public class AppDAO extends BaseDAO<App> implements AppIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<App> getEntityClass()
{
public Class<App> getEntityClass() {
return App.class;
}
}
......@@ -3,7 +3,6 @@ package com.jsh.dao.basic;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.App;
public interface AppIDAO extends BaseIDAO<App>
{
public interface AppIDAO extends BaseIDAO<App> {
}
......@@ -3,15 +3,14 @@ package com.jsh.dao.basic;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.Assetname;
public class AssetNameDAO extends BaseDAO<Assetname> implements AssetNameIDAO
{
public class AssetNameDAO extends BaseDAO<Assetname> implements AssetNameIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Assetname> getEntityClass()
{
public Class<Assetname> getEntityClass() {
return Assetname.class;
}
}
......@@ -3,7 +3,6 @@ package com.jsh.dao.basic;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.Assetname;
public interface AssetNameIDAO extends BaseIDAO<Assetname>
{
public interface AssetNameIDAO extends BaseIDAO<Assetname> {
}
Supports Markdown
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