Search in sources :

Example 6 with ContactForm

use of com.eservice.api.model.contact_form.ContactForm in project sinsim by WilsonHu.

the class ContactFormController method add.

/**
 * 一次性同时上传 联系单,联系单的变更条目,联系单的签核信息
 *
 * @param jsonContactFormAllInfo
 * @return
 */
@PostMapping("/add")
@Transactional(rollbackFor = Exception.class)
public Result add(String jsonContactFormAllInfo) {
    ContactFormAllInfo contactFormAllInfo = JSON.parseObject(jsonContactFormAllInfo, ContactFormAllInfo.class);
    if (contactFormAllInfo == null || contactFormAllInfo.equals("")) {
        return ResultGenerator.genFailResult("JSON数据异常");
    }
    String message = null;
    ContactForm contactForm = contactFormAllInfo.getContactForm();
    List<ChangeItem> changeItemList = contactFormAllInfo.getChangeItemList();
    ContactSign contactSign = contactFormAllInfo.getContactSign();
    try {
        if (null == contactForm) {
            message = " contactForm 为空!";
            throw new RuntimeException();
        }
        if (contactForm.getContactType().equals(Constant.STR_LXD_TYPE_BIANGENG)) {
            if (null == changeItemList) {
                message = " 类型为变更联系单时,变更条目不能为空!";
                throw new RuntimeException();
            }
        }
        if (null == contactSign) {
            message = " contactSign 为空!";
            throw new RuntimeException();
        }
        // 生成联系单
        contactForm.setCreateDate(new Date());
        contactForm.setStatus(Constant.STR_LXD_INITIAL);
        String firstPartOfLxdNum = contactForm.getNum().replace("xxx", "");
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
        String thisYear = formatter.format(new Date());
        String lastSerialNumber = getLxdLastSerialNumber(thisYear, contactForm.getApplicantDepartment());
        if (lastSerialNumber == "") {
            String firstLxdOfTheDepartment = contactForm.getNum().replace("xxx", "001");
            contactForm.setNum(firstLxdOfTheDepartment);
        } else {
            Integer newSerialNumber;
            try {
                newSerialNumber = Integer.valueOf(lastSerialNumber) + 1;
            } catch (Exception e) {
                logger.warn("exception: " + e);
                newSerialNumber = 0;
            }
            String newNum = firstPartOfLxdNum + String.format("%03d", newSerialNumber);
            contactForm.setNum(newNum);
        }
        // 如果是在新建联系单就添加附件,此时联系单单号未确定。需要后端来更新。
        if (contactForm.getAttachedFile().contains("xxx")) {
            String oldNameOfAttachedFile = contactForm.getAttachedFile();
            String newNameOfAttachedFile = contactForm.getAttachedFile().replace("xxx", contactForm.getNum().split("-")[2]);
            // 根据订单名称 重新命名附件文件
            File file = new File(oldNameOfAttachedFile);
            if (file == null || !file.exists()) {
                logger.error(oldNameOfAttachedFile + "文件不存在!");
            } else {
                file.renameTo(new File(newNameOfAttachedFile));
            }
            contactForm.setAttachedFile(newNameOfAttachedFile);
        }
        contactFormService.saveAndGetID(contactForm);
        // 生成联系单变更条目, 如果类型不是变更联系单时,这部分为空
        if (contactForm.getContactType().equals(Constant.STR_LXD_TYPE_BIANGENG)) {
            for (int i = 0; i < changeItemList.size(); i++) {
                changeItemList.get(i).setContactFormId(contactForm.getId());
                changeItemService.save(changeItemList.get(i));
            }
        }
        // 生成联系单的审核记录
        contactSign.setCreateTime(new Date());
        contactSign.setContactFormId(contactForm.getId());
        contactSignService.save(contactSign);
        /**
         * 联系单的落实,也在add时添加,比如技术部(联系单的主要落实者)也可以在发起联系单时,直接指定落实信息。
         */
        ContactFulfill contactFulfill = contactFormAllInfo.getContactFulfill();
        if (contactFulfill != null) {
            contactFulfill.setContactFormId(contactForm.getId());
            if (contactFulfill.getFulfillMan() == null || contactFulfill.getFulfillMan().equals("")) {
                contactFulfill.setStatus(Constant.STR_FULFILL_STATUS_UN_ASSIGN);
            } else {
                contactFulfill.setStatus(Constant.STR_FULFILL_STATUS_FULFILLING);
            }
            contactFulfill.setCreateDate(new Date());
            contactFulfillService.save(contactFulfill);
        } else {
            logger.info("新增联系单时,落实单为空");
        }
    } catch (Exception ex) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        logger.warn("添加联系单/联系单变更条目/联系单审核信息 出错: " + message);
        return ResultGenerator.genFailResult("添加联系单/联系单变更条目/联系单审核信息 出错!" + message + ex.getMessage());
    }
    // 返回ID给前端,前端新增联系单时不关闭页面。
    return ResultGenerator.genSuccessResult(contactForm.getId());
}
Also used : ContactFulfill(com.eservice.api.model.contact_fulfill.ContactFulfill) ContactSign(com.eservice.api.model.contact_sign.ContactSign) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) Date(java.util.Date) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ContactForm(com.eservice.api.model.contact_form.ContactForm) ContactFormAllInfo(com.eservice.api.model.contact_form.ContactFormAllInfo) ChangeItem(com.eservice.api.model.change_item.ChangeItem) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ContactForm

