use of com.eservice.api.model.contact_form.ContactFormAllInfo in project sinsim by WilsonHu.
the class ContactFormServiceImpl method getAllInfo.
public ContactFormAllInfo getAllInfo(Integer contactFormId) {
ContactFormAllInfo contactFormAllInfo = new ContactFormAllInfo();
ContactForm cf = contactFormService.findById(contactFormId);
if (null == cf) {
logger.warn("根据该contactFormId" + contactFormId + " 找不到对应的contactForm");
return null;
}
// //
ContactSign cs = contactSignService.getContactSignByLxdId(contactFormId);
if (null == cs) {
logger.warn("根据该contactFormId" + contactFormId + " 找不到对应的contactSign");
return null;
}
// 落实单
// 如果有多个落实单,只认最新的落实单(创建日期最新)
ContactFulfill cff = contactFulfillService.getLatestFulFillByLxdId(contactFormId);
if (null == cff) {
logger.warn("根据该contactFormId " + contactFormId + " 找不到对应的落实单 (之前期的联系单还不存在落实单信息)");
/**
* 方便前台处理
*(cff为空时,对于旧的联系单,前端无法读取cff的信息, Cannot read property 'xxxx' of null",会造成无法显示)
*/
cff = new ContactFulfill();
logger.warn("cff为空时,对于旧的联系单,前端无法读取cff的信息");
} else {
}
contactFormAllInfo.setContactFulfill(cff);
contactFormAllInfo.setContactForm(cf);
contactFormAllInfo.setContactSign(cs);
if (cf.getContactType().equals(Constant.STR_LXD_TYPE_BIANGENG)) {
List<ChangeItem> changeItemList = changeItemService.selectChangeItemList(contactFormId);
contactFormAllInfo.setChangeItemList(changeItemList);
}
return contactFormAllInfo;
}
use of com.eservice.api.model.contact_form.ContactFormAllInfo 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());
}
use of com.eservice.api.model.contact_form.ContactFormAllInfo in project sinsim by WilsonHu.
the class ContactFormController method buildLxdExcel.
@PostMapping("/buildLxdExcel")
public Result buildLxdExcel(@RequestParam Integer contact_form_id, String account) {
ContactFormAllInfo cf = contactFormService.getAllInfo(contact_form_id);
if (null == cf) {
return ResultGenerator.genFailResult("根据该contact_form_id 找不到对应的联系单");
}
// 是否是变更单
Boolean isChange = cf.getContactForm().getContactType().indexOf(Constant.STR_LXD_TYPE_BIANGENG) >= 0;
InputStream fs = null;
POIFSFileSystem pfs = null;
HSSFWorkbook wb = null;
FileOutputStream out = null;
String downloadPath = "";
/*
* 返回给docker外部下载
*/
String downloadPathForNginx = "";
Boolean displayEnable = commonService.isDisplayPrice(account);
try {
String templateFile = isChange ? "empty_lxd_change_template.xls" : "empty_lxd_work_template.xls";
ClassPathResource resource = new ClassPathResource(templateFile);
fs = resource.getInputStream();
pfs = new POIFSFileSystem(fs);
wb = new HSSFWorkbook(pfs);
// 读取了模板内所有sheet1内容
HSSFSheet workSheet = wb.getSheetAt(0);
// 在相应的单元格进行赋值(A2)
// 表单编号
HSSFCell numCell = workSheet.getRow(1).getCell((short) 3);
numCell.setCellValue(new HSSFRichTextString(cf.getContactForm().getNum()));
// 订单号
numCell = workSheet.getRow(1).getCell((short) 6);
numCell.setCellValue(new HSSFRichTextString(cf.getContactForm().getOrderNum()));
// 提出部门
HSSFCell dpartCell = workSheet.getRow(2).getCell((short) 2);
dpartCell.setCellValue(cf.getContactForm().getApplicantDepartment());
// 申请人
HSSFCell apCell = workSheet.getRow(2).getCell((short) 7);
apCell.setCellValue(cf.getContactForm().getApplicantPerson());
// 审核状态
HSSFCell statusCell = workSheet.getRow(2).getCell((short) 11);
statusCell.setCellValue(cf.getContactForm().getStatus());
// 申请日期
HSSFCell dateCell = workSheet.getRow(3).getCell((short) 2);
String createDate = cf.getContactForm().getCreateDate() == null ? "" : formatter.format(cf.getContactForm().getCreateDate());
dateCell.setCellValue(createDate);
// ECO希望完成日期
HSSFCell ECODateCell = workSheet.getRow(3).getCell((short) 9);
String ecoDate = cf.getContactForm().getHopeDate() == null ? "" : formatter.format(cf.getContactForm().getHopeDate());
ECODateCell.setCellValue(ecoDate);
// 变更理由/主题
HSSFCell titleCell = workSheet.getRow(4).getCell((short) 2);
titleCell.setCellValue(cf.getContactForm().getContactTitle());
// 变更内容 (包含已知常规内容 + “其他变更”)
HSSFCell contentCell = workSheet.getRow(5).getCell((short) 2);
if (cf.getContactForm().getContactContentElse() != null && !cf.getContactForm().getContactContentElse().isEmpty()) {
contentCell.setCellValue(cf.getContactForm().getContactContent() + "(" + cf.getContactForm().getContactContentElse() + ")");
} else {
contentCell.setCellValue(cf.getContactForm().getContactContent());
}
short startRow = 6;
if (// 是变更单 (变更条目的列表)
isChange) {
startRow = 7;
// 设置变更项目内容
HSSFRow curRow = workSheet.getRow(startRow);
List<ChangeItem> changeItemList = cf.getChangeItemList();
Integer index = 0;
for (ChangeItem item : changeItemList) {
if (index > 0) {
startRow += index;
// insert new row
// set the style for each cell
insertRow(workSheet, startRow - 1, 1);
workSheet.addMergedRegion(new CellRangeAddress(7 + index, 7 + index, 1, 4));
workSheet.addMergedRegion(new CellRangeAddress(7 + index, 7 + index, 5, 9));
workSheet.addMergedRegion(new CellRangeAddress(7 + index, 7 + index, 10, 11));
curRow = workSheet.getRow(startRow);
}
curRow.getCell((short) 1).setCellValue(item.getOldInfo());
curRow.getCell((short) 5).setCellValue(item.getNewInfo());
if (displayEnable) {
curRow.getCell((short) 10).setCellValue(item.getRemarks());
} else {
curRow.getCell((short) 10).setCellValue("/");
}
index++;
}
} else {
}
for (short i = startRow; i < workSheet.getLastRowNum(); i++) {
if (this.getCellStringValue(workSheet.getRow(i).getCell((short) 1)).indexOf("附件") >= 0) {
// 附件
workSheet.getRow(i).getCell((short) 2).setCellValue("有");
}
if (this.getCellStringValue(workSheet.getRow(i).getCell((short) 1)).indexOf("签核角色") >= 0) {
ContactSign contactSign = cf.getContactSign();
List<SignContentItem> contactSignContentList = JSON.parseArray(contactSign.getSignContent(), SignContentItem.class);
short j = 0;
for (SignContentItem item : contactSignContentList) {
j++;
String checkRole = roleService.findById(item.getRoleId()).getRoleName();
workSheet.getRow(i + j).getCell((short) 1).setCellValue(new HSSFRichTextString(checkRole));
workSheet.getRow(i + j).getCell((short) 2).setCellValue(new HSSFRichTextString(item.getUser()));
String date = item.getDate() == null ? "" : formatter.format(item.getDate());
workSheet.getRow(i + j).getCell((short) 3).setCellValue(new HSSFRichTextString(date));
// 成本核算员跟财务经理的意见,只给销售人员和王总看。
if (item.getRoleId() == 13 || item.getRoleId() == 14) {
if (displayEnable) {
workSheet.getRow(i + j).getCell((short) 4).setCellValue(new HSSFRichTextString(item.getComment()));
} else {
workSheet.getRow(i + j).getCell((short) 4).setCellValue(new HSSFRichTextString("/"));
}
} else {
workSheet.getRow(i + j).getCell((short) 4).setCellValue(new HSSFRichTextString(item.getComment()));
}
workSheet.getRow(i + j).getCell((short) 11).setCellValue(new HSSFRichTextString(this.getResultString(item.getShenHeEnabled(), item.getResult())));
if (!item.getShenHeEnabled()) {
for (int q = 0; q < 11; q++) {
HSSFCellStyle style = workSheet.getRow(i + j).getCell(q + 1).getCellStyle();
style.setFillBackgroundColor((short) IndexedColors.GREY_80_PERCENT.index);
workSheet.getRow(i + j).getCell(q + 1).setCellStyle(style);
}
}
}
break;
}
}
String fileName = cf.getContactForm().getNum().replaceAll("/", "-") + ".xls";
downloadPath = lxdAttachedSavedDir + fileName;
// downloadPathForNginx = "/excel/" + fileName;
downloadPathForNginx = "/" + fileName;
out = new FileOutputStream(downloadPath);
wb.write(out);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fs.close();
pfs.close();
out.close();
wb.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if ("".equals(downloadPath)) {
return ResultGenerator.genFailResult("生成文件失败!");
} else {
return ResultGenerator.genSuccessResult(downloadPathForNginx);
}
}
use of com.eservice.api.model.contact_form.ContactFormAllInfo 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();
}
Aggregations