一、这周完成的功能:
a.派车单登记
b.派车单审核
c.财务收款
d.单车月结算
二、核心源码:
1、Mapper配置文件
<mapper namespace="DispatchlistMapper">
<resultMap type="com.hp.bean.Dispatchlist" id="baseResultMap">
<id column="disId" property="disId"/>
<result column="outDate" property="outDate"/>
<result column="outTime" property="outTime"/>
<result column="driPhone" property="driPhone"/>
<result column="sartAddr" property="sartAddr"/>
<result column="paymethod" property="paymethod"/>
<result column="category" property="category"/>
<result column="status" property="status"/>
<result column="disRemark" property="disRemark"/>
<association property="customer" column="cstId" javaType="com.hp.bean.Customer">
<id column="cstId" property="cstId"/>
<result column="cstName" property="cstName"/>
<result column="cstContact" property="cstContact"/>
<result column="cstPhone" property="cstPhone"/>
</association>
<association property="salesman" column="salId" javaType="com.hp.bean.Salesman">
<id column="salId" property="salId"/>
<result column="salName" property="salName"/>
</association>
<association property="carinfo" column="salId" javaType="com.hp.bean.Carinfo">
<id column="carId" property="carId"/>
<result column="carNum" property="carNum"/>
</association>
<association property="driver" column="salId" javaType="com.hp.bean.Driver">
<id column="driId" property="driId"/>
<result column="driName" property="driName"/>
</association>
<association property="expenses" column="salId" javaType="com.hp.bean.Expenses">
<id column="expId" property="expId"/>
<result column="carRental" property="carRental"/>
<result column="discount" property="discount"/>
<result column="actualAmount" property="actualAmount"/>
</association>
</resultMap>
<insert id="addDisp" parameterType="com.hp.bean.Dispatchlist">
insert into dispatchlist(disId,cstId,outDate,outTime,sartAddr,
carId,driId,salId,paymethod,category,status,disRemark)
values(#{disId},#{customer.cstId},#{outDate},#{outTime},#{sartAddr},
#{carinfo.carId},#{driver.driId},#{salesman.salId},#{paymethod},
#{category},#{status},#{disRemark})
</insert>
<select id="findDispByStatus" resultMap="baseResultMap" parameterType="string">
select d.*,c.cstName,c.cstContact,c.cstPhone,car.carNum,dr.driName,
s.salName,e.actualAmount,e.discount,e.carRental from dispatchlist d, customer c,
carinfo car, driver dr, expenses e, salesman s where d.cstId = c.cstId
and d.carId = car.carId and d.driId = dr.driId and d.salId = s.salId
and d.disId = e.disId and d.status = #{status}
</select>
<select id="findDispById" resultMap="baseResultMap" parameterType="string">
select d.*,c.cstName,c.cstContact,c.cstPhone,car.carNum,dr.driName,
s.salName,e.actualAmount,e.discount,e.carRental,e.expId from dispatchlist d, customer c,
carinfo car, driver dr, expenses e, salesman s where d.cstId = c.cstId
and d.carId = car.carId and d.driId = dr.driId and d.salId = s.salId
and d.disId = e.disId and d.disId = #{disId}
</select>
<update id="updDispStatus" parameterType="com.hp.bean.Dispatchlist">
update dispatchlist set status = #{status} where disid = #{disId}
</update>
<select id="getAllSum" resultType="com.hp.bean.Settlement" parameterType="com.hp.bean.Condition">
select sum(e.actualAmount) totalBusi,sum(e.oilExp) oilTotal,sum(e.bridgeExp) bridgeTotal,
sum(e.stopExp) stopTotal,sum(e.repairExp) repairTotal,sum(e.tyreExp) tyreTotal,sum(e.subsidy) subsubsidy,
sum(e.mileage) totalKilom from dispatchlist d, expenses e
where d.disId = e.disId and carId = #{carId} and d.status = #{status}
and date_format(d.outDate,‘%Y-%m‘) = #{time}
</select>
</mapper>
<mapper namespace="ExpensesMapper">
<insert id="addExp" parameterType="com.hp.bean.Dispatchlist">
insert into expenses(carRental,discount,actualAmount,disId)
values(#{expenses.carRental},#{expenses.discount},#{expenses.actualAmount},#{disId})
</insert>
<update id="updExp" parameterType="com.hp.bean.Expenses">
update expenses set oilExp = #{oilExp},bridgeExp = #{bridgeExp},stopExp = #{stopExp},
repairExp = #{repairExp},tyreExp = #{tyreExp},subsidy = #{subsidy},mileage = #{mileage},
expRemark = #{expRemark} where expId = #{expId}
</update>
</mapper>
<mapper namespace="FinanceMapper">
<insert id="addFin" parameterType="com.hp.bean.Finance">
insert into finance(expId,receivable,received,arrears,settlement,disId,collectionDate,finRemark)
values(#{expId},#{receivable},#{received},#{arrears},#{settlement},#{disId},#{collectionDate},#{finRemark})
</insert>
</mapper>
<mapper namespace="SettlementMapper">
<insert id="addSet" parameterType="com.hp.bean.Settlement">
insert into settlement(carId,operation,setyear,setmonth,totalBusi,totalKilom,
salary,oilTotal,bridgeTotal,stopTotal,repairTotal,tyreTotal,subsubsidy,
premium,bonus,profit,finRemark)
values(#{carId},#{operation},#{setyear},#{setmonth},#{totalBusi},#{totalKilom},
#{salary},#{oilTotal},#{bridgeTotal},#{stopTotal},#{repairTotal},#{tyreTotal},
#{subsubsidy},#{premium},#{bonus},#{profit},#{finRemark})
</insert>
<select id="findByTime" parameterType="com.hp.bean.Settlement" resultType="com.hp.bean.Settlement">
select * from settlement s, carinfo c where s.carId = c.carId
<if test="setyear != null and setyear != ‘‘">
and s.setyear = #{setyear}
</if>
<if test="setmonth != null and setmonth != ‘‘">
and s.setmonth = #{setmonth}
</if>
<if test="carId != null and carId != ‘‘">
and s.carId = #{carId}
</if>
</select>
<select id="findByCarid" resultType="com.hp.bean.Settlement">
select * from settlement s, carinfo c where s.carId = c.carId and s.carId = #{carId}
</select>
</mapper>
2、service接口编写
public interface DispatchlistService {
public CollectionBean findAllList();
public Integer addDisp(Dispatchlist dispatchlist);
public List<Dispatchlist> findDispByStatus(String status);
public Dispatchlist findDispById(String disId);
}
public interface ExpensesService {
public Integer updExp(Expenses expenses);
}
public interface SettlementService {
public Integer addSet(Settlement settlement);
public List<Settlement> findByTime(Settlement settlement);
}
public interface FinanceService {
public Integer addExp(Finance finance);
}
3、service实现类编写
@Service("dispatchlistService")
@Transactional
public class DispatchlistServiceImpl implements DispatchlistService{
@Autowired
private BaseDao baseDao;
@Override
public Integer addDisp(Dispatchlist dispatchlist) {
baseDao.insert("DispatchlistMapper.addDisp", dispatchlist);
baseDao.insert("ExpensesMapper.addExp", dispatchlist);
return null;
}
@SuppressWarnings("unchecked")
@Override
public CollectionBean findAllList() {
List<Carinfo> carinfos = (List<Carinfo>) baseDao.findForList("CarinfoMapper.findAllCar", null);
List<Customer> customers = (List<Customer>) baseDao.findForList("CustomerMapper.findAllCustomer", null);
List<Driver> drivers = (List<Driver>) baseDao.findForList("DriverMapper.findAllDriver", null);
List<Salesman> salesmans = (List<Salesman>) baseDao.findForList("SalesmanMapper.findAllSales", null);
return new CollectionBean(carinfos, customers, drivers, salesmans);
}
@Override
public List<Dispatchlist> findDispByStatus(String status) {
return (List<Dispatchlist>) baseDao.findForList("DispatchlistMapper.findDispByStatus", status);
}
@Override
public Dispatchlist findDispById(String disId) {
return (Dispatchlist) baseDao.findForObject("DispatchlistMapper.findDispById", disId);
}
}
@Service("expensesService")
@Transactional
public class ExpensesServiceImpl implements ExpensesService{
@Autowired
private BaseDao baseDao;
@Override
public Integer updExp(Expenses expenses) {
baseDao.update("ExpensesMapper.updExp", expenses);
Dispatchlist d = new Dispatchlist();
d.setStatus("未付款");
d.setDisId(expenses.getDisId());
baseDao.update("DispatchlistMapper.updDispStatus", d);
return null;
}
}
@Service("settlementService")
@Transactional
public class SettlementServiceImpl implements SettlementService{
@Autowired
private BaseDao baseDao;
@Override
public Integer addSet(Settlement settlement) {
// TODO Auto-generated method stub
return (Integer) baseDao.update("SettlementMapper.addSet", settlement);
}
@Override
public List<Settlement> findByTime(Settlement settlement) {
// TODO Auto-generated method stub
return (List<Settlement>) baseDao.findForList("SettlementMapper.findByTime", settlement);
}
}
@Service("financeService")
@Transactional
public class FinanceServiceImpl implements FinanceService{
@Autowired
private BaseDao baseDao;
@Override
public Integer addExp(Finance finance) {
baseDao.update("FinanceMapper.addFin", finance);
if(finance.getArrears() == 0) {
Dispatchlist d = new Dispatchlist();
d.setStatus("已付款");
d.setDisId(finance.getDisId());
baseDao.update("DispatchlistMapper.updDispStatus", d);
}
return null;
}
}
4、controller控制层编写
@Controller
@Scope("prototype")
public class DispatchlistController {
@Autowired
private DispatchlistService dispatchlistService;
@RequestMapping(value = "/findAllObjects",produces = {"application/json;charset=UTF-8"},method = RequestMethod.POST)
@ResponseBody
public String findAllObjects() {
CollectionBean collectionBean = dispatchlistService.findAllList();
return JSONObject.fromObject(collectionBean).toString();
}
@RequestMapping(value = "/addDisp",method = RequestMethod.POST)
@ResponseBody
public String DispatchlistService(Dispatchlist dispatchlist) {
dispatchlistService.addDisp(dispatchlist);
return "adddisp.html";
}
@RequestMapping(value="/toDisp",method = RequestMethod.GET)
public String toDisp(Integer did) {
return "dispatch.html?did="+did;
}
@RequestMapping(value = "/findDispByStatus",produces = {"application/json;charset=UTF-8"},method = RequestMethod.POST)
@ResponseBody
public String findDispByStatus(String status) {
List<Dispatchlist> list = dispatchlistService.findDispByStatus(status);
return JSONArray.fromObject(list).toString();
}
@RequestMapping(value="/toexam")
@ResponseBody
public String toexam(String disId) {
return "examine.html?disId="+disId;
}
@RequestMapping(value = "/findDispById",produces = {"application/json;charset=UTF-8"})
@ResponseBody
public String findById(String disId) {
Dispatchlist dispatchlist = dispatchlistService.findDispById(disId);
return JSONObject.fromObject(dispatchlist).toString();
}
}
@Controller
@Scope("prototype")
public class ExpensesController {
@Autowired
private ExpensesService expensesService;
@RequestMapping(value = "/updExp",method = RequestMethod.POST)
@ResponseBody
public String updExp(Expenses expenses) {
expensesService.updExp(expenses);
return "toDisp?did=1";
}
}
@Controller
@Scope("prototype")
public class SettlementController {
@Autowired
private DispatchlistService dispatchlistService;
@Autowired
private SettlementService settlementService;
@RequestMapping(value = "/getAllSum",produces = {"application/json;charset=UTF-8"})
@ResponseBody
public String getAllSum(Settlement settlement) {
Condition condition = new Condition(settlement.getCarId(),
settlement.getSetyear()+"-"+settlement.getSetmonth());
Settlement settl = dispatchlistService.getAllSum(condition);
return JSONObject.fromObject(settl).toString();
}
@RequestMapping(value = "/addset",method = RequestMethod.POST)
@ResponseBody
public String addset(Settlement settlement) {
List<Settlement> list = settlementService.findByTime(settlement);
if(null != list && list.size() > 0) {
return "该车已结算";
}
settlementService.addSet(settlement);
return "settlement.html";
}
@RequestMapping(value = "/findAllSet", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
@ResponseBody
public String findAllSet(Settlement settlement) {
List<Settlement> list = settlementService.findByTime(settlement);
return JSONArray.fromObject(list).toString();
}
}
@Controller
@Scope("prototype")
public class FinanceController {
@Autowired
private FinanceService financeService;
@RequestMapping(value = "/addfee",method = RequestMethod.POST)
@ResponseBody
public String addfee(Finance finance) {
financeService.addExp(finance);
return "toDisp?did=2";
}
}
三、部分效果图
1、派车单登记
2、派车单审核
3、财务收款
4、单车月结算
四、遇到的问题:
暂无
五、解决办法
暂无
六、燃尽图
原文:https://www.cnblogs.com/tangjc/p/13360899.html