use of com.eservice.api.model.contact_form.ContactForm in project sinsim by WilsonHu.

the class ContactFormController method list.

@PostMapping("/list")
public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
    PageHelper.startPage(page, size);
    List<ContactForm> list = contactFormService.findAll();
    PageInfo pageInfo = new PageInfo(list);
    return ResultGenerator.genSuccessResult(pageInfo);
}
Also used : PageInfo(com.github.pagehelper.PageInfo) ContactForm(com.eservice.api.model.contact_form.ContactForm) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with ContactForm

use of com.eservice.api.model.contact_form.ContactForm in project sinsim by WilsonHu.

the class ContactSignController method update.

/**
 *  联系单审核的更新,同时更新对应的联系单
 * @param contactSign
 * @return
 */
@PostMapping("/update")
@Transactional(rollbackFor = Exception.class)
public Result update(String contactSign) {
    if (contactSign == null || "".equals(contactSign)) {
        ResultGenerator.genFailResult("联系单审核信息不能为空!");
    }
    logger.info("contactSign:" + contactSign);
    ContactSign cs = JSON.parseObject(contactSign, ContactSign.class);
    if (cs == null) {
        ResultGenerator.genFailResult("审核信息JSON解析失败!");
    }
    ContactForm cf = contactFormService.findById(cs.getContactFormId());
    if (null == cf) {
        ResultGenerator.genFailResult("根据传入的签核信息里的联系单ID 找不到对应的联系单");
    }
    cs.setUpdateTime(new Date());
    List<SignContentItem> contactSignContentList = JSON.parseArray(cs.getSignContent(), SignContentItem.class);
    boolean haveReject = false;
    String currentStep = "";
    for (SignContentItem item : contactSignContentList) {
        if (item.getResult().equals(Constant.SIGN_REJECT)) {
            haveReject = true;
        }
        // 签核在初始化,则把当前步骤设为发起部门 --> 就是下个要签核的部门
        if (item.getResult() == Constant.SIGN_INITIAL && item.getShenHeEnabled()) {
            currentStep = roleService.findById(item.getRoleId()).getRoleName();
            break;
        }
    }
    // 都已经签核
    if (!haveReject) {
        if (currentStep.equals("")) {
            currentStep = Constant.SIGN_FINISHED;
        }
        cs.setCurrentStep(currentStep);
    }
    contactSignService.update(cs);
    String msgInfo = null;
    if (haveReject) {
        /**
         * 被拒绝了,
         * contactSign的每个状态,更新为 初始状态
         * contactForm的状态,更新为 被拒绝。
         */
        for (SignContentItem item : contactSignContentList) {
            item.setResult(Constant.SIGN_INITIAL);
        }
        cs.setSignContent(JSONObject.toJSONString(contactSignContentList));
        logger.warn("got Reject signContent: " + JSONObject.toJSONString(contactSignContentList));
        contactSignService.update(cs);
        cf.setStatus(Constant.STR_LXD_REJECTED);
        contactFormService.update(cf);
        /**
         * 推送 "签核被拒绝"消息
         */
        msgInfo = Constant.STR_MSG_PUSH_SIGN_REFUESED;
    } else {
        // 没有被拒,且刚刚开始
        if (cf.getStatus().equals(Constant.STR_LXD_INITIAL)) {
            cf.setStatus(Constant.STR_LXD_CHECKING);
        }
        // 没有被拒,且联系单签核完成
        if (currentStep.equals(Constant.SIGN_FINISHED)) {
            cf.setStatus(Constant.STR_LXD_CHECKING_FINISHED);
            // 推送 "签核完成" 消息给 发起人
            msgInfo = Constant.STR_MSG_PUSH_SIGN_DONE;
        } else {
            // 推送 "轮到签核" 消息给 轮到联系单签核的人
            msgInfo = Constant.STR_MSG_PUSH_IS_TURN_TO_SIGN;
        }
        contactFormService.update(cf);
    }
    commonService.pushLxdMsgToAftersale(cs, cf, haveReject, msgInfo);
    return ResultGenerator.genSuccessResult();
}
Also used : ContactSign(com.eservice.api.model.contact_sign.ContactSign) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) ContactForm(com.eservice.api.model.contact_form.ContactForm) Date(java.util.Date) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with ContactForm

use of com.eservice.api.model.contact_form.ContactForm in project sinsim by WilsonHu.

the class ContactFormController method update.

/**
 * 一是修改联系单时要update (包括变更条目的修改),二是审核联系单时也要Update。 即使已经开始审批过程了,还要允许修改。
 * 允许财务部修改是否需要总经理审核
 *
 * @param
 * @return
 */
@Transactional(rollbackFor = Exception.class)
@PostMapping("/update")
public Result update(String jsonContactFormAllInfo) {
    ContactFormAllInfo contactFormAllInfo = JSON.parseObject(jsonContactFormAllInfo, ContactFormAllInfo.class);
    if (contactFormAllInfo == null || contactFormAllInfo.equals("")) {
        return ResultGenerator.genFailResult("JSON数据异常");
    }
    logger.info("更新联系单 " + jsonContactFormAllInfo);
    String message = null;
    ContactForm contactForm = contactFormAllInfo.getContactForm();
    List<ChangeItem> changeItemList = contactFormAllInfo.getChangeItemList();
    ContactSign contactSign = contactFormAllInfo.getContactSign();
    try {
        if (null == contactForm) {
            message = " contactForm 为空!";
            throw new RuntimeException();
        }
        if (null == contactForm.getId()) {
            message = " contactForm 的Id 不能为空!";
            throw new RuntimeException();
        }
        if (contactFormService.findById(contactForm.getId()) == null) {
            message = " 根据该id找不到对应的联系单!";
            throw new RuntimeException();
        }
        if (contactForm.getContactType().equals(Constant.STR_LXD_TYPE_BIANGENG)) {
            if (null == changeItemList) {
                message = " 类型为变更联系单时,变更条目不能为空!";
                throw new RuntimeException();
            }
        }
        if (null == contactSign) {
            message = " contactSign 为空!";
            throw new RuntimeException();
        }
        if (contactForm.getStatus().equals(Constant.STR_LXD_CHECKING)) {
            // 重新计算当前审核阶段
            List<SignContentItem> contactSignContentList = JSON.parseArray(contactSign.getSignContent(), SignContentItem.class);
            String currentStep = "";
            // int num=-1;
            for (SignContentItem item : contactSignContentList) {
                String step = roleService.findById(item.getRoleId()).getRoleName();
                // 审核状态是初始化,并且是启用的就是当前步骤
                if (item.getResult() == Constant.SIGN_INITIAL && item.getShenHeEnabled()) {
                    currentStep = step;
                    break;
                }
            // 检查当前current step 是否禁用掉
            // if(step.equals(contactSign.getCurrentStep()))
            // {
            // num=item.getNumber();
            // if(item.getResult() == Constant.SIGN_INITIAL&&item.getShenHeEnabled()) {
            // break;
            // }
            // }else{
            // if(num>-1&&item.getNumber()>num)
            // {
            // if(item.getResult() == Constant.SIGN_INITIAL&&item.getShenHeEnabled()) {
            // currentStep=step;
            // break;
            // }
            // }
            // }
            }
            if (currentStep != "") {
                contactSign.setCurrentStep(currentStep);
                logger.info("当前审核阶段 不为空:" + currentStep);
            } else {
                /**
                 * 当前审核阶段 为空, 表示已经不存在:需要审核但是还没审核(Result为0)的步骤,即已经全部审核完成了。
                 * 此时需要更新状态。【被取消的那一步,刚好是最后一步,且前面都已经完成审核】
                 * 实列:一开始是勾着王总审核的,王总前面全部审批完成,再修改取消了王总审核,此时审核应该为完成。
                 */
                logger.info("当前审核阶段 为空:" + currentStep);
                contactSign.setCurrentStep(Constant.SIGN_FINISHED);
                contactForm.setStatus(Constant.STR_LXD_CHECKING_FINISHED);
            }
        }
        if (contactForm.getContactType().equals(Constant.STR_LXD_TYPE_BIANGENG)) {
            // 更新联系单变更条目
            List<ChangeItem> changeItemListExist = changeItemService.selectChangeItemList(contactForm.getId());
            for (int i = 0; i < changeItemList.size(); i++) {
                if (changeItemList.get(i).getContactFormId() != null) {
                    if (changeItemList.get(i).getContactFormId().intValue() != contactForm.getId().intValue()) {
                        message = " 变更条目里的ContactFormId 和 联系单的id 不匹配!";
                        throw new RuntimeException();
                    }
                }
                // step1.如果是已经存在的条目,则更新
                if (changeItemService.findById(changeItemList.get(i).getId()) != null) {
                    changeItemService.update(changeItemList.get(i));
                    logger.info("更新了 id为 " + changeItemList.get(i).getId() + " 的变更条目");
                } else {
                    // step2.如果是新增的条目,则新增。
                    changeItemList.get(i).setContactFormId(contactForm.getId());
                    changeItemService.save(changeItemList.get(i));
                    logger.info("新增了一个 " + changeItemList.get(i).getNewInfo() + " 的变更条目");
                }
                // step3. 如果目前已存在的条目 不在传进来的条目中,表示该条目应该删除。
                boolean isIncluded = false;
                // List<ChangeItem> changeItemListExist = changeItemService.selectChangeItemList(contactForm.getId());
                for (int ei = 0; ei < changeItemListExist.size(); ei++) {
                    // exist item
                    // 每个条目都和传进来的每个条目进行比较
                    isIncluded = false;
                    for (int ii = 0; ii < changeItemList.size(); ii++) {
                        // input item
                        if (changeItemListExist.get(ei).getId().equals(changeItemList.get(ii).getId())) {
                            isIncluded = true;
                            break;
                        }
                    }
                    if (!isIncluded) {
                        changeItemService.deleteById(changeItemListExist.get(ei).getId());
                        logger.info("删除了 id为 " + changeItemListExist.get(ei).getId() + " 的变更条目");
                    }
                }
            }
            // 如果传进来变更列表的是空的,说明要把之前旧的全部都删除
            if (changeItemList.size() == 0) {
                for (int ei = 0; ei < changeItemListExist.size(); ei++) {
                    // exist item
                    changeItemService.deleteById(changeItemListExist.get(ei).getId());
                    logger.info("all, 删除了 id为 " + changeItemListExist.get(ei).getId() + " 的变更条目");
                }
            }
        }
        // 更新 联系单的审核记录
        contactSign.setUpdateTime(new Date());
        if (contactSign.getContactFormId().intValue() != contactForm.getId()) {
            message = " contactSign里的ContactFormId 和 联系单的id 不匹配!";
            throw new RuntimeException();
        }
        // 统一更新审核数据, currentstep等
        contactSignService.update(contactSign);
        contactForm.setUpdateDate(new Date());
        // 统一更新联系单
        contactFormService.update(contactForm);
        /**
         * 联系单的落实,新增/更新
         */
        ContactFulfill contactFulfill = contactFormAllInfo.getContactFulfill();
        if (contactFulfill != null) {
            contactFulfill.setContactFormId(contactForm.getId());
            if (contactFulfill.getId() == null || contactFulfill.getId() == 0) {
                // 新增加的落实信息,比如在二期旧的联系单上添加落实信息,比如在新建联系单时未写落实信息,后面再补上时。
                if (contactFulfill.getFulfillMan() == null) {
                    contactFulfill.setStatus(Constant.STR_FULFILL_STATUS_UN_ASSIGN);
                } else {
                    contactFulfill.setStatus(Constant.STR_FULFILL_STATUS_FULFILLING);
                }
                contactFulfill.setCreateDate(new Date());
                contactFulfillService.save(contactFulfill);
            } else {
                contactFulfill.setUpdateDate(new Date());
                contactFulfillService.update(contactFulfill);
            }
        } else {
            logger.info("更新联系单时,落实单为空");
        }
    } catch (Exception ex) {
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        logger.warn("更新 联系单/联系单变更条目/联系单审核信息 出错: " + message);
        return ResultGenerator.genFailResult("更新 联系单/联系单变更条目/联系单审核信息 出错!" + message + ex.getMessage());
    }
    return ResultGenerator.genSuccessResult();
}
Also used : ContactFulfill(com.eservice.api.model.contact_fulfill.ContactFulfill) ContactSign(com.eservice.api.model.contact_sign.ContactSign) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) Date(java.util.Date) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SignContentItem(com.eservice.api.model.contract_sign.SignContentItem) ContactForm(com.eservice.api.model.contact_form.ContactForm) ContactFormAllInfo(com.eservice.api.model.contact_form.ContactFormAllInfo) ChangeItem(com.eservice.api.model.change_item.ChangeItem) PostMapping(org.springframework.web.bind.annotation.PostMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ContactForm

use of com.eservice.api.model.contact_form.ContactForm in project sinsim by WilsonHu.

the class ContactFormController method getLxdAttachedFile.

/**
 * 根据联系单ID 返回 联系单的附件的文件名称 下载路径的前面部分是统一的,放在xxx_ip/download/下(nginx配置),
 * 比如,访问下面地址可以下载该装车单
 * http://xx.xx.xx.xx/lxdAttached/lxd_lxdNum111_lxdAttached__0.xlsx
 *
 * @param contact_form_id
 * @param flag : 哪种附件,比如新建联系单时添加的附件,签核时添加的附件
 * @return 类似 lxd_lxdNum111_lxdAttached__0.xlsx
 */
@PostMapping("/getLxdAttachedFile")
public Result getLxdAttachedFile(@RequestParam Integer contact_form_id, @RequestParam String flag) {
    ContactForm cf = contactFormService.findById(contact_form_id);
    if (null == cf) {
        return ResultGenerator.genFailResult("根据该contact_form_id 找不到对应的联系单");
    }
    if (cf.getAttachedFile() == null) {
        return ResultGenerator.genFailResult("该联系单没有附件");
    }
    String fileName = null;
    if (flag.contains(Constant.STRING_LXD_ATTACHED_FILE_BY_CREATER)) {
        fileName = cf.getAttachedFile().substring(lxdAttachedSavedDir.length());
    } else if (flag.contains(Constant.STRING_LXD_ATTACHED_FILE_DURING_SIGN)) {
        fileName = cf.getAttachedDuringSign().substring(lxdAttachedSavedDir.length());
    } else {
        return ResultGenerator.genFailResult("没有对应的附件类型!");
    }
    return ResultGenerator.genSuccessResult(fileName);
}
Also used : ContactForm(com.eservice.api.model.contact_form.ContactForm) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ContactForm (com.eservice.api.model.contact_form.ContactForm)11 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 ContactSign (com.eservice.api.model.contact_sign.ContactSign)6 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)5 Transactional (org.springframework.transaction.annotation.Transactional)5 ChangeItem (com.eservice.api.model.change_item.ChangeItem)4 Date (java.util.Date)4 ContactFormAllInfo (com.eservice.api.model.contact_form.ContactFormAllInfo)3 ContactFulfill (com.eservice.api.model.contact_fulfill.ContactFulfill)3 SignContentItem (com.eservice.api.model.contract_sign.SignContentItem)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 ContactFormDetail (com.eservice.api.model.contact_form.ContactFormDetail)1 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)1 Role (com.eservice.api.model.role.Role)1 User (com.eservice.api.model.user.User)1 UserDetail (com.eservice.api.model.user.UserDetail)1