Commit d7390541 by wuwenlong

会计起管理dev;

parent 67649b9a
......@@ -57,6 +57,8 @@ public class HGCB001 extends DaoEPBase {
public static final String INSERT = "HGCB001.insert";
public static final String UPDATE = "HGCB001.update";
public static final String DELETE = "HGCB001.delete";
public static final String QUERY_NO_AUTH = "HGCB001.queryNoAuth";
private Long id = new Long(0);
private String accountCode = " "; /* 企业编码*/
......
......@@ -2,22 +2,24 @@ package com.baosight.hggp.hg.cb.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.common.DdynamicEnum;
import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.cb.domain.HGCB001;
import com.baosight.hggp.hg.cb.tools.HGCBTools;
import com.baosight.hggp.hg.cw.domain.HGCW001;
import com.baosight.hggp.hg.cw.tools.HGCWTools;
import com.baosight.hggp.hg.xs.domain.Company;
import com.baosight.hggp.util.CommonMethod;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.*;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.exception.PlatException;
import com.baosight.iplat4j.core.service.impl.ServiceBase;
import org.apache.commons.collections.CollectionUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author yukang
......@@ -74,17 +76,16 @@ public class ServiceHGCB001 extends ServiceBase {
public EiInfo save(EiInfo inInfo) {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
List<HGCB001> hgcb001List = MapUtils.toDaoEPBase(resultRows,HGCB001.class);
checkSaveData(hgcb001List);
// 写入数据
for (int i = 0; i < resultRows.size(); i++) {
HGCB001 HGCB001 = new HGCB001();
HGCB001.fromMap(resultRows.get(i));
HGCB001.setAccountPeriod(DateUtils.formatShort(HGCB001.getAccountPeriod()));
if (HGCB001.getId() == null || HGCB001.getId() == 0) {
this.add(HGCB001);
} else {
this.modify(HGCB001);
}
}
Optional.ofNullable(hgcb001List).orElse(new ArrayList<>()).forEach(hgcb001 -> {
hgcb001.setAccountPeriod(DateUtils.formatShort(hgcb001.getAccountPeriod()));
});
List<HGCB001> addList = Optional.ofNullable(hgcb001List).orElse(new ArrayList<>()).stream().filter(o -> Objects.isNull(o.getId())||o.getId()==0).collect(Collectors.toList());
add(addList);
List<HGCB001> updateList = Optional.ofNullable(hgcb001List).orElse(new ArrayList<>()).stream().filter(o -> Objects.nonNull(o.getId())&&o.getId()!=0).collect(Collectors.toList());
modify(updateList);
inInfo = this.query(inInfo);
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + resultRows.size() + "]条数据保存成功!");
......@@ -94,24 +95,53 @@ public class ServiceHGCB001 extends ServiceBase {
return inInfo;
}
private void checkSaveData(List<HGCB001> hgcb001List){
if(CollectionUtils.isNotEmpty(hgcb001List)) {
List<String> stringList = hgcb001List.stream().map(o -> {
return o.getCompanyCode() + "-" + o.getAccountPeriod();
}).collect(Collectors.toList());
long count = stringList.stream().distinct().count();
AssertUtils.isTrue(stringList.size() != count, "账期重复,请检查数据!");
}
}
/**
* 新增操作
*
* @param HGCB001
* @param addList
* @return
*/
public void add(HGCB001 HGCB001) {
DaoUtils.insert("HGCB001.insert", HGCB001);
public void add(List<HGCB001> addList) {
Map<String,List<String>> periodMap = Optional.ofNullable(addList).orElse(new ArrayList<>()).stream().collect(
Collectors.groupingBy(HGCB001::getCompanyCode,Collectors.mapping(HGCB001::getAccountPeriod,Collectors.toList())));
Optional.ofNullable(periodMap).orElse(new HashMap<>()).forEach((k,v)->{
Map paramMap = new HashMap();
paramMap.put(HGCB001.FIELD_COMPANY_CODE,k);
paramMap.put("accountPeriods",v);
List dbList = HGCBTools.HgCb001.queryNoAuth(paramMap);
AssertUtils.isNotEmpty(dbList,"账期重复,请检查数据!");
});
DaoUtils.insertBatch(HGCB001.INSERT, addList);
}
/**
* 修改操作
*
* @param HGCB001
* @param updateList
* @return
*/
public void modify(HGCB001 HGCB001) {
DaoUtils.update("HGCB001.update", HGCB001);
public void modify(List<HGCB001> updateList) {
Map<String,List<String>> periodMap = Optional.ofNullable(updateList).orElse(new ArrayList<>()).stream().collect(
Collectors.groupingBy(HGCB001::getCompanyCode,Collectors.mapping(HGCB001::getAccountPeriod,Collectors.toList()))); List<Long> notIds = Optional.ofNullable(updateList).orElse(new ArrayList<>()).stream().map(HGCB001::getId).collect(Collectors.toList());
Optional.ofNullable(periodMap).orElse(new HashMap<>()).forEach((k,v)->{
Map paramMap = new HashMap();
paramMap.put(HGCB001.FIELD_COMPANY_CODE,k);
paramMap.put("accountPeriods",v);
paramMap.put("notIds",notIds);
List dbList = HGCBTools.HgCb001.queryNoAuth(paramMap);
AssertUtils.isNotEmpty(dbList,"账期重复,请检查数据!");
});
DaoUtils.updateBatch(HGCB001.UPDATE, updateList);
}
/**
......@@ -175,9 +205,13 @@ public class ServiceHGCB001 extends ServiceBase {
public EiInfo delete(EiInfo inInfo) {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
for (int i = 0; i < resultRows.size(); i++) {
DaoUtils.update("HGCB001.delete", resultRows.get(i));
}
List<HGCB001> hgcb001List = MapUtils.toDaoEPBase(resultRows,HGCB001.class);
Optional.ofNullable(hgcb001List).orElse(new ArrayList<>()).stream().forEach(o -> {
AssertUtils.isTrue(o.getAccountPeriodStatus()== CommonConstant.YesNo.NO_0,String.format(
"%s[%s]账期已关账,无法删除!",o.getCompanyName(),o.getAccountPeriod()
));
});
DaoUtils.updateBatch("HGCB001.delete", hgcb001List);
inInfo = this.query(inInfo);
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + resultRows.size() + "]条数据删除成功!");
......@@ -196,24 +230,24 @@ public class ServiceHGCB001 extends ServiceBase {
public EiInfo switchRow(EiInfo inInfo) {
try {
List<Map> resultRows = inInfo.getBlock(EiConstant.resultBlock).getRows();
HGCB001 HGCB001 = new HGCB001();
HGCB001.fromMap(resultRows.get(0));
Integer accountPeriodStatus = HGCB001.getAccountPeriodStatus();
HGCB001 hgcb001 = new HGCB001();
hgcb001.fromMap(resultRows.get(0));
Integer accountPeriodStatus = hgcb001.getAccountPeriodStatus();
if (accountPeriodStatus == 1) {
//开账 - 做关账
HGCB001.setAccountPeriodStatus(0);
DaoUtils.update("HGCB001.updateSwitchRow", HGCB001);
//当前账期的上个账期是否关账,当前账期对应的业务账是否关账
hgcb001.setAccountPeriodStatus(0);
DaoUtils.update("HGCB001.updateSwitchRow", hgcb001);
} else if (accountPeriodStatus == 0) {
//先找是否已经有开账的记录
int switchRowNum = dao.count("HGCB001.getSwitchRowNum", HGCB001);
//当前账期的下个账期是否开账状态
int switchRowNum = dao.count("HGCB001.getSwitchRowNum", hgcb001);
if (switchRowNum > 0) {
inInfo.setStatus(EiConstant.STATUS_FAILURE);
inInfo.setMsg("操作失败!已经有一个会计期为开账状态!");
return inInfo;
}
HGCB001.setAccountPeriodStatus(1);
DaoUtils.update("HGCB001.updateSwitchRow", HGCB001);
hgcb001.setAccountPeriodStatus(1);
DaoUtils.update("HGCB001.updateSwitchRow", hgcb001);
}
inInfo = this.query(inInfo);
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
......@@ -224,4 +258,42 @@ public class ServiceHGCB001 extends ServiceBase {
return inInfo;
}
private void checkSwitchDate(HGCB001 hgcb001){
try {
HGCB001 dbhgcb001 = null;
switch (hgcb001.getAccountPeriodStatus()) {
case 0:
Date nextDate = DateUtils.addMonths(DateUtils.parseDate(hgcb001.getAccountPeriod(), DateUtil.DATE12_PATTERN), 1);
String nextDateStr = DateUtil.toDateStr(nextDate,DateUtil.DATE12_PATTERN);
dbhgcb001 = HGCBTools.HgCb001.getNoAuth(new HashMap(){{
put(HGCW001.FIELD_COMPANY_CODE,hgcb001.getCompanyCode());
put(HGCW001.FIELD_ACCOUNT_PERIOD,nextDateStr);
}});
AssertUtils.isTrue(Objects.nonNull(dbhgcb001)&&dbhgcb001.getAccountPeriodStatus()== CommonConstant.YesNo.NO_0,String.format("下个账期为关账状态:%s[%s]账期会计账已经关账!",dbhgcb001.getCompanyName(),dbhgcb001.getAccountPeriod()));
break;
case 1:
Date lastDate = DateUtils.addMonths(DateUtils.parseDate(hgcb001.getAccountPeriod(), DateUtil.DATE12_PATTERN), -1);
String lastDateStr = DateUtil.toDateStr(lastDate,DateUtil.DATE12_PATTERN);
dbhgcb001 = HGCBTools.HgCb001.getNoAuth(new HashMap(){{
put(HGCW001.FIELD_COMPANY_CODE,hgcb001.getCompanyCode());
put(HGCW001.FIELD_ACCOUNT_PERIOD,lastDateStr);
}});
AssertUtils.isNull(Objects.isNull(dbhgcb001),String.format("会计账期缺失:%s[%s]账期会计账不存在!",hgcb001.getCompanyName(),lastDateStr));
AssertUtils.isTrue(dbhgcb001.getAccountPeriodStatus()== CommonConstant.YesNo.YES_1,String.format("上个账期未关账:%s[%s]账期会计账未关账!",dbhgcb001.getCompanyName(),dbhgcb001.getAccountPeriod()));
HGCW001 hgcw001 = HGCWTools.HgCw001.getNoAuth(new HashMap(){{
put(HGCW001.FIELD_COMPANY_CODE,hgcb001.getCompanyCode());
put(HGCW001.FIELD_ACCOUNT_PERIOD,hgcb001.getAccountPeriod());
}});
AssertUtils.isTrue(Objects.nonNull(hgcw001)&&hgcw001.getAccountPeriodStatus()== CommonConstant.YesNo.YES_1,String.format("业务账未关账:%s[%s]账期业务账未关账!",hgcb001.getCompanyName(),hgcb001.getAccountPeriod()));
break;
default:
AssertUtils.isTrue(true,"会计账期状态异常!");
break;
}
} catch (ParseException e) {
AssertUtils.isTrue(true,"会计账期会计期异常!");
e.printStackTrace();
}
}
}
......@@ -23,6 +23,59 @@
-->
<sqlMap namespace="HGCB001">
<sql id="no_auth_condition">
<isNotEmpty prepend=" AND " property="notIds">
ID NOT IN <iterate close=")" open="(" conjunction="," property="notIds">#notIds[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="ids">
ID IN <iterate close=")" open="(" conjunction="," property="ids">#ids[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriods">
ACCOUNT_PERIOD IN <iterate close=")" open="(" conjunction="," property="accountPeriods">#accountPeriods[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="id">
ID = #id#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountCode">
ACCOUNT_CODE = #accountCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="companyCode">
COMPANY_CODE = #companyCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="companyName">
COMPANY_NAME = #companyName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountYear">
ACCOUNT_YEAR = #accountYear#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriod">
ACCOUNT_PERIOD = #accountPeriod#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriodStatus">
ACCOUNT_PERIOD_STATUS = #accountPeriodStatus#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdBy">
CREATED_BY = #createdBy#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdName">
CREATED_NAME = #createdName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdTime">
CREATED_TIME = #createdTime#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedBy">
UPDATED_BY = #updatedBy#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedName">
UPDATED_NAME = #updatedName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedTime">
UPDATED_TIME = #updatedTime#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="depCode">
DEP_CODE = #depCode#
</isNotEmpty>
</sql>
<sql id="condition">
<include refid="HGXSDataAuth.authCondition"/>
<isNotEmpty prepend=" AND " property="id">
......@@ -287,4 +340,27 @@
ID = #id#
</update>
<select id="queryNoAuth" parameterClass="java.util.HashMap"
resultClass="com.baosight.hggp.hg.cb.domain.HGCB001">
SELECT
ID as "id",
ACCOUNT_CODE as "accountCode", <!-- 企业编码 -->
COMPANY_CODE as "companyCode", <!-- 公司编码 -->
COMPANY_NAME as "companyName", <!-- 公司名称 -->
ACCOUNT_YEAR as "accountYear", <!-- 会计年度 -->
ACCOUNT_PERIOD as "accountPeriod", <!-- 会计期 -->
ACCOUNT_PERIOD_STATUS as "accountPeriodStatus", <!-- 会计期状态0:关账1:开账 -->
CREATED_BY as "createdBy", <!-- 记录创建者 -->
CREATED_NAME as "createdName", <!-- 记录创建名称 -->
CREATED_TIME as "createdTime", <!-- 记录创建时间 -->
UPDATED_BY as "updatedBy", <!-- 记录修改者 -->
UPDATED_NAME as "updatedName", <!-- 记录修改名称 -->
UPDATED_TIME as "updatedTime", <!-- 记录修改时间 -->
DEP_CODE as "depCode" <!-- 部门编码 -->
FROM ${hggpSchema}.HGCB001 WHERE 1=1
where 1=1
<include refid="no_auth_condition"/>
</select>
</sqlMap>
......@@ -46,6 +46,7 @@ import java.util.stream.Collectors;
*/
public class HGCBTools {
public static void setBaseInfo(List<HGCB004> cb004s) {
for (HGCB004 hgcb004 : cb004s) {
......@@ -74,6 +75,22 @@ public class HGCBTools {
public static class HgCb001 {
public static List<HGCB001> listByIds(List<Long> ids){
List<HGCB001> hgcb001s = queryNoAuth(new HashMap(){{put("ids",ids);}});
return hgcb001s;
}
public static List<HGCB001> queryNoAuth(Map paramMap){
List<HGCB001> hgcb001s = DaoBase.getInstance().query(HGCB001.QUERY_NO_AUTH, paramMap);
return hgcb001s;
}
public static HGCB001 getNoAuth(Map paramMap){
List<HGCB001> list = queryNoAuth(paramMap);
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
/**
* 查询当前公司账期
* @param params 业务账期
......
......@@ -63,6 +63,8 @@ public class HGCW001 extends DaoEPBase {
public static final String INSERT = "HGCW001.insert";
public static final String UPDATE = "HGCW001.update";
public static final String DELETE = "HGCW001.delete";
public static final String QUERY_NO_AUTH = "HGCW001.queryNoAuth";
private Long id = new Long(0);
private String accountCode = " "; /* 企业编码*/
......
......@@ -23,6 +23,60 @@
-->
<sqlMap namespace="HGCW001">
<sql id="no_auth_condition">
<isNotEmpty prepend=" AND " property="id">
ID = #id#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountCode">
ACCOUNT_CODE = #accountCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="companyCode">
COMPANY_CODE = #companyCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="companyName">
COMPANY_NAME = #companyName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountYear">
ACCOUNT_YEAR = #accountYear#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriod">
ACCOUNT_PERIOD = #accountPeriod#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriodStatus">
ACCOUNT_PERIOD_STATUS = #accountPeriodStatus#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriodDateStart">
ACCOUNT_PERIOD_DATE_START = #accountPeriodDateStart#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="accountPeriodDateEnd">
ACCOUNT_PERIOD_DATE_END = #accountPeriodDateEnd#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdBy">
CREATED_BY = #createdBy#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdName">
CREATED_NAME = #createdName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="createdTime">
CREATED_TIME = #createdTime#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedBy">
UPDATED_BY = #updatedBy#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedName">
UPDATED_NAME = #updatedName#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="updatedTime">
UPDATED_TIME = #updatedTime#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="depCode">
DEP_CODE = #depCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="companyCodes">
COMPANY_CODE IN <iterate close=")" open="(" conjunction="," property="companyCodes">#companyCodes[]#</iterate>
</isNotEmpty>
</sql>
<sql id="condition">
<include refid="HGXSDataAuth.authCondition"/>
<isNotEmpty prepend=" AND " property="id">
......@@ -332,4 +386,26 @@
</select>
<select id="queryNoAuth" parameterClass="java.util.HashMap"
resultClass="com.baosight.hggp.hg.cw.domain.HGCW001">
SELECT
ID as "id",
ACCOUNT_CODE as "accountCode", <!-- 企业编码 -->
COMPANY_CODE as "companyCode", <!-- 公司编码 -->
COMPANY_NAME as "companyName", <!-- 公司名称 -->
ACCOUNT_YEAR as "accountYear", <!-- 会计年度 -->
ACCOUNT_PERIOD as "accountPeriod", <!-- 会计期 -->
ACCOUNT_PERIOD_STATUS as "accountPeriodStatus", <!-- 会计期状态0:关账1:开账 -->
ACCOUNT_PERIOD_DATE_START as "accountPeriodDateStart", <!-- 账期开始日期 -->
ACCOUNT_PERIOD_DATE_END as "accountPeriodDateEnd", <!-- 账期结束日期 -->
CREATED_BY as "createdBy", <!-- 记录创建者 -->
CREATED_NAME as "createdName", <!-- 记录创建名称 -->
CREATED_TIME as "createdTime", <!-- 记录创建时间 -->
UPDATED_BY as "updatedBy", <!-- 记录修改者 -->
UPDATED_NAME as "updatedName", <!-- 记录修改名称 -->
UPDATED_TIME as "updatedTime", <!-- 记录修改时间 -->
DEP_CODE as "depCode" <!-- 部门编码 -->
FROM ${hggpSchema}.HGCW001 WHERE 1=1
<include refid="no_auth_condition"/>
</select>
</sqlMap>
......@@ -59,6 +59,17 @@ public class HGCWTools {
AssertUtils.isEmpty(list, "未找到公司符合"+bussinessTime+"开账的账期");
return list.get(0);
}
public static List<HGCW001> queryNoAuth(Map paramMap){
List<HGCW001> list = DaoBase.getInstance().query(HGCW001.QUERY_NO_AUTH, paramMap);
return list;
}
public static HGCW001 getNoAuth(Map paramMap){
List<HGCW001> list = queryNoAuth(paramMap);
return CollectionUtils.isEmpty(list) ? null : list.get(0);
}
}
public static class HgCw002 {
......
......@@ -22,6 +22,7 @@ public class DateUtil {
public static final String DATE8_PATTERN = "yyyyMMdd";
public static final String DATE10_PATTERN = "yyyy-MM-dd";
public static final String DATE11_PATTERN = "M月d日";
public static final String DATE12_PATTERN = "yyyyMM";
public static final String TIME6_PATTERN = "HHmmss";
public static final String TIME8_PATTERN = "HH:mm:ss";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment