添加事务控制

This commit is contained in:
cjl
2019-01-11 16:07:43 +08:00
parent 5df1748c79
commit 85d96bb226
25 changed files with 3856 additions and 3671 deletions

View File

@@ -1,149 +1,149 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.AccountHeadVo4ListEx;
import com.jsh.erp.service.accountHead.AccountHeadService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author jishenghua 752*718*920
*/
@RestController
@RequestMapping(value = "/accountHead")
public class AccountHeadController {
private Logger logger = LoggerFactory.getLogger(AccountHeadController.class);
@Resource
private AccountHeadService accountHeadService;
/**
* 获取最大的id
* @param request
* @return
*/
@GetMapping(value = "/getMaxId")
public BaseResponseInfo getMaxId(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
Long maxId = accountHeadService.getMaxId();
map.put("maxId", maxId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查询单位的累计应收和累计应付,收预付款不计入此处
* @param supplierId
* @param endTime
* @param supType
* @param request
* @return
*/
@GetMapping(value = "/findTotalPay")
public BaseResponseInfo findTotalPay(@RequestParam("supplierId") Integer supplierId,
@RequestParam("endTime") String endTime,
@RequestParam("supType") String supType,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
Double sum = 0.0;
String getS = supplierId.toString();
int i = 1;
if (supType.equals("customer")) { //客户
i = 1;
} else if (supType.equals("vendor")) { //供应商
i = -1;
}
//收付款部分
sum = sum + (allMoney(getS, "付款", "合计",endTime) + allMoney(getS, "付款", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "收款", "合计",endTime) + allMoney(getS, "收款", "实际",endTime)) * i;
sum = sum + (allMoney(getS, "收入", "合计",endTime) - allMoney(getS, "收入", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "支出", "合计",endTime) - allMoney(getS, "支出", "实际",endTime)) * i;
outer.put("getAllMoney", sum);
map.put("rows", outer);
res.code = 200;
res.data = map;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 根据编号查询单据信息
* @param number
* @param request
* @return
*/
@GetMapping(value = "/getDetailByNumber")
public BaseResponseInfo getDetailByNumber(@RequestParam("billNo") String billNo,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
AccountHeadVo4ListEx ahl = new AccountHeadVo4ListEx();
try {
List<AccountHeadVo4ListEx> list = accountHeadService.getDetailByNumber(billNo);
if(list.size() == 1) {
ahl = list.get(0);
}
res.code = 200;
res.data = ahl;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 统计总金额
* @param getS
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
public Double allMoney(String getS, String type, String mode, String endTime) {
Double allMoney = 0.0;
try {
Integer supplierId = Integer.valueOf(getS);
Double sum = accountHeadService.findAllMoney(supplierId, type, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if (allMoney < 0) {
allMoney = -allMoney;
}
return allMoney;
}
}
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.AccountHeadVo4ListEx;
import com.jsh.erp.service.accountHead.AccountHeadService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author jishenghua 752*718*920
*/
@RestController
@RequestMapping(value = "/accountHead")
public class AccountHeadController {
private Logger logger = LoggerFactory.getLogger(AccountHeadController.class);
@Resource
private AccountHeadService accountHeadService;
/**
* 获取最大的id
* @param request
* @return
*/
@GetMapping(value = "/getMaxId")
public BaseResponseInfo getMaxId(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
Long maxId = accountHeadService.getMaxId();
map.put("maxId", maxId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查询单位的累计应收和累计应付,收预付款不计入此处
* @param supplierId
* @param endTime
* @param supType
* @param request
* @return
*/
@GetMapping(value = "/findTotalPay")
public BaseResponseInfo findTotalPay(@RequestParam("supplierId") Integer supplierId,
@RequestParam("endTime") String endTime,
@RequestParam("supType") String supType,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
Double sum = 0.0;
String getS = supplierId.toString();
int i = 1;
if (supType.equals("customer")) { //客户
i = 1;
} else if (supType.equals("vendor")) { //供应商
i = -1;
}
//收付款部分
sum = sum + (allMoney(getS, "付款", "合计",endTime) + allMoney(getS, "付款", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "收款", "合计",endTime) + allMoney(getS, "收款", "实际",endTime)) * i;
sum = sum + (allMoney(getS, "收入", "合计",endTime) - allMoney(getS, "收入", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "支出", "合计",endTime) - allMoney(getS, "支出", "实际",endTime)) * i;
outer.put("getAllMoney", sum);
map.put("rows", outer);
res.code = 200;
res.data = map;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 根据编号查询单据信息
* @param billNo
* @param request
* @return
*/
@GetMapping(value = "/getDetailByNumber")
public BaseResponseInfo getDetailByNumber(@RequestParam("billNo") String billNo,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
AccountHeadVo4ListEx ahl = new AccountHeadVo4ListEx();
try {
List<AccountHeadVo4ListEx> list = accountHeadService.getDetailByNumber(billNo);
if(list.size() == 1) {
ahl = list.get(0);
}
res.code = 200;
res.data = ahl;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 统计总金额
* @param getS
* @param type
* @param mode 合计或者金额
* @param endTime
* @return
*/
public Double allMoney(String getS, String type, String mode, String endTime) {
Double allMoney = 0.0;
try {
Integer supplierId = Integer.valueOf(getS);
Double sum = accountHeadService.findAllMoney(supplierId, type, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if (allMoney < 0) {
allMoney = -allMoney;
}
return allMoney;
}
}

View File

@@ -1,150 +1,106 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.AccountItem;
import com.jsh.erp.datasource.vo.AccountItemVo4List;
import com.jsh.erp.service.accountItem.AccountItemService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji sheng hua 752*718*920
*/
@RestController
@RequestMapping(value = "/accountItem")
public class AccountItemController {
private Logger logger = LoggerFactory.getLogger(AccountItemController.class);
@Resource
private AccountItemService accountItemService;
@PostMapping(value = "/saveDetials")
public String saveDetials(@RequestParam("inserted") String inserted,
@RequestParam("deleted") String deleted,
@RequestParam("updated") String updated,
@RequestParam("headerId") Long headerId,
@RequestParam("listType") String listType,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
try {
//转为json
JSONArray insertedJson = JSONArray.parseArray(inserted);
JSONArray deletedJson = JSONArray.parseArray(deleted);
JSONArray updatedJson = JSONArray.parseArray(updated);
if (null != insertedJson) {
for (int i = 0; i < insertedJson.size(); i++) {
AccountItem accountItem = new AccountItem();
JSONObject tempInsertedJson = JSONObject.parseObject(insertedJson.getString(i));
accountItem.setHeaderid(headerId);
if (tempInsertedJson.get("AccountId") != null && !tempInsertedJson.get("AccountId").equals("")) {
accountItem.setAccountid(tempInsertedJson.getLong("AccountId"));
}
if (tempInsertedJson.get("InOutItemId") != null && !tempInsertedJson.get("InOutItemId").equals("")) {
accountItem.setInoutitemid(tempInsertedJson.getLong("InOutItemId"));
}
if (tempInsertedJson.get("EachAmount") != null && !tempInsertedJson.get("EachAmount").equals("")) {
Double eachAmount = tempInsertedJson.getDouble("EachAmount");
if (listType.equals("付款")) {
eachAmount = 0 - eachAmount;
}
accountItem.setEachamount(eachAmount);
} else {
accountItem.setEachamount(0.0);
}
accountItem.setRemark(tempInsertedJson.getString("Remark"));
accountItemService.insertAccountItemWithObj(accountItem);
}
}
if (null != deletedJson) {
for (int i = 0; i < deletedJson.size(); i++) {
JSONObject tempDeletedJson = JSONObject.parseObject(deletedJson.getString(i));
accountItemService.deleteAccountItem(tempDeletedJson.getLong("Id"));
}
}
if (null != updatedJson) {
for (int i = 0; i < updatedJson.size(); i++) {
JSONObject tempUpdatedJson = JSONObject.parseObject(updatedJson.getString(i));
AccountItem accountItem = accountItemService.getAccountItem(tempUpdatedJson.getLong("Id"));
accountItem.setId(tempUpdatedJson.getLong("Id"));
accountItem.setHeaderid(headerId);
if (tempUpdatedJson.get("AccountId") != null && !tempUpdatedJson.get("AccountId").equals("")) {
accountItem.setAccountid(tempUpdatedJson.getLong("AccountId"));
}
if (tempUpdatedJson.get("InOutItemId") != null && !tempUpdatedJson.get("InOutItemId").equals("")) {
accountItem.setInoutitemid(tempUpdatedJson.getLong("InOutItemId"));
}
if (tempUpdatedJson.get("EachAmount") != null && !tempUpdatedJson.get("EachAmount").equals("")) {
Double eachAmount = tempUpdatedJson.getDouble("EachAmount");
if (listType.equals("付款")) {
eachAmount = 0 - eachAmount;
}
accountItem.setEachamount(eachAmount);
} else {
accountItem.setEachamount(0.0);
}
accountItem.setRemark(tempUpdatedJson.getString("Remark"));
accountItemService.updateAccountItemWithObj(accountItem);
}
}
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} catch (DataAccessException e) {
e.printStackTrace();
logger.error(">>>>>>>>>>>>>>>>>>>保存明细信息异常", e);
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
@GetMapping(value = "/getDetailList")
public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<AccountItemVo4List> dataList = new ArrayList<AccountItemVo4List>();
if(headerId != 0) {
dataList = accountItemService.getDetailList(headerId);
}
JSONObject outer = new JSONObject();
outer.put("total", dataList.size());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (AccountItemVo4List ai : dataList) {
JSONObject item = new JSONObject();
item.put("Id", ai.getId());
item.put("AccountId", ai.getAccountid());
item.put("AccountName", ai.getAccountName());
item.put("InOutItemId", ai.getInoutitemid());
item.put("InOutItemName", ai.getInOutItemName());
Double eachAmount = ai.getEachamount();
item.put("EachAmount", eachAmount < 0 ? 0 - eachAmount : eachAmount);
item.put("Remark", ai.getRemark());
dataArray.add(item);
}
}
outer.put("rows", dataArray);
res.code = 200;
res.data = outer;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
}
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.AccountItem;
import com.jsh.erp.datasource.vo.AccountItemVo4List;
import com.jsh.erp.service.accountItem.AccountItemService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji sheng hua 752*718*920
*/
@RestController
@RequestMapping(value = "/accountItem")
public class AccountItemController {
private Logger logger = LoggerFactory.getLogger(AccountItemController.class);
@Resource
private AccountItemService accountItemService;
/**
* create by: cjl
* description:
* 业务逻辑操作放在service层controller只做参数解析和视图封装
* create time: 2019/1/11 15:08
* @Param: inserted
 * @Param: deleted
 * @Param: updated
 * @Param: headerId
 * @Param: listType
 * @Param: request
* @return java.lang.String
*/
@PostMapping(value = "/saveDetials")
public String saveDetials(@RequestParam("inserted") String inserted,
@RequestParam("deleted") String deleted,
@RequestParam("updated") String updated,
@RequestParam("headerId") Long headerId,
@RequestParam("listType") String listType,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
try {
accountItemService.saveDetials(inserted,deleted,updated,headerId,listType);
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} catch (DataAccessException e) {
e.printStackTrace();
logger.error(">>>>>>>>>>>>>>>>>>>保存明细信息异常", e);
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
@GetMapping(value = "/getDetailList")
public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<AccountItemVo4List> dataList = new ArrayList<AccountItemVo4List>();
if(headerId != 0) {
dataList = accountItemService.getDetailList(headerId);
}
JSONObject outer = new JSONObject();
outer.put("total", dataList.size());
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (AccountItemVo4List ai : dataList) {
JSONObject item = new JSONObject();
item.put("Id", ai.getId());
item.put("AccountId", ai.getAccountid());
item.put("AccountName", ai.getAccountName());
item.put("InOutItemId", ai.getInoutitemid());
item.put("InOutItemName", ai.getInOutItemName());
Double eachAmount = ai.getEachamount();
item.put("EachAmount", eachAmount < 0 ? 0 - eachAmount : eachAmount);
item.put("Remark", ai.getRemark());
dataArray.add(item);
}
}
outer.put("rows", dataArray);
res.code = 200;
res.data = outer;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
}

File diff suppressed because it is too large Load Diff