123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460 |
- package com.idea.oa.apply.controller;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.github.pagehelper.PageInfo;
- import com.rockstar.flow.exception.FlowException;
- import com.idea.oa.apply.model.ApplyUseMoney;
- import com.idea.oa.apply.model.ApplyUseMoneyDetail;
- import com.idea.oa.apply.model.ApplyUseMoneyDetailExample;
- import com.idea.oa.apply.model.inout.AddConfirmResultUseMoney;
- import com.idea.oa.apply.model.inout.ApplyUseMoneyIn;
- import com.idea.oa.apply.service.ApplyUseMoneyDetailService;
- import com.idea.oa.apply.service.ApplyUseMoneyService;
- import com.idea.oa.apply.util.constant.ConstantFlowType;
- import com.idea.oa.costManage.model.ExpenseLedger;
- import com.idea.oa.costManage.service.ExpenseLedgerService;
- import com.idea.oa.flow2.model.*;
- import com.idea.oa.flow2.model.in.FlowMainCcVo;
- import com.idea.oa.flow2.service.FlowMainCcService;
- import com.idea.oa.flow2.service.FlowMainPushService;
- import com.idea.oa.flow2.service.FlowMainService;
- import com.rockstar.common.base.BaseController;
- import com.rockstar.common.domain.AjaxResult;
- import com.rockstar.frame.model.extend.DateTrans;
- import com.rockstar.frame.model.extend.TableSplitResult;
- import com.rockstar.frame.model.extend.Tablepar;
- import com.rockstar.shiro.util.ShiroUtils;
- import com.rockstar.util.UUIDUtils;
- import io.swagger.annotations.Api;
- import org.apache.commons.collections.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.StringUtils;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.math.BigDecimal;
- import java.math.MathContext;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * Created by zt
- */
- @Controller
- @RequestMapping(value = "/ApplyUseMoneyController")
- @Api(value = "申请流程/分表_申请费用报支表")
- public class ApplyUseMoneyController extends BaseController {
- // @Autowired
- // private TaskService taskService;
- // @Autowired
- // private FlowService flowService;
- @Autowired
- private FlowMainCcService flowMainCcService;
- //主表
- @Autowired
- private ApplyUseMoneyService modelService;
- // @Autowired
- // private FlowMainLogService flowMainLogService;
- @Autowired
- private ApplyUseMoneyDetailService applyUseMoneyDetailService;
- @Autowired
- private FlowMainService flowMainService;
- @Autowired
- private FlowMainPushService flowMainPushService;
- @Autowired
- private ExpenseLedgerService expenseLedgerService;
- // @Autowired
- // private ProActiService proActiService;
- @PostMapping(value = "findApplyUseMoneyListByInfo", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public TableSplitResult findApplyUseMoneyListByInfo(Tablepar tablepar, String name,String startTime,String endTime) {
- PageInfo<Map> page=modelService.findApplyUseMoneyListByInfo(tablepar, name, startTime, endTime);
- TableSplitResult<Map> result=new TableSplitResult<>(page.getPageNum(), page.getTotal(), page.getList());
- return result;
- }
- @PostMapping(value = "findAllApplyUseMoneyListByInfo", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public List<Map> findAllApplyUseMoneyListByInfo(String name,String startTime,String endTime) {
- List<Map> result=modelService.findAllApplyUseMoneyListByInfo(name, startTime, endTime);
- return result;
- }
- /**
- * 添加审核结果
- * 根据不同的状态值confirmResult判断是 1:审核通过,转下一步;2:退回发起人;3:退回上节点;4:结束流程;
- *
- * @param addConfirmResult
- * @return
- */
- @PostMapping(value = "AddConfirmResultUseMoney", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- @Transactional
- public AjaxResult AddConfirmResultUseMoney(AddConfirmResultUseMoney addConfirmResult) throws FlowException {
- System.out.println("AddConfirmResultUseMoney");
- System.out.println(addConfirmResult);
- if (addConfirmResult.getConfirmResult() == null) {
- return result(-1);
- }
- String deploymentid = ConstantFlowType.USE_MONEY_DEPLOYMENTID;
- String constantFlowType = ConstantFlowType.USE_MONEY;
- FlowMainPush flowMainPush = flowMainPushService.selectByPrimaryKey(addConfirmResult.getFlowMainPushId());
- String isOkString=null;
- {//进行审核判断
- ApplyUseMoneyDetailExample example = new ApplyUseMoneyDetailExample();
- example.createCriteria().andUseMoneyIdEqualTo(flowMainPush.getFormId());
- List<ApplyUseMoneyDetail> applyUseMoneyDetails = applyUseMoneyDetailService.selectByExample(example);
- // 付款总金额
- BigDecimal feeMoneyTotal = new BigDecimal(0);
- for (ApplyUseMoneyDetail applyUseMoneyDetail : applyUseMoneyDetails) {
- BigDecimal feeMoney = applyUseMoneyDetail.getFeeMoney() == null ? new BigDecimal(0) : applyUseMoneyDetail.getFeeMoney();
- feeMoneyTotal = feeMoneyTotal.add(feeMoney, MathContext.DECIMAL32);
- }
- double feeMoneyTotalDouble = feeMoneyTotal.doubleValue();
- //添加判断条件
- HashMap<String, Object> conditionMap = new HashMap<>();
- conditionMap.put("billMoney", feeMoneyTotalDouble);
- isOkString = flowMainService.doConfirmResult(addConfirmResult, deploymentid, constantFlowType, flowMainPush, conditionMap);
- if (!"ok_end".equals(isOkString) && !"ok_noEnd".equals(isOkString)) {
- return AjaxResult.error(isOkString);
- }
- }
- Boolean isEnd = false;//是否结束
- Boolean isAgree = false;//是否同意
- if (addConfirmResult.getConfirmResult().equals("4")) {//结束流程
- isEnd = true;
- isAgree = false;
- } else if (addConfirmResult.getConfirmResult().equals("1")) {//1:审核通过,转下一步
- if ("ok_end".equals(isOkString)) {
- isEnd = true;
- isAgree = true;
- }
- }
- //添加业务信息
- if (!StringUtils.isEmpty(addConfirmResult.getMakeNum())||!StringUtils.isEmpty(addConfirmResult.getPayType())||!StringUtils.isEmpty(addConfirmResult.getPayRemark())||addConfirmResult.getPayTime()!=null) {
- ApplyUseMoney updateApplyUseMoney = new ApplyUseMoney();
- updateApplyUseMoney.setId(flowMainPush.getFormId());
- updateApplyUseMoney.setMakeNum(addConfirmResult.getMakeNum());
- updateApplyUseMoney.setMakeDate(addConfirmResult.getMakeDate());
- updateApplyUseMoney.setPayType(addConfirmResult.getPayType());
- updateApplyUseMoney.setPayTime(addConfirmResult.getPayTime());
- updateApplyUseMoney.setPayRemark(addConfirmResult.getPayRemark());
- updateApplyUseMoney.setUpdatedAt(new Date());
- updateApplyUseMoney.setUpdatedBy(ShiroUtils.getUser().getId());
- modelService.updateByPrimaryKeySelective(updateApplyUseMoney);
- }
- //增加判断,费用明细能够进行修改(目前只允许修改类型fee_type费用类型)
- if (!StringUtils.isEmpty(addConfirmResult.getApplyUseMoneyDetailListString())) {
- JSONArray jsonArray = JSONArray.parseArray(addConfirmResult.getApplyUseMoneyDetailListString());
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject object = jsonArray.getJSONObject(i);
- ApplyUseMoneyDetail applyUseMoneyDetail = JSONObject.parseObject(object.toJSONString(), ApplyUseMoneyDetail.class);// 将string类型直接封装成对象
- if (StringUtils.isEmpty(applyUseMoneyDetail.getId())) {
- continue;
- }
- ApplyUseMoneyDetail updateapplyUseMoneyDetail = new ApplyUseMoneyDetail();
- updateapplyUseMoneyDetail.setId(applyUseMoneyDetail.getId());
- updateapplyUseMoneyDetail.setFeeType(applyUseMoneyDetail.getFeeType());
- applyUseMoneyDetail.setUpdatedBy(ShiroUtils.getUser().getId());
- applyUseMoneyDetail.setUpdatedAt(new Date());
- applyUseMoneyDetailService.updateByPrimaryKeySelective(updateapplyUseMoneyDetail);
- }
- }
- //添加业务信息(将请假信息中的修改掉,剩余年假,剩余调休,冻结年假,冻结调休都修改掉)
- if (isEnd&&isAgree) {
- // 添加费用报支台账
- List<ExpenseLedger> expenseLedgers = modelService.getUserMoneyByMoneyId(flowMainPush.getFormId());
- if(CollectionUtils.isNotEmpty(expenseLedgers)){
- for(ExpenseLedger expenseLedger:expenseLedgers){
- expenseLedger.setId(UUIDUtils.middleUUID());
- expenseLedger.setSource("2");
- expenseLedgerService.insert(expenseLedger);
- }
- }
- }
- return result(1);
- }
- /**
- * 发起付款申请流程
- *
- * @param record
- * @return
- */
- @PostMapping(value = "addApplyUseMoney", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- @Transactional
- public AjaxResult addApplyUseMoney(ApplyUseMoneyIn record) throws FlowException {
- System.out.println("addApplyUseMoney");
- System.out.println(record);
- if (false) {
- return AjaxResult.error("这是一个错误测试信息");
- }
- return myaddApplyPayment(record, null);
- }
- /**
- * 申请人重新发起申请
- *
- * @param record
- * @return
- */
- @PostMapping(value = "addApplyUseMoneyAgain", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- @Transactional
- public AjaxResult addApplyUseMoneyAgain(ApplyUseMoneyIn record) throws FlowException {
- System.out.println("addApplyUseMoneyAgain");
- if (StringUtils.isEmpty(record.getFlowMainId())) {
- return AjaxResult.error("没有传入flowMainId的值");
- }
- System.out.println(record);
- // record.setRemark("重新发起申请[" + record.getFlowMainId() + "],");
- {//修改重新发起前的表状态
- FlowMain flowMain1 = new FlowMain();
- flowMain1.setId(record.getFlowMainId());
- flowMain1.setReturnStatus(1);//0/null无状态,1已撤回并且已重新发起
- flowMain1.setUpdatedAt(new Date());
- flowMain1.setUpdatedBy(ShiroUtils.getUser().getId());
- flowMainService.updateByPrimaryKeySelective(flowMain1);
- }
- return myaddApplyPayment(record, "重新发起申请[" + record.getFlowMainId() + "],");
- }
- /**
- * 根据推送表的FlowMainPushId获取信息
- *
- * @param flowMainPushId
- * @return
- */
- @PostMapping(value = "getInfoByFlowMainPushId", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public ApplyUseMoneyIn getInfoByFlowMainPushId(String flowMainPushId) {
- ApplyUseMoneyIn myApplyUseMoneyIn = modelService.getInfoByFlowMainPushId(flowMainPushId);
- if (myApplyUseMoneyIn != null) {
- {//获取抄送人
- // FlowMainCcExample example = new FlowMainCcExample();
- // example.createCriteria().andFlowMainIdEqualTo(myApplyUseMoneyIn.getFlowMainId());
- // List<FlowMainCc> flowMainCcList = flowMainCcService.selectByExample(example);
- List<FlowMainCcVo> flowMainCcList = flowMainCcService.selectVoByFlowMainId(myApplyUseMoneyIn.getFlowMainId());
- // HashSet<String> set = new HashSet<>();
- // for (FlowMainCc flowMainCc : flowMainCcList) {
- // set.add(flowMainCc.getCcUser());
- // }
- // StringBuilder stringBuilder = new StringBuilder();
- // if (!set.isEmpty()) {
- // for (String s : set) {
- // stringBuilder.append(s + ",");
- // }
- // }
- // myApplyUseMoneyIn.setCcList(stringBuilder.toString());
- myApplyUseMoneyIn.setFlowMainCcList(flowMainCcList);
- }
- // 付款总金额
- BigDecimal feeMoneyTotal = new BigDecimal(0);
- {//获取apply_use_money_detail数据
- ApplyUseMoneyDetailExample example = new ApplyUseMoneyDetailExample();
- example.createCriteria().andUseMoneyIdEqualTo(myApplyUseMoneyIn.getId());
- List<ApplyUseMoneyDetail> applyUseMoneyDetails = applyUseMoneyDetailService.selectByExample(example);
- for (ApplyUseMoneyDetail applyUseMoneyDetail : applyUseMoneyDetails) {
- BigDecimal feeMoney = applyUseMoneyDetail.getFeeMoney();
- feeMoneyTotal = feeMoneyTotal.add(feeMoney, MathContext.DECIMAL32);
- }
- myApplyUseMoneyIn.setFeeMoneyTotal(feeMoneyTotal.doubleValue());
- myApplyUseMoneyIn.setApplyUseMoneyDetailList(applyUseMoneyDetails);
- }
- }
- return myApplyUseMoneyIn;
- }
- /**
- * 根据主表的FlowMainId获取信息
- *
- * @param flowMainId
- * @return
- */
- @PostMapping(value = "getInfoByFlowMainId", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public ApplyUseMoneyIn getInfoByFlowMainId(String flowMainId) {
- ApplyUseMoneyIn myApplyUseMoneyIn = modelService.getInfoByFlowMainId(flowMainId);
- if (myApplyUseMoneyIn != null) {
- {//获取抄送人
- // FlowMainCcExample example = new FlowMainCcExample();
- // example.createCriteria().andFlowMainIdEqualTo(myApplyUseMoneyIn.getFlowMainId());
- // List<FlowMainCc> flowMainCcList = flowMainCcService.selectByExample(example);
- List<FlowMainCcVo> flowMainCcList = flowMainCcService.selectVoByFlowMainId(myApplyUseMoneyIn.getFlowMainId());
- // HashSet<String> set = new HashSet<>();
- // for (FlowMainCc flowMainCc : flowMainCcList) {
- // set.add(flowMainCc.getCcUser());
- // }
- // StringBuilder stringBuilder = new StringBuilder();
- // if (!set.isEmpty()) {
- // for (String s : set) {
- // stringBuilder.append(s + ",");
- // }
- // }
- // myApplyUseMoneyIn.setCcList(stringBuilder.toString());
- myApplyUseMoneyIn.setFlowMainCcList(flowMainCcList);
- }
- {//获取apply_use_money_detail数据
- ApplyUseMoneyDetailExample example = new ApplyUseMoneyDetailExample();
- example.createCriteria().andUseMoneyIdEqualTo(myApplyUseMoneyIn.getId());
- List<ApplyUseMoneyDetail> applyUseMoneyDetails = applyUseMoneyDetailService.selectByExample(example);
- myApplyUseMoneyIn.setApplyUseMoneyDetailList(applyUseMoneyDetails);
- }
- }
- return myApplyUseMoneyIn;
- }
- // public static void main(String[] args) {
- //
- // String applyUseMoneyDetailListString = "[{\"fileDataIds\":\"\",\"feeMoney\":\"1请3惹太呀u8i9o0\",\"feeType\":\"差旅费\"}]";
- // JSONArray jsonArray = JSONArray.parseArray(applyUseMoneyDetailListString);
- //
- // for (int i = 0; i < jsonArray.size(); i++) {
- // JSONObject object = jsonArray.getJSONObject(i);
- // ApplyUseMoneyDetail applyUseMoneyDetail = JSONObject.parseObject(object.toJSONString(), ApplyUseMoneyDetail.class);// 将string类型直接封装成对象
- // System.out.println(applyUseMoneyDetail);
- // }
- //
- // // BigDecimal feeMoneyTotal=new BigDecimal(1.1);
- //// System.out.println(feeMoneyTotal.toString());
- //// BigDecimal bigDecimal = new BigDecimal(2.3);
- //// System.out.println(bigDecimal.toString());
- //// feeMoneyTotal=feeMoneyTotal.add(bigDecimal, MathContext.DECIMAL32);
- //// System.out.println(feeMoneyTotal.doubleValue());
- ////
- //// HashMap<String, Object> feeMoneyTotalMap = new HashMap<>();
- //// feeMoneyTotalMap.put("billMoney",feeMoneyTotal.doubleValue());
- //// Object conditionMapString = JSONObject.toJSON(feeMoneyTotalMap);
- //// System.out.println(conditionMapString);
- //// Map<String, Object> Mapmaps=(Map) JSON.parse(conditionMapString.toString());
- //// System.out.println(Mapmaps);
- // }
- /**
- * 发起付款申请流程
- *
- * @param record
- * @return
- */
- public AjaxResult myaddApplyPayment(ApplyUseMoneyIn record, String addSystemRemark) throws FlowException {
- if (StringUtils.isEmpty(record.getApplyUseMoneyDetailListString())) {
- return AjaxResult.error("没有获取到金额信息,请重新确认");
- }
- // 存入付款申请
- // record
- // 付款总金额
- BigDecimal feeMoneyTotal = new BigDecimal(0);
- {
- record.setUpdatedAt(new Date());
- record.setCreatedAt(record.getUpdatedAt());
- record.setCreatedBy(ShiroUtils.getUser().getId());
- record.setUpdatedBy(record.getCreatedBy());
- record.setStatus(0);
- modelService.insert(record);
- String applyUseMoneyDetailListString = record.getApplyUseMoneyDetailListString();
- JSONArray jsonArray = JSONArray.parseArray(applyUseMoneyDetailListString);
- for (int i = 0; i < jsonArray.size(); i++) {
- JSONObject object = jsonArray.getJSONObject(i);
- ApplyUseMoneyDetail applyUseMoneyDetail = JSONObject.parseObject(object.toJSONString(), ApplyUseMoneyDetail.class);// 将string类型直接封装成对象
- applyUseMoneyDetail.setUseMoneyId(record.getId());
- applyUseMoneyDetail.setUpdatedAt(new Date());
- applyUseMoneyDetail.setCreatedAt(applyUseMoneyDetail.getUpdatedAt());
- applyUseMoneyDetail.setCreatedBy(ShiroUtils.getUser().getId());
- applyUseMoneyDetail.setUpdatedBy(applyUseMoneyDetail.getCreatedBy());
- applyUseMoneyDetail.setStatus(0);
- applyUseMoneyDetailService.insert(applyUseMoneyDetail);
- BigDecimal feeMoney = applyUseMoneyDetail.getFeeMoney() == null ? new BigDecimal(0) : applyUseMoneyDetail.getFeeMoney();
- feeMoneyTotal = feeMoneyTotal.add(feeMoney, MathContext.DECIMAL32);
- }
- }
- double feeMoneyTotalDouble = feeMoneyTotal.doubleValue();
- HashMap<String, Object> feeMoneyTotalMap = new HashMap<>();
- feeMoneyTotalMap.put("billMoney", feeMoneyTotalDouble);
- String applyTheme = "" + ShiroUtils.getUser().getTruename() + "的报支申请单";
- AjaxResult ajaxResult = flowMainService.doFlowMain(applyTheme, record.getId(), addSystemRemark, record.getCcList(), ConstantFlowType.USE_MONEY_PROCESSDEFINE, ConstantFlowType.USE_MONEY_DEPLOYMENTID, feeMoneyTotalMap, ConstantFlowType.USE_MONEY_NAME, ConstantFlowType.USE_MONEY,ShiroUtils.getUser());
- if (ajaxResult.get("code").equals(1688)) {
- return AjaxResult.success();
- }
- return ajaxResult;
- }
- @PostMapping(value = "list", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public Object list(Tablepar tablepar, ApplyUseMoney model, DateTrans dt) {
- PageInfo<ApplyUseMoney> page = modelService.list(tablepar, model, dt);
- TableSplitResult<ApplyUseMoney> result = new TableSplitResult<ApplyUseMoney>(page.getPageNum(), page.getTotal(), page.getList());
- return result;
- }
- @PostMapping(value = "listAll", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public Object listAll(ApplyUseMoney model, DateTrans dt) {
- return modelService.listAll(model, dt);
- }
- @PostMapping(value = "add", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public AjaxResult add(ApplyUseMoney record) {
- record.setCreatedAt(new Date());
- int result = modelService.insert(record);
- return result(result);
- }
- @PostMapping(value = "remove/{id}", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public AjaxResult remove(@PathVariable("id") String id) {
- int result = modelService.deleteByPrimaryKey(id);
- return result(result);
- }
- @PostMapping(value = "edit", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public AjaxResult editSave(ApplyUseMoney model) {
- int result = modelService.updateByPrimaryKeySelective(model);
- return result(result);
- }
- @PostMapping(value = "getById", produces = {"application/json;charset=UTF-8"})
- @ResponseBody
- public ApplyUseMoney getById(String id) {
- return modelService.selectByPrimaryKey(id);
- }
- }
|