ThirdPartyCompanyServiceImpl.java 41 KB

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