|
|
@@ -20,6 +20,8 @@ import com.usoftchina.saas.document.service.VendApamountService;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
import com.usoftchina.saas.utils.DateUtils;
|
|
|
+import com.usoftchina.saas.utils.ObjectUtils;
|
|
|
+import io.netty.util.internal.ObjectUtil;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -213,8 +215,8 @@ public class VendApamountServiceImpl extends CommonBaseServiceImpl<VendApamountM
|
|
|
if (hasCurrency == 0){
|
|
|
throw new BizException(BizExceptionCode.BIZ_NOCURRENCY_SAVE);
|
|
|
}
|
|
|
- int count = getMapper().validVendCodeAndCurrency(vendCode, BaseContextHolder.getCompanyId(), currency,id);
|
|
|
- if (count > 0){
|
|
|
+ VendApamount oldVendApamount = getMapper().getVendApamountByVendCodeAndCurrency(vendCode, BaseContextHolder.getCompanyId(), currency,id);
|
|
|
+ if (!ObjectUtils.isEmpty(oldVendApamount)){
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -268,8 +270,8 @@ public class VendApamountServiceImpl extends CommonBaseServiceImpl<VendApamountM
|
|
|
}
|
|
|
Long companyId = BaseContextHolder.getCompanyId();
|
|
|
StringBuilder err = new StringBuilder();
|
|
|
- List<VendApamount> list = new ArrayList<>();
|
|
|
- VendApamount listDTO = null;
|
|
|
+ List<VendApamount> addList = new ArrayList<>();//新增
|
|
|
+ List<VendApamount> updateList = new ArrayList<>();//更新
|
|
|
List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
if (!CollectionUtils.isEmpty(details)) {
|
|
|
int i = 0;
|
|
|
@@ -279,6 +281,7 @@ public class VendApamountServiceImpl extends CommonBaseServiceImpl<VendApamountM
|
|
|
throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
|
|
|
}
|
|
|
VendApamount vendApamount = JSONObject.parseObject(detail.getDd_maindata(), VendApamount.class);
|
|
|
+ vendApamount.setCompanyId(companyId);
|
|
|
if(vendApamount.getId()==null){vendApamount.setId(0L);}
|
|
|
if(vendApamount.getVa_payamount()==null){vendApamount.setVa_payamount(0.00);}
|
|
|
if(vendApamount.getVa_beginapamount()==null){vendApamount.setVa_beginapamount(0.00);}
|
|
|
@@ -289,64 +292,88 @@ public class VendApamountServiceImpl extends CommonBaseServiceImpl<VendApamountM
|
|
|
if (vendors.size() == 0){
|
|
|
err.append("第" + (i + 3) + "行 : 供应商编号不存在或该供应商已禁用!<br/> ");
|
|
|
}else{
|
|
|
- int hasVendNameByCode = getMapper().hasVendNameByCode(vendApamount.getVa_vendcode(),BaseContextHolder.getCompanyId(),vendApamount.getVa_vendname());
|
|
|
+ int hasVendNameByCode = getMapper().hasVendNameByCode(vendApamount.getVa_vendcode(),companyId,vendApamount.getVa_vendname());
|
|
|
if(hasVendNameByCode==0){
|
|
|
err.append("第" + (i + 3) + "行 : 供应商名称与编号不匹配!<br/> ");
|
|
|
}
|
|
|
vendApamount.setVa_vendid(vendors.get(0).getId());
|
|
|
}
|
|
|
- int hasCurrency = getMapper().hasCurrency(vendApamount.getVa_currency(), BaseContextHolder.getCompanyId());
|
|
|
+ int hasCurrency = getMapper().hasCurrency(vendApamount.getVa_currency(), companyId);
|
|
|
if (hasCurrency == 0){
|
|
|
err.append("第" + (i + 3) + "行 : 币别不存在!<br/> ");
|
|
|
}
|
|
|
- int count = getMapper().validVendCodeAndCurrency(vendApamount.getVa_vendcode(), BaseContextHolder.getCompanyId(), vendApamount.getVa_currency(),0L);
|
|
|
- if (count > 0){
|
|
|
- //校验是否可以修改或新增供应商期初
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
+ VendApamount oldVendApamount = getMapper().getVendApamountByVendCodeAndCurrency(vendApamount.getVa_vendcode(), companyId, vendApamount.getVa_currency(),0L);
|
|
|
+ if (!ObjectUtils.isEmpty(oldVendApamount)){
|
|
|
+ //更新
|
|
|
+ //校验是否可以修改供应商期初
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
map.put("v_id",vendApamount.getVa_vendid());//供应商ID
|
|
|
map.put("v_code", vendApamount.getVa_vendcode());//供应商编号
|
|
|
map.put("v_type","vendCurrency");
|
|
|
map.put("v_currency",vendApamount.getVa_currency());
|
|
|
- map.put("v_companyid",BaseContextHolder.getCompanyId());
|
|
|
+ map.put("v_companyid",companyId);
|
|
|
map.put("v_res","");
|
|
|
getMapper().check(map);
|
|
|
Object result = map.get("v_res");
|
|
|
if(!StringUtils.isEmpty(result)){
|
|
|
err.append("第" + (i + 3) + "行 : "+result.toString()+"<br/> ");
|
|
|
+ }else{
|
|
|
+ //加载已存在的数据
|
|
|
+ vendApamount.setId(oldVendApamount.getId());
|
|
|
+ vendApamount.setVa_payamount(oldVendApamount.getVa_payamount());
|
|
|
+ vendApamount.setVa_preamount(oldVendApamount.getVa_preamount());
|
|
|
+ vendApamount.setVa_begindate(oldVendApamount.getVa_begindate());
|
|
|
+ }
|
|
|
+ vendApamount.setUpdaterId(companyId);
|
|
|
+ vendApamount.setUpdateTime(new Date());
|
|
|
+ //期初日期是否已结账
|
|
|
+ int checkBeginData = getMapper().checkBeginData(sdf.format(vendApamount.getVa_begindate()),companyId);
|
|
|
+ if(checkBeginData > 0){
|
|
|
+ err.append("第" + (i + 3) + "行 : "+BizExceptionCode.BIZ_NOPERIOD_UPDATE.getMessage()+"!<br/> ");
|
|
|
+ }
|
|
|
+ //更新余额
|
|
|
+ vendApamount.setVa_leftamount(vendApamount.getVa_beginapamount()-vendApamount.getVa_beginprepayamount()+vendApamount.getVa_payamount()-vendApamount.getVa_preamount());
|
|
|
+ updateList.add(vendApamount);
|
|
|
+ }else{
|
|
|
+ //新增
|
|
|
+ vendApamount.setCreatorId(companyId);
|
|
|
+ vendApamount.setCreateTime(new Date());
|
|
|
+ vendApamount.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号,当前日期既为本月第一天
|
|
|
+ vendApamount.setVa_begindate(calendar.getTime());
|
|
|
+ //更新余额
|
|
|
+ vendApamount.setVa_leftamount(vendApamount.getVa_beginapamount()-vendApamount.getVa_beginprepayamount()+vendApamount.getVa_payamount()-vendApamount.getVa_preamount());
|
|
|
+ addList.add(vendApamount);
|
|
|
}
|
|
|
- list.add(vendApamount);
|
|
|
i++;
|
|
|
}
|
|
|
if (err.length() > 0) {
|
|
|
dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
throw new BizException(12345, err.toString());
|
|
|
}
|
|
|
- for (VendApamount vendApamount : list) {
|
|
|
- //新增
|
|
|
- vendApamount.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
- vendApamount.setCreatorId(BaseContextHolder.getUserId());
|
|
|
- vendApamount.setCreateTime(new Date());
|
|
|
- vendApamount.setCreatorName(BaseContextHolder.getUserName());
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMM");
|
|
|
- //更新余额
|
|
|
- vendApamount.setVa_leftamount(vendApamount.getVa_beginapamount()-vendApamount.getVa_beginprepayamount()+vendApamount.getVa_payamount()-vendApamount.getVa_preamount());
|
|
|
- //获取当前期间
|
|
|
- String now = getMapper().selectPeriod(BaseContextHolder.getCompanyId());
|
|
|
- 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号,当前日期既为本月第一天
|
|
|
- vendApamount.setVa_begindate(calendar.getTime());
|
|
|
- getMapper().insertSelective(vendApamount);
|
|
|
- vendorMapper.updateVendleftamountByPrimaryKey(vendApamount.getVa_vendid());
|
|
|
+ //新增和更新 批量执行到数据库
|
|
|
+ if(addList.size()>0){
|
|
|
+ getMapper().batchInsert(addList);
|
|
|
+ }
|
|
|
+ if(updateList.size()>0){
|
|
|
+ getMapper().batchUpdate(updateList);
|
|
|
}
|
|
|
- dataImportMapper.updateDataImport(id);
|
|
|
+ //校验是否可以修改供应商期初
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("v_type","vendCurrency");
|
|
|
+ map.put("v_companyid",companyId);
|
|
|
+ getMapper().checkForImport(map);
|
|
|
}
|
|
|
}
|
|
|
}
|