Commit 5cc26a22 authored by 季圣华's avatar 季圣华
Browse files

更新后端,采用Springboot+mybatis

parent bb6f5528
package com.jsh.action.materials;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.*;
import com.jsh.model.vo.materials.DepotItemModel;
import com.jsh.service.materials.DepotItemIService;
import com.jsh.service.materials.MaterialIService;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
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 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();
//转为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++) {
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())) {
depotItem.setOperNumber(tempInsertedJson.getDouble("OperNumber"));
try {
String Unit = tempInsertedJson.get("Unit").toString();
Double oNumber = tempInsertedJson.getDouble("OperNumber");
Long mId = Long.parseLong(tempInsertedJson.get("MaterialId").toString());
//以下进行单位换算
String UnitName = findUnitName(mId); //查询计量单位名称
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)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (Unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber * ratio); //数量乘以比例
}
} else {
depotItem.setBasicNumber(oNumber); //其他情况
}
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
}
if (!StringUtils.isEmpty(tempInsertedJson.get("UnitPrice").toString())) {
depotItem.setUnitPrice(tempInsertedJson.getDouble("UnitPrice"));
}
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxUnitPrice").toString())) {
depotItem.setTaxUnitPrice(tempInsertedJson.getDouble("TaxUnitPrice"));
}
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())) {
depotItem.setDepotId(new Depot(tempInsertedJson.getLong("DepotId")));
}
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())) {
depotItem.setTaxRate(tempInsertedJson.getDouble("TaxRate"));
}
if (!StringUtils.isEmpty(tempInsertedJson.get("TaxMoney").toString())) {
depotItem.setTaxMoney(tempInsertedJson.getDouble("TaxMoney"));
}
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"));
}
depotItemService.create(depotItem);
}
}
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++) {
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())) {
depotItem.setOperNumber(tempUpdatedJson.getDouble("OperNumber"));
try {
String Unit = tempUpdatedJson.get("Unit").toString();
Double oNumber = tempUpdatedJson.getDouble("OperNumber");
Long mId = Long.parseLong(tempUpdatedJson.get("MaterialId").toString());
//以下进行单位换算
String UnitName = findUnitName(mId); //查询计量单位名称
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)) { //如果等于基础单位
depotItem.setBasicNumber(oNumber); //数量一致
} else if (Unit.equals(otherUnit)) { //如果等于副单位
depotItem.setBasicNumber(oNumber * ratio); //数量乘以比例
}
} else {
depotItem.setBasicNumber(oNumber); //其他情况
}
} catch (Exception e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>设置基础数量异常", e);
}
}
if (!StringUtils.isEmpty(tempUpdatedJson.get("UnitPrice").toString())) {
depotItem.setUnitPrice(tempUpdatedJson.getDouble("UnitPrice"));
}
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxUnitPrice").toString())) {
depotItem.setTaxUnitPrice(tempUpdatedJson.getDouble("TaxUnitPrice"));
}
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())) {
depotItem.setDepotId(new Depot(tempUpdatedJson.getLong("DepotId")));
}
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())) {
depotItem.setTaxRate(tempUpdatedJson.getDouble("TaxRate"));
}
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxMoney").toString())) {
depotItem.setTaxMoney(tempUpdatedJson.getDouble("TaxMoney"));
}
if (!StringUtils.isEmpty(tempUpdatedJson.get("TaxLastMoney").toString())) {
depotItem.setTaxLastMoney(tempUpdatedJson.getDouble("TaxLastMoney"));
}
depotItem.setOtherField1(tempUpdatedJson.getString("OtherField1"));
depotItem.setOtherField2(tempUpdatedJson.getString("OtherField2"));
depotItem.setOtherField3(tempUpdatedJson.getString("OtherField3"));
depotItem.setOtherField4(tempUpdatedJson.getString("OtherField4"));
depotItem.setOtherField5(tempUpdatedJson.getString("OtherField5"));
depotItem.setMType(tempUpdatedJson.getString("MType"));
depotItemService.create(depotItem);
}
}
//========标识位===========
flag = true;
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>保存仓管通明细信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>保存仓管通明细信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "保存仓管通明细", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "保存仓管通明细对应主表编号为 " + model.getHeaderId() + " " + tipMsg + "!", "保存仓管通明细" + tipMsg));
Log.infoFileSync("==================结束调用保存仓管通明细方法saveDetials()===================");
}
/**
* 查询计量单位信息
*
* @return
*/
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")) {
unitName = "";
}
}
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return unitName;
}
/**
* 查找明细信息
*
* @return
*/
public void findBy() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getCondition());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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());
String ratio; //比例
if (depotItem.getMaterialId().getUnitId() == null || depotItem.getMaterialId().getUnitId().equals("")) {
ratio = "";
} 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 materialOther = getOtherInfo(mpArr, depotItem);
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());
item.put("BasicNumber", depotItem.getBasicNumber());
item.put("UnitPrice", depotItem.getUnitPrice());
item.put("TaxUnitPrice", depotItem.getTaxUnitPrice());
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("TaxRate", depotItem.getTaxRate());
item.put("TaxMoney", depotItem.getTaxMoney());
item.put("TaxLastMoney", depotItem.getTaxLastMoney());
item.put("OtherField1", depotItem.getOtherField1());
item.put("OtherField2", depotItem.getOtherField2());
item.put("OtherField3", depotItem.getOtherField3());
item.put("OtherField4", depotItem.getOtherField4());
item.put("OtherField5", depotItem.getOtherField5());
item.put("MType", depotItem.getMType());
item.put("op", 1);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找仓管通信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询仓管通信息结果异常", e);
}
}
/**
* 查找所有的明细
*
* @return
*/
public void findByAll() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
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);
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
String materialOther = getOtherInfo(mpArr, depotItem);
item.put("MaterialOther", materialOther);
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);
}
item.put("UnitPrice", unitPrice);
item.put("prevSum", prevSum);
item.put("InSum", InSum);
item.put("OutSum", OutSum);
item.put("thisSum", prevSum + InSum - OutSum);
item.put("thisAllPrice", prevPrice + InPrice - OutPrice);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 根据商品id和仓库id查询库存数量
*
* @return
*/
public void findStockNumById() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionById());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
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());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("thisSum", prevSum + InSum - OutSum);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 只根据商品id查询库存数量
*
* @return
*/
public void findStockNumByMaterialId() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionById());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("thisSum", InSum - OutSum);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 只根据商品id查询单据列表
*
* @return
*/
public void findDetailByTypeAndMaterialId() {
try {
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
Long mId = model.getMaterialId();
depotItemService.findDetailByTypeAndMaterialId(pageUtil, mId);
List dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (dataList != null) {
for (Integer i = 0; i < dataList.size(); i++) {
JSONObject item = new JSONObject();
Object dl = dataList.get(i); //获取对象
Object[] arr = (Object[]) dl; //转为数组
item.put("Number", arr[0]); //商品编号
item.put("Type", arr[1]); //进出类型
item.put("BasicNumber", arr[2]); //数量
item.put("OperTime", arr[3]); //时间
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
} catch (JshException e) {
e.printStackTrace();
}
}
/**
* 查找礼品卡信息
*
* @return
*/
public void findGiftByAll() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
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("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
String materialOther = getOtherInfo(mpArr, depotItem);
item.put("MaterialOther", materialOther);
item.put("MaterialColor", depotItem.getMaterialId().getColor());
item.put("MaterialUnit", depotItem.getMaterialId().getUnit());
item.put("thisSum", InSum - OutSum);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 进货统计
*
* @return
*/
public void buyIn() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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());
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
String materialOther = getOtherInfo(mpArr, depotItem);
item.put("MaterialOther", materialOther);
item.put("MaterialColor", depotItem.getMaterialId().getColor());
item.put("MaterialUnit", depotItem.getMaterialId().getUnit());
item.put("InSum", InSum);
item.put("OutSum", OutSum);
item.put("InSumPrice", InSumPrice);
item.put("OutSumPrice", OutSumPrice);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 销售统计
*
* @return
*/
public void saleOut() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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());
item.put("Id", depotItem.getId());
item.put("MaterialId", depotItem.getMaterialId() == null ? "" : depotItem.getMaterialId().getId());
item.put("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
//扩展信息
String materialOther = getOtherInfo(mpArr, depotItem);
item.put("MaterialOther", materialOther);
item.put("MaterialColor", depotItem.getMaterialId().getColor());
item.put("MaterialUnit", depotItem.getMaterialId().getUnit());
item.put("OutSum", OutSumRetail + OutSum);
item.put("InSum", InSumRetail + InSum);
item.put("OutSumPrice", OutSumRetailPrice + OutSumPrice);
item.put("InSumPrice", InSumRetailPrice + InSumPrice);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 统计总计金额
*
* @return
*/
public void totalCountMoney() {
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
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);
thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice);
}
}
outer.put("totalCount", thisAllPrice);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 导出excel表格
*
* @return
*/
@SuppressWarnings("unchecked")
public String exportExcel() {
Log.infoFileSync("===================调用导出信息action方法exportExcel开始=======================");
try {
PageUtil<DepotItem> pageUtil = new PageUtil<DepotItem>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getConditionALL());
depotItemService.find(pageUtil);
List<DepotItem> dataList = pageUtil.getPageList();
//存放数据json数组
Integer pid = model.getProjectId();
JSONArray dataArray = new JSONArray();
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);
Double unitPrice = 0.0;
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("MaterialName", depotItem.getMaterialId().getName());
item.put("MaterialModel", depotItem.getMaterialId().getModel());
item.put("MaterialStandard", depotItem.getMaterialId().getStandard());
item.put("MaterialColor", depotItem.getMaterialId().getColor());
item.put("MaterialUnit", depotItem.getMaterialId().getUnit());
item.put("UnitPrice", unitPrice);
item.put("prevSum", prevSum);
item.put("InSum", InSum);
item.put("OutSum", OutSum);
item.put("thisSum", prevSum + InSum - OutSum);
item.put("thisAllPrice", prevPrice + InPrice - OutPrice);
dataArray.add(item);
}
}
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.getShowModel().setMsgTip("export excel exception");
}
Log.infoFileSync("===================调用导出信息action方法exportExcel结束==================");
return EXCEL;
}
/**
* 数量合计
*
* @param type
* @param MId
* @param MonthTime
* @param isPrev
* @return
*/
@SuppressWarnings("unchecked")
public Integer sumNumber(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Integer sumNumber = 0;
String allNumber = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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 = "0";
}
allNumber = allNumber.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumNumber = Integer.parseInt(allNumber);
return sumNumber;
}
/**
* 仅根据商品Id进行数量合计
*
* @param type
* @param MId
* @return
*/
@SuppressWarnings("unchecked")
public Integer sumNumberByMaterialId(String type, Long MId) {
Integer sumNumber = 0;
String allNumber = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try {
depotItemService.findByTypeAndMaterialId(pageUtil, type, MId);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumNumber = Integer.parseInt(allNumber);
return sumNumber;
}
/**
* 数量合计-礼品卡
*
* @param type
* @param MId
* @param MonthTime
* @param isPrev
* @return
*/
@SuppressWarnings("unchecked")
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);
allNumber = pageUtil.getPageList().toString();
allNumber = allNumber.substring(1, allNumber.length() - 1);
if (allNumber.equals("null")) {
allNumber = "0";
}
allNumber = allNumber.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumNumber = Integer.parseInt(allNumber);
return sumNumber;
}
/**
* 价格合计
*
* @param type
* @param MId
* @param MonthTime
* @param isPrev
* @return
*/
@SuppressWarnings("unchecked")
public Double sumPrice(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Double sumPrice = 0.0;
String allPrice = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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 = "0";
}
allPrice = allPrice.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumPrice = Double.parseDouble(allPrice);
return sumPrice;
}
@SuppressWarnings("unchecked")
public Integer sumNumberBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Integer sumNumber = 0;
String allNumber = "";
String sumType = "Number";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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 = "0";
}
allNumber = allNumber.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumNumber = Integer.parseInt(allNumber);
return sumNumber;
}
@SuppressWarnings("unchecked")
public Double sumPriceBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Double sumPrice = 0.0;
String allPrice = "";
String sumType = "Price";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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 = "0";
}
allPrice = allPrice.replace(".0", "");
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sumPrice = Double.parseDouble(allPrice);
return sumPrice;
}
/**
* 获取扩展信息
*
* @return
*/
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() + ")");
}
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("自定义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("自定义3")) {
materialOther = materialOther + ((depotItem.getMaterialId().getOtherField3() == null || depotItem.getMaterialId().getOtherField3().equals("")) ? "" : "(" + depotItem.getMaterialId().getOtherField3() + ")");
}
}
return materialOther;
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("HeaderId_n_eq", model.getHeaderId());
condition.put("Id_s_order", "asc");
return condition;
}
private Map<String, Object> getConditionALL() {
/**
* 拼接搜索条件
*/
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");
return condition;
}
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("MaterialId_n_eq", model.getMaterialId());
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public DepotItemModel getModel() {
return model;
}
public void setDepotItemService(DepotItemIService depotItemService) {
this.depotItemService = depotItemService;
}
public void setMaterialService(MaterialIService materialService) {
this.materialService = materialService;
}
}
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;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
* 商品管理
* @author jishenghua qq:752718920
*/
@SuppressWarnings("serial")
public class MaterialAction extends BaseAction<MaterialModel> {
public static final String EXCEL = "excel"; //action返回excel结果
private MaterialIService materialService;
private MaterialModel model = new MaterialModel();
/**
* 增加商品
*
* @return
*/
public void create() {
Log.infoFileSync("==================开始调用增加商品信息方法create()===================");
Boolean flag = false;
try {
Material material = new Material();
material.setMaterialCategory(new MaterialCategory(model.getCategoryId()));
material.setName(model.getName());
material.setMfrs(model.getMfrs());
material.setPacking(model.getPacking());
material.setSafetyStock(model.getSafetyStock());
material.setModel(model.getModel());
material.setStandard(model.getStandard());
material.setColor(model.getColor());
material.setUnit(model.getUnit());
material.setRetailPrice(model.getRetailPrice());
material.setLowPrice(model.getLowPrice());
material.setPresetPriceOne(model.getPresetPriceOne());
material.setPresetPriceTwo(model.getPresetPriceTwo());
if (model.getUnitId() != null) {
material.setUnitId(new Unit(model.getUnitId()));
} else {
material.setUnitId(null);
}
material.setFirstOutUnit(model.getFirstOutUnit());
material.setFirstInUnit(model.getFirstInUnit());
material.setPriceStrategy(model.getPriceStrategy());
material.setRemark(model.getRemark());
material.setEnabled(model.getEnabled());
material.setOtherField1(model.getOtherField1());
material.setOtherField2(model.getOtherField2());
material.setOtherField3(model.getOtherField3());
materialService.create(material);
//========标识位===========
flag = true;
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加商品信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加商品信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加商品名称为 " + model.getName() + " " + tipMsg + "!", "增加商品" + tipMsg));
Log.infoFileSync("==================结束调用增加商品方法create()===================");
}
/**
* 删除商品
*
* @return
*/
public String delete() {
Log.infoFileSync("====================开始调用删除商品信息方法delete()================");
try {
materialService.delete(model.getMaterialID());
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getMaterialID() + " 的商品异常", e);
tipMsg = "失败";
tipType = 1;
}
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除商品ID为 " + model.getMaterialID() + " " + tipMsg + "!", "删除商品" + tipMsg));
Log.infoFileSync("====================结束调用删除商品信息方法delete()================");
return SUCCESS;
}
/**
* 更新商品
*
* @return
*/
public void update() {
Boolean flag = false;
try {
Material material = materialService.get(model.getMaterialID());
material.setMaterialCategory(new MaterialCategory(model.getCategoryId()));
material.setName(model.getName());
material.setMfrs(model.getMfrs());
material.setPacking(model.getPacking());
material.setSafetyStock(model.getSafetyStock());
material.setModel(model.getModel());
material.setStandard(model.getStandard());
material.setColor(model.getColor());
material.setUnit(model.getUnit());
material.setRetailPrice(model.getRetailPrice());
material.setLowPrice(model.getLowPrice());
material.setPresetPriceOne(model.getPresetPriceOne());
material.setPresetPriceTwo(model.getPresetPriceTwo());
if (model.getUnitId() != null) {
material.setUnitId(new Unit(model.getUnitId()));
} else {
material.setUnitId(null);
}
material.setFirstOutUnit(model.getFirstOutUnit());
material.setFirstInUnit(model.getFirstInUnit());
material.setPriceStrategy(model.getPriceStrategy());
material.setRemark(model.getRemark());
material.setOtherField1(model.getOtherField1());
material.setOtherField2(model.getOtherField2());
material.setOtherField3(model.getOtherField3());
materialService.update(material);
flag = true;
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品ID为 : " + model.getMaterialID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品ID为 " + model.getMaterialID() + " " + tipMsg + "!", "更新商品" + tipMsg));
}
/**
* 批量删除指定ID商品
*
* @return
*/
public String batchDelete() {
try {
materialService.batchDelete(model.getMaterialIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除商品ID为:" + model.getMaterialIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
}
logService.create(new Logdetails(getUser(), "批量删除商品", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除商品ID为 " + model.getMaterialIDs() + " " + tipMsg + "!", "批量删除商品" + tipMsg));
return SUCCESS;
}
/**
* 批量设置状态-启用或者禁用
*
* @return
*/
public String batchSetEnable() {
try {
materialService.batchSetEnable(model.getEnabled(), model.getMaterialIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量修改状态,商品ID为:" + model.getMaterialIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
}
logService.create(new Logdetails(getUser(), "批量修改商品状态", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量修改状态,商品ID为 " + model.getMaterialIDs() + " " + tipMsg + "!", "批量修改商品状态" + tipMsg));
return SUCCESS;
}
/**
* 查找该商品是否存在
*
* @return
*/
public void checkIsExist() {
try {
Boolean flag = false;
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
pageUtil.setAdvSearch(getConditionCheckIsExist());
materialService.find(pageUtil);
List<Material> dataList = pageUtil.getPageList();
if (null != dataList && dataList.size() > 0) {
flag = true;
} else {
flag = false;
}
//回写查询结果
toClient(flag.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 查找商品信息
*
* @return
*/
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类型的判断
{
pageUtil.setAdvSearch(getCondition_all());
} else if (1 != lei) {
pageUtil.setAdvSearch(getCondition());
}
materialService.find(pageUtil);
getSession().put("pageUtilMaterial", pageUtil);
List<Material> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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());
//扩展信息
String materialOther = "";
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.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("自定义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() + ")");
}
}
item.put("MaterialOther", materialOther);
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("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("op", 1);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 根据id来查询商品名称
*
* @return
*/
public void findById() {
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setAdvSearch(getConditionById());
materialService.find(pageUtil);
List<Material> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
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("Model", material.getModel());
item.put("Standard", material.getStandard());
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("FirstOutUnit", material.getFirstOutUnit());
item.put("FirstInUnit", material.getFirstInUnit());
item.put("PriceStrategy", material.getPriceStrategy());
item.put("Remark", material.getRemark());
item.put("op", 1);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品信息结果异常", e);
}
}
/**
* 查找商品信息-下拉框
*
* @return
*/
public void findBySelect() {
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
pageUtil.setAdvSearch(getCondition_Select());
materialService.find(pageUtil);
List<Material> dataList = pageUtil.getPageList();
String mpList = model.getMpList(); //商品属性
String[] mpArr = mpList.split(",");
//存放数据json数组
JSONArray dataArray = new JSONArray();
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("")) {
ratio = "";
} 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() + ")");
}
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("自定义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("自定义3")) {
MaterialName = MaterialName + ((material.getOtherField3() == null || material.getOtherField3().equals("")) ? "" : "(" + material.getOtherField3() + ")");
}
}
MaterialName = MaterialName + ((material.getUnit() == null || material.getUnit().equals("")) ? "" : "(" + material.getUnit() + ")") + ratio;
item.put("MaterialName", MaterialName);
dataArray.add(item);
}
}
//回写查询结果
toClient(dataArray.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找供应商信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询供应商信息结果异常", e);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 查找商品信息-统计排序
*
* @return
*/
public void findByOrder() {
try {
PageUtil<Material> pageUtil = new PageUtil<Material>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
pageUtil.setAdvSearch(getCondition_Order());
materialService.find(pageUtil);
List<Material> dataList = pageUtil.getPageList();
//存放数据json数组
JSONObject outer = new JSONObject();
String mId = "";
if (null != dataList) {
for (Material material : dataList) {
mId = mId + material.getId() + ",";
}
}
if (mId != "") {
mId = mId.substring(0, mId.lastIndexOf(","));
}
outer.put("mIds", mId);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找供应商信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询供应商信息结果异常", e);
}
}
/**
* 导入excel表格-供应商
*
* @return
*/
@SuppressWarnings("unchecked")
public String importExcel() {
//excel表格file
Boolean result = false;
String returnStr = "";
try {
InputStream in = materialService.importExcel(model.getMaterialFile());
if (null != in) {
model.setFileName(Tools.getRandomChar() + Tools.getNow2(Calendar.getInstance().getTime()) + "_wrong.xls");
model.setExcelStream(in);
returnStr = MaterialConstants.BusinessForExcel.EXCEL;
} else {
result = true;
try {
toClient(result.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写导入信息结果异常", e);
}
//导入数据成功
returnStr = SUCCESS;
}
} catch (JshException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>导入excel表格信息异常", e);
}
return returnStr;
}
/**
* 导出excel表格
*
* @return
*/
@SuppressWarnings("unchecked")
public String exportExcel() {
Log.infoFileSync("===================调用导出信息action方法exportExcel开始=======================");
try {
String sName = "pageUtilMaterial";
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.getShowModel().setMsgTip("export excel exception");
}
Log.infoFileSync("===================调用导出信息action方法exportExcel结束==================");
return EXCEL;
}
/**
* 拼接搜索条件(查全部)
*
* @return
*/
private Map<String, Object> getCondition_all() {
/**
* 拼接搜索条件
*/
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());
condition.put("Id_s_order", "asc");
return condition;
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
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());
condition.put("CategoryId_s_in", model.getCategoryIds());
condition.put("Id_s_order", "asc");
return condition;
}
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());
condition.put("Model_s_eq", model.getModel());
condition.put("Color_s_eq", model.getColor());
condition.put("Standard_s_eq", model.getStandard());
condition.put("Mfrs_s_eq", model.getMfrs());
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) {
condition.put("Unit_s_eq", model.getUnit());
}
if (model.getUnitId() != null) {
condition.put("UnitId_n_eq", model.getUnitId());
}
return condition;
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Id_n_eq", model.getMaterialID());
return condition;
}
/**
* 拼接搜索条件-下拉框
*
* @return
*/
private Map<String, Object> getCondition_Select() {
/**
* 拼接搜索条件
*/
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() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name,Model_s_order", "asc");
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public MaterialModel getModel() {
return model;
}
public void setMaterialService(MaterialIService materialService) {
this.materialService = materialService;
}
}
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.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> {
private MaterialCategoryIService materialCategoryService;
private MaterialCategoryModel model = new MaterialCategoryModel();
@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();
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) {
Log.errorFileSync(">>>>>>>>>>>>>查找商品类别信息异常", e);
model.getShowModel().setMsgTip("exceptoin");
}
return SUCCESS;
}
/**
* 增加商品类别
*
* @return
*/
public void create() {
Log.infoFileSync("==================开始调用增加商品类别信息方法create()===================");
Boolean flag = false;
try {
MaterialCategory materialCategory = new MaterialCategory();
materialCategory.setMaterialCategory(new MaterialCategory(model.getParentId()));
materialCategory.setCategoryLevel(model.getCategoryLevel());
materialCategory.setName(model.getName());
materialCategoryService.create(materialCategory);
//========标识位===========
flag = true;
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加商品类别信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加商品类别信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加商品类别名称为 " + model.getName() + " " + tipMsg + "!", "增加商品类别" + tipMsg));
Log.infoFileSync("==================结束调用增加商品类别方法create()===================");
}
/**
* 删除商品类别
*
* @return
*/
public String delete() {
Log.infoFileSync("====================开始调用删除商品类别信息方法delete()================");
try {
materialCategoryService.delete(model.getMaterialCategoryID());
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getMaterialCategoryID() + " 的商品类别异常", e);
tipMsg = "失败";
tipType = 1;
}
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除商品类别ID为 " + model.getMaterialCategoryID() + " " + tipMsg + "!", "删除商品类别" + tipMsg));
Log.infoFileSync("====================结束调用删除商品类别信息方法delete()================");
return SUCCESS;
}
/**
* 更新商品类别
*
* @return
*/
public void update() {
Boolean flag = false;
try {
MaterialCategory materialCategory = materialCategoryService.get(model.getMaterialCategoryID());
materialCategory.setMaterialCategory(new MaterialCategory(model.getParentId()));
materialCategory.setCategoryLevel(model.getCategoryLevel());
materialCategory.setName(model.getName());
materialCategoryService.update(materialCategory);
flag = true;
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品类别ID为 : " + model.getMaterialCategoryID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品类别回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品类别ID为 " + model.getMaterialCategoryID() + " " + tipMsg + "!", "更新商品类别" + tipMsg));
}
/**
* 批量删除指定ID商品类别
*
* @return
*/
public String batchDelete() {
try {
materialCategoryService.batchDelete(model.getMaterialCategoryIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除商品类别ID为:" + model.getMaterialCategoryIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
}
logService.create(new Logdetails(getUser(), "批量删除商品类别", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除商品类别ID为 " + model.getMaterialCategoryIDs() + " " + tipMsg + "!", "批量删除商品类别" + tipMsg));
return SUCCESS;
}
/**
* 查找商品类别信息
*
* @return
*/
public void findBy() {
try {
PageUtil<MaterialCategory> pageUtil = new PageUtil<MaterialCategory>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getCondition());
materialCategoryService.find(pageUtil);
List<MaterialCategory> dataList = pageUtil.getPageList();
//开始拼接json数据
// {"total":28,"rows":[
// {"productid":"AV-CB-01","attr1":"Adult Male","itemid":"EST-18"}
// ]}
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (MaterialCategory materialCategory : dataList) {
JSONObject item = new JSONObject();
item.put("Id", materialCategory.getId());
item.put("ParentId", materialCategory.getMaterialCategory().getId());
item.put("ParentName", materialCategory.getMaterialCategory().getName());
item.put("CategoryLevel", materialCategory.getCategoryLevel());
item.put("Name", materialCategory.getName());
item.put("op", 1);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品类别信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品类别信息结果异常", e);
}
}
/**
* 根据id来查询商品名称
*
* @return
*/
public void findById() {
try {
PageUtil<MaterialCategory> pageUtil = new PageUtil<MaterialCategory>();
pageUtil.setAdvSearch(getConditionById());
materialCategoryService.find(pageUtil);
List<MaterialCategory> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
if (null != dataList) {
for (MaterialCategory materialCategory : dataList) {
outer.put("name", materialCategory.getName());
outer.put("parentId", materialCategory.getMaterialCategory().getId());
}
}
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品类别信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品类别信息结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
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);
condition.put("Id_s_order", "asc");
return condition;
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getConditionById() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Id_n_eq", model.getMaterialCategoryID());
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public MaterialCategoryModel getModel() {
return model;
}
public void setMaterialCategoryService(MaterialCategoryIService materialCategoryService) {
this.materialCategoryService = materialCategoryService;
}
}
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.MaterialProperty;
import com.jsh.model.vo.materials.MaterialPropertyModel;
import com.jsh.service.materials.MaterialPropertyIService;
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 ji s h e n g hua qq:75 27 18 920
*/
@SuppressWarnings("serial")
public class MaterialPropertyAction extends BaseAction<MaterialPropertyModel> {
private MaterialPropertyIService materialPropertyService;
private MaterialPropertyModel model = new MaterialPropertyModel();
/**
* 更新商品属性
*
* @return
*/
public void update() {
Boolean flag = false;
try {
MaterialProperty materialProperty = materialPropertyService.get(model.getId());
materialProperty.setNativeName(model.getNativeName());
materialProperty.setEnabled(model.getEnabled());
materialProperty.setSort(model.getSort());
materialProperty.setAnotherName(model.getAnotherName());
materialPropertyService.update(materialProperty);
flag = true;
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改商品属性ID为 : " + model.getId() + "失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改商品属性回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新商品属性", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新商品属性ID为 " + model.getId() + " " + tipMsg + "!", "更新商品属性" + tipMsg));
}
/**
* 查找商品属性
*
* @return
*/
public void findBy() {
try {
PageUtil<MaterialProperty> pageUtil = new PageUtil<MaterialProperty>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
pageUtil.setAdvSearch(getCondition());
materialPropertyService.find(pageUtil);
List<MaterialProperty> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (MaterialProperty materialProperty : dataList) {
JSONObject item = new JSONObject();
item.put("id", materialProperty.getId());
item.put("nativeName", materialProperty.getNativeName());
item.put("enabled", materialProperty.getEnabled());
item.put("sort", materialProperty.getSort());
item.put("anotherName", materialProperty.getAnotherName());
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找商品属性异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询商品属性结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("nativeName_s_like", model.getNativeName());
condition.put("sort_s_order", "asc");
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public MaterialPropertyModel getModel() {
return model;
}
public void setMaterialPropertyService(MaterialPropertyIService materialPropertyService) {
this.materialPropertyService = materialPropertyService;
}
}
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.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> {
private PersonIService personService;
private PersonModel model = new PersonModel();
@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();
condition.put("Id_s_order", "asc");
personService.find(pageUtil);
mapData.put("personList", pageUtil.getPageList());
} 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();
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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) {
Log.errorFileSync(">>>>>>>>>>>>>查找系统基础数据信息异常", e);
model.getShowModel().setMsgTip("exceptoin");
}
return SUCCESS;
}
/**
* 根据类型获取经手人信息 1-业务员,2-仓管员,3-财务员
*
* @return
*/
public void getPersonByNumType() {
try {
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
Map<String, Object> condition = pageUtil.getAdvSearch();
String type = "";
if (model.getType().equals("1")) {
type = "业务员";
} else if (model.getType().equals("2")) {
type = "仓管员";
} else if (model.getType().equals("3")) {
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) {
JSONObject item = new JSONObject();
item.put("id", person.getId());
item.put("name", person.getName());
dataArray.add(item);
}
}
//回写查询结果
toClient(dataArray.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 根据Id获取经手人信息
*
* @return
*/
public void getPersonByIds() {
try {
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
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) {
sb.append(person.getName() + " ");
}
}
//回写查询结果
toClient(sb.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>查找信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>回写查询信息结果异常", e);
}
}
/**
* 增加经手人
*
* @return
*/
public void create() {
Log.infoFileSync("==================开始调用增加经手人信息方法create()===================");
Boolean flag = false;
try {
Person person = new Person();
person.setType(model.getType());
person.setName(model.getName());
personService.create(person);
//========标识位===========
flag = true;
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>增加经手人信息异常", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>增加经手人信息回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "增加经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "增加经手人名称为 " + model.getName() + " " + tipMsg + "!", "增加经手人" + tipMsg));
Log.infoFileSync("==================结束调用增加经手人方法create()===================");
}
/**
* 删除经手人
*
* @return
*/
public String delete() {
Log.infoFileSync("====================开始调用删除经手人信息方法delete()================");
try {
personService.delete(model.getPersonID());
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>删除ID为 " + model.getPersonID() + " 的经手人异常", e);
tipMsg = "失败";
tipType = 1;
}
model.getShowModel().setMsgTip(tipMsg);
logService.create(new Logdetails(getUser(), "删除经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "删除经手人ID为 " + model.getPersonID() + " " + tipMsg + "!", "删除经手人" + tipMsg));
Log.infoFileSync("====================结束调用删除经手人信息方法delete()================");
return SUCCESS;
}
/**
* 更新经手人
*
* @return
*/
public void update() {
Boolean flag = false;
try {
Person person = personService.get(model.getPersonID());
person.setType(model.getType());
person.setName(model.getName());
personService.update(person);
flag = true;
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>修改经手人ID为 : " + model.getPersonID() + "信息失败", e);
flag = false;
tipMsg = "失败";
tipType = 1;
} finally {
try {
toClient(flag.toString());
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>修改经手人回写客户端结果异常", e);
}
}
logService.create(new Logdetails(getUser(), "更新经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "更新经手人ID为 " + model.getPersonID() + " " + tipMsg + "!", "更新经手人" + tipMsg));
}
/**
* 批量删除指定ID经手人
*
* @return
*/
public String batchDelete() {
try {
personService.batchDelete(model.getPersonIDs());
model.getShowModel().setMsgTip("成功");
//记录操作日志使用
tipMsg = "成功";
tipType = 0;
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>批量删除经手人ID为:" + model.getPersonIDs() + "信息异常", e);
tipMsg = "失败";
tipType = 1;
}
logService.create(new Logdetails(getUser(), "批量删除经手人", model.getClientIp(),
new Timestamp(System.currentTimeMillis())
, tipType, "批量删除经手人ID为 " + model.getPersonIDs() + " " + tipMsg + "!", "批量删除经手人" + tipMsg));
return SUCCESS;
}
/**
* 查找经手人信息
*
* @return
*/
public void findBy() {
try {
PageUtil<Person> pageUtil = new PageUtil<Person>();
pageUtil.setPageSize(model.getPageSize());
pageUtil.setCurPage(model.getPageNo());
pageUtil.setAdvSearch(getCondition());
personService.find(pageUtil);
List<Person> dataList = pageUtil.getPageList();
JSONObject outer = new JSONObject();
outer.put("total", pageUtil.getTotalCount());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (Person person : dataList) {
JSONObject item = new JSONObject();
item.put("Id", person.getId());
item.put("Type", person.getType());
item.put("Name", person.getName());
item.put("op", 1);
dataArray.add(item);
}
}
outer.put("rows", dataArray);
//回写查询结果
toClient(outer.toString());
} catch (DataAccessException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找经手人信息异常", e);
} catch (IOException e) {
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询经手人信息结果异常", e);
}
}
/**
* 拼接搜索条件
*
* @return
*/
private Map<String, Object> getCondition() {
/**
* 拼接搜索条件
*/
Map<String, Object> condition = new HashMap<String, Object>();
condition.put("Name_s_like", model.getName());
condition.put("Type_s_eq", model.getType());
return condition;
}
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
@Override
public PersonModel getModel() {
return model;
}
public void setPersonService(PersonIService personService) {
this.personService = personService;
}
}
package com.jsh.base;
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;
/**
* struts2工具类
*
* @author jishenghua qq752718920
* struts2 base action 一些常用方法获取
*/
@SuppressWarnings("serial")
public abstract class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
public LogIService logService;
/**
* 操作日志使用 是否成功表示
*/
public String tipMsg = "成功";
/**
* 操作日志使用 是否成功表示 0 ==成功 1==失败
*/
public short tipType = 0;
/**
* 获取session
*
* @return
*/
public static Map<String, Object> getSession() {
return ActionContext.getContext().getSession();
}
/**
* 获取request
*
* @return
*/
public static HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* 获取response
*
* @return response
*/
public static HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
public void setLogService(LogIService logService) {
this.logService = logService;
}
/**
* 添加错误信息
*
* @param anErrorMessage
*/
public void addActionError(String anErrorMessage) {
super.addActionError(anErrorMessage);
}
/**
* 添加消息
*
* @param aMessage
*/
public void addActionMessage(String aMessage) {
clearErrorsAndMessages();
super.addActionMessage(aMessage);
}
/**
* 添加字段错误
*
* @param fieldName
* @param errorMessage
*/
public void addFieldError(String fieldName, String errorMessage) {
clearErrorsAndMessages();
super.addFieldError(fieldName, errorMessage);
}
/**
* 登录用户信息
*
* @return 登录用户对象
*/
public Basicuser getUser() {
return (Basicuser) getSession().get("user");
}
/**
* 回写客户端数据
*
* @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 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 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> {
protected Class<T> entityClass;
public void setPoJoClass(Class<T> c) {
this.entityClass = c;
}
protected Class<T> getEntityClass() {
return this.entityClass;
}
@Override
public Serializable create(T t) throws DataAccessException {
return this.getHibernateTemplate().save(t);
}
@Override
public void delete(T t) throws DataAccessException {
this.getHibernateTemplate().delete(t);
}
@Override
public T get(Long objID) throws DataAccessException {
return (T) this.getHibernateTemplate().get(getEntityClass(), objID);
}
@Override
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 + ")");
}
@SuppressWarnings("unchecked")
@Override
public void find(PageUtil<T> pageUtil) throws DataAccessException {
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession()
.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) {
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
}
pageUtil.setPageList(query.list());
}
// @SuppressWarnings("unchecked")
// @Override
// public List<T> find(Map<String, Object> conditon)throws DataAccessException
// {
// return this.getHibernateTemplate().find(" from " + getEntityClass().getName() + " where 1=1 "+ SearchConditionUtil.getCondition(conditon));
// }
// @SuppressWarnings("unchecked")
// @Override
// public List<T> find(String hql) throws DataAccessException
// {
// return this.getHibernateTemplate().find(" from " + getEntityClass().getName() + " where 1=1 "+ hql);
// }
@SuppressWarnings("unchecked")
@Override
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));
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
return query.list();
}
@SuppressWarnings("unchecked")
@Override
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);
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
return query.list();
}
@SuppressWarnings("unchecked")
@Override
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();
}
@SuppressWarnings("unchecked")
@Override
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();
}
@Override
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;
/**
* 常用增删改查操作
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public interface BaseIDAO<T> {
/**
* 设置操作类对象
*
* @param paramClass
*/
void setPoJoClass(Class<T> paramClass);
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
Serializable create(T t) throws DataAccessException;
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
void save(T t) throws DataAccessException;
/**
* 删除
*
* @param t 对象
* @throws DataAccessException
*/
void delete(T t) throws DataAccessException;
/**
* 获取
*
* @param objID ID
* @return 对象
* @throws DataAccessException
*/
T get(Long objID) throws DataAccessException;
/**
* 修改信息
*
* @param t 要修改的对象
* @throws DataAccessException
*/
void update(T t) throws DataAccessException;
/**
* 批量删除信息
*
* @param 以逗号分割的ID
* @throws DataAccessException
*/
void batchDelete(String objIDs) throws DataAccessException;
/**
* 查找列表
*
* @param pageUtil 分页工具类
* @throws DataAccessException
*/
void find(PageUtil<T> pageUtil) throws DataAccessException;
/**
* 根据条件查询列表--没有分页信息
* @param conditon 查询条件
* @return 查询列表数据
*/
// List<T> find(Map<String,Object> conditon)throws DataAccessException;
/**
* 根据hql查询 --没有分页信息
* @param hql hibernate查询
* @return 查询列表数据
*/
// List<T> find(String hql)throws DataAccessException;
/**
* 根据搜索条件查询--分页
*
* @param conditon 查询条件
* @param pageSize 每页个数
* @param pageNo 页码
* @return 查询列表数据
* @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;
/**
* 查找符合条件的总数
*
* @param conditon
* @return
* @throws DataAccessException
*/
Integer countSum(Map<String, Object> conditon) throws DataAccessException;
/**
* 查找符合条件的总数
*
* @param hql
* @return
* @throws DataAccessException
*/
Integer countSum(String hql) throws DataAccessException;
}
package com.jsh.base;
import com.jsh.util.PageUtil;
import org.springframework.dao.DataAccessException;
import java.io.Serializable;
/**
* 服务层底层接口
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public interface BaseIService<T> {
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
Serializable create(T t) throws DataAccessException;
/**
* 增加
*
* @param t 对象
* @throws DataAccessException
*/
void save(T t) throws DataAccessException;
/**
* 删除
*
* @param t 对象
* @throws DataAccessException
*/
void delete(T t) throws DataAccessException;
/**
* 删除
*
* @param id 对象ID
* @throws DataAccessException
*/
void delete(Long id) throws DataAccessException;
/**
* 获取
*
* @param objID ID
* @return 对象
* @throws DataAccessException
*/
T get(Long objID) throws DataAccessException;
/**
* 修改信息
*
* @param t 要修改的对象
* @throws DataAccessException
*/
void update(T t) throws DataAccessException;
/**
* 批量删除信息
*
* @param 以逗号分割的ID
* @throws DataAccessException
*/
void batchDelete(String objIDs) throws DataAccessException;
/**
* 查找列表
*
* @param pageUtil 分页工具类
* @throws DataAccessException
*/
void find(PageUtil<T> pageUtil) throws DataAccessException;
/**
* 检查名称是否存在,页面唯一性效验使用
*
* @param filedName 效验的字段名称
* @param filedVale 校验值
* @param idFiled ID字段名称
* @param objectID 修改时对象ID
* @return true==存在 false==不存在
* @throws DataAccessException
*/
Boolean checkIsNameExist(String filedName, String filedVale, String idFiled, Long objectID) throws DataAccessException;
/**
* 检查UserBusiness是否存在,页面唯一性效验使用
*
* @param TypeName 类型名称
* @param TypeVale 类型值
* @param KeyIdName 关键id
* @param KeyIdValue 关键值
* @param UBName 关系名称
* @param UBValue 关系值
* @return true==存在 false==不存在
* @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
* @param KeyIdValue 关键值
* @return true==存在 false==不存在
* @throws DataAccessException
*/
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;
/**
* 底层服务层
*
* @param <T>
* @author ji-sheng-hua qq752718920
*/
public abstract class BaseService<T> implements BaseIService<T> {
protected Class<T> entityClass;
/**
* Dao对象
*/
private BaseIDAO<T> baseDao;
protected BaseIDAO<T> getBaseDao() {
return this.baseDao;
}
public void setBaseDao(BaseIDAO<T> baseDao) {
this.baseDao = baseDao;
setPoJoClass(getEntityClass());
}
private void setPoJoClass(Class<T> c) {
this.baseDao.setPoJoClass(c);
}
protected abstract Class<T> getEntityClass();
@Override
public Serializable create(T t) throws DataAccessException {
return baseDao.create(t);
}
@Override
public void save(T t) throws DataAccessException {
baseDao.save(t);
}
@Override
public void delete(T t) throws DataAccessException {
baseDao.delete(t);
}
@Override
public void delete(Long id) throws DataAccessException {
baseDao.batchDelete(id.toString());
}
@Override
public T get(Long objID) throws DataAccessException {
return baseDao.get(objID);
}
@Override
public void update(T t) throws DataAccessException {
baseDao.update(t);
}
@Override
public void batchDelete(String objIDs) throws DataAccessException {
baseDao.batchDelete(objIDs);
}
@Override
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 {
PageUtil<T> pageUtil = new PageUtil<T>();
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)
return true;
return false;
}
@Override
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>();
condition.put(TypeName + "_s_eq", TypeVale);
condition.put(KeyIdName + "_s_eq", KeyIdValue);
condition.put(UBName + "_s_like", UBValue);
pageUtil.setAdvSearch(condition);
baseDao.find(pageUtil);
List<T> dataList = pageUtil.getPageList();
if (null != dataList && dataList.size() > 0)
return true;
return false;
}
@Override
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>();
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)
return true;
return false;
}
}
package com.jsh.base;
import org.apache.log4j.Logger;
/**
* 封装log4j日志信息,打印日志信息类
*
* @author ji/sheng/hua qq_7527.18920
* @since 2014-01-22
*/
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) {
log.debug(getLogDetail(msg));
}
/**
* 打印debug异常信息
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void debugFileSync(Object msg, Throwable e) {
log.debug(getLogDetail(msg), e);
}
/**
* 打印info日志信息
*
* @param msg 日志信息
*/
public static void infoFileSync(Object msg) {
log.info(getLogDetail(msg));
}
/**
* 打印 info日志带异常信息
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void infoFileSync(Object msg, Throwable e) {
log.info(getLogDetail(msg), e);
}
/**
* 打印warn日期信息
*
* @param msg 日志信息
*/
public static void warnFileSync(Object msg) {
log.warn(getLogDetail(msg));
}
/**
* 打印warn日志信息带异常
*
* @param msg日志信息
* @param e 异常堆栈
*/
public static void warnFileSync(Object msg, Throwable e) {
log.warn(getLogDetail(msg), e);
}
/**
* 打印error日志信息
*
* @param msg 日志信息
*/
public static void errorFileSync(Object msg) {
log.error(getLogDetail(msg));
}
/**
* 打印error日志信息带异常
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void errorFileSync(Object msg, Throwable e) {
log.error(getLogDetail(msg), e);
}
/**
* 打印fatal日志信息
*
* @param msg 日志信息
*/
public static void fatalFileSync(Object msg) {
log.fatal(getLogDetail(msg));
}
/**
* 打印fatal日志信息带异常
*
* @param msg 日志信息
* @param e 异常堆栈
*/
public static void fatalFileSync(Object msg, Throwable e) {
log.fatal(getLogDetail(msg), e);
}
/**
* 拼装日志详细信息
*
* @param message 要打印的日志信息
* @return 封装后的日志详细信息
*/
private static synchronized String getLogDetail(Object message) {
String msg = "";
if (null != message)
msg = message.toString();
StringBuffer bf = new StringBuffer();
try {
ex.fillInStackTrace();
throw ex;
} catch (Exception ex) {
StackTraceElement[] trace = ex.getStackTrace();
//获取异常堆栈中的调用类信息
final int pos = 2;
bf.append(msg);
bf.append(" [class:");
bf.append(trace[pos].getClassName());
bf.append(" method:");
bf.append(trace[pos].getMethodName());
bf.append(" line:");
bf.append(trace[pos].getLineNumber());
bf.append("]");
}
return bf.toString();
}
}
package com.jsh.dao.asset;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.Asset;
public class AssetDAO extends BaseDAO<Asset> implements AssetIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Asset> getEntityClass() {
return Asset.class;
}
}
package com.jsh.dao.asset;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.Asset;
public interface AssetIDAO extends BaseIDAO<Asset> {
}
package com.jsh.dao.asset;
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 {
@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()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
}
package com.jsh.dao.asset;
import com.jsh.model.po.Asset;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
public interface ReportIDAO {
/**
* 查找资产列表
*
* @param pageUtil 分页工具类
* @param reportType 报表统计字段
* @throws JshException
*/
void find(PageUtil<Asset> pageUtil, String reportType, String reportName) throws JshException;
}
package com.jsh.dao.basic;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.Account;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
import org.hibernate.Query;
public class AccountDAO extends BaseDAO<Account> implements AccountIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Account> getEntityClass() {
return Account.class;
}
@SuppressWarnings("unchecked")
public void findAccountInOutList(PageUtil<Account> pageUtil, Long accountId) throws JshException {
StringBuffer queryString = new StringBuffer();
//主表出入库涉及的账户
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 + "' ");
}
//主表收入和支出涉及的账户
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 + "' ");
}
//明细中涉及的账户(收款,付款,收预付款)
queryString.append("UNION ALL " +
"select ah.BillNo,ah.Type as newType,s.supplier,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_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 + "' ");
}
//主表中转出的账户
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 + "' ");
}
//明细中被转入的账户
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 + "' ");
}
//多账户的情况
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 + "\"%' ");
}
queryString.append(" ORDER BY oTime desc");
Query query;
query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
// 分页查询
int pageNo = pageUtil.getCurPage();
int pageSize = pageUtil.getPageSize();
if (0 != pageNo && 0 != pageSize) {
query.setFirstResult((pageNo - 1) * pageSize);
query.setMaxResults(pageSize);
}
pageUtil.setPageList(query.list());
}
}
package com.jsh.dao.basic;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.Account;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
public interface AccountIDAO extends BaseIDAO<Account> {
public void findAccountInOutList(PageUtil<Account> pageUtil, Long accountId) throws JshException;
}
package com.jsh.dao.basic;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.App;
public class AppDAO extends BaseDAO<App> implements AppIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<App> getEntityClass() {
return App.class;
}
}
package com.jsh.dao.basic;
import com.jsh.base.BaseIDAO;
import com.jsh.model.po.App;
public interface AppIDAO extends BaseIDAO<App> {
}
package com.jsh.dao.basic;
import com.jsh.base.BaseDAO;
import com.jsh.model.po.Assetname;
public class AssetNameDAO extends BaseDAO<Assetname> implements AssetNameIDAO {
/**
* 设置dao映射基类
*
* @return
*/
@Override
public Class<Assetname> getEntityClass() {
return Assetname.class;
}
}
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