|
|
@@ -21,6 +21,8 @@ import com.usoftchina.saas.document.service.CustAramountService;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
+import com.usoftchina.saas.utils.DateUtils;
|
|
|
+import com.usoftchina.saas.utils.ObjectUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -46,7 +48,8 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
private DataImportMapper dataImportMapper;
|
|
|
@Autowired
|
|
|
private CompanyApi companyApi;
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private SubledgerMapper subledgerMapper;
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(CustAramountServiceImpl.class);
|
|
|
|
|
|
public PageInfo<CustAramountList> getListDataByCondition(PageRequest page, ListReqDTO listReqDTO){
|
|
|
@@ -81,13 +84,19 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
CustAramount custAramount = getMapper().getCustAramount(id,BaseContextHolder.getCompanyId());
|
|
|
validMoney(custAramount);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
+ String ca_begindate = sdf.format(custAramount.getCa_begindate());
|
|
|
//判断本次期间是否已结账,结账了就不能删除
|
|
|
- int checkBeginData = getMapper().checkBeginData(sdf.format(custAramount.getCa_begindate()),BaseContextHolder.getCompanyId());
|
|
|
+ int checkBeginData = getMapper().checkBeginData(ca_begindate,BaseContextHolder.getCompanyId());
|
|
|
if(checkBeginData > 0){
|
|
|
throw new BizException(BizExceptionCode.BIZ_NOPERIOD_DELETE);
|
|
|
}
|
|
|
-
|
|
|
+ //删除中间表subledger数据
|
|
|
+ String delcond="sl_kind='期初余额' and sl_currency='"+custAramount.getCa_currency()+"' and sl_custid='"+custAramount.getCa_custid()+"'"+
|
|
|
+ " and sl_ym="+ca_begindate;
|
|
|
+ subledgerMapper.deleteBycondition(delcond,BaseContextHolder.getCompanyId());
|
|
|
getMapper().deleteByPrimaryKey(id);
|
|
|
+ //更新供应商资料本位币余额
|
|
|
+ customerMapper.updateCustleftamountByPrimaryKey(custAramount.getCa_custid());
|
|
|
//记录LOG
|
|
|
messageLogService.delete(generateMsgObj(id));
|
|
|
}
|
|
|
@@ -111,15 +120,17 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
|
|
|
public DocBaseDTO saveData(CustAramount custAramount){
|
|
|
DocBaseDTO docBaseDTO = null;
|
|
|
+ if(custAramount.getId()==null){custAramount.setId(0L);}
|
|
|
if(custAramount.getCa_recamount()==null){custAramount.setCa_recamount(0.00);}
|
|
|
if(custAramount.getCa_beginaramount()==null){custAramount.setCa_beginaramount(0.00);}
|
|
|
if(custAramount.getCa_beginprerecamount()==null){custAramount.setCa_beginprerecamount(0.00);}
|
|
|
if(custAramount.getCa_preamount()==null){custAramount.setCa_preamount(0.00);}
|
|
|
//判断是否已存在数据
|
|
|
boolean hasData = hasData(custAramount.getCa_custcode(),custAramount.getCa_currency(),custAramount.getId());
|
|
|
- if(hasData){
|
|
|
- validMoney(custAramount);
|
|
|
+ if(hasData&&custAramount.getId() == 0){
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_SAMECUSTAR_SAVE);
|
|
|
}
|
|
|
+ validMoney(custAramount);
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
//更新余额
|
|
|
custAramount.setCa_leftamount(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()+custAramount.getCa_recamount()-custAramount.getCa_preamount());
|
|
|
@@ -164,9 +175,47 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
}
|
|
|
//调用更新
|
|
|
customerMapper.updateCustleftamountByPrimaryKey(custAramount.getCa_custid());
|
|
|
+ updateSubledger(custAramount);
|
|
|
return docBaseDTO;
|
|
|
}
|
|
|
|
|
|
+ private void updateSubledger(CustAramount custAramount){
|
|
|
+ //中间表subledger处理
|
|
|
+ Subledger subledger = new Subledger();
|
|
|
+ subledger.setSl_code("期初余额");
|
|
|
+ subledger.setSl_kind("期初余额");
|
|
|
+ subledger.setSl_vendid(0);
|
|
|
+ subledger.setSl_custid(Math.toIntExact(custAramount.getCa_custid()));
|
|
|
+ subledger.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ subledger.setSl_date(custAramount.getCa_begindate());
|
|
|
+ subledger.setSl_ym(DateUtils.getYm(custAramount.getCa_begindate()));
|
|
|
+ subledger.setSl_currency(custAramount.getCa_currency());
|
|
|
+ if(custAramount.getCa_beginaramount()>custAramount.getCa_beginprerecamount()){
|
|
|
+ subledger.setSl_preamount(new Double(0));
|
|
|
+ subledger.setSl_amount(Math.abs(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()));
|
|
|
+ }else{
|
|
|
+ subledger.setSl_amount(new Double(0));
|
|
|
+ subledger.setSl_preamount(Math.abs(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()));
|
|
|
+ }
|
|
|
+ subledger.setSl_orderamount(Math.abs(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()));
|
|
|
+ subledger.setSl_namount(Math.abs(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()));
|
|
|
+ subledger.setCreateTime(new Date());
|
|
|
+ subledger.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ subledger.setCreatorName(BaseContextHolder.getUserName());
|
|
|
+ //获取当前期间
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
+ String sl_ym = sdf.format(custAramount.getCa_begindate());
|
|
|
+ String con="sl_kind='期初余额' and sl_custid="+Math.toIntExact(custAramount.getCa_custid())+" and sl_currency='"+custAramount.getCa_currency()+"'"+
|
|
|
+ " and sl_ym="+sl_ym;
|
|
|
+ Long sl_id = subledgerMapper.selectIdBycondition(con,BaseContextHolder.getCompanyId());
|
|
|
+ subledger.setId(sl_id);
|
|
|
+ if ( sl_id!=null && sl_id > 0 ) {
|
|
|
+ subledgerMapper.updateByPrimaryKeySelective(subledger);
|
|
|
+ }else {
|
|
|
+ subledgerMapper.insertSelective(subledger);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
|
|
|
private boolean hasData(String custCode, String currency,Long id){
|
|
|
int hasCustCode = getMapper().hasCustCode(custCode, BaseContextHolder.getCompanyId());
|
|
|
@@ -177,8 +226,8 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
if (hasCurrency == 0){
|
|
|
throw new BizException(BizExceptionCode.BIZ_NOCURRENCY_SAVE);
|
|
|
}
|
|
|
- int count = getMapper().validCustCodeAndCurrency(custCode, BaseContextHolder.getCompanyId(), currency,id);
|
|
|
- if (count > 0){
|
|
|
+ CustAramount custAramount = getMapper().getCustAramountByCustCodeAndCurrency(custCode, BaseContextHolder.getCompanyId(), currency,id);
|
|
|
+ if (!ObjectUtils.isEmpty(custAramount)){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -232,8 +281,8 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
}
|
|
|
Long companyId = BaseContextHolder.getCompanyId();
|
|
|
StringBuilder err = new StringBuilder();
|
|
|
- List<CustAramount> list = new ArrayList<>();
|
|
|
- CustAramount listDTO = null;
|
|
|
+ List<CustAramount> addList = new ArrayList<>();//新增
|
|
|
+ List<CustAramount> updateList = new ArrayList<>();//更新
|
|
|
List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
if (!CollectionUtils.isEmpty(details)) {
|
|
|
int i = 0;
|
|
|
@@ -243,6 +292,7 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
|
|
|
}
|
|
|
CustAramount custAramount = JSONObject.parseObject(detail.getDd_maindata(), CustAramount.class);
|
|
|
+ custAramount.setCompanyId(companyId);
|
|
|
if(custAramount.getId()==null){custAramount.setId(0L);}
|
|
|
if(custAramount.getCa_recamount()==null){custAramount.setCa_recamount(0.00);}
|
|
|
if(custAramount.getCa_beginaramount()==null){custAramount.setCa_beginaramount(0.00);}
|
|
|
@@ -251,7 +301,7 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
//判断是否已存在数据
|
|
|
List<Customer> customers = customerMapper.getCustomersByCondition("cu_statuscode = 'ENABLE' AND cu_code = '"+custAramount.getCa_custcode()+"'",BaseContextHolder.getCompanyId());
|
|
|
if (customers.size() == 0){
|
|
|
- err.append("第" + (i + 3) + "行 : 客户编号不存在或该客户状态为禁用!<br/> ");
|
|
|
+ err.append("第" + (i + 3) + "行 : 客户编号不存在或该客户已禁用!<br/> ");
|
|
|
}else{
|
|
|
int hasCustNameByCode = getMapper().hasCustNameByCode(custAramount.getCa_custcode(),BaseContextHolder.getCompanyId(),custAramount.getCa_custname());
|
|
|
if(hasCustNameByCode==0){
|
|
|
@@ -263,9 +313,11 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
if (hasCurrency == 0){
|
|
|
err.append("第" + (i + 3) + "行 : 币别不存在!<br/> ");
|
|
|
}
|
|
|
- int count = getMapper().validCustCodeAndCurrency(custAramount.getCa_custcode(), BaseContextHolder.getCompanyId(), custAramount.getCa_currency(),0L);
|
|
|
- if (count > 0){
|
|
|
- //校验是否可以修改或新增客户期初
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
+ CustAramount oldCustAramount = getMapper().getCustAramountByCustCodeAndCurrency(custAramount.getCa_custcode(), BaseContextHolder.getCompanyId(), custAramount.getCa_currency(),0L);
|
|
|
+ if (!ObjectUtils.isEmpty(oldCustAramount)){
|
|
|
+ //更新
|
|
|
+ //校验是否修改客户期初
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
map.put("v_id",custAramount.getCa_custid());//客户ID
|
|
|
map.put("v_code", custAramount.getCa_custcode());//客户编号
|
|
|
@@ -277,39 +329,86 @@ public class CustAramountServiceImpl extends CommonBaseServiceImpl<CustAramountM
|
|
|
Object result = map.get("v_res");
|
|
|
if(!StringUtils.isEmpty(result)){
|
|
|
err.append("第" + (i + 3) + "行 : "+result.toString()+"<br/> ");
|
|
|
+ }else{
|
|
|
+ //加载已存在的数据
|
|
|
+ custAramount.setId(oldCustAramount.getId());
|
|
|
+ custAramount.setCa_recamount(oldCustAramount.getCa_recamount());
|
|
|
+ custAramount.setCa_preamount(oldCustAramount.getCa_preamount());
|
|
|
+ custAramount.setCa_begindate(oldCustAramount.getCa_begindate());
|
|
|
}
|
|
|
+ custAramount.setUpdaterId(companyId);
|
|
|
+ custAramount.setUpdateTime(new Date());
|
|
|
+ //期初日期是否已结账
|
|
|
+ int checkBeginData = getMapper().checkBeginData(sdf.format(custAramount.getCa_begindate()),companyId);
|
|
|
+ if(checkBeginData > 0){
|
|
|
+ err.append("第" + (i + 3) + "行 : "+BizExceptionCode.BIZ_NOPERIOD_UPDATE.getMessage()+"!<br/> ");
|
|
|
+ }
|
|
|
+ //更新余额
|
|
|
+ custAramount.setCa_leftamount(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()+custAramount.getCa_recamount()-custAramount.getCa_preamount());
|
|
|
+ updateList.add(custAramount);
|
|
|
+ }else{
|
|
|
+ //新增
|
|
|
+ custAramount.setCreatorId(companyId);
|
|
|
+ custAramount.setCreateTime(new Date());
|
|
|
+ custAramount.setCreatorName(BaseContextHolder.getUserName());
|
|
|
+ //获取当前期间
|
|
|
+ String now = getMapper().selectPeriod(companyId);
|
|
|
+ Date date = null;
|
|
|
+ try {
|
|
|
+ date = sdf.parse(now);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
|
|
|
+ custAramount.setCa_begindate(calendar.getTime());
|
|
|
+ //更新余额
|
|
|
+ custAramount.setCa_leftamount(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()+custAramount.getCa_recamount()-custAramount.getCa_preamount());
|
|
|
+ addList.add(custAramount);
|
|
|
}
|
|
|
- list.add(custAramount);
|
|
|
i++;
|
|
|
}
|
|
|
if (err.length() > 0) {
|
|
|
dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
throw new BizException(12345, err.toString());
|
|
|
}
|
|
|
- for (CustAramount custAramount : list) {
|
|
|
- //新增
|
|
|
- custAramount.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
- custAramount.setCreatorId(BaseContextHolder.getUserId());
|
|
|
- custAramount.setCreateTime(new Date());
|
|
|
- custAramount.setCreatorName(BaseContextHolder.getUserName());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
- //更新余额
|
|
|
- custAramount.setCa_leftamount(custAramount.getCa_beginaramount()-custAramount.getCa_beginprerecamount()+custAramount.getCa_recamount()-custAramount.getCa_preamount());
|
|
|
- //获取当前期间
|
|
|
- String now = getMapper().selectPeriod(BaseContextHolder.getCompanyId());
|
|
|
- Date date = null;
|
|
|
- try {
|
|
|
- date = sdf.parse(now);
|
|
|
- } catch (ParseException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ //新增和更新 批量执行到数据库
|
|
|
+ if(addList.size()>0){
|
|
|
+ //校验是否有重复的数据
|
|
|
+ HashSet<Map<String,String>> hs = new HashSet<Map<String,String>>();
|
|
|
+ for(CustAramount list : addList){
|
|
|
+ Map<String,String> m = new HashMap<String,String>();
|
|
|
+ m.put("custCode",list.getCa_custcode());
|
|
|
+ m.put("currency",list.getCa_currency());
|
|
|
+ hs.add(m);
|
|
|
+ }
|
|
|
+ if(addList.size()==hs.size()){
|
|
|
+ getMapper().batchInsert(addList);
|
|
|
+ }else{
|
|
|
+ throw new BizException(12345, "检测到有客户编号和币别相同的数据,无法导入");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(updateList.size()>0){
|
|
|
+ //校验是否有重复的数据
|
|
|
+ HashSet<Map<String,String>> hs = new HashSet<Map<String,String>>();
|
|
|
+ for(CustAramount list : updateList){
|
|
|
+ Map<String,String> m = new HashMap<String,String>();
|
|
|
+ m.put("custCode",list.getCa_custcode());
|
|
|
+ m.put("currency",list.getCa_currency());
|
|
|
+ hs.add(m);
|
|
|
+ }
|
|
|
+ if(updateList.size()==hs.size()){
|
|
|
+ getMapper().batchUpdate(updateList);
|
|
|
+ }else{
|
|
|
+ throw new BizException(12345, "检测到有客户编号和币别相同的数据,无法导入");
|
|
|
}
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(date);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
|
|
|
- custAramount.setCa_begindate(calendar.getTime());
|
|
|
- getMapper().insertSelective(custAramount);
|
|
|
- customerMapper.updateCustleftamountByPrimaryKey(custAramount.getCa_custid());
|
|
|
}
|
|
|
+ //校验是否可以修改供应商期初
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("v_type","custCurrency");
|
|
|
+ map.put("v_companyid",companyId);
|
|
|
+ getMapper().checkForImport(map);
|
|
|
dataImportMapper.updateDataImport(id);
|
|
|
}
|
|
|
}
|