ThirdPartyCompanyServiceImpl.java 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. package com.goafanti.organization.service.impl;
  2. import java.io.UnsupportedEncodingException;
  3. import java.lang.reflect.InvocationTargetException;
  4. import java.math.BigDecimal;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.Date;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. import javax.mail.MessagingException;
  13. import javax.servlet.http.HttpServletResponse;
  14. import org.apache.commons.beanutils.BeanUtils;
  15. import org.apache.commons.collections4.map.HashedMap;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import com.goafanti.admin.bo.AdminListBo;
  20. import com.goafanti.common.bo.EmailBo;
  21. import com.goafanti.common.bo.Result;
  22. import com.goafanti.common.constant.AFTConstants;
  23. import com.goafanti.common.dao.AdminMapper;
  24. import com.goafanti.common.dao.CompanyLibraryMapper;
  25. import com.goafanti.common.dao.FinancialPaymentMapper;
  26. import com.goafanti.common.dao.OfficialFeePriceMapper;
  27. import com.goafanti.common.dao.PatentPriceMapper;
  28. import com.goafanti.common.dao.PaymentLogMapper;
  29. import com.goafanti.common.dao.PaymentNodeMapper;
  30. import com.goafanti.common.dao.SoftWritingPriceMapper;
  31. import com.goafanti.common.dao.TOrderMidMapper;
  32. import com.goafanti.common.dao.TOrderOutsourceMapper;
  33. import com.goafanti.common.dao.TOrderPaymentMapper;
  34. import com.goafanti.common.dao.TOrderTaskMapper;
  35. import com.goafanti.common.dao.TTaskMidMapper;
  36. import com.goafanti.common.dao.ThirdPartyCompanyMapper;
  37. import com.goafanti.common.enums.NoticeStatus;
  38. import com.goafanti.common.model.Admin;
  39. import com.goafanti.common.model.CompanyLibrary;
  40. import com.goafanti.common.model.Notice;
  41. import com.goafanti.common.model.OfficialFeePrice;
  42. import com.goafanti.common.model.PatentPrice;
  43. import com.goafanti.common.model.PaymentLog;
  44. import com.goafanti.common.model.PaymentNode;
  45. import com.goafanti.common.model.SoftWritingPrice;
  46. import com.goafanti.common.model.TOrderPayment;
  47. import com.goafanti.common.model.TOrderTask;
  48. import com.goafanti.common.model.TTaskMid;
  49. import com.goafanti.common.model.ThirdPartyCompany;
  50. import com.goafanti.common.utils.AsyncUtils;
  51. import com.goafanti.common.utils.DateUtils;
  52. import com.goafanti.common.utils.excel.NewExcelUtil;
  53. import com.goafanti.core.mybatis.BaseMybatisDao;
  54. import com.goafanti.core.mybatis.page.Pagination;
  55. import com.goafanti.core.shiro.token.TokenManager;
  56. import com.goafanti.order.bo.TOrderTaskDetailBo;
  57. import com.goafanti.order.enums.NewOrderDunType;
  58. import com.goafanti.order.enums.NewProjectStatus;
  59. import com.goafanti.organization.bo.InputNodeList;
  60. import com.goafanti.organization.bo.InputPaymentList;
  61. import com.goafanti.organization.bo.InputPaymentNode;
  62. import com.goafanti.organization.bo.InuptFinancialPayment;
  63. import com.goafanti.organization.bo.NoticeInformationBo;
  64. import com.goafanti.organization.bo.OutPaymentLog;
  65. import com.goafanti.organization.bo.OutPaymentNode;
  66. import com.goafanti.organization.bo.OutThirdPartyCompany;
  67. import com.goafanti.organization.bo.ProjectTypePuls;
  68. import com.goafanti.organization.bo.outFinancialPayment;
  69. import com.goafanti.organization.bo.outNodeList;
  70. import com.goafanti.organization.bo.outPaymentList;
  71. import com.goafanti.organization.bo.outPaymentListFinance;
  72. import com.goafanti.organization.bo.outPaymentListPatent;
  73. import com.goafanti.organization.bo.outProjectBo;
  74. import com.goafanti.organization.bo.outOrderPayment;
  75. import com.goafanti.organization.service.ThirdPartyCompanyService;
  76. @Service
  77. public class ThirdPartyCompanyServiceImpl extends BaseMybatisDao<ThirdPartyCompanyMapper> implements ThirdPartyCompanyService {
  78. @Autowired
  79. private ThirdPartyCompanyMapper thirdPartyCompanyMapper;
  80. @Autowired
  81. private CompanyLibraryMapper companyLibraryMapper;
  82. @Autowired
  83. private PaymentNodeMapper paymentNodeMapper;
  84. @Autowired
  85. private TOrderPaymentMapper tOrderPaymentMapper;
  86. @Autowired
  87. private PaymentLogMapper paymentLogMapper;
  88. @Autowired
  89. private AdminMapper adminMapper;
  90. @Autowired
  91. private FinancialPaymentMapper financialPaymentMapper;
  92. @Autowired
  93. private TOrderTaskMapper tOrderTaskMapper;
  94. @Autowired
  95. private SoftWritingPriceMapper softWritingPriceMapper;
  96. @Autowired
  97. private OfficialFeePriceMapper officialFeePriceMapper;
  98. @Autowired
  99. private PatentPriceMapper patentPriceMapper;
  100. @Autowired
  101. private TOrderOutsourceMapper tOrderOutsourceMapper;
  102. @Autowired
  103. private TTaskMidMapper tTaskMidMapper;
  104. @Autowired
  105. private TOrderMidMapper tOrderMidMapper;
  106. @Autowired
  107. private AsyncUtils asyncUtils;
  108. @Override
  109. public int addCompany(ThirdPartyCompany t,Integer calculation,Integer type) {
  110. CompanyLibrary c=new CompanyLibrary();
  111. String aid=TokenManager.getAdminId();
  112. if(calculation==0) {
  113. List<Integer> list=companyLibraryMapper.selectName(t.getCompanyName(),1,aid);
  114. if (list.size()<1) {
  115. c.setCompanyName(t.getCompanyName());
  116. c.setAid(aid);
  117. c.setType(1);//类型 0软著 1其他 2专利
  118. companyLibraryMapper.insertSelectiveGetId(c);
  119. t.setCid(c.getId());
  120. }else {
  121. t.setCid(list.get(0));
  122. }
  123. t.setTotalAmount(t.getUnitPrice().multiply(new BigDecimal(t.getQuantity())));
  124. }
  125. if (type!=null&&type==1) {
  126. tOrderTaskMapper.updateAddCostAmount(t.getTid(), t.getTotalAmount());
  127. tOrderMidMapper.updateAddCostAmount(t.getTid(), t.getTotalAmount());
  128. }
  129. thirdPartyCompanyMapper.insertSelective(t);
  130. return 1;
  131. }
  132. @Override
  133. public int updateCompany(ThirdPartyCompany t,Integer calculation) {
  134. if (calculation==0) {//0其他 1计算
  135. CompanyLibrary c=new CompanyLibrary();
  136. String aid=TokenManager.getAdminId();
  137. List<Integer> list=companyLibraryMapper.selectName(t.getCompanyName(),1,aid);
  138. if (list.size()<1) {
  139. c.setCompanyName(t.getCompanyName());
  140. c.setAid(aid);
  141. c.setType(1);//0系统 1录入
  142. companyLibraryMapper.insertSelectiveGetId(c);
  143. t.setCid(c.getId());
  144. }else {
  145. t.setCid(list.get(0));
  146. }
  147. t.setTotalAmount(t.getUnitPrice().multiply(new BigDecimal(t.getQuantity())));
  148. }
  149. thirdPartyCompanyMapper.updateByPrimaryKeySelective(t);
  150. return 1;
  151. }
  152. @Override
  153. public List<CompanyLibrary> selectVague(String name,Integer type) {
  154. String aid = null;
  155. if(type==null)type=1;
  156. if (type==1) aid=TokenManager.getAdminId();
  157. return companyLibraryMapper.selectVague(name,type,aid);
  158. }
  159. @Override
  160. public int addPaymentNode(InputPaymentNode p) {
  161. if (StringUtils.isNoneBlank(p.getPartyTimes())) {
  162. p.setPartyTime(DateUtils.StringToDate(p.getPartyTimes(), AFTConstants.YYYYMMDD));
  163. }
  164. return paymentNodeMapper.insertSelective(p);
  165. }
  166. @Override
  167. public boolean addNodeCheck(InputPaymentNode p) {
  168. ThirdPartyCompany t=thirdPartyCompanyMapper.selectByPrimaryKey(p.getCid());
  169. List<OutPaymentNode> list=paymentNodeMapper.selectByTidAndCid(p.getTid(),p.getCid());
  170. BigDecimal sum=p.getTotalAmount()==null?new BigDecimal(0):p.getTotalAmount();
  171. for (OutPaymentNode pn : list) {
  172. if (p.getId()==null || !pn.getId().equals(p.getId())) {
  173. sum=sum.add(pn.getTotalAmount());
  174. }
  175. }
  176. if(p.getUnitPrice()==null)p.setUnitPrice(t.getUnitPrice());
  177. if(p.getTotalAmount()==null)p.setTotalAmount(p.getUnitPrice().multiply(new BigDecimal(p.getQuantity())));
  178. if(p.getTotalAmount()==null)p.setTotalAmount(new BigDecimal(0));
  179. if (p.getTotalAmount().compareTo(t.getTotalAmount())>0) {
  180. return true;
  181. }
  182. if (sum.compareTo(t.getTotalAmount())>0) {
  183. return true;
  184. }
  185. return false;
  186. }
  187. @Override
  188. public int updatePaymentNode(InputPaymentNode p) {
  189. if (StringUtils.isNoneBlank(p.getPartyTimes())) {
  190. p.setPartyTime(DateUtils.StringToDate(p.getPartyTimes(), AFTConstants.YYYYMMDD));
  191. }
  192. if (p.getDunType()!=0) {
  193. PaymentNode pn=paymentNodeMapper.selectByPrimaryKey(p.getId());
  194. pn.setPartyTime(null);
  195. paymentNodeMapper.updateByPrimaryKey(pn);
  196. }
  197. return paymentNodeMapper.updateByPrimaryKeySelective(p);
  198. }
  199. @Override
  200. public List<OutThirdPartyCompany> selectCompany(Integer tid) {
  201. List<OutThirdPartyCompany> list=thirdPartyCompanyMapper.selectByTid(tid);
  202. if (!TokenManager.hasRole(AFTConstants.FINANCE)&&
  203. !TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)&&
  204. !TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)&&
  205. !TokenManager.hasRole(AFTConstants.OUTSOURCE_AUDITOR)) {
  206. outProjectBo op =null;
  207. if(!list.isEmpty()) op=tOrderOutsourceMapper.selectByTid(tid);
  208. //外包type
  209. for (OutThirdPartyCompany oc : list) {
  210. // start_type 0外包 1供应商
  211. if (oc.getStartType()==1) {
  212. //project_tyoe 0 正常 1专利 2软著 3审计
  213. if(op==null)op=new outProjectBo();
  214. if(op.getProjectType()==null)op.setProjectType(0);
  215. //patent_type 专利类型 0申请/变更/转让 1买卖
  216. if((op.getProjectType()==1&&oc.getPatentType()==0)
  217. || op.getProjectType()==2 ) {
  218. oc.setUnitPrice("***");
  219. oc.setTotalAmount("***");
  220. }
  221. }
  222. }
  223. }
  224. return list;
  225. }
  226. @Override
  227. public List<OutPaymentNode> selectPaymentNode(Integer tid) {
  228. List<OutPaymentNode> list=paymentNodeMapper.selectByTid(tid,null);
  229. return list;
  230. }
  231. @Override
  232. public int deleteCompany(String id) {
  233. if (id.contains(",")) {
  234. String []ids =id.split(",");
  235. for (String s : ids) {
  236. thirdPartyCompanyMapper.deleteByPrimaryKey(Integer.valueOf(s));
  237. }
  238. }else {
  239. Integer tpcId=Integer.valueOf(id);
  240. ThirdPartyCompany tpc=thirdPartyCompanyMapper.selectByPrimaryKey(tpcId);
  241. thirdPartyCompanyMapper.deleteByPrimaryKey(tpcId);
  242. List<outOrderPayment> list=tOrderPaymentMapper.selectList(tpcId, null, null);
  243. for (outOrderPayment o : list) {
  244. TOrderPayment t=new TOrderPayment();
  245. t.setId(o.getId());
  246. t.setStatus(4);
  247. tOrderPaymentMapper.updateByPrimaryKeySelective(t);
  248. }
  249. paymentNodeMapper.deleteByParam(tpcId,null);
  250. sumTaskCost(tpc.getTid());
  251. updateCountByTid(tpc.getId());
  252. }
  253. return 1;
  254. }
  255. public void sumTaskCost(Integer tid) {
  256. List<OutThirdPartyCompany>list=thirdPartyCompanyMapper.selectByTid(tid);
  257. BigDecimal tCount=new BigDecimal(0);
  258. for (OutThirdPartyCompany op : list) {
  259. tCount=tCount.add(new BigDecimal(op.getTotalAmount()));
  260. }
  261. tTaskMidMapper.updateCostAmount(tid,tCount);
  262. }
  263. @Override
  264. public int deletePaymentNode(String ids) {
  265. if (ids.contains(",")) {
  266. String []ids2 =ids.split(",");
  267. for (String s : ids2) {
  268. paymentNodeMapper.deleteByPrimaryKey(Integer.valueOf(s));
  269. }
  270. }else {
  271. Integer id=Integer.valueOf(ids);
  272. paymentNodeMapper.deleteByPrimaryKey(Integer.valueOf(id));
  273. List<outOrderPayment> list=tOrderPaymentMapper.selectList(null, id, null);
  274. for (outOrderPayment o : list) {
  275. TOrderPayment t=new TOrderPayment();
  276. t.setId(o.getId());
  277. t.setStatus(4);
  278. tOrderPaymentMapper.updateByPrimaryKeySelective(t);
  279. }
  280. }
  281. return 1;
  282. }
  283. @Override
  284. public int addOrderPayment(TOrderPayment p) {
  285. p.setStatus(0);
  286. p.setProcessStatus(1);
  287. AdminListBo a =adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  288. p.setAid(a.getId());
  289. p.setAname(a.getName());
  290. if (p.getChooseType()==2) {
  291. TOrderTask t=new TOrderTask();
  292. t.setId(p.getTid());
  293. t.setCheckStatus(3);
  294. tOrderTaskMapper.updateByPrimaryKeySelective(t);
  295. }
  296. tOrderPaymentMapper.insertSelectiveGetId(p);
  297. NoticeInformationBo ni=financialPaymentMapper.selectBypidGetNotice(p.getId());
  298. addNoticAndSendEmail(ni,a,NoticeStatus.PAYMENT_NODE.getCode());
  299. PaymentLog pl=new PaymentLog(p.getId(),0,"发起付款:"+p.getRemarks(),a.getId(),a.getName());
  300. paymentLogMapper.insertSelective(pl);
  301. return 1;
  302. }
  303. @Override
  304. public outOrderPayment OrderPaymentDetails(Integer id) {
  305. TOrderPayment tp=tOrderPaymentMapper.selectByPrimaryKey(id);
  306. Integer type=tp.getChooseType();
  307. outOrderPayment op=tOrderPaymentMapper.selectByidGetDetails(id);
  308. op.setChooseType(type);
  309. ThirdPartyCompany tpc=thirdPartyCompanyMapper.selectByPrimaryKey(tp.getTpcId());
  310. if(tp.getChooseType()!=2&&tpc!=null&&!op.getCompanyName().equals(tpc.getCompanyName()))op.setCompanyName(op.getCompanyName()+"("+tpc.getCompanyName()+")");
  311. if (type==0&&tp.getStatus()!=4) {//支付种类 0第三方 1催款 2官费
  312. op.setInitialQuantity(tpc.getQuantity());
  313. op.setInitialTotalAmount(tpc.getTotalAmount().toString());
  314. op.setInitialUnitPrice(tpc.getUnitPrice().toString());
  315. op.setInitialPaymentAmount(tpc.getPartyAmount().toString());
  316. }else if (type==1&&tp.getStatus()!=4) {
  317. PaymentNode pn=paymentNodeMapper.selectByPrimaryKey(tp.getNodeId());
  318. op.setInitialQuantity(pn.getQuantity());
  319. op.setInitialTotalAmount(pn.getTotalAmount().toString());
  320. op.setInitialUnitPrice(pn.getUnitPrice().toString());
  321. op.setInitialPaymentAmount(pn.getPartyAmount().toString());
  322. }else if (type==2) {
  323. ProjectTypePuls tt=thirdPartyCompanyMapper.selectByTidGetDtails(tp.getTid());
  324. op.setInitialQuantity(tt.getQuantity());
  325. if (tt.getCostReduction()==1) {
  326. op.setInitialUnitPrice(tt.getProportion85().toEngineeringString());
  327. }else {
  328. op.setInitialUnitPrice(tt.getOfficialAmount().toEngineeringString());
  329. }
  330. BigDecimal count=new BigDecimal(op.getInitialQuantity()).multiply(new BigDecimal(op.getInitialUnitPrice()));
  331. op.setInitialTotalAmount(count.toEngineeringString());
  332. }
  333. // if (!TokenManager.hasRole(AFTConstants.FINANCE)&&
  334. // !TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)&&
  335. // !TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)&&
  336. // !TokenManager.hasRole(AFTConstants.OUTSOURCE_AUDITOR)) {
  337. // outProjectBo ob=tOrderOutsourceMapper.selectByTid(tp.getTid());
  338. // if (ob!=null &&ob.getStartType()!=null&& ob.getStartType()==1) {
  339. // if((ob.getProjectType()==1&&ob.getPatentType()==0)||(ob.getProjectType()==2)) {
  340. // op.setInitialUnitPrice("***");
  341. // op.setInitialTotalAmount("***");
  342. // }
  343. // }
  344. //
  345. // }
  346. return op;
  347. }
  348. @Override
  349. public int updateOrderPayment(TOrderPayment p) {
  350. TOrderPayment tp=new TOrderPayment();
  351. tp.setId(p.getId());
  352. tp.setRemarks(p.getRemarks());
  353. tp.setStatus(p.getStatus());
  354. tp.setQuantity(p.getQuantity());
  355. Integer type=NoticeStatus.PAYMENT_NODE.getCode();
  356. String auditStr="重新发起付款:";
  357. //状态 0审核 1待支付 2驳回 3已支付 4取消
  358. if (p.getStatus()==0) {
  359. tp.setApplicationAmount(p.getApplicationAmount());
  360. tp.setChooseType(p.getChooseType());
  361. tp.setPaymentType(p.getPaymentType());
  362. tp.setPaymentAmount(p.getPaymentAmount());
  363. tp.setPaymentStatus(p.getPaymentStatus());
  364. }else if (p.getStatus()==1) {
  365. type= NoticeStatus.PAYMENT_YES.getCode();
  366. tp.setApplicationAmount(p.getApplicationAmount());
  367. auditStr="审核通过:";
  368. }else if(p.getStatus()==2) {
  369. type= NoticeStatus.PAYMENT_NO.getCode();
  370. tp.setApplicationAmount(p.getApplicationAmount());
  371. auditStr="审核驳回:";
  372. }else if (p.getStatus()==3) {
  373. type=NoticeStatus.PAYMENT_COMPLETE.getCode();
  374. tp.setPaymentAmount(p.getPaymentAmount()!=null?p.getPaymentAmount():p.getApplicationAmount());
  375. confirmPayment(p);
  376. auditStr="审核完成";
  377. }else if(p.getStatus()==4) {
  378. auditStr="付款取消";
  379. }
  380. NoticeInformationBo ni=financialPaymentMapper.selectBypidGetNotice(p.getId());
  381. AdminListBo a =adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  382. addNoticAndSendEmail(ni,a,type);
  383. PaymentLog pl=new PaymentLog(p.getId(),p.getStatus(),auditStr+p.getAuditNotes()==null?"":p.getAuditNotes(),a.getId(),a.getName());
  384. paymentLogMapper.insertSelective(pl);
  385. return tOrderPaymentMapper.updateByPrimaryKeySelective(tp);
  386. }
  387. private void confirmPayment(TOrderPayment p) {
  388. //如果确定支付
  389. int flag=0;
  390. TOrderPayment tp=tOrderPaymentMapper.selectByPrimaryKey(p.getId());
  391. ThirdPartyCompany tpc=new ThirdPartyCompany();
  392. if (p.getPaymentAmount()==null||p.getPaymentAmount().compareTo(new BigDecimal(0))==0) {
  393. p.setPaymentAmount(tp.getApplicationAmount());
  394. }
  395. if(tp.getChooseType()==0){
  396. tpc=thirdPartyCompanyMapper.selectByPrimaryKey(tp.getTpcId());
  397. }else if (tp.getChooseType()==1) {
  398. PaymentNode pn=paymentNodeMapper.selectByPrimaryKey(tp.getNodeId());
  399. BigDecimal count=pn.getTotalAmount();
  400. BigDecimal party=pn.getPartyAmount();
  401. party=party.add(p.getPaymentAmount());
  402. if (party.compareTo(new BigDecimal(0))==0) {
  403. flag=0;
  404. }else if (party.compareTo(count)==0) {
  405. flag=2;
  406. }else if (party.compareTo(count)==-1) {
  407. flag=1;
  408. }
  409. pn.setStatus(flag);
  410. pn.setPartyAmount(p.getPaymentAmount());
  411. paymentNodeMapper.updateByPrimaryKeySelective(pn);
  412. tpc=thirdPartyCompanyMapper.selectByPrimaryKey(pn.getCid());
  413. }
  414. if(tp.getChooseType()!=2){
  415. tpc.setPartyAmount(tpc.getPartyAmount().add(p.getPaymentAmount()));
  416. thirdPartyCompanyMapper.updateByPrimaryKeySelective(tpc);
  417. }
  418. p.setPaymentAmount(tp.getApplicationAmount());
  419. financialPaymentMapper.updateOrderCost(p.getId(),p.getPaymentAmount());
  420. }
  421. @Override
  422. public List<OutPaymentLog> selectPaymentLog(Integer id) {
  423. return paymentLogMapper.selectByPid(id);
  424. }
  425. @Override
  426. public List<outOrderPayment> selectOrderPayment(Integer id) {
  427. List<outOrderPayment> list=tOrderPaymentMapper.selectByTid(id,null,0);
  428. // if (!TokenManager.hasRole(AFTConstants.FINANCE)&&
  429. // !TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)&&
  430. // !TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)&&
  431. // !TokenManager.hasRole(AFTConstants.OUTSOURCE_AUDITOR)) {
  432. // outProjectBo op =null;
  433. // if(!list.isEmpty()) op=tOrderOutsourceMapper.selectByTid(id);
  434. // if (op!=null &&op.getStartType()!=null&&op.getStartType()==1) {
  435. // if((op.getProjectType()==1&&op.getPatentType()==0)||(op.getProjectType()==2)) {
  436. // for (outOrderPayment oc : list) {
  437. // if (oc.getChooseType()!=2) {
  438. // oc.setApplicationAmount("***");
  439. // }
  440. // }
  441. // }
  442. // }
  443. // }
  444. return list;
  445. }
  446. @Override
  447. public int addfinancialPayment(InuptFinancialPayment f) {
  448. f.setPaymentTime(DateUtils.StringToDate(f.getPaymentTimes(), AFTConstants.YYYYMMDD));
  449. financialPaymentMapper.insertSelectiveGetId(f);
  450. return f.getId();
  451. }
  452. @Override
  453. public List<outFinancialPayment> selectfinancialPayment(Integer id) {
  454. return financialPaymentMapper.selectByPid(id);
  455. }
  456. public void addNoticAndSendEmail(NoticeInformationBo in,AdminListBo a,Integer type) {
  457. String str=NoticeStatus.getValueByCode(type)+": 订单编号 -"+in.getOrderNo()+
  458. ",客户名称:"+in.getBuyerName()+", 操作人:"+a.getName()+"-"+a.getDepartmentName()+"。";
  459. Notice n =new Notice();
  460. EmailBo bo = new EmailBo(NoticeStatus.getValueByCode(type), a.getEmail(), a.getDepartmentName(), a.getName(),
  461. in.getOrderNo(), in.getSalesmanName());
  462. n.setId(UUID.randomUUID().toString());
  463. if (type==NoticeStatus.PAYMENT_NODE.getCode()||type==NoticeStatus.PAYMENT_NODE.getCode()) {
  464. n.setAid(in.getFinanceId());
  465. bo.setAddress(in.getFinanceEmail());
  466. } else if(type==NoticeStatus.PAYMENT_NO.getCode()||type==NoticeStatus.PAYMENT_YES.getCode()
  467. ||type==NoticeStatus.PAYMENT_COMPLETE.getCode()) {
  468. n.setAid(in.getTechId());
  469. bo.setAddress(in.getTechEmail());
  470. }
  471. n.setNoticeType(type);
  472. n.setContent(str);
  473. n.setReaded(0);//未读
  474. asyncUtils.addNotice(n);
  475. if(StringUtils.isNotBlank(a.getEmail())) {
  476. try {
  477. asyncUtils.send(bo);
  478. } catch (UnsupportedEncodingException | MessagingException e) {
  479. e.printStackTrace();
  480. }
  481. }
  482. }
  483. @Override
  484. public int checkPayment(TOrderPayment p) {
  485. //没有填写申请金额的情况下计算金额
  486. checkGetAmount(p);
  487. if (p.getChooseType()==2) {
  488. TOrderTask tot=tOrderTaskMapper.selectByPrimaryKey(p.getTid());
  489. List<outOrderPayment> list2=tOrderPaymentMapper.selectByTid(p.getTid(),p.getChooseType(),1);
  490. int x=p.getQuantity();
  491. for (outOrderPayment out : list2) {
  492. x+=out.getQuantity();
  493. }
  494. if (x>tot.getCommodityQuantity()) {
  495. return -2;
  496. }
  497. }else {
  498. BigDecimal total=new BigDecimal(0);
  499. BigDecimal a=p.getApplicationAmount()==null?new BigDecimal(0):p.getApplicationAmount();
  500. List<outOrderPayment> list=new ArrayList<>();
  501. //支付种类 0第三方 1催款2官费
  502. if (p.getChooseType()==0) {
  503. //首先不能大于第三方
  504. list=tOrderPaymentMapper.selectList(p.getTpcId(),null,p.getChooseType());
  505. }else if (p.getChooseType()==1) {
  506. list=tOrderPaymentMapper.selectList(null,p.getNodeId(),p.getChooseType());
  507. }
  508. for (outOrderPayment o : list) {
  509. a=a.add(new BigDecimal(o.getApplicationAmount()));
  510. }
  511. if (p.getChooseType()==0) {
  512. ThirdPartyCompany t=thirdPartyCompanyMapper.selectByPrimaryKey(p.getTpcId());
  513. total=t.getTotalAmount();
  514. }else if (p.getChooseType()==1) {
  515. PaymentNode n=paymentNodeMapper.selectByPrimaryKey(p.getNodeId());
  516. total=n.getTotalAmount();
  517. }
  518. if (a.compareTo(total) == 1) {
  519. return -1;
  520. }
  521. }
  522. return 0;
  523. }
  524. @Override
  525. public boolean checkprojectDun(TOrderPayment p) {
  526. PaymentNode pn=paymentNodeMapper.selectByPrimaryKey(p.getNodeId());
  527. TOrderTaskDetailBo tt=tOrderTaskMapper.getOrderTaskDetail(p.getTid().toString());
  528. // 项目状态 0-项目待提交 1-项目已提交,2-项目评审,3-项目立项,4-项目公示,5-项目抽查,6-项目备案,7-项目下证,8-项目验收,
  529. // 9-项目拨款 10- 项目进度10% 11- 项目进度30% 12- 项目进度70%
  530. if(pn.getDunType()==1) {
  531. return false;
  532. }
  533. if (pn.getDunType()==0&&pn.getPartyTime().getTime()<new Date().getTime()) {//如果自定义则看触发时间
  534. return false;
  535. }else if (NewOrderDunType.CGZH_WC.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  536. &&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())) {
  537. return false;
  538. }else if (NewOrderDunType.COMMON_NGS.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  539. &&(tt.getProjectStatus()>=NewProjectStatus.YTJ.getCode()&&tt.getProjectStatus()<=NewProjectStatus.YWCXZ.getCode()
  540. ||tt.getProjectStatus()>=NewProjectStatus.YBH.getCode())) {
  541. return false;
  542. }else if (NewOrderDunType.COMMON_XZ.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  543. &&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())) {
  544. return false;
  545. } else if (NewOrderDunType.KJXM_LX.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  546. &&(tt.getProjectStatus()>=NewProjectStatus.YLX.getCode()&&tt.getProjectStatus()<=NewProjectStatus.LXYBK.getCode())) {
  547. return false;
  548. } else if (NewOrderDunType.KJXM_BK.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  549. &&(tt.getProjectStatus()<=NewProjectStatus.LXYBK.getCode())) {
  550. return false;
  551. } else if (NewOrderDunType.KJJR_BK.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  552. &&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())) {
  553. return false;
  554. } else if (NewOrderDunType.RJKF_LX.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  555. &&((tt.getProjectStatus()>=NewProjectStatus.YTJ.getCode()&&tt.getProjectStatus()<=NewProjectStatus.YWCXZ.getCode())
  556. ||tt.getProjectStatus()>=NewProjectStatus.YBH.getCode())) {
  557. return false;
  558. } else if (NewOrderDunType.RJKF_WZ.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  559. &&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())) {
  560. return false;
  561. } else if (NewOrderDunType.ZSCQ_GS_SL_XZ.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())) {
  562. // 0 正常 1专利 2软著 3审计 4双软 5高新 6商标
  563. if (tt.getBpType()==1
  564. &&(tt.getProjectStatus()==NewProjectStatus.YTJ.getCode()&&tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode()
  565. ||tt.getProjectStatus()==NewProjectStatus.YBH.getCode())) {
  566. return false;
  567. }else if (tt.getBpType()!=1&&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())){
  568. return false;
  569. }
  570. } else if (NewOrderDunType.ZSCQ_XZ.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  571. &&(tt.getProjectStatus()==NewProjectStatus.YWCXZ.getCode())) {
  572. return false;
  573. } else if (NewOrderDunType.GX_YGS.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  574. &&(tt.getProjectStatus()>=NewProjectStatus.YNGS.getCode()&&tt.getProjectStatus()<=NewProjectStatus.YXZ.getCode())) {
  575. return false;
  576. } else if (NewOrderDunType.GX_YXZ.getCode()==Integer.valueOf(""+pn.getProjectType()+pn.getDunType())
  577. &&(tt.getProjectStatus()==NewProjectStatus.YXZ.getCode())) {
  578. return false;
  579. }
  580. return true;
  581. }
  582. @SuppressWarnings("unchecked")
  583. @Override
  584. public Pagination<outPaymentList> selectPaymentList(InputPaymentList i) {
  585. Map<String, Object> map =new HashMap<>();
  586. map.put("aid", TokenManager.getAdminId());
  587. if (i.getContractNo()!=null)map.put("contractNo", i.getContractNo());
  588. if (i.getOrderNo()!=null)map.put("orderNo", i.getOrderNo());
  589. if (i.getUserName()!=null)map.put("userName", i.getUserName());
  590. if (i.getDepId()!=null)map.put("depId", i.getDepId());
  591. if (i.getAname()!=null)map.put("aname", i.getAname());
  592. if (i.getFinanceName()!=null)map.put("financeName", i.getFinanceName());
  593. if (i.getCname()!=null)map.put("cname", i.getCname());
  594. if (i.getPname()!=null)map.put("pname", i.getPname());
  595. if (i.getStatus()!=null)map.put("status", i.getStatus());
  596. if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)) {
  597. map.put("lvl", 1);
  598. }else if (TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.VICE_CEO)||
  599. TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  600. TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)) {
  601. map.put("lvl", 2);
  602. }else if (TokenManager.hasRole(AFTConstants.TECH)||TokenManager.hasRole(AFTConstants.TECH_MANAGER)) {
  603. map.put("lvl", 3);
  604. }else if(TokenManager.hasRole(AFTConstants.PATENT_AUDITOR))
  605. {
  606. map.put("lvl", 4);
  607. }else {
  608. map.put("lvl", 0);
  609. }
  610. Pagination<outPaymentList> p=(Pagination<outPaymentList>)findPage("selectPaymentList","selectPaymentCount",
  611. map,i.getPageNo(),i.getPageSize());
  612. return p;
  613. }
  614. @SuppressWarnings("unchecked")
  615. @Override
  616. public Pagination<outNodeList> selectPaymentList(InputNodeList i) {
  617. Map<String, Object> map =new HashMap<>();
  618. map.put("aid", TokenManager.getAdminId());
  619. if (i.getContractNo()!=null)map.put("contractNo", i.getContractNo());
  620. if (i.getOrderNo()!=null)map.put("orderNo", i.getOrderNo());
  621. if (i.getUserName()!=null)map.put("userName", i.getUserName());
  622. if (i.getCname()!=null)map.put("cname", i.getCname());
  623. if (i.getPname()!=null)map.put("pname", i.getPname());
  624. if (i.getStatus()!=null)map.put("status", i.getStatus());
  625. if (i.getStartTime()!=null&&i.getEndTime()!=null) {
  626. map.put("startTime", DateUtils.StringToDate(i.getStartTime(), AFTConstants.YYYYMMDD));
  627. map.put("endTime", DateUtils.StringToDate(i.getEndTime()+" 23:59:59", AFTConstants.YYYYMMDDHHMMSS));
  628. }
  629. if (TokenManager.hasRole(AFTConstants.FINANCE)) {
  630. map.put("lvl", 1);
  631. }else if (TokenManager.hasRole(AFTConstants.FINANCE_MANAGER)) {
  632. map.put("lvl", 2);
  633. }else if (TokenManager.hasRole(AFTConstants.FINANCE_ADMIN)||TokenManager.hasRole(AFTConstants.VICE_CEO)||
  634. TokenManager.hasRole(AFTConstants.CED)||TokenManager.hasRole(AFTConstants.SUPERADMIN)||
  635. TokenManager.hasRole(AFTConstants.APPROVAL_DECISION)) {
  636. map.put("lvl", 3);
  637. }else {
  638. map.put("lvl", 0);
  639. }
  640. return (Pagination<outNodeList>)findPage("selectNodeList","selectNodeCount",
  641. map,i.getPageNo(),i.getPageSize());
  642. }
  643. @Override
  644. public int insertSoftWritingPrice(SoftWritingPrice s) {
  645. return softWritingPriceMapper.insertSelective(s);
  646. }
  647. @Override
  648. public int updateSoftWritingPrice(SoftWritingPrice s) {
  649. //
  650. return softWritingPriceMapper.updateByPrimaryKeySelective(s);
  651. }
  652. @Override
  653. public Integer pushSelectByCid(String companyName,int i) {
  654. String aid=null;
  655. if (i==1) {
  656. aid=TokenManager.getAdminId();
  657. }
  658. List<Integer> list=companyLibraryMapper.selectName(companyName,i,aid);
  659. if (list.size()<1) {
  660. CompanyLibrary c=new CompanyLibrary();
  661. c.setCompanyName(companyName);
  662. c.setType(i);
  663. companyLibraryMapper.insertSelectiveGetId(c);
  664. return c.getId();
  665. }else {
  666. return list.get(0);
  667. }
  668. }
  669. @SuppressWarnings("unchecked")
  670. @Override
  671. public Pagination<SoftWritingPrice> listSoftWritingPrice(SoftWritingPrice s, Integer pageNo, Integer pageSize) {
  672. Map<String, Object> map =new HashMap<>();
  673. map.put("s", s);
  674. return (Pagination<SoftWritingPrice>)findPage("softWritingPriceList","softWritingPriceCount",
  675. map,pageNo,pageSize);
  676. }
  677. @Override
  678. public int deleteSoftWritingPrice(Integer id) {
  679. SoftWritingPrice sw=softWritingPriceMapper.selectByPrimaryKey(id);
  680. int i=softWritingPriceMapper.selectCountByCid(sw.getCid());
  681. if (i==1) {
  682. companyLibraryMapper.deleteByPrimaryKey(sw.getCid());
  683. }
  684. return softWritingPriceMapper.deleteByPrimaryKey(id);
  685. }
  686. @Override
  687. public boolean checkSoftWritingPrice(SoftWritingPrice s) {
  688. SoftWritingPrice sw=new SoftWritingPrice();
  689. if(s.getId()!=null)sw=softWritingPriceMapper.selectByPrimaryKey(s.getId());
  690. if (s.getId()!=null) {
  691. s.setCid(sw.getCid());
  692. }
  693. List<SoftWritingPrice>list=softWritingPriceMapper.checkSoftWritingPrice(s);
  694. if (list.size()<1) {
  695. return false;
  696. }else if (list.size()==1&&s.getId()!=null) {
  697. for (SoftWritingPrice ss : list) {
  698. if(ss.getId().equals(s.getId()))return false;
  699. }
  700. }
  701. return true;
  702. }
  703. @Override
  704. public Map<String ,Object> updateGroupPayment(String ids) {
  705. String [] idss=ids.split(",");
  706. List<Integer>elist=new ArrayList<>();
  707. List<Integer> list=new ArrayList<>();
  708. List<Notice> nlist=new ArrayList<>();
  709. Date date=new Date();
  710. for (String s : idss) {
  711. TOrderPayment top=tOrderPaymentMapper.selectByPrimaryKey(Integer.valueOf(s));
  712. if (top!=null&&top.getStatus()==1) {
  713. top.setStatus(3);
  714. top.setPaymentAmount(top.getApplicationAmount());
  715. tOrderPaymentMapper.updateByPrimaryKeySelective(top);
  716. list.add(top.getId());
  717. //做已付款金额计算
  718. confirmPayment(top);
  719. //发送站内通知
  720. Notice n =new Notice();
  721. n.setId(UUID.randomUUID().toString());
  722. NoticeInformationBo ni=financialPaymentMapper.selectBypidGetNotice(Integer.valueOf(s));
  723. AdminListBo a =adminMapper.getDeptNameByAid(TokenManager.getAdminId());
  724. n.setAid(ni.getTechId());
  725. n.setCreateTime(date);
  726. n.setNoticeType(NoticeStatus.PAYMENT_COMPLETE.getCode());
  727. String str=NoticeStatus.getValueByCode(n.getNoticeType())+": 订单编号 -"+ni.getOrderNo()+
  728. ",客户名称:"+ni.getBuyerName()+", 操作人:"+a.getName()+"-"+a.getDepartmentName()+"。";
  729. n.setContent(str);
  730. n.setReaded(0);//未读
  731. nlist.add(n);
  732. }else {
  733. elist.add(Integer.valueOf(s));
  734. }
  735. }
  736. if(!nlist.isEmpty())asyncUtils.addNoticeBatch(nlist);
  737. Map<String ,Object> map=new HashMap<>();
  738. map.put("OK", list);
  739. map.put("fail", elist);
  740. return map;
  741. }
  742. @Override
  743. public int addOfficialFeePrice(OfficialFeePrice o) {
  744. return officialFeePriceMapper.insertSelective(o);
  745. }
  746. @Override
  747. public int updateOfficialFeePrice(OfficialFeePrice o) {
  748. return officialFeePriceMapper.updateByPrimaryKeySelective(o);
  749. }
  750. @Override
  751. public int deleteOfficialFeePrice(Integer id) {
  752. return officialFeePriceMapper.deleteByPrimaryKey(id);
  753. }
  754. @SuppressWarnings("unchecked")
  755. @Override
  756. public Pagination<OfficialFeePrice> listOfficialFeePrice(Integer type, Integer patentType, Integer pageSize, Integer pageNo){
  757. Map<String, Object>map=new HashedMap<String, Object>();
  758. if(type!=null)map.put("type", type);
  759. if(patentType!=null)map.put("patentType", patentType);
  760. return (Pagination<OfficialFeePrice>)findPage("selectListOfficialFeePrice","countListOfficialFeePrice",
  761. map,pageNo,pageSize);
  762. }
  763. @Override
  764. public int deleteFinancialPayment(Integer id) {
  765. return financialPaymentMapper.deleteByPrimaryKey(id);
  766. }
  767. @Override
  768. public void calculationUnitPrice(ThirdPartyCompany t) {
  769. SoftWritingPrice s=new SoftWritingPrice();
  770. s.setCid(t.getCid());
  771. s.setMaterial(t.getMaterial());
  772. s.setUrgent(t.getUrgent());
  773. List<SoftWritingPrice> list=softWritingPriceMapper.checkSoftWritingPrice(s);
  774. for (SoftWritingPrice sw : list) {
  775. t.setUnitPrice(sw.getUnitPrice());
  776. t.setTotalAmount(sw.getUnitPrice().multiply(new BigDecimal(t.getQuantity())));
  777. }
  778. }
  779. @Override
  780. public void calculationPatentUnitPrice(ThirdPartyCompany t) {
  781. PatentPrice p=patentPriceMapper.selectBycid(t.getCid());
  782. // 专利名称 0实用新型 1发明专利 2外观专利 3 其他
  783. BigDecimal unitPrice=null;
  784. if (t.getPatentNameType()==0) {
  785. unitPrice=p.getUtilityModel();
  786. }else if (t.getPatentNameType()==1) {
  787. unitPrice=p.getInventionPatent();
  788. }else if (t.getPatentNameType()==2) {
  789. unitPrice=p.getAppearancePatent();
  790. }
  791. t.setUnitPrice(unitPrice);
  792. t.setTotalAmount(unitPrice.multiply(new BigDecimal(t.getQuantity())));
  793. }
  794. @Override
  795. public int addpatentPrice(PatentPrice p) {
  796. return patentPriceMapper.insertSelective(p);
  797. }
  798. @Override
  799. public int updatepatentPrice(PatentPrice p) {
  800. return patentPriceMapper.updateByPrimaryKeySelective(p);
  801. }
  802. @Override
  803. public int deletepatentPrice(Integer id) {
  804. PatentPrice pp=patentPriceMapper.selectByPrimaryKey(id);
  805. if (pp.getCid()!=null) {
  806. companyLibraryMapper.deleteByPrimaryKey(pp.getCid());
  807. }
  808. return patentPriceMapper.deleteByPrimaryKey(id);
  809. }
  810. @Override
  811. public List<PatentPrice> listpatentPrice(String name) {
  812. return patentPriceMapper.selectlist(name);
  813. }
  814. @Override
  815. public boolean addCompanyChekeNumber(ThirdPartyCompany t) {
  816. TOrderTask tt=tOrderTaskMapper.selectByPrimaryKey(t.getTid());
  817. List<OutThirdPartyCompany> list =thirdPartyCompanyMapper.selectByTid(t.getTid());
  818. Integer count=t.getQuantity();
  819. for (OutThirdPartyCompany out : list) {
  820. if (t.getId()==null||!t.getId().equals(out.getId())) {
  821. count+=out.getQuantity();
  822. }
  823. }
  824. if (tt.getCommodityQuantity()>=count) {
  825. return false;
  826. }
  827. return true;
  828. }
  829. @Override
  830. public void checkGetAmount(TOrderPayment p) {
  831. if(p.getApplicationAmount()==null) {
  832. BigDecimal count=new BigDecimal(0);
  833. if(p.getChooseType()==0) {
  834. ThirdPartyCompany tpc=thirdPartyCompanyMapper.selectByPrimaryKey(p.getTpcId());
  835. count=tpc.getUnitPrice().multiply(new BigDecimal(p.getQuantity()));
  836. } else if (p.getChooseType()==1) {
  837. PaymentNode pn=paymentNodeMapper.selectByPrimaryKey(p.getNodeId());
  838. count=pn.getUnitPrice().multiply(new BigDecimal(p.getQuantity()));
  839. }else if (p.getChooseType()==2) {
  840. ProjectTypePuls ot=thirdPartyCompanyMapper.selectByTidGetDtails(p.getTid());
  841. if (ot.getCostReduction()==0) {
  842. count=ot.getOfficialAmount().multiply(new BigDecimal(p.getQuantity()));
  843. }else {
  844. count=ot.getProportion85().multiply(new BigDecimal(p.getQuantity()));
  845. }
  846. }
  847. p.setApplicationAmount(count);
  848. }
  849. }
  850. @Override
  851. public Result exportPaymentList(HttpServletResponse response, InputPaymentList ip, Integer type) {
  852. if (type==null) type=0;
  853. @SuppressWarnings("unchecked")
  854. List<outPaymentList> list=(List<outPaymentList>) selectPaymentList(ip).getList();
  855. if (type==0) {
  856. List<outPaymentListFinance> list2=new ArrayList<outPaymentListFinance>();
  857. for (outPaymentList out : list) {
  858. outPaymentListFinance out2=new outPaymentListFinance();
  859. try {
  860. BeanUtils.copyProperties(out2, out);
  861. } catch (IllegalAccessException | InvocationTargetException e) {
  862. e.printStackTrace();
  863. }
  864. list2.add(out2);
  865. }
  866. NewExcelUtil<outPaymentListFinance> excelUtil=new NewExcelUtil<>(outPaymentListFinance.class);
  867. return excelUtil.exportExcel(list2, "财务成本列表", response);
  868. }else {
  869. List<outPaymentListPatent> list3=new ArrayList<outPaymentListPatent>();
  870. for (outPaymentList out : list) {
  871. outPaymentListPatent out3=new outPaymentListPatent();
  872. try {
  873. BeanUtils.copyProperties(out3, out);
  874. } catch (IllegalAccessException | InvocationTargetException e) {
  875. e.printStackTrace();
  876. }
  877. StringBuffer s=new StringBuffer();
  878. if (out3.getOfficialCost()!=null&&out3.getOfficialCost()==1) {
  879. s.append("含官费");
  880. if (out3.getCostReduction()!=null&&out3.getCostReduction()==1) {
  881. s.append(",有费减");
  882. }else {
  883. s.append(",无费减");
  884. }
  885. }else {
  886. s.append("不含官费");
  887. }
  888. out3.setOfficialName(s.toString());
  889. list3.add(out3);
  890. }
  891. NewExcelUtil<outPaymentListPatent> p=new NewExcelUtil<>(outPaymentListPatent.class);
  892. return p.exportExcel(list3, "专利成本列表", response);
  893. }
  894. }
  895. @Override
  896. public boolean checkOfficialFeePrice(OfficialFeePrice o) {
  897. OfficialFeePrice x=officialFeePriceMapper.countOfficialFeePrice(o);
  898. if(o.getId()==null&&x!=null) {
  899. return true;
  900. }else if(o.getId()!=null&&o.getId()!=x.getId()) {
  901. return true;
  902. }
  903. return false;
  904. }
  905. @Override
  906. public int pushPaymentExamine(PaymentLog in,String pids) {
  907. Admin a=adminMapper.selectAllByid(TokenManager.getAdminId());
  908. int processStatus=0;
  909. if (in.getStatus()==1) {
  910. processStatus=2;
  911. }else {
  912. processStatus=0;
  913. }
  914. if (in.getPid()!=null) {
  915. in.setAid(a.getId());
  916. in.setAname(a.getName());
  917. TOrderPayment tp=new TOrderPayment();
  918. tp.setId(in.getPid());
  919. tp.setProcessStatus(processStatus);
  920. tOrderPaymentMapper.updateByPrimaryKeySelective(tp);
  921. return paymentLogMapper.insertSelective(in);
  922. }else if(StringUtils.isNotBlank(pids)) {
  923. List<String> ss=Arrays.asList(pids.split(","));
  924. tOrderPaymentMapper.updateByids(ss,processStatus);
  925. paymentLogMapper.insertBatch(ss,a.getAid(),a.getName(),in.getRemarks(),in.getStatus());
  926. return 1;
  927. }else {
  928. return 0;
  929. }
  930. }
  931. @Override
  932. public boolean checkQuantity(TOrderPayment p) {
  933. TOrderPayment tp=tOrderPaymentMapper.selectByPrimaryKey(p.getId());
  934. TOrderTask tt=tOrderTaskMapper.selectByPrimaryKey(tp.getTid());
  935. List<outOrderPayment> list =tOrderPaymentMapper.selectByTid(tt.getId(), 2,1);
  936. Integer q=0;
  937. for (outOrderPayment o : list) {
  938. if (p.getId().equals(o.getId())) {
  939. q+=p.getQuantity();
  940. }else {
  941. q+=o.getQuantity();
  942. }
  943. }
  944. if (q>tt.getCommodityQuantity()) {
  945. return true;
  946. }
  947. return false;
  948. }
  949. @Override
  950. public Map<String, Object> checkThirdParty(Integer id) {
  951. int x =tOrderPaymentMapper.selectByCid(id);
  952. int y = paymentNodeMapper.selectByCid(id);
  953. Integer i=0;
  954. String desc="您已有%s,确定则一并删除。";
  955. Map<String, Object> map=new HashedMap<String, Object>();
  956. StringBuffer src=new StringBuffer();
  957. if(x>0){
  958. i++;
  959. src.append("付款记录、");
  960. }
  961. if(y>0){
  962. i++;
  963. src.append("付款催款、");
  964. }
  965. map.put("code", i);
  966. if (i!=0) {
  967. src.delete(src.length()-1, src.length());
  968. desc=String.format(desc, src);
  969. map.put("desc", desc);
  970. }
  971. return map;
  972. }
  973. @Override
  974. public Object updateCheck(Integer id,Integer type) {
  975. Map<String, Object> map=new HashedMap<String, Object>();
  976. if (type==0) {
  977. Integer i=0;
  978. String desc="您已有%s,确定则一并删除。";
  979. StringBuffer src=new StringBuffer();
  980. List<OutThirdPartyCompany> list=thirdPartyCompanyMapper.selectByTid(id);
  981. List<OutPaymentNode> list2=paymentNodeMapper.selectByTid(id, null);
  982. List<outOrderPayment> list3=tOrderPaymentMapper.selectByTid(id, null,1);
  983. if (!list.isEmpty()) {
  984. src.append("第三方").append("、");
  985. i++;
  986. }
  987. if (!list2.isEmpty()) {
  988. src.append("付款催款").append("、");
  989. i++;
  990. }
  991. if (!list3.isEmpty()) {
  992. src.append("付款记录").append("、");
  993. i++;
  994. }
  995. if (i!=0) {
  996. src.delete(src.length()-1, src.length());
  997. desc=String.format(desc, src);
  998. map.put("desc", desc);
  999. }
  1000. map.put("code", i);
  1001. }else if(type==1) {
  1002. thirdPartyCompanyMapper.deleteByTid(id);
  1003. paymentNodeMapper.deleteByParam(null,id);
  1004. List<outOrderPayment> list=tOrderPaymentMapper.selectByTid(id,null,0);
  1005. List<String> ss=new ArrayList<String>();
  1006. for (outOrderPayment o : list) {
  1007. TOrderPayment t=new TOrderPayment();
  1008. t.setId(o.getId());
  1009. t.setStatus(4);
  1010. ss.add(o.getId().toString());
  1011. tOrderPaymentMapper.updateByPrimaryKeySelective(t);
  1012. }
  1013. Admin a=adminMapper.selectByPrimaryKey(TokenManager.getAdminId());
  1014. if (!list.isEmpty()&&a.getAid()!=null) {
  1015. paymentLogMapper.insertBatch(ss, a.getAid(), a.getName(), "切换取消支付", 4);
  1016. }
  1017. tOrderTaskMapper.resstPayment(id);
  1018. updateCountByTid(id);
  1019. map.put("desc", "已全部删除");
  1020. }
  1021. return map;
  1022. }
  1023. /**
  1024. * 根据项目编号重新计算订单成本与已付
  1025. * @param id
  1026. */
  1027. private void updateCountByTid(Integer id) {
  1028. List<TTaskMid> list=tTaskMidMapper.selectListByTid(id);
  1029. BigDecimal cost=new BigDecimal(0);
  1030. BigDecimal party=new BigDecimal(0);
  1031. for (TTaskMid t : list) {
  1032. cost=cost.add(t.getCostAmount());
  1033. party=party.add(t.getPartyAmount());
  1034. }
  1035. tOrderMidMapper.updateCostAmount(id, cost,party);
  1036. }
  1037. @Override
  1038. public Object checkNode(Integer id) {
  1039. Integer i=0;
  1040. String desc="您已有%s,确定则一并删除。";
  1041. StringBuffer src=new StringBuffer();
  1042. Map<String, Object> map=new HashedMap<String, Object>();
  1043. List<outOrderPayment> list3=tOrderPaymentMapper.selectList(null, id, null);
  1044. if (!list3.isEmpty()) {
  1045. src.append("付款记录");
  1046. i++;
  1047. }
  1048. if (i!=0) {
  1049. desc=String.format(desc, src);
  1050. map.put("desc", desc);
  1051. }
  1052. map.put("code", i);
  1053. return map;
  1054. }
  1055. }