|
|
@@ -0,0 +1,661 @@
|
|
|
+package com.usoftchina.saas.document.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import com.usoftchina.saas.account.api.CompanyApi;
|
|
|
+import com.usoftchina.saas.account.dto.CompanyDTO;
|
|
|
+import com.usoftchina.saas.base.Result;
|
|
|
+import com.usoftchina.saas.base.service.CommonBaseServiceImpl;
|
|
|
+import com.usoftchina.saas.commons.api.MaxnumberService;
|
|
|
+import com.usoftchina.saas.commons.api.MessageLogService;
|
|
|
+import com.usoftchina.saas.commons.dto.BatchDealBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.DocBaseDTO;
|
|
|
+import com.usoftchina.saas.commons.dto.ListReqDTO;
|
|
|
+import com.usoftchina.saas.commons.exception.BizExceptionCode;
|
|
|
+import com.usoftchina.saas.commons.po.BillCodeSeq;
|
|
|
+import com.usoftchina.saas.commons.po.DataImportDetail;
|
|
|
+import com.usoftchina.saas.commons.po.Operation;
|
|
|
+import com.usoftchina.saas.commons.po.Status;
|
|
|
+import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
+import com.usoftchina.saas.document.dto.VendorDTO;
|
|
|
+import com.usoftchina.saas.document.dto.VendorListDTO;
|
|
|
+import com.usoftchina.saas.document.entities.*;
|
|
|
+import com.usoftchina.saas.document.mapper.DataImportMapper;
|
|
|
+import com.usoftchina.saas.document.mapper.SubledgerMapper;
|
|
|
+import com.usoftchina.saas.document.mapper.VendorMapper;
|
|
|
+import com.usoftchina.saas.document.mapper.VendorcontactMapper;
|
|
|
+import com.usoftchina.saas.document.service.VendorService;
|
|
|
+import com.usoftchina.saas.document.service.VendorkindService;
|
|
|
+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.JsonUtils;
|
|
|
+import com.usoftchina.saas.utils.RegexpUtils;
|
|
|
+import com.usoftchina.saas.utils.http.HttpUtil;
|
|
|
+import com.usoftchina.saas.utils.http.HttpUtil.Response;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author chenwei
|
|
|
+ * @Date 2018/10/13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VendorServiceImpl extends CommonBaseServiceImpl<VendorMapper, Vendor> implements VendorService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VendorcontactMapper vendorcontactMapper;
|
|
|
+ @Autowired
|
|
|
+ private MessageLogService messageLogService;
|
|
|
+ @Autowired
|
|
|
+ private MaxnumberService maxnumberService;
|
|
|
+ @Autowired
|
|
|
+ private SubledgerMapper subledgerMapper;
|
|
|
+ @Autowired
|
|
|
+ private VendorMapper vendorMapper;
|
|
|
+ @Autowired
|
|
|
+ private DataImportMapper dataImportMapper;
|
|
|
+ @Autowired
|
|
|
+ private VendorkindService vendorkindService;
|
|
|
+ @Autowired
|
|
|
+ private CompanyApi companyApi;
|
|
|
+ @Value("${b2b.baseUrl.common}")
|
|
|
+ private String b2bUrl;
|
|
|
+
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(VendorServiceImpl.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageInfo<VendorDTO> getVendorsByCondition(PageRequest page, ListReqDTO listReqDTO) {
|
|
|
+ //设置分页
|
|
|
+ if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
|
|
|
+ page = new PageRequest();
|
|
|
+ page.setNumber(1);
|
|
|
+ page.setSize(10);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
+ List<VendorDTO> vendorList = getList(listReqDTO);
|
|
|
+ //取分页信息
|
|
|
+ PageInfo<VendorDTO> pageInfo = new PageInfo<VendorDTO>(vendorList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过ID查找主从表数据
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public VendorListDTO getListById(Long id) {
|
|
|
+ VendorListDTO vendorListDTO = new VendorListDTO();
|
|
|
+ Vendor vendor = getMapper().selectByPrimaryKey(id);
|
|
|
+ List<Vendorcontact> vendorcontactList = vendorcontactMapper.selectByFK(id);
|
|
|
+ //设置主从表信息
|
|
|
+ vendorListDTO.setMain(vendor);
|
|
|
+ vendorListDTO.setItems(vendorcontactList);
|
|
|
+ return vendorListDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorDTO findByUU(Long uu){
|
|
|
+ VendorDTO vendorDTO = getMapper().selectByUU(uu, BaseContextHolder.getCompanyId());
|
|
|
+ return vendorDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public VendorDTO findByName(String name){
|
|
|
+ VendorDTO vendorDTO = getMapper().selectByName(name, BaseContextHolder.getCompanyId());
|
|
|
+ return vendorDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回列表数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PageInfo<VendorList> getListDataByCondition(PageRequest page, ListReqDTO listReqDTO){
|
|
|
+ //设置分页
|
|
|
+ if (null == page || page.getSize() == 0 || page.getNumber() == 0) {
|
|
|
+ page = new PageRequest();
|
|
|
+ page.setNumber(1);
|
|
|
+ page.setSize(10);
|
|
|
+ }
|
|
|
+ PageHelper.startPage(page.getNumber(), page.getSize());
|
|
|
+ //取分页信息
|
|
|
+ String condition = listReqDTO.getFinalCondition();
|
|
|
+ List<VendorList> list = getMapper().getListDataByCondition(condition, BaseContextHolder.getCompanyId());
|
|
|
+ PageInfo<VendorList> pageInfo = new PageInfo<VendorList>(list);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存主从表数据
|
|
|
+ * @param vendorListDTO
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public DocBaseDTO saveFormData(VendorListDTO vendorListDTO) {
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ String userName= BaseContextHolder.getUserName();
|
|
|
+ Long userId = BaseContextHolder.getUserId();
|
|
|
+ if (null == vendorListDTO || null == vendorListDTO.getMain()){
|
|
|
+ throw new BizException(BizExceptionCode.EMPTY_DATA);
|
|
|
+ }
|
|
|
+ Vendor main = vendorListDTO.getMain();
|
|
|
+ main.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ List<Vendorcontact> items = vendorListDTO.getItems();
|
|
|
+ String ve_code = main.getVe_code().trim().toUpperCase();
|
|
|
+
|
|
|
+ //获取已结账的期间
|
|
|
+ String YM = subledgerMapper.selectUnPeriod(companyId);
|
|
|
+ if(YM==null || YM.equals("")){
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
|
|
|
+ YM = simpleDateFormat.format(main.getVe_begindate());
|
|
|
+ }else{
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
|
|
|
+ String beginDate = simpleDateFormat.format(main.getVe_begindate());
|
|
|
+ if(Integer.valueOf(YM)>Integer.valueOf(beginDate)){
|
|
|
+ int code = BizExceptionCode.LIMIT_PERIOD_VENDOR.getCode();
|
|
|
+ String mes = String.format(BizExceptionCode.LIMIT_PERIOD_VENDOR.getMessage(),YM);
|
|
|
+ throw new BizException(code , mes);
|
|
|
+ }
|
|
|
+ YM = beginDate;
|
|
|
+ }
|
|
|
+ ve_code = RegexpUtils.replaceSpecCharacter(ve_code);
|
|
|
+ if (vendorListDTO.isCodeModified()) {
|
|
|
+ ve_code = pushMaxnubmer(ve_code, main.getId());
|
|
|
+ }
|
|
|
+ //String code = pushMaxnubmer(ve_code, main.getId());
|
|
|
+ if(main.getId() == 0){
|
|
|
+ int count = getMapper().getCountByCode(ve_code, companyId);
|
|
|
+ if(count > 0){
|
|
|
+ throw new BizException(BizExceptionCode.REPEAT_CODE);
|
|
|
+ }
|
|
|
+ count = getMapper().getCountByName(main.getVe_name(), companyId);
|
|
|
+ if (count > 0){
|
|
|
+ throw new BizException(BizExceptionCode.REPEAT_NAME);
|
|
|
+ }
|
|
|
+ //保存主表信息
|
|
|
+ main.setVe_code(ve_code);
|
|
|
+ //更新应付款余额
|
|
|
+ Double beginapamount = main.getVe_beginapamount()==null ? new Double(0):main.getVe_beginapamount();
|
|
|
+ Double beginprepayamount = main.getVe_beginprepayamount()==null ? new Double(0):main.getVe_beginprepayamount();
|
|
|
+ Double payamount = main.getVe_payamount()==null? new Double(0):main.getVe_payamount();
|
|
|
+ Double preamount = main.getVe_preamount()==null? new Double(0):main.getVe_preamount();
|
|
|
+ main.setVe_leftamount(beginapamount-beginprepayamount+payamount-preamount);
|
|
|
+ //更新录入人录入时间ID
|
|
|
+ main.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ getMapper().insertSelective(main);
|
|
|
+ Long mainId = main.getId();
|
|
|
+ //更新明细表vc_veid
|
|
|
+ for(Vendorcontact item : items){
|
|
|
+ item.setVc_veid(mainId);
|
|
|
+ item.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ item.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+
|
|
|
+ }
|
|
|
+ //保存明细表信息
|
|
|
+ if (items.size() > 0){
|
|
|
+ vendorcontactMapper.batchInsert(items);
|
|
|
+ }
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.save(generateMsgObj(mainId, ve_code));
|
|
|
+ }else{
|
|
|
+ main.setVe_code(ve_code);
|
|
|
+ Long mainId = main.getId();
|
|
|
+ Vendor oldVendor = getMapper().selectByPrimaryKey(main.getId());
|
|
|
+
|
|
|
+ int count = getMapper().getCountByCode(ve_code, companyId);
|
|
|
+ if (!ve_code.equals(oldVendor.getVe_code())){
|
|
|
+ if (count > 0){
|
|
|
+ throw new BizException(BizExceptionCode.REPEAT_CODE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!main.getVe_name().equals(oldVendor.getVe_name())){
|
|
|
+ count = getMapper().getCountByName(main.getVe_name(), companyId);
|
|
|
+ if (count > 0){
|
|
|
+ throw new BizException(BizExceptionCode.REPEAT_NAME);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //有关联时不可修改名称编号
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("v_id",main.getId());
|
|
|
+ map.put("v_code", ve_code);
|
|
|
+ map.put("v_type","vend");
|
|
|
+ map.put("v_companyid",BaseContextHolder.getCompanyId());
|
|
|
+ map.put("v_res","");
|
|
|
+ vendorMapper.check(map);
|
|
|
+ Object result = map.get("v_res");
|
|
|
+ if(!StringUtils.isEmpty(result)){
|
|
|
+ //限制关联单据不可修改金额
|
|
|
+ Vendor vendor = getMapper().selectByPrimaryKey(main.getId());
|
|
|
+ if (vendor.getVe_beginapamount().doubleValue() != main.getVe_beginapamount().doubleValue() ||
|
|
|
+ vendor.getVe_beginprepayamount().doubleValue() != main.getVe_beginprepayamount().doubleValue() ||
|
|
|
+ vendor.getVe_begindate().compareTo(main.getVe_begindate()) != 0){
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_RELUPDATE_AMOUNT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查期初日期是否已结转
|
|
|
+ count = getMapper().validFinish(mainId,companyId);
|
|
|
+ if (count>0) {
|
|
|
+ Vendor vendortpl = getMapper().selectByPrimaryKey(mainId);
|
|
|
+ //期初应收
|
|
|
+ main.setVe_beginapamount(vendortpl.getVe_beginapamount());
|
|
|
+ //期初预收
|
|
|
+ main.setVe_beginprepayamount(vendortpl.getVe_beginprepayamount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //启用B2B对账
|
|
|
+ if (StringUtils.isEmpty(oldVendor.getVe_uu()) && !StringUtils.isEmpty(main.getVe_uu())){
|
|
|
+ try {
|
|
|
+ enableApCheck(main.getVe_uu());
|
|
|
+ } catch (Exception e) {
|
|
|
+ LOGGER.info("请求B2B对账启用接口失败!, time={}", DateUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ getMapper().updateByPrimaryKeySelective(main);
|
|
|
+ if (items.size() > 0) {
|
|
|
+ List<Vendorcontact> updateItems = new ArrayList<Vendorcontact>();
|
|
|
+ List<Vendorcontact> insertItems = new ArrayList<Vendorcontact>();
|
|
|
+ //获取执行更新、插入的明细数据
|
|
|
+ for(Vendorcontact vendorcontact : items){
|
|
|
+ if(vendorcontact.getId() == 0){
|
|
|
+ vendorcontact.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ vendorcontact.setCreateTime(new Date());
|
|
|
+ vendorcontact.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ vendorcontact.setVc_veid(main.getId());
|
|
|
+ insertItems.add(vendorcontact);
|
|
|
+ }else{
|
|
|
+ vendorcontact.setUpdaterId(BaseContextHolder.getUserId());
|
|
|
+ vendorcontact.setUpdateTime(new Date());
|
|
|
+ updateItems.add(vendorcontact);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (insertItems.size() > 0){
|
|
|
+ vendorcontactMapper.batchInsert(insertItems);
|
|
|
+ }
|
|
|
+ if (updateItems.size() > 0){
|
|
|
+ vendorcontactMapper.batchUpdate(items);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.update(generateMsgObj(main.getId(), ve_code));
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新应收款余额
|
|
|
+ Double ve_leftamount = (main.getVe_beginapamount() == null ? new Double(0) : main.getVe_beginapamount())
|
|
|
+ - (main.getVe_beginprepayamount() == null ? new Double(0) : main.getVe_beginprepayamount())
|
|
|
+ + (main.getVe_payamount() == null ? new Double(0) : main.getVe_payamount())
|
|
|
+ - (main.getVe_preamount() == null ? new Double(0) : main.getVe_preamount());
|
|
|
+ main.setVe_leftamount(ve_leftamount);
|
|
|
+ getMapper().updateByPrimaryKeySelective(main);
|
|
|
+
|
|
|
+ //插入中间表
|
|
|
+ Double amount = (main.getVe_beginapamount() == null ? new Double(0) : main.getVe_beginapamount())
|
|
|
+ - (main.getVe_beginprepayamount() == null ? new Double(0) : main.getVe_beginprepayamount());
|
|
|
+ Subledger subledger = new Subledger();
|
|
|
+ subledger.setSl_code("期初余额");
|
|
|
+ subledger.setSl_kind("期初余额");
|
|
|
+ subledger.setSl_vendid(Math.toIntExact(main.getId()));
|
|
|
+ subledger.setSl_custid(0);
|
|
|
+ subledger.setCompanyId(BaseContextHolder.getCompanyId());
|
|
|
+ subledger.setSl_date(DateUtils.getFirstDay(main.getVe_begindate()));
|
|
|
+ subledger.setSl_ym(DateUtils.getYm(main.getVe_begindate()));
|
|
|
+ subledger.setSl_currency(main.getVe_currency());
|
|
|
+ if (amount > new Double(0)){
|
|
|
+ subledger.setSl_preamount(new Double(0));
|
|
|
+ subledger.setSl_amount(Math.abs(amount));
|
|
|
+ }else {
|
|
|
+ subledger.setSl_amount(new Double(0));
|
|
|
+ subledger.setSl_preamount(Math.abs(amount));
|
|
|
+ }
|
|
|
+ subledger.setSl_orderamount(Math.abs(amount));
|
|
|
+ subledger.setSl_namount((subledger.getSl_orderamount() == null ? new Double(0) : subledger.getSl_orderamount()) +
|
|
|
+ (subledger.getSl_discount() == null ? new Double(0) : subledger.getSl_discount()) -
|
|
|
+ (subledger.getSl_yamount() == null ? new Double(0) : subledger.getSl_yamount()));
|
|
|
+ subledger.setCreateTime(new Date());
|
|
|
+ subledger.setCreatorId(BaseContextHolder.getUserId());
|
|
|
+ subledger.setCreatorName(BaseContextHolder.getUserName());
|
|
|
+ Long sl_id = subledgerMapper.selectByKindCodeVendid("期初余额","期初余额",
|
|
|
+ Math.toIntExact(main.getId()),BaseContextHolder.getCompanyId(),YM);
|
|
|
+
|
|
|
+ subledger.setId(sl_id);
|
|
|
+ if ( sl_id!=null && sl_id > 0 ) {
|
|
|
+ subledgerMapper.updateByPrimaryKeySelective(subledger);
|
|
|
+ }else {
|
|
|
+ subledgerMapper.insertSelective(subledger);
|
|
|
+ }
|
|
|
+
|
|
|
+ return generateMsgObj(main.getId(), ve_code);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 启用B2B对账
|
|
|
+ * @param ve_uu
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void enableApCheck(String ve_uu) throws Exception {
|
|
|
+ CompanyDTO companyDTO = companyApi.getCompanyById(BaseContextHolder.getCompanyId()).getData();
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("venduu", ve_uu);
|
|
|
+ map.put("custuu", companyDTO.getUu());
|
|
|
+ map.put("apcheck", 1);
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
+ List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
|
|
+ data.add(map);
|
|
|
+ params.put("data", JsonUtils.toJsonString(data));
|
|
|
+ Response response = HttpUtil.sendPostRequest(b2bUrl + "/erp/vendor/apcheck?access_id=" + companyDTO.getUu(), params, true, companyDTO.getAccessKey());
|
|
|
+ if (response.getStatusCode() == 200){
|
|
|
+ LOGGER.info("供应商UU={},启用B2B对账成功!", ve_uu);
|
|
|
+ }else {
|
|
|
+ LOGGER.info("供应商UU={},启用B2B对账失败!,原因={}", ve_uu, response.getResponseText());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除主从表数据
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void deleteById(Long id) {
|
|
|
+ if(id != null && id > 0){
|
|
|
+ String code = getMapper().getCodeById(id, BaseContextHolder.getCompanyId());
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("v_id",id);
|
|
|
+ map.put("v_code", code);
|
|
|
+ map.put("v_type","vend");
|
|
|
+ map.put("v_companyid",BaseContextHolder.getCompanyId());
|
|
|
+ map.put("v_res","");
|
|
|
+ vendorMapper.check(map);
|
|
|
+ Object result = map.get("v_res");
|
|
|
+ if(!StringUtils.isEmpty(result)){
|
|
|
+ throw new BizException(BizExceptionCode.USING_EXISTS.getCode(),result.toString());
|
|
|
+ }else{
|
|
|
+ vendorcontactMapper.deleteByFK(id);
|
|
|
+ getMapper().deleteByPrimaryKey(id);
|
|
|
+ //删除中间表
|
|
|
+ subledgerMapper.deleteVendor("期初余额", "期初余额", Math.toIntExact(id));
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.delete(generateMsgObj(id, code));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DocBaseDTO close(Long id){
|
|
|
+ if(id != null && id > 0){
|
|
|
+ Vendor vendor = new Vendor();
|
|
|
+ vendor.setId(id);
|
|
|
+ vendor.setVe_status(Status.BANNED.getDisplay());
|
|
|
+ vendor.setVe_statuscode(Status.BANNED.name());
|
|
|
+ vendor.setUpdaterId(BaseContextHolder.getUserId());
|
|
|
+ vendor.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ String code = getMapper().getCodeById(id, BaseContextHolder.getCompanyId());
|
|
|
+ getMapper().updateByPrimaryKeySelective(vendor);
|
|
|
+ //记录LOG
|
|
|
+ DocBaseDTO docBaseDTO = generateMsgObj(id, code);
|
|
|
+ messageLogService.customizeLog(docBaseDTO, Operation.BANNED);
|
|
|
+ return docBaseDTO;
|
|
|
+ }else{
|
|
|
+ throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开启
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DocBaseDTO open(Long id){
|
|
|
+ if (id != null && id > 0){
|
|
|
+ Vendor vendor = getMapper().selectByPrimaryKey(id);
|
|
|
+ if(vendor == null){
|
|
|
+ throw new BizException(BizExceptionCode.NO_DATA);
|
|
|
+ }
|
|
|
+ if (Status.BANNED.name().equals(vendor.getVe_statuscode())){
|
|
|
+ String code = vendor.getVe_code();
|
|
|
+ vendor = new Vendor();
|
|
|
+ vendor.setId(id);
|
|
|
+ vendor.setVe_statuscode(Status.ENABLE.name());
|
|
|
+ vendor.setVe_status(Status.ENABLE.getDisplay());
|
|
|
+ getMapper().updateByPrimaryKeySelective(vendor);
|
|
|
+ //记录LOG
|
|
|
+ DocBaseDTO docBaseDTO = generateMsgObj(id, code);
|
|
|
+ messageLogService.customizeLog(docBaseDTO, Operation.ENABLE);
|
|
|
+ return docBaseDTO;
|
|
|
+ }else {
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_ENABLE);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BizException(BizExceptionCode.ILLEGAL_ID);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String batchClose(BatchDealBaseDTO baseDTOs) {
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
+ for (DocBaseDTO docBaseDTO : baseDTOs.getBaseDTOs()){
|
|
|
+ try{
|
|
|
+ close(docBaseDTO.getId());
|
|
|
+ }catch (Exception e){
|
|
|
+ String msg = BizExceptionCode.DEAL_FAILED.getMessage();
|
|
|
+ errorMsg.append(String.format(msg, docBaseDTO.getCode(), e.getMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errorMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String batchOpen(BatchDealBaseDTO baseDTOs) {
|
|
|
+ StringBuilder errorMsg = new StringBuilder();
|
|
|
+ for (DocBaseDTO docBaseDTO : baseDTOs.getBaseDTOs()){
|
|
|
+ try{
|
|
|
+ open(docBaseDTO.getId());
|
|
|
+ }catch (Exception e){
|
|
|
+ String msg = BizExceptionCode.DEAL_FAILED.getMessage();
|
|
|
+ errorMsg.append(String.format(msg, docBaseDTO.getCode(), e.getMessage()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return errorMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean deleteContact(Long id) {
|
|
|
+ Long ve_id = vendorcontactMapper.selectByPrimaryKey(id).getVc_veid();
|
|
|
+ String code = getMapper().getCodeById(ve_id, BaseContextHolder.getCompanyId());
|
|
|
+ vendorcontactMapper.deleteByPrimaryKey(id);
|
|
|
+ //记录LOG
|
|
|
+ messageLogService.deleteDetail(generateMsgObj(id, code));
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean batchDelete(BatchDealBaseDTO baseDTOs) {
|
|
|
+ if (null == baseDTOs || null == baseDTOs.getBaseDTOs() ||
|
|
|
+ baseDTOs.getBaseDTOs().size() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (DocBaseDTO base : baseDTOs.getBaseDTOs()) {
|
|
|
+ deleteById(base.getId());
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveToFormal(Integer id, boolean update) {
|
|
|
+ if (null == id || "0".equals(id)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ StringBuilder err = new StringBuilder();
|
|
|
+ List<VendorListDTO> list = new ArrayList<>();
|
|
|
+ VendorListDTO listDTO = null;
|
|
|
+ List<DataImportDetail> details = dataImportMapper.selectDataById(id);
|
|
|
+ if (!CollectionUtils.isEmpty(details)) {
|
|
|
+ Map<String, List<DataImportDetail>> datas = CollectionUtils.groupBy(details, DataImportDetail::getDd_codevalue);
|
|
|
+ Integer detno = null;
|
|
|
+ for (String code : datas.keySet()) {
|
|
|
+ listDTO = new VendorListDTO();
|
|
|
+ List<Vendorcontact> details_ = new ArrayList<>();
|
|
|
+ int i = getMapper().validateCodeWhenInsert(code, companyId);
|
|
|
+ List<DataImportDetail> data = datas.get(code);
|
|
|
+ DataImportDetail main = dataImportMapper.selectMainBycode(code, id, companyId);
|
|
|
+ if (StringUtils.isEmpty(main)) {
|
|
|
+ throw new BizException(BizExceptionCode.BIZ_REPORT_NOTCORRECT);
|
|
|
+ }
|
|
|
+ Vendor vendor = JSONObject.parseObject(main.getDd_maindata(), Vendor.class);
|
|
|
+ vendor.setVe_status(Status.ENABLE.getDisplay());
|
|
|
+ vendor.setVe_statuscode(Status.ENABLE.name());
|
|
|
+ if (!StringUtils.isEmpty(vendor.getVe_type())) {
|
|
|
+ Vendorkind type = vendorkindService.getTypeByname(vendor.getVe_type());
|
|
|
+ if (null == type) {
|
|
|
+ throw new BizException(70110581,"供应商: " + vendor.getVe_name() + " 类型: " + vendor.getVe_type() + " 在系统中不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //编号不存在
|
|
|
+ if (i == 0) {
|
|
|
+ vendor.setId(0l);
|
|
|
+ //编号存在、需要更新
|
|
|
+ } else if (update){
|
|
|
+ Long pr_id = getMapper().selectIdByCode(code, companyId);
|
|
|
+ vendor.setId(pr_id);
|
|
|
+ //编号存在、不需要处理
|
|
|
+ } else {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //添加从表
|
|
|
+ if (data.size() > 0) {
|
|
|
+ detno = 1;
|
|
|
+ int count = 0;
|
|
|
+ for (DataImportDetail productDetail : data) {
|
|
|
+ Vendorcontact detail = JSONObject.parseObject(productDetail.getDd_detaildata(), Vendorcontact.class);
|
|
|
+ if (null != detail) {
|
|
|
+ detail.setVc_veid(vendor.getId());
|
|
|
+ detail.setVc_detno(detno);
|
|
|
+ detno++;
|
|
|
+ if ("是".equals(detail.getVc_default())) {
|
|
|
+ detail.setVc_default("1");
|
|
|
+ count++;
|
|
|
+ } else {
|
|
|
+ detail.setVc_default("0");
|
|
|
+ }
|
|
|
+ details_.add(detail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count > 1) {
|
|
|
+ throw new BizException(70110582,"供应商: " + vendor.getVe_name() + " 存在多个默认联系人");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ listDTO.setMain(vendor);
|
|
|
+ listDTO.setItems(details_);
|
|
|
+ list.add(listDTO);
|
|
|
+ }
|
|
|
+ if (err.length() > 0) {
|
|
|
+ dataImportMapper.updateDataImportError(err.toString(), id);
|
|
|
+ throw new BizException(12345, err.toString());
|
|
|
+ }
|
|
|
+ for (VendorListDTO dto : list) {
|
|
|
+ saveFormData(dto);
|
|
|
+ }
|
|
|
+ dataImportMapper.updateDataImport(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<VendorDTO> getList(ListReqDTO listReqDTO){
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ String condition = listReqDTO.getFinalCondition();
|
|
|
+ if(condition == null){
|
|
|
+ condition = "1=1";
|
|
|
+ }
|
|
|
+ List<VendorDTO> vendorDTOList = getMapper().getVendorsByCondition(condition, companyId);
|
|
|
+ return vendorDTOList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造日记记录对象
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private DocBaseDTO generateMsgObj(Long id, String code){
|
|
|
+ return new DocBaseDTO(id, code, "Vendor");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 检验获取并更新单号
|
|
|
+ * @Param: [code, id]
|
|
|
+ * @return: java.lang.String
|
|
|
+ * @Author: chenwei
|
|
|
+ * @Date: 2018/10/26
|
|
|
+ */
|
|
|
+ private String pushMaxnubmer(String code, Long id) {
|
|
|
+ if (null == code) {
|
|
|
+ throw new BizException(BizExceptionCode.NULL_CODE);
|
|
|
+ }
|
|
|
+ Long companyId = BaseContextHolder.getCompanyId();
|
|
|
+ String billcode = null;
|
|
|
+ synchronized (VendorServiceImpl.class) {
|
|
|
+ Integer count = "0".equals(String.valueOf(id)) ? getMapper().validateCodeWhenInsert(code, companyId) :
|
|
|
+ getMapper().validateCodeWhenUpdate(code, id, companyId);
|
|
|
+ Result<String> res = maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.VENDOR.getCaller());
|
|
|
+ if (res.isSuccess()) {
|
|
|
+ billcode = res.getData();
|
|
|
+ } else {
|
|
|
+ throw new BizException(123456, res.getMessage());
|
|
|
+ }
|
|
|
+ //billcode = maxnumberService.pushMaxnubmer(count, code, BillCodeSeq.VENDOR.getCaller()).getData();
|
|
|
+ }
|
|
|
+ return billcode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * String转Date类型
|
|
|
+ *
|
|
|
+ * @param dateStr
|
|
|
+ * 时间字符串
|
|
|
+ * @return Date类型时间
|
|
|
+ * @throws Exception
|
|
|
+ * 异常
|
|
|
+ */
|
|
|
+ public static Date string2Date(String dateStr, String format) throws Exception {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
+ if (dateStr != null) {
|
|
|
+ return sdf.parse(dateStr);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Date转String
|
|
|
+ *
|
|
|
+ * @param date
|
|
|
+ * Date类型时间
|
|
|
+ * @return 时间字符串
|
|
|
+ */
|
|
|
+ public static String date2String(Date date, String format) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
+ if (date != null) {
|
|
|
+ return sdf.format(date);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|