"jetbrains:/idea/checkout/git" did not exist on "445b55449c73a292ba6abe7a22f82811e0d121c2"
Commit 5cc26a22 authored by 季圣华's avatar 季圣华
Browse files

更新后端,采用Springboot+mybatis

parent bb6f5528
package com.jsh.erp.datasource.vo;
public class DepotHeadVo4StatementAccount {
private String number;
private String type;
private Double discountLastMoney;
private Double changeAmount;
private Double allPrice;
private String supplierName;
private String oTime;
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Double getDiscountLastMoney() {
return discountLastMoney;
}
public void setDiscountLastMoney(Double discountLastMoney) {
this.discountLastMoney = discountLastMoney;
}
public Double getChangeAmount() {
return changeAmount;
}
public void setChangeAmount(Double changeAmount) {
this.changeAmount = changeAmount;
}
public Double getAllPrice() {
return allPrice;
}
public void setAllPrice(Double allPrice) {
this.allPrice = allPrice;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public String getoTime() {
return oTime;
}
public void setoTime(String oTime) {
this.oTime = oTime;
}
}
\ No newline at end of file
package com.jsh.erp.service;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author jishenghua 752718920 2018-10-7 15:25:58
*/
@Service
public class CommonQueryManager {
@Resource
private InterfaceContainer container;
/**
* 查询单条
*
* @param apiName 接口名称
* @param id ID
*/
public Object selectOne(String apiName, String id) {
if (StringUtil.isNotEmpty(apiName) && StringUtil.isNotEmpty(id)) {
return container.getCommonQuery(apiName).selectOne(id);
}
return null;
}
/**
* 查询
* @param apiName
* @param parameterMap
* @return
*/
public List<?> select(String apiName, Map<String, String> parameterMap) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).select(parameterMap);
}
return new ArrayList<Object>();
}
/**
* 计数
* @param apiName
* @param parameterMap
* @return
*/
public int counts(String apiName, Map<String, String> parameterMap) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).counts(parameterMap);
}
return 0;
}
/**
* 插入
* @param apiName
* @param beanJson
* @return
*/
public int insert(String apiName, String beanJson, HttpServletRequest request) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).insert(beanJson, request);
}
return 0;
}
/**
* 更新
* @param apiName
* @param beanJson
* @param id
* @return
*/
public int update(String apiName, String beanJson, Long id) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).update(beanJson, id);
}
return 0;
}
/**
* 删除
* @param apiName
* @param id
* @return
*/
public int delete(String apiName, Long id) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).delete(id);
}
return 0;
}
/**
* 批量删除
* @param apiName
* @param ids
* @return
*/
public int batchDelete(String apiName, String ids) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).batchDelete(ids);
}
return 0;
}
/**
* 判断是否存在
* @param apiName
* @param id
* @param name
* @return
*/
public int checkIsNameExist(String apiName, Long id, String name) {
if (StringUtil.isNotEmpty(apiName)) {
return container.getCommonQuery(apiName).checkIsNameExist(id, name);
}
return 0;
}
}
\ No newline at end of file
package com.jsh.erp.service;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* 通用查询接口
* 功能:1、单条查询 2、分页+搜索 3、查询数量
*
* @author jishenghua
* @version 1.0
*/
public interface ICommonQuery {
/**
* 查询:解析JSON,查询资源。
*
* @param condition 资源id
* @return 资源
*/
Object selectOne(String condition);
/**
* 自定义查询
*
* @param parameterMap 查询参数
* @return 查询结果
*/
List<?> select(Map<String, String> parameterMap);
/**
* 查询数量
*
* @param parameterMap 查询参数
* @return 查询结果
*/
int counts(Map<String, String> parameterMap);
/**
* 新增数据
*
* @param beanJson
* @return
*/
int insert(String beanJson, HttpServletRequest request);
/**
* 更新数据
*
* @param beanJson
* @return
*/
int update(String beanJson, Long id);
/**
* 删除数据
*
* @param id
* @return
*/
int delete(Long id);
/**
* 批量删除数据
*
* @param ids
* @return
*/
int batchDelete(String ids);
/**
* 查询名称是否存在
*
* @param id
* @return
*/
int checkIsNameExist(Long id, String name);
}
\ No newline at end of file
package com.jsh.erp.service;
import com.jsh.erp.utils.AnnotationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.Map;
/**
* @author jishenghua 2018-10-7 15:25:09
*/
@Service
public class InterfaceContainer {
private final Map<String, Integer> nameTypeMap;
private final Map<Integer, ICommonQuery> configComponentMap;
public InterfaceContainer() {
nameTypeMap = new HashMap<>();
configComponentMap = new HashMap<>();
}
@Autowired(required = false)
private void init(ICommonQuery[] configComponents) {
for (ICommonQuery configComponent : configComponents) {
ResourceInfo info = AnnotationUtils.getAnnotation(configComponent, ResourceInfo.class);
if (info != null) {
initResourceInfo(info);
configComponentMap.put(info.type(), configComponent);
}
}
}
public int getResourceType(String apiName) {
if (!nameTypeMap.containsKey(apiName))
throw new RuntimeException("资源:" + apiName + "的组件不存在");
return nameTypeMap.get(apiName);
}
public ICommonQuery getCommonQuery(String apiName) {
return getCommonQuery(this.getResourceType(apiName));
}
private ICommonQuery getCommonQuery(int resourceType) {
Assert.isTrue(configComponentMap.containsKey(resourceType));
return configComponentMap.get(resourceType);
}
private synchronized void initResourceInfo(ResourceInfo info) {
if (nameTypeMap.containsKey(info.value())) {
Assert.isTrue(nameTypeMap.get(info.value()).equals(info.type()));
} else {
nameTypeMap.put(info.value(), info.type());
}
}
}
package com.jsh.erp.service;
import java.lang.annotation.*;
/**
* @author jishenghua 2018-10-7 15:25:39
* user-5
* role-10
* app-15
* depot-20
* log-25
* functions-30
* inOutItem-35
* unit-40
* person-45
* userBusiness-50
* systemConfig-55
* materialProperty-60
* account-65
* supplier-70
* materialCategory-75
* material-80
* depotHead-85
* depotItem-90
* accountHead-95
* accountItem-100
*/
@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface ResourceInfo {
String value();
int type();
}
package com.jsh.erp.service.account;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.service.depot.DepotResource;
import com.jsh.erp.service.depot.DepotService;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "account_component")
@AccountResource
public class AccountComponent implements ICommonQuery {
@Resource
private AccountService accountService;
@Override
public Object selectOne(String condition) {
return null;
}
@Override
public List<?> select(Map<String, String> map) {
return getAccountList(map);
}
private List<?> getAccountList(Map<String, String> map) {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String serialNo = StringUtil.getInfo(search, "serialNo");
String remark = StringUtil.getInfo(search, "remark");
String order = QueryUtils.order(map);
return accountService.select(name, serialNo, remark, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public int counts(Map<String, String> map) {
String search = map.get(Constants.SEARCH);
String name = StringUtil.getInfo(search, "name");
String serialNo = StringUtil.getInfo(search, "serialNo");
String remark = StringUtil.getInfo(search, "remark");
return accountService.countAccount(name, serialNo, remark);
}
@Override
public int insert(String beanJson, HttpServletRequest request) {
return accountService.insertAccount(beanJson, request);
}
@Override
public int update(String beanJson, Long id) {
return accountService.updateAccount(beanJson, id);
}
@Override
public int delete(Long id) {
return accountService.deleteAccount(id);
}
@Override
public int batchDelete(String ids) {
return accountService.batchDeleteAccount(ids);
}
@Override
public int checkIsNameExist(Long id, String name) {
return accountService.checkIsNameExist(id, name);
}
}
package com.jsh.erp.service.account;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "account", type = 65)
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountResource {
}
package com.jsh.erp.service.account;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.AccountHeadMapper;
import com.jsh.erp.datasource.mappers.AccountItemMapper;
import com.jsh.erp.datasource.mappers.AccountMapper;
import com.jsh.erp.datasource.mappers.DepotHeadMapper;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.datasource.vo.AccountVo4List;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class AccountService {
private Logger logger = LoggerFactory.getLogger(AccountService.class);
@Resource
private AccountMapper accountMapper;
@Resource
private DepotHeadMapper depotHeadMapper;
@Resource
private AccountHeadMapper accountHeadMapper;
@Resource
private AccountItemMapper accountItemMapper;
public Account getAccount(long id) {
return accountMapper.selectByPrimaryKey(id);
}
public List<Account> getAccount() {
AccountExample example = new AccountExample();
return accountMapper.selectByExample(example);
}
public List<AccountVo4List> select(String name, String serialNo, String remark, int offset, int rows) {
List<AccountVo4List> resList = new ArrayList<AccountVo4List>();
List<AccountVo4List> list = accountMapper.selectByConditionAccount(name, serialNo, remark, offset, rows);
String timeStr = Tools.getCurrentMonth();
if (null != list && null !=timeStr) {
for (AccountVo4List al : list) {
DecimalFormat df = new DecimalFormat(".##");
Double thisMonthAmount = getAccountSum(al.getId(), timeStr, "month") + getAccountSumByHead(al.getId(), timeStr, "month") + getAccountSumByDetail(al.getId(), timeStr, "month") + getManyAccountSum(al.getId(), timeStr, "month");
String thisMonthAmountFmt = "0";
if (thisMonthAmount != 0) {
thisMonthAmountFmt = df.format(thisMonthAmount);
}
al.setThismonthamount(thisMonthAmountFmt); //本月发生额
Double currentAmount = getAccountSum(al.getId(), "", "month") + getAccountSumByHead(al.getId(), "", "month") + getAccountSumByDetail(al.getId(), "", "month") + getManyAccountSum(al.getId(), "", "month") + al.getInitialamount();
al.setCurrentamount(currentAmount);
resList.add(al);
}
}
return resList;
}
public int countAccount(String name, String serialNo, String remark) {
return accountMapper.countsByAccount(name, serialNo, remark);
}
public int insertAccount(String beanJson, HttpServletRequest request) {
Account account = JSONObject.parseObject(beanJson, Account.class);
return accountMapper.insertSelective(account);
}
public int updateAccount(String beanJson, Long id) {
Account account = JSONObject.parseObject(beanJson, Account.class);
account.setId(id);
return accountMapper.updateByPrimaryKeySelective(account);
}
public int deleteAccount(Long id) {
return accountMapper.deleteByPrimaryKey(id);
}
public int batchDeleteAccount(String ids) {
List<Long> idList = StringUtil.strToLongList(ids);
AccountExample example = new AccountExample();
example.createCriteria().andIdIn(idList);
return accountMapper.deleteByExample(example);
}
public int checkIsNameExist(Long id, String name) {
AccountExample example = new AccountExample();
example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name);
List<Account> list = accountMapper.selectByExample(example);
return list.size();
}
public List<Account> findBySelect() {
AccountExample example = new AccountExample();
example.setOrderByClause("id desc");
return accountMapper.selectByExample(example);
}
/**
* 单个账户的金额求和-入库和出库
*
* @param id
* @return
*/
public Double getAccountSum(Long id, String timeStr, String type) {
Double accountSum = 0.0;
try {
DepotHeadExample example = new DepotHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountidEqualTo(id).andPaytypeNotEqualTo("预付款")
.andOpertimeGreaterThanOrEqualTo(bTime).andOpertimeLessThanOrEqualTo(eTime);
} else if (type.equals("date")) {
example.createCriteria().andAccountidEqualTo(id).andPaytypeNotEqualTo("预付款")
.andOpertimeLessThanOrEqualTo(mTime);
}
} else {
example.createCriteria().andAccountidEqualTo(id).andPaytypeNotEqualTo("预付款");
}
List<DepotHead> dataList = depotHeadMapper.selectByExample(example);
if (dataList != null) {
for (DepotHead depotHead : dataList) {
if(depotHead.getChangeamount()!=null) {
accountSum = accountSum + depotHead.getChangeamount();
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-收入、支出、转账的单据表头的合计
*
* @param id
* @return
*/
public Double getAccountSumByHead(Long id, String timeStr, String type) {
Double accountSum = 0.0;
try {
AccountHeadExample example = new AccountHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountidEqualTo(id)
.andBilltimeGreaterThanOrEqualTo(bTime).andBilltimeLessThanOrEqualTo(eTime);
} else if (type.equals("date")) {
example.createCriteria().andAccountidEqualTo(id)
.andBilltimeLessThanOrEqualTo(mTime);
}
} else {
example.createCriteria().andAccountidEqualTo(id);
}
List<AccountHead> dataList = accountHeadMapper.selectByExample(example);
if (dataList != null) {
for (AccountHead accountHead : dataList) {
if(accountHead.getChangeamount()!=null) {
accountSum = accountSum + accountHead.getChangeamount();
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-收款、付款、转账、收预付款的单据明细的合计
*
* @param id
* @return
*/
public Double getAccountSumByDetail(Long id, String timeStr, String type) {
Double accountSum = 0.0;
try {
AccountHeadExample example = new AccountHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andBilltimeGreaterThanOrEqualTo(bTime).andBilltimeLessThanOrEqualTo(eTime);
} else if (type.equals("date")) {
example.createCriteria().andBilltimeLessThanOrEqualTo(mTime);
}
}
List<AccountHead> dataList = accountHeadMapper.selectByExample(example);
if (dataList != null) {
String ids = "";
for (AccountHead accountHead : dataList) {
ids = ids + accountHead.getId() + ",";
}
if (!ids.equals("")) {
ids = ids.substring(0, ids.length() - 1);
}
AccountItemExample exampleAi = new AccountItemExample();
if (!ids.equals("")) {
List<Long> idList = StringUtil.strToLongList(ids);
exampleAi.createCriteria().andAccountidEqualTo(id).andHeaderidIn(idList);
} else {
exampleAi.createCriteria().andAccountidEqualTo(id);
}
List<AccountItem> dataListOne = accountItemMapper.selectByExample(exampleAi);
if (dataListOne != null) {
for (AccountItem accountItem : dataListOne) {
if(accountItem.getEachamount()!=null) {
accountSum = accountSum + accountItem.getEachamount();
}
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找进销存信息异常", e);
} catch (Exception e) {
logger.error(">>>>>>>>>异常信息:", e);
}
return accountSum;
}
/**
* 单个账户的金额求和-多账户的明细合计
*
* @param id
* @return
*/
public Double getManyAccountSum(Long id, String timeStr, String type) {
Double accountSum = 0.0;
try {
DepotHeadExample example = new DepotHeadExample();
if (!timeStr.equals("")) {
Date bTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
Date eTime = StringUtil.getDateByString(timeStr + "-31 00:00:00", null);
Date mTime = StringUtil.getDateByString(timeStr + "-01 00:00:00", null);
if (type.equals("month")) {
example.createCriteria().andAccountidlistLike("%" +id.toString() + "%")
.andOpertimeGreaterThanOrEqualTo(bTime).andOpertimeLessThanOrEqualTo(eTime);
} else if (type.equals("date")) {
example.createCriteria().andAccountidlistLike("%" +id.toString() + "%")
.andOpertimeLessThanOrEqualTo(mTime);
}
} else {
example.createCriteria().andAccountidlistLike("%" +id.toString() + "%");
}
List<DepotHead> dataList = depotHeadMapper.selectByExample(example);
if (dataList != null) {
for (DepotHead depotHead : dataList) {
String accountIdList = depotHead.getAccountidlist();
String accountMoneyList = depotHead.getAccountmoneylist();
accountIdList = accountIdList.replace("[", "").replace("]", "").replace("\"", "");
accountMoneyList = accountMoneyList.replace("[", "").replace("]", "").replace("\"", "");
String[] aList = accountIdList.split(",");
String[] amList = accountMoneyList.split(",");
for (int i = 0; i < aList.length; i++) {
if (aList[i].toString().equals(id.toString())) {
accountSum = accountSum + Double.parseDouble(amList[i].toString());
}
}
}
}
} catch (DataAccessException e) {
logger.error(">>>>>>>>>查找信息异常", e);
}
return accountSum;
}
public List<AccountVo4InOutList> findAccountInOutList(Long accountId, Integer offset, Integer rows) {
return accountMapper.findAccountInOutList(accountId, offset, rows);
}
public int findAccountInOutListCount(Long accountId) {
return accountMapper.findAccountInOutListCount(accountId);
}
}
package com.jsh.erp.service.accountHead;
import com.jsh.erp.service.ICommonQuery;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.QueryUtils;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@Service(value = "accountHead_component")
@AccountHeadResource
public class AccountHeadComponent implements ICommonQuery {
@Resource
private AccountHeadService accountHeadService;
@Override
public Object selectOne(String condition) {
return null;
}
@Override
public List<?> select(Map<String, String> map) {
return getAccountHeadList(map);
}
private List<?> getAccountHeadList(Map<String, String> map) {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String billNo = StringUtil.getInfo(search, "billNo");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
String order = QueryUtils.order(map);
return accountHeadService.select(type, billNo, beginTime, endTime, QueryUtils.offset(map), QueryUtils.rows(map));
}
@Override
public int counts(Map<String, String> map) {
String search = map.get(Constants.SEARCH);
String type = StringUtil.getInfo(search, "type");
String billNo = StringUtil.getInfo(search, "billNo");
String beginTime = StringUtil.getInfo(search, "beginTime");
String endTime = StringUtil.getInfo(search, "endTime");
return accountHeadService.countAccountHead(type, billNo, beginTime, endTime);
}
@Override
public int insert(String beanJson, HttpServletRequest request) {
return accountHeadService.insertAccountHead(beanJson, request);
}
@Override
public int update(String beanJson, Long id) {
return accountHeadService.updateAccountHead(beanJson, id);
}
@Override
public int delete(Long id) {
return accountHeadService.deleteAccountHead(id);
}
@Override
public int batchDelete(String ids) {
return accountHeadService.batchDeleteAccountHead(ids);
}
@Override
public int checkIsNameExist(Long id, String name) {
return accountHeadService.checkIsNameExist(id, name);
}
}
package com.jsh.erp.service.accountHead;
import com.jsh.erp.service.ResourceInfo;
import java.lang.annotation.*;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo(value = "accountHead", type = 95)
@Inherited
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountHeadResource {
}
